CMS 3D CMS Logo

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

#include <ServiceRegistry.h>

Classes

class  Operate
 

Public Member Functions

template<typename T >
Tget () const
 
template<typename T >
bool isAvailable () const
 
ServiceToken presentToken () const
 
virtual ~ServiceRegistry ()
 

Static Public Member Functions

template<typename T >
static ServiceToken createContaining (std::auto_ptr< T > iService)
 create a service token that holds the service defined by iService More...
 
template<typename T >
static ServiceToken createContaining (std::auto_ptr< T > iService, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
 
template<typename T >
static ServiceToken createContaining (boost::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper)
 create a service token that holds the service held by iWrapper More...
 
template<typename T >
static ServiceToken createContaining (boost::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
 
static ServiceToken createServicesFromConfig (std::string const &config)
 
static ServiceToken createSet (std::vector< ParameterSet > &)
 
static ServiceToken createSet (std::vector< ParameterSet > &, ServiceToken, serviceregistry::ServiceLegacy, bool associate=true)
 
static ServiceRegistryinstance ()
 

Private Member Functions

ServiceRegistry const & operator= (ServiceRegistry const &)
 
 ServiceRegistry ()
 
 ServiceRegistry (ServiceRegistry const &)
 
ServiceToken setContext (ServiceToken const &iNewToken)
 
void unsetContext (ServiceToken const &iOldToken)
 

Private Attributes

boost::shared_ptr
< serviceregistry::ServicesManager
manager_
 

Friends

class edm::FwkImpl
 
int main (int argc, char *argv[])
 
class Operate
 

Detailed Description

Definition at line 37 of file ServiceRegistry.h.

Constructor & Destructor Documentation

ServiceRegistry::~ServiceRegistry ( )
virtual

Definition at line 39 of file ServiceRegistry.cc.

39  {
40  }
ServiceRegistry::ServiceRegistry ( )
private

Definition at line 32 of file ServiceRegistry.cc.

32  {
33  }
edm::ServiceRegistry::ServiceRegistry ( ServiceRegistry const &  )
private

Member Function Documentation

template<typename T >
static ServiceToken edm::ServiceRegistry::createContaining ( std::auto_ptr< T iService)
inlinestatic

create a service token that holds the service defined by iService

Definition at line 100 of file ServiceRegistry.h.

References HDQMDatabaseProducer::config, and wrapper.

Referenced by edm::ScheduleItems::addCPRandTNS(), spf::SherpackFetcher::FnFileGet(), and main().

100  {
101  std::vector<edm::ParameterSet> config;
102  boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(config));
103  boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
104  wrapper(new serviceregistry::ServiceWrapper<T>(iService));
105  manager->put(wrapper);
106  return manager;
107  }
static HepMC::HEPEVT_Wrapper wrapper
template<typename T >
static ServiceToken edm::ServiceRegistry::createContaining ( std::auto_ptr< T iService,
ServiceToken  iToken,
serviceregistry::ServiceLegacy  iLegacy 
)
inlinestatic

Definition at line 109 of file ServiceRegistry.h.

References HDQMDatabaseProducer::config, and wrapper.

111  {
112  std::vector<edm::ParameterSet> config;
113  boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(iToken,
114  iLegacy,
115  config));
116  boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
117  wrapper(new serviceregistry::ServiceWrapper<T>(iService));
118  manager->put(wrapper);
119  return manager;
120  }
static HepMC::HEPEVT_Wrapper wrapper
template<typename T >
static ServiceToken edm::ServiceRegistry::createContaining ( boost::shared_ptr< serviceregistry::ServiceWrapper< T > >  iWrapper)
inlinestatic

create a service token that holds the service held by iWrapper

Definition at line 123 of file ServiceRegistry.h.

References HDQMDatabaseProducer::config.

123  {
124  std::vector<edm::ParameterSet> config;
125  boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(config));
126  manager->put(iWrapper);
127  return manager;
128  }
template<typename T >
static ServiceToken edm::ServiceRegistry::createContaining ( boost::shared_ptr< serviceregistry::ServiceWrapper< T > >  iWrapper,
ServiceToken  iToken,
serviceregistry::ServiceLegacy  iLegacy 
)
inlinestatic

