CMS 3D CMS Logo

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, MakerHolderType2Maker
 
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 createServiceFor (MakerHolder const &)
 
void createServices ()
 
void fillListOfMakers (std::vector< ParameterSet > &)
 
ServicesManager const & operator= (ServicesManager const &)=delete
 
 ServicesManager (ServicesManager const &)=delete
 

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 55 of file ServicesManager.h.

Definition at line 54 of file ServicesManager.h.

Constructor & Destructor Documentation

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

Definition at line 65 of file ServicesManager.cc.

References createServices(), and fillListOfMakers().

Referenced by put().

65  : type2Maker_(new Type2Maker) {
66  //First create the list of makers
67  fillListOfMakers(iConfiguration);
68 
70  }
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 72 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().

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

Member Function Documentation

void ServicesManager::connect ( ActivityRegistry iOther)

causes our ActivityRegistry's signals to be forwarded to iOther

Definition at line 212 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(), put(), 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(), o2o_db_cfgmap.DbManagerDAQ::update_hashmap(), Vispa.Plugins.EdmBrowser.EdmBrowserTabController.EdmBrowserTabController::updateViewMenu(), and Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController::updateViewMenu().

212 { registry_.connect(iOther); }
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 214 of file ServicesManager.cc.

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

Referenced by put(), and edm::ServiceToken::ServiceToken().

214 { iOther.connect(registry_); }
void ServicesManager::copySlotsFrom ( ActivityRegistry iOther)

the copy the argument's slots to the our signals

Definition at line 216 of file ServicesManager.cc.

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

Referenced by put(), and edm::ServiceToken::ServiceToken().

216 { registry_.copySlotsFrom(iOther); }
void copySlotsFrom(ActivityRegistry &iOther)
void ServicesManager::copySlotsTo ( ActivityRegistry iOther)

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

Definition at line 218 of file ServicesManager.cc.

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

Referenced by put(), and edm::ServiceToken::ServiceToken().

218 { iOther.copySlotsFrom(registry_); }
void ServicesManager::createServiceFor ( MakerHolder const &  iMaker)
private

Definition at line 251 of file ServicesManager.cc.

References edm::serviceregistry::ServicesManager::MakerHolder::add(), cms::Exception::addContext(), beamerCreator::create(), objects.autophobj::filler, reco::get(), edm::ParameterSet::getParameter(), edm::serviceregistry::ServicesManager::MakerHolder::pset_, AlCaHLTBitMon_QueryRunRegistry::string, and edm::convertException::wrap().

Referenced by createServices(), get(), isAvailable(), and put().

