test
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,
std::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 (std::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_
 
edm::propagate_const
< std::shared_ptr
< ServicesManager > > 
associatedManager_
 
ActivityRegistry registry_
 
std::vector< TypeIDBaserequestedCreationOrder_
 
edm::propagate_const
< std::unique_ptr< Type2Maker > > 
type2Maker_
 
Type2Service type2Service_
 

Detailed Description

Definition at line 43 of file ServicesManager.h.

Member Typedef Documentation

Definition at line 57 of file ServicesManager.h.

Definition at line 56 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
edm::propagate_const< std::unique_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(), Exception, fillListOfMakers(), reco::helper::VirtualJetProducerHelper::intersection(), edm::serviceregistry::kConfigurationOverrides, edm::serviceregistry::kOverlapIsError, edm::serviceregistry::kTokenOverrides, edm::ServiceToken::manager_, registry_, AlCaHLTBitMon_QueryRunRegistry::string, type2Maker_, type2Service_, and edm::typeDemangle().

80  :
81  associatedManager_(associate ? iToken.manager_ : std::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(typeDemangle(itType->name()));
152  LogInfo("Configuration") << "Warning: You have reconfigured service\n"
153  << "'" << type << "' in a subprocess.\n"
154  << "This service has already been configured.\n"
155  << "This particular service may not be reconfigured in a subprocess.\n"
156  << "The reconfiguration will be ignored.\n";
157  type2Maker_->erase(itFound);
158  } else {
159  // This is not a process wide service, so the configuration overrides the token.
160  type2Service_.erase(type2Service_.find(*itType));
161  }
162  }
163  break;
164  }
165  //make sure our signals are propagated to our 'inherited' Services
166  if (associate) registry_.copySlotsFrom(associatedManager_->registry_);
167  }
168  createServices();
169  }
type
Definition: HCALResponse.h:21
void fillListOfMakers(std::vector< ParameterSet > &)
std::map< TypeIDBase, MakerHolder > Type2Maker
void copySlotsFrom(ActivityRegistry &iOther)
std::set< TypeID > TypeSet
std::string typeDemangle(char const *mangledName)
edm::propagate_const< std::unique_ptr< Type2Maker > > type2Maker_
edm::propagate_const< std::shared_ptr< ServicesManager > > associatedManager_
ServicesManager::~ServicesManager ( )

Definition at line 175 of file ServicesManager.cc.

References actualCreationOrder_, and type2Service_.

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

215  {
216  registry_.connect(iOther);
217  }
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 220 of file ServicesManager.cc.

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

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

the copy the argument's slots to the our signals

Definition at line 225 of file ServicesManager.cc.

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

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

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

Definition at line 230 of file ServicesManager.cc.

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

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

Definition at line 271 of file ServicesManager.cc.

References cms::Exception::addContext(), SurfaceDeformationFactory::create(), reco::get(), cmsPerfStripChart::operate(), requestedCreationOrder_, AlCaHLTBitMon_QueryRunRegistry::string, unpackBuffers-CaloStage2::token, type2Maker_, and edm::convertException::wrap().

Referenced by ServicesManager().

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

Definition at line 235 of file ServicesManager.cc.

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

Referenced by ServicesManager().

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

Definition at line 74 of file ServicesManager.h.

References assert(), edm::propagate_const< T >::get(), mergeVDriftHistosByStation::name, edm::errors::NotFound, edm::Exception::throwThis(), type2Maker_, and type2Service_.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), rrapi.RRApi::columns(), rrapi.RRApi::count(), rrapi.RRApi::data(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), rrapi.RRApi::report(), rrapi.RRApi::reports(), rrapi.RRApi::tables(), rrapi.RRApi::tags(), rrapi.RRApi::templates(), and rrapi.RRApi::workspaces().

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

returns true of the particular service is accessible

Definition at line 100 of file ServicesManager.h.

References assert(), edm::propagate_const< T >::get(), type2Maker_, and type2Service_.

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

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

Definition at line 125 of file ServicesManager.h.

References actualCreationOrder_, and type2Service_.

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

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

Member Data Documentation

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

Definition at line 165 of file ServicesManager.h.

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

edm::propagate_const<std::shared_ptr<ServicesManager> > edm::serviceregistry::ServicesManager::associatedManager_
private

Definition at line 159 of file ServicesManager.h.

Referenced by ServicesManager().

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

Definition at line 164 of file ServicesManager.h.

Referenced by createServices(), and fillListOfMakers().

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

Definition at line 162 of file ServicesManager.h.

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