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(), and edm::makeParameterSets().

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 92 of file HcalPedestalValidator.cc.

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