Definition at line 130 of file ServiceRegistry.h.

References HDQMDatabaseProducer::config.

132  {
133  std::vector<edm::ParameterSet> config;
134  boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(iToken,
135  iLegacy,
136  config));
137  manager->put(iWrapper);
138  return manager;
139  }
ServiceToken ServiceRegistry::createServicesFromConfig ( std::string const &  config)
static

Definition at line 81 of file ServiceRegistry.cc.

References createSet(), edm::makeParameterSets(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by HPDNoiseLibraryReader::initializeServices().

81  {
82  boost::shared_ptr<ParameterSet> params;
83  makeParameterSets(config, params);
84 
85  std::auto_ptr<std::vector<ParameterSet> > serviceSets = params->popVParameterSet(std::string("services"));
86  //create the services
87  return ServiceToken(ServiceRegistry::createSet(*serviceSets));
88  }
static ServiceToken createSet(std::vector< ParameterSet > &)
void makeParameterSets(std::string const &configtext, boost::shared_ptr< ParameterSet > &main)
essentially the same as the previous method
ServiceToken ServiceRegistry::createSet ( std::vector< ParameterSet > &  iPS)
static

Definition at line 91 of file ServiceRegistry.cc.

Referenced by createServicesFromConfig(), cond::FWIncantation::FWIncantation(), evf::FWEPWrapper::init(), evf::iDie::initFramework(), cond::Utilities::initializePluginManager(), and edm::ScheduleItems::initServices().

91  {
92  using namespace serviceregistry;
93  boost::shared_ptr<ServicesManager> returnValue(new ServicesManager(iPS));
94  return ServiceToken(returnValue);
95  }
ServiceToken ServiceRegistry::createSet ( std::vector< ParameterSet > &  iPS,
ServiceToken  iToken,
serviceregistry::ServiceLegacy  iLegacy,
bool  associate = true 
)
static

Definition at line 98 of file ServiceRegistry.cc.

101  {
102  using namespace serviceregistry;
103  boost::shared_ptr<ServicesManager> returnValue(new ServicesManager(iToken, iLegacy, iPS, associate));
104  return ServiceToken(returnValue);
105  }
template<typename T >
T& edm::ServiceRegistry::get ( void  ) const
inline

Definition at line 63 of file ServiceRegistry.h.

References manager_, edm::errors::NotFound, and edm::Exception::throwThis().

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

63  {
64  if(0 == manager_.get()) {
66  "Service"
67  " no ServiceRegistry has been set for this thread");
68  }
69  return manager_-> template get<T>();
70  }
boost::shared_ptr< serviceregistry::ServicesManager > manager_
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
ServiceRegistry & ServiceRegistry::instance ( )
static

Definition at line 108 of file ServiceRegistry.cc.

Referenced by edm::ScheduleItems::initSchedule(), edm::Service< SiStripCondObjBuilderFromDb >::isAvailable(), edm::Service< SiStripCondObjBuilderFromDb >::operator*(), edm::Service< SiStripCondObjBuilderFromDb >::operator->(), and edm::ServiceRegistry::Operate::~Operate().

108  {
109  static boost::thread_specific_ptr<ServiceRegistry> s_registry;
110  if(0 == s_registry.get()){
111  s_registry.reset(new ServiceRegistry);
112  }
113  return *s_registry;
114  }
template<typename T >
bool edm::ServiceRegistry::isAvailable ( ) const
inline

Definition at line 73 of file ServiceRegistry.h.

References manager_, edm::errors::NotFound, and edm::Exception::throwThis().

73  {
74  if(0 == manager_.get()) {
76  "Service"
77  " no ServiceRegistry has been set for this thread");
78  }
79  return manager_-> template isAvailable<T>();
80  }
boost::shared_ptr< serviceregistry::ServicesManager > manager_
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
ServiceRegistry const& edm::ServiceRegistry::operator= ( ServiceRegistry const &  )
private
ServiceToken ServiceRegistry::presentToken ( ) const