251  {
252  std::string serviceType = iMaker.pset_->getParameter<std::string>("@service_type");
253  std::unique_ptr<ParameterSetDescriptionFillerBase> filler(
255  ConfigurationDescriptions descriptions(filler->baseType(), serviceType);
256  filler->fill(descriptions);
257 
258  try {
259  convertException::wrap([&]() { descriptions.validate(*(iMaker.pset_), serviceType); });
260  } catch (cms::Exception& iException) {
261  std::ostringstream ost;
262  ost << "Validating configuration of service of type " << serviceType;
263  iException.addContext(ost.str());
264  throw;
265  }
266  try {
267  convertException::wrap([&]() {
268  // This creates the service
269  iMaker.add(*this);
270  });
271  } catch (cms::Exception& iException) {
272  std::ostringstream ost;
273  ost << "Constructing service of type " << serviceType;
274  iException.addContext(ost.str());
275  throw;
276  }
277  }
def create(alignables, pedeDump, additionalData, outputFile, config)
void addContext(std::string const &context)
Definition: Exception.cc:165
auto wrap(F iFunc) -> decltype(iFunc())
T get(const Candidate &c)
Definition: component.h:55
void ServicesManager::createServices ( )
private

Definition at line 279 of file ServicesManager.cc.

References createServiceFor(), cmsPerfStripChart::operate(), requestedCreationOrder_, and type2Maker_.

Referenced by put(), and ServicesManager().

279  {
280  //create a shared_ptr of 'this' that will not delete us
281  std::shared_ptr<ServicesManager> shareThis(this, NoOp());
282 
283  ServiceToken token(shareThis);
284 
285  //Now make our services to ones obtained via ServiceRegistry
286  // when this goes out of scope, it will revert back to the previous Service set
288 
289  //Now, make each Service. If a service depends on a service that has yet to be
290  // created, that other service will automatically be made
291 
292  for (std::vector<TypeIDBase>::const_iterator idIter = requestedCreationOrder_.begin(),
293  idEnd = requestedCreationOrder_.end();
294  idIter != idEnd;
295  ++idIter) {
296  Type2Maker::iterator itMaker = type2Maker_->find(*idIter);
297 
298  // Check to make sure this maker is still there. They are deleted
299  // sometimes and that is OK.
300  if (itMaker != type2Maker_->end()) {
301  createServiceFor(itMaker->second);
302  }
303  }
304  //No longer need the makers
305  type2Maker_ = nullptr; // propagate_const<T> has no reset() function
306  }
void createServiceFor(MakerHolder const &)
std::vector< TypeIDBase > requestedCreationOrder_
edm::propagate_const< std::unique_ptr< Type2Maker > > type2Maker_
def operate(timelog, memlog, json_f, num)
void ServicesManager::fillListOfMakers ( std::vector< ParameterSet > &  iConfiguration)
private

Definition at line 220 of file ServicesManager.cc.

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

Referenced by put(), and ServicesManager().

220  {
221  for (std::vector<ParameterSet>::iterator itParam = iConfiguration.begin(), itParamEnd = iConfiguration.end();
222  itParam != itParamEnd;
223  ++itParam) {
224  std::shared_ptr<ServiceMakerBase> base(
225  ServicePluginFactory::get()->create(itParam->getParameter<std::string>("@service_type")));
226 
227  if (nullptr == base.get()) {
228  throw Exception(errors::Configuration, "Service")
229  << "could not find a service named " << itParam->getParameter<std::string>("@service_type")
230  << ". Please check spelling.";
231  }
232  Type2Maker::iterator itFound = type2Maker_->find(TypeIDBase(base->serviceType()));
233  if (itFound != type2Maker_->end()) {
234  throw Exception(errors::Configuration, "Service")
235  << " the service " << itParam->getParameter<std::string>("@service_type")
236  << " provides the same service as " << itFound->second.pset_->getParameter<std::string>("@service_type")
237  << "\n Please reconfigure job to only use one of these services.";
238  }
239  type2Maker_->insert(
240  Type2Maker::value_type(TypeIDBase(base->serviceType()), MakerHolder(base, *itParam, registry_)));
241  requestedCreationOrder_.push_back(TypeIDBase(base->serviceType()));
242  }
243  }
def create(alignables, pedeDump, additionalData, outputFile, config)
base
Make Sure CMSSW is Setup ##.
std::vector< TypeIDBase > requestedCreationOrder_
edm::propagate_const< std::unique_ptr< Type2Maker > > type2Maker_
T get(const Candidate &c)
Definition: component.h:55
template<typename T >
T& edm::serviceregistry::ServicesManager::get ( ) const
inline

Definition at line 72 of file ServicesManager.h.

References createServiceFor(), edm::propagate_const< T >::get(), dataset::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().

72  {
73  Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
74  Type2Maker::const_iterator itFoundMaker;
75  if (itFound == type2Service_.end()) {
76  //do on demand building of the service
77  if (nullptr == type2Maker_.get() ||
78  type2Maker_->end() == (itFoundMaker = type2Maker_->find(TypeIDBase(typeid(T))))) {
80  "Service Request unable to find requested service with compiler type name '",
81  typeid(T).name(),
82  "'.\n");
83  } else {
84  const_cast<ServicesManager&>(*this).createServiceFor(itFoundMaker->second);
85  itFound = type2Service_.find(TypeIDBase(typeid(T)));
86  //the 'add()' should have put the service into the list
87  assert(itFound != type2Service_.end());
88  }
89  }
90  //convert it to its actual type
91  std::shared_ptr<ServiceWrapper<T>> ptr(std::dynamic_pointer_cast<ServiceWrapper<T>>(itFound->second));
92  assert(nullptr != ptr.get());
93  return ptr->get();
94  }
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
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 98 of file ServicesManager.h.

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

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

Referenced by put().

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 123 of file ServicesManager.h.

References actualCreationOrder_, connect(), connectTo(), copySlotsFrom(), copySlotsTo(), createServiceFor(), createServices(), fillListOfMakers(), operator=(), ServicesManager(), and type2Service_.

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

123  {
124  Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
125  if (itFound != type2Service_.end()) {
126  return false;
127  }
128  type2Service_[TypeIDBase(typeid(T))] = iPtr;
129  actualCreationOrder_.push_back(TypeIDBase(typeid(T)));
130  return true;
131  }
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().

edm::propagate_const<std::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().

edm::propagate_const<std::unique_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().