CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
edm::serviceregistry::ServicesManager Class Reference

#include <ServicesManager.h>

Classes

struct  MakerHolder
 

Public Types

typedef std::map< TypeIDBase,
MakerHolder
Type2Maker
 
typedef std::map< TypeIDBase,
boost::shared_ptr
< ServiceWrapperBase > > 
Type2Service
 

Public Member Functions

void connect (ActivityRegistry &iOther)
 causes our ActivityRegistry's signals to be forwarded to iOther More...
 
void connectTo (ActivityRegistry &iOther)
 causes iOther's signals to be forward to us More...
 
void copySlotsFrom (ActivityRegistry &)
 the copy the argument's slots to the our signals More...
 
void copySlotsTo (ActivityRegistry &)
 copy our Service's slots to the argument's signals More...
 
template<typename T >
Tget () const
 
template<typename T >
bool isAvailable () const
 returns true of the particular service is accessible More...
 
template<typename T >
bool put (boost::shared_ptr< ServiceWrapper< T > > iPtr)
 returns false if put fails because a service of this type already exists More...
 
 ServicesManager (std::vector< ParameterSet > &iConfiguration)
 
 ServicesManager (ServiceToken iToken, ServiceLegacy iLegacy, std::vector< ParameterSet > &iConfiguration, bool associate=true)
 
 ~ServicesManager ()
 

Private Member Functions

void createServices ()
 
void fillListOfMakers (std::vector< ParameterSet > &)
 
ServicesManager const & operator= (ServicesManager const &)
 
 ServicesManager (ServicesManager const &)
 

Private Attributes

std::vector< TypeIDBaseactualCreationOrder_
 
boost::shared_ptr
< ServicesManager
associatedManager_
 
ActivityRegistry registry_
 
std::vector< TypeIDBaserequestedCreationOrder_
 
std::auto_ptr< Type2Makertype2Maker_
 
Type2Service type2Service_
 

Detailed Description

Definition at line 42 of file ServicesManager.h.

Member Typedef Documentation

Definition at line 56 of file ServicesManager.h.

Definition at line 55 of file ServicesManager.h.

Constructor & Destructor Documentation

ServicesManager::ServicesManager ( std::vector< ParameterSet > &  iConfiguration)

Definition at line 69 of file ServicesManager.cc.

References createServices(), and fillListOfMakers().

69  :
70  type2Maker_(new Type2Maker) {
71  //First create the list of makers
72  fillListOfMakers(iConfiguration);
73 
75  }
void fillListOfMakers(std::vector< ParameterSet > &)
std::map< TypeIDBase, MakerHolder > Type2Maker
std::auto_ptr< Type2Maker > type2Maker_
ServicesManager::ServicesManager ( ServiceToken  iToken,
ServiceLegacy  iLegacy,
std::vector< ParameterSet > &  iConfiguration,
bool  associate = true 
)

Takes the services described by iToken and places them into the manager. Conflicts over Services provided by both the iToken and iConfiguration are resolved based on the value of iLegacy

Definition at line 77 of file ServicesManager.cc.

References associatedManager_, edm::errors::Configuration, edm::ActivityRegistry::copySlotsFrom(), createServices(), edm::hlt::Exception, fillListOfMakers(), reco::helper::VirtualJetProducerHelper::intersection(), edm::serviceregistry::kConfigurationOverrides, edm::serviceregistry::kOverlapIsError, edm::serviceregistry::kTokenOverrides, edm::ServiceToken::manager_, registry_, type2Maker_, type2Service_, and edm::typeDemangle().