The token can be passed to another thread in order to have the same services available in the other thread.

Definition at line 72 of file ServiceRegistry.cc.

References manager_.

72  {
73  return manager_;
74  }
boost::shared_ptr< serviceregistry::ServicesManager > manager_
ServiceToken ServiceRegistry::setContext ( ServiceToken const &  iNewToken)
private

Definition at line 57 of file ServiceRegistry.cc.

References edm::ServiceToken::manager_, and manager_.

57  {
58  ServiceToken returnValue(manager_);
59  manager_ = iNewToken.manager_;
60  return returnValue;
61  }
boost::shared_ptr< serviceregistry::ServicesManager > manager_
void ServiceRegistry::unsetContext ( ServiceToken const &  iOldToken)
private

Definition at line 64 of file ServiceRegistry.cc.

References edm::ServiceToken::manager_, and manager_.

Referenced by edm::ServiceRegistry::Operate::~Operate().

64  {
65  manager_ = iOldToken.manager_;
66  }
boost::shared_ptr< serviceregistry::ServicesManager > manager_

Friends And Related Function Documentation

friend class edm::FwkImpl
friend

Definition at line 55 of file ServiceRegistry.h.

int main ( int  argc,
char *  argv[] 
)
friend

Definition at line 93 of file HcalPedestalValidator.cc.

93  {
94 
95 // CORAL required variables to be set, even if not needed
96  const char* foo1 = "CORAL_AUTH_USER=blaaah";
97  const char* foo2 = "CORAL_AUTH_PASSWORD=blaaah";
98  if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
99  if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2));
100 
101  Args args;
102  args.defineParameter ("-p", "raw pedestals");
103  args.defineParameter ("-w", "raw widths");
104  args.defineParameter ("-run", "current run number <0>");
105  args.defineParameter ("-ptag", "raw pedestal tag <NULL>");
106  args.defineParameter ("-wtag", "raw width tag <ptag>");
107  args.defineParameter ("-pref", "reference pedestals");
108  args.defineParameter ("-wref", "reference widths");
109  args.defineParameter ("-ptagref", "reference pedestal tag <NULL>");
110  args.defineParameter ("-wtagref", "reference width tag <ptagref>");
111  args.defineParameter ("-pval", "validated pedestals");
112  args.defineParameter ("-wval", "validated widths");
113  args.defineOption ("-help", "this help");
114 
115  args.parse (argn, argv);
116  std::vector<std::string> arguments = args.arguments ();
117  if (args.optionIsSet ("-help")) {
118  args.printOptionsHelp ();
119  return -1;
120  }
121 
122 // read parameters from command line
123  std::string RawPedSource = args.getParameter("-p");
124  std::string RawPedWidSource = args.getParameter("-w");
125  std::string RawPedTag = args.getParameter("-ptag").empty() ? "" : args.getParameter("-ptag");
126  std::string RawPedWidTag = args.getParameter("-wtag").empty() ? RawPedTag : args.getParameter("-wtag");
127  int RawPedRun = args.getParameter("-run").empty() ? 0 : (int)strtoll (args.getParameter("-run").c_str(),0,0);
128  int RawPedWidRun = RawPedRun;
129  std::string RefPedSource = args.getParameter("-pref");
130  std::string RefPedWidSource = args.getParameter("-wref");
131  std::string RefPedTag = args.getParameter("-ptagref").empty() ? "" : args.getParameter("-ptagref");
132  std::string RefPedWidTag = args.getParameter("-wtagref").empty() ? RefPedTag : args.getParameter("-wtagref");
133  int RefPedRun = RawPedRun;
134  int RefPedWidRun = RefPedRun;
135  std::string outputPedDest = args.getParameter("-pval");
136  std::string outputPedWidDest = args.getParameter("-wval");
137  std::string outputPedTag = "";
138  std::string outputPedWidTag = "";
139  int outputPedRun = RawPedRun;
140  int outputPedWidRun = outputPedRun;
141 
142  // need to know how to make proper topology in the future.
144 
145 // get reference objects
146  HcalPedestals* RefPeds = 0;
147  RefPeds = new HcalPedestals (&topo);
148  if (!getObject (RefPeds, RefPedSource, RefPedTag, RefPedRun)) {
149  std::cerr << "HcalPedestalValidator-> Failed to get reference Pedestals" << std::endl;
150  return 1;
151  }
152  HcalPedestalWidths* RefPedWids = 0;
153  RefPedWids = new HcalPedestalWidths (&topo);
154  if (!getObject (RefPedWids, RefPedWidSource, RefPedWidTag, RefPedWidRun)) {
155  std::cerr << "HcalPedestalValidator-> Failed to get reference PedestalWidths" << std::endl;
156  return 2;
157  }
158 
159 // get input raw objects
160  HcalPedestals* RawPeds = 0;
161  RawPeds = new HcalPedestals (&topo);
162  if (!getObject (RawPeds, RawPedSource, RawPedTag, RawPedRun)) {
163  std::cerr << "HcalPedestalValidator-> Failed to get raw Pedestals" << std::endl;
164  return 3;
165  }
166  HcalPedestalWidths* RawPedWids = 0;
167  RawPedWids = new HcalPedestalWidths (&topo);
168  if (!getObject (RawPedWids, RawPedWidSource, RawPedWidTag, RawPedWidRun)) {
169  std::cerr << "HcalPedestalValidator-> Failed to get raw PedestalWidths" << std::endl;
170  return 4;
171  }
172 
173 // make output objects
174  HcalPedestals* outputPeds = 0;
175  outputPeds = new HcalPedestals (&topo);
176  HcalPedestalWidths* outputPedWids = 0;
177  outputPedWids = new HcalPedestalWidths (&topo);
178 
179 // run algorithm
180  int nstat[4]={2500,2500,2500,2500};
181  int Flag=HcalPedestalAnalysis::HcalPedVal(nstat,RefPeds,RefPedWids,RawPeds,RawPedWids,outputPeds,outputPedWids);
182 
183  delete RefPeds;
184  delete RefPedWids;
185  delete RawPeds;
186  delete RawPedWids;
187 
188 
189 // store new objects if necessary
190  if (Flag%100000>0) {
191  if (outputPeds) {
192  if (!putObject (&outputPeds, outputPedDest, outputPedTag, outputPedRun)) {
193  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals" << std::endl;
194  return 5;
195  }
196  }
197  if (outputPedWids) {
198  if (!putObject (&outputPedWids, outputPedWidDest, outputPedWidTag, outputPedWidRun)) {
199  std::cerr << "HcalPedestalAnalyzer-> Failed to put output PedestalWidths" << std::endl;
200  return 6;
201  }
202  }
203  }
204  delete outputPeds;
205  delete outputPedWids;
206 
207 return 0;
208 }
void defineOption(const std::string &fOption, const std::string &fComment="")
TObject * getObject(TDirectory *fDir, const std::vector< std::string > &fObjectName)
Definition: compareHists.cc:44
std::vector< std::string > arguments() const
void printOptionsHelp() const
void parse(int nArgs, char *fArgs[])
dictionary args
static int HcalPedVal(int nstat[4], const HcalPedestals *fRefPedestals, const HcalPedestalWidths *fRefPedestalWidths, HcalPedestals *fRawPedestals, HcalPedestalWidths *fRawPedestalWidths, HcalPedestals *fValPedestals, HcalPedestalWidths *fValPedestalWidths)
void defineParameter(const std::string &fParameter, const std::string &fComment="")
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)
friend class Operate
friend

Definition at line 57 of file ServiceRegistry.h.

Member Data Documentation

boost::shared_ptr<serviceregistry::ServicesManager> edm::ServiceRegistry::manager_
private

Definition at line 152 of file ServiceRegistry.h.

Referenced by get(), isAvailable(), presentToken(), setContext(), and unsetContext().