80  :
81  associatedManager_(associate ? iToken.manager_ : boost::shared_ptr<ServicesManager>()),
82  type2Maker_(new Type2Maker) {
83  fillListOfMakers(iConfiguration);
84 
85  //find overlaps between services in iToken and iConfiguration
86  typedef std::set< TypeIDBase> TypeSet;
87  TypeSet configTypes;
88  for(Type2Maker::iterator itType = type2Maker_->begin(), itTypeEnd = type2Maker_->end();
89  itType != itTypeEnd;
90  ++itType) {
91  configTypes.insert(itType->first);
92  }
93 
94  TypeSet tokenTypes;
95  if(0 != iToken.manager_.get()) {
96  for(Type2Service::iterator itType = iToken.manager_->type2Service_.begin(),
97  itTypeEnd = iToken.manager_->type2Service_.end();
98  itType != itTypeEnd;
99  ++itType) {
100  tokenTypes.insert(itType->first);
101  }
102 
103  typedef std::set<TypeIDBase> IntersectionType;
104  IntersectionType intersection;
105  std::set_intersection(configTypes.begin(), configTypes.end(),
106  tokenTypes.begin(), tokenTypes.end(),
107  inserter(intersection, intersection.end()));
108 
109  switch(iLegacy) {
110  case kOverlapIsError :
111  if(!intersection.empty()) {
112  throw Exception(errors::Configuration, "Service")
113  << "the Service " << (*type2Maker_).find(*(intersection.begin()))->second.pset_->getParameter<std::string>("@service_type")
114  << " already has an instance of that type of Service";
115  } else {
116  //get all the services from Token
117  type2Service_ = iToken.manager_->type2Service_;
118  }
119  break;
120  case kTokenOverrides :
121  //get all the services from Token
122  type2Service_ = iToken.manager_->type2Service_;
123 
124  //remove from type2Maker the overlapping services so we never try to make them
125  for(IntersectionType::iterator itType = intersection.begin(), itTypeEnd = intersection.end();
126  itType != itTypeEnd;
127  ++itType) {
128  Type2Maker::iterator itFound = type2Maker_->find(*itType);
129  //HLT needs it such that even if a service isn't created we store its PSet if needed
130  if(itFound->second.maker_->saveConfiguration()) {
131  itFound->second.pset_->addUntrackedParameter("@save_config", true);
132  }
133  type2Maker_->erase(itFound);
134  }
135  break;
137  //get all the services from the Configuration, except process wide services
138  type2Service_ = iToken.manager_->type2Service_;
139 
140  //now remove the ones we do not want
141  for(IntersectionType::iterator itType = intersection.begin(), itTypeEnd = intersection.end();
142  itType != itTypeEnd;
143  ++itType) {
144  Type2Maker::iterator itFound = type2Maker_->find(*itType);
145  if(itFound->second.maker_->processWideService()) {
146  // This is a process wide service, so the token overrides the configuration.
147  //HLT needs it such that even if a service isn't created we store its PSet if needed
148  if(itFound->second.maker_->saveConfiguration()) {
149  itFound->second.pset_->addUntrackedParameter("@save_config", true);
150  }
151  std::string type;
152  typeDemangle(itType->name(), type);
153  LogInfo("Configuration") << "Warning: You have reconfigured service\n"
154  << "'" << type << "' in a subprocess.\n"
155  << "This service has already been configured.\n"
156  << "This particular service may not be reconfigured in a subprocess.\n"
157  << "The reconfiguration will be ignored.\n";
158  type2Maker_->erase(itFound);
159  } else {
160  // This is not a process wide service, so the configuration overrides the token.
161  type2Service_.erase(type2Service_.find(*itType));
162  }
163  }
164  break;
165  }
166  //make sure our signals are propagated to our 'inherited' Services
167  if (associate) registry_.copySlotsFrom(associatedManager_->registry_);
168  }
169  createServices();
170  }
type
Definition: HCALResponse.h:22
void fillListOfMakers(std::vector< ParameterSet > &)
std::map< TypeIDBase, MakerHolder > Type2Maker
void copySlotsFrom(ActivityRegistry &iOther)
std::auto_ptr< Type2Maker > type2Maker_
void typeDemangle(char const *mangledName, std::string &demangledName)
boost::shared_ptr< ServicesManager > associatedManager_
ServicesManager::~ServicesManager ( )

Definition at line 176 of file ServicesManager.cc.

References actualCreationOrder_, and type2Service_.

176  {
177  // Force the Service destructors to execute in the reverse order of construction.
178  // Note that services passed in by a token are not included in this loop and
179  // do not get destroyed until the ServicesManager object that created them is destroyed
180  // which occurs after the body of this destructor is executed (the correct order).
181  // Services directly passed in by a put and not created in the constructor
182  // may or not be detroyed in the desired order because this class does not control
183  // their creation (as I'm writing this comment everything in a standard cmsRun
184  // executable is destroyed in the desired order).
185  for(std::vector<TypeIDBase>::const_reverse_iterator idIter = actualCreationOrder_.rbegin(),
186  idEnd = actualCreationOrder_.rend();
187  idIter != idEnd;
188  ++idIter) {
189 
190  Type2Service::iterator itService = type2Service_.find(*idIter);
191 
192  if(itService != type2Service_.end()) {
193 
194  // This will cause the Service's destruction if
195  // there are no other shared pointers around
196  itService->second.reset();
197  }
198  }
199  }
std::vector< TypeIDBase > actualCreationOrder_
edm::serviceregistry::ServicesManager::ServicesManager ( ServicesManager const &  )
private

Member Function Documentation

void ServicesManager::connect ( ActivityRegistry iOther)

causes our ActivityRegistry's signals to be forwarded to iOther

Definition at line 216 of file ServicesManager.cc.

References edm::ActivityRegistry::connect(), and registry_.

Referenced by Vispa.Gui.ZoomableScrollArea.ZoomableScrollArea::__init__(), Vispa.Views.PropertyView.BooleanProperty::__init__(), Vispa.Gui.FindDialog.FindDialog::_addScript(), Vispa.Gui.FindDialog.FindDialog::_addStringProperty(), Vispa.Main.Application.Application::_connectSignals(), Vispa.Plugins.ConfigEditor.CodeTableView.CodeTableView::_createItem(), Vispa.Gui.BoxContentDialog.BoxContentDialog::addButton(), Vispa.Gui.ToolBoxContainer.ToolBoxContainer::addWidget(), Vispa.Views.PropertyView.PropertyView::append(), Vispa.Views.PropertyView.PropertyView::appendAddRow(), Vispa.Main.Application.Application::createAction(), Vispa.Views.PropertyView.TextEditWithButtonProperty::createButton(), Vispa.Views.LineDecayView.LineDecayView::createLineDecayContainer(), Vispa.Views.PropertyView.TextEditWithButtonProperty::createLineEdit(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.PropertyView.TextEditWithButtonProperty::createTextEdit(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::filterDialog(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Gui.PortWidget.PortWidget::mouseMoveEvent(), Vispa.Views.PropertyView.BooleanProperty::setChecked(), Vispa.Main.SplitterTab.SplitterTab::setController(), Vispa.Plugins.Browser.BrowserTab.BrowserTab::setController(), Vispa.Views.PropertyView.BooleanProperty::setReadOnly(), Vispa.Views.PropertyView.DropDownProperty::setReadOnly(), Vispa.Views.PropertyView.TextEditWithButtonProperty::setReadOnly(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::setTab(), Vispa.Views.PropertyView.IntegerProperty::setValue(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::switchCenterView(), Vispa.Plugins.EdmBrowser.EdmBrowserTabController.EdmBrowserTabController::updateViewMenu(), and Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController::updateViewMenu().

216  {
217  registry_.connect(iOther);
218  }
void connect(ActivityRegistry &iOther)
forwards our signals to slots connected to iOther
void ServicesManager::connectTo ( ActivityRegistry iOther)

causes iOther's signals to be forward to us

Definition at line 221 of file ServicesManager.cc.

References edm::ActivityRegistry::connect(), and registry_.

221  {
222  iOther.connect(registry_);
223  }
void ServicesManager::copySlotsFrom ( ActivityRegistry iOther)

the copy the argument's slots to the our signals

Definition at line 226 of file ServicesManager.cc.

References edm::ActivityRegistry::copySlotsFrom(), and registry_.

226  {
227  registry_.copySlotsFrom(iOther);
228  }
void copySlotsFrom(ActivityRegistry &iOther)
void ServicesManager::copySlotsTo ( ActivityRegistry iOther)

copy our Service's slots to the argument's signals

Definition at line 231 of file ServicesManager.cc.

References edm::ActivityRegistry::copySlotsFrom(), and registry_.

231  {
232  iOther.copySlotsFrom(registry_);
233  }
void ServicesManager::createServices ( )
private

Definition at line 272 of file ServicesManager.cc.

References cms::Exception::addContext(), edm::convertException::badAllocToEDM(), trackerHits::c, edm::convertException::charPtrToEDM(), SurfaceDeformationFactory::create(), alignCSCRings::e, cppFunctionSkipper::exception, reco::get(), cmsPerfStripChart::operate(), requestedCreationOrder_, alignCSCRings::s, edm::convertException::stdToEDM(), edm::convertException::stringToEDM(), type2Maker_, edm::convertException::unknownToEDM(), and edm::ConfigurationDescriptions::validate().

Referenced by ServicesManager().

272  {
273 
274  //create a shared_ptr of 'this' that will not delete us
275  boost::shared_ptr<ServicesManager> shareThis(this, NoOp());
276 
277  ServiceToken token(shareThis);
278 
279  //Now make our services to ones obtained via ServiceRegistry
280  // when this goes out of scope, it will revert back to the previous Service set
282 
283  //Now, make each Service. If a service depends on a service that has yet to be
284  // created, that other service will automatically be made
285 
286  for(std::vector<TypeIDBase>::const_iterator idIter = requestedCreationOrder_.begin(),
287  idEnd = requestedCreationOrder_.end();
288  idIter != idEnd;
289  ++idIter) {
290  Type2Maker::iterator itMaker = type2Maker_->find(*idIter);
291 
292  // Check to make sure this maker is still there. They are deleted
293  // sometimes and that is OK.
294  if(itMaker != type2Maker_->end()) {
295 
296  std::string serviceType = itMaker->second.pset_->getParameter<std::string>("@service_type");
297  std::auto_ptr<ParameterSetDescriptionFillerBase> filler(
299  ConfigurationDescriptions descriptions(filler->baseType());
300  filler->fill(descriptions);
301 
302  try {
303  try {
304  descriptions.validate(*(itMaker->second.pset_), serviceType);
305  }
306  catch (cms::Exception& e) { throw; }
307  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
308  catch (std::exception& e) { convertException::stdToEDM(e); }
309  catch(std::string& s) { convertException::stringToEDM(s); }
310  catch(char const* c) { convertException::charPtrToEDM(c); }
311  catch (...) { convertException::unknownToEDM(); }
312  }
313  catch (cms::Exception & iException) {
314  std::ostringstream ost;
315  ost << "Validating configuration of service of type " << serviceType;
316  iException.addContext(ost.str());
317  throw;
318  }
319  try {
320  try {
321  // This creates the service
322  itMaker->second.add(*this);
323  }
324  catch (cms::Exception& e) { throw; }
325  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
326  catch (std::exception& e) { convertException::stdToEDM(e); }
327  catch(std::string& s) { convertException::stringToEDM(s); }
328  catch(char const* c) { convertException::charPtrToEDM(c); }
329  catch (...) { convertException::unknownToEDM(); }
330  }
331  catch (cms::Exception & iException) {
332  std::ostringstream ost;
333  ost << "Constructing service of type " << serviceType;
334  iException.addContext(ost.str());
335  throw;
336  }
337  }
338  }
339  //No longer need the makers
340  type2Maker_.reset();
341  }
std::auto_ptr< Type2Maker > type2Maker_
void stdToEDM(std::exception const &e)
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
std::vector< TypeIDBase > requestedCreationOrder_
void addContext(std::string const &context)
Definition: Exception.cc:227
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:56
void ServicesManager::fillListOfMakers ( std::vector< ParameterSet > &  iConfiguration)
private

Definition at line 236 of file ServicesManager.cc.

References newFWLiteAna::base, edm::errors::Configuration, SurfaceDeformationFactory::create(), edm::hlt::Exception, reco::get(), registry_, requestedCreationOrder_, and type2Maker_.

Referenced by ServicesManager().

236  {
237  for(std::vector<ParameterSet>::iterator itParam = iConfiguration.begin(),
238  itParamEnd = iConfiguration.end();
239  itParam != itParamEnd;
240  ++itParam) {
241  boost::shared_ptr<ServiceMakerBase> base(ServicePluginFactory::get()->create(itParam->getParameter<std::string>("@service_type")));
242 
243  if(0 == base.get()) {
244  throw Exception(errors::Configuration, "Service")
245  << "could not find a service named "
246  << itParam->getParameter<std::string>("@service_type")
247  << ". Please check spelling.";
248  }
249  Type2Maker::iterator itFound = type2Maker_->find(TypeIDBase(base->serviceType()));
250  if(itFound != type2Maker_->end()) {
251  throw Exception(errors::Configuration, "Service")
252  << " the service " << itParam->getParameter<std::string>("@service_type")
253  << " provides the same service as "
254  << itFound->second.pset_->getParameter<std::string>("@service_type")
255  << "\n Please reconfigure job to only use one of these services.";
256  }
257  type2Maker_->insert(Type2Maker::value_type(TypeIDBase(base->serviceType()),
258  MakerHolder(base,
259  *itParam,
260  registry_)));
261  requestedCreationOrder_.push_back(TypeIDBase(base->serviceType()));
262  }
263  }
tuple base
Main Program
Definition: newFWLiteAna.py:92
std::auto_ptr< Type2Maker > type2Maker_
Container::value_type value_type
std::vector< TypeIDBase > requestedCreationOrder_
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:56
template<typename T >
T& edm::serviceregistry::ServicesManager::get ( void  ) const
inline

Definition at line 73 of file ServicesManager.h.

References mergeVDriftHistosByStation::name, edm::errors::NotFound, edm::Exception::throwThis(), type2Maker_, and type2Service_.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), and betterConfigParser.BetterConfigParser::getResultingSection().

73  {
74  Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
75  Type2Maker::const_iterator itFoundMaker ;
76  if(itFound == type2Service_.end()) {
77  //do on demand building of the service
78  if(0 == type2Maker_.get() ||
79  type2Maker_->end() == (itFoundMaker = type2Maker_->find(TypeIDBase(typeid(T))))) {
81  "Service Request unable to find requested service with compiler type name '",
82  typeid(T).name(),
83  "'.\n");
84  } else {
85  itFoundMaker->second.add(const_cast<ServicesManager&>(*this));
86  itFound = type2Service_.find(TypeIDBase(typeid(T)));
87  //the 'add()' should have put the service into the list
88  assert(itFound != type2Service_.end());
89  }
90  }
91  //convert it to its actual type
92  boost::shared_ptr<ServiceWrapper<T> > ptr(boost::dynamic_pointer_cast<ServiceWrapper<T> >(itFound->second));
93  assert(0 != ptr.get());
94  return ptr->get();
95  }
std::auto_ptr< Type2Maker > type2Maker_
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
long double T
template<typename T >
bool edm::serviceregistry::ServicesManager::isAvailable ( ) const
inline

returns true of the particular service is accessible

Definition at line 99 of file ServicesManager.h.

References type2Maker_, and type2Service_.

99  {
100  Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
101  Type2Maker::const_iterator itFoundMaker ;
102  if(itFound == type2Service_.end()) {
103  //do on demand building of the service
104  if(0 == type2Maker_.get() ||
105  type2Maker_->end() == (itFoundMaker = type2Maker_->find(TypeIDBase(typeid(T))))) {
106  return false;
107  } else {
108  //Actually create the service in order to 'flush out' any
109  // configuration errors for the service
110  itFoundMaker->second.add(const_cast<ServicesManager&>(*this));
111  itFound = type2Service_.find(TypeIDBase(typeid(T)));
112  //the 'add()' should have put the service into the list
113  assert(itFound != type2Service_.end());
114  }
115  }
116  return true;
117  }
std::auto_ptr< Type2Maker > type2Maker_
long double T
ServicesManager const& edm::serviceregistry::ServicesManager::operator= ( ServicesManager const &  )
private
template<typename T >
bool edm::serviceregistry::ServicesManager::put ( boost::shared_ptr< ServiceWrapper< T > >  iPtr)
inline

returns false if put fails because a service of this type already exists

Definition at line 124 of file ServicesManager.h.

References actualCreationOrder_, and type2Service_.

Referenced by edm::serviceregistry::ServiceMaker< T, TMaker >::make().

124  {
125  Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
126  if(itFound != type2Service_.end()) {
127  return false;
128  }
129  type2Service_[ TypeIDBase(typeid(T)) ] = iPtr;
130  actualCreationOrder_.push_back(TypeIDBase(typeid(T)));
131  return true;
132  }
std::vector< TypeIDBase > actualCreationOrder_
long double T

Member Data Documentation

std::vector<TypeIDBase> edm::serviceregistry::ServicesManager::actualCreationOrder_
private

Definition at line 164 of file ServicesManager.h.

Referenced by put(), and ~ServicesManager().

boost::shared_ptr<ServicesManager> edm::serviceregistry::ServicesManager::associatedManager_
private

Definition at line 158 of file ServicesManager.h.

Referenced by ServicesManager().

ActivityRegistry edm::serviceregistry::ServicesManager::registry_
private
std::vector<TypeIDBase> edm::serviceregistry::ServicesManager::requestedCreationOrder_
private

Definition at line 163 of file ServicesManager.h.

Referenced by createServices(), and fillListOfMakers().

std::auto_ptr<Type2Maker> edm::serviceregistry::ServicesManager::type2Maker_
private
Type2Service edm::serviceregistry::ServicesManager::type2Service_
private

Definition at line 161 of file ServicesManager.h.

Referenced by get(), isAvailable(), put(), ServicesManager(), and ~ServicesManager().