CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ServiceRegistry.h
Go to the documentation of this file.
1 #ifndef ServiceRegistry_ServiceRegistry_h
2 #define ServiceRegistry_ServiceRegistry_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : ServiceRegistry
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon Sep 5 13:33:00 EDT 2005
19 //
20 
21 // system include files
22 #include <vector>
23 
24 // user include files
29 
30 // forward declarations
31 namespace edm {
32  class FwkImpl;
33  namespace serviceregistry {
34  template< typename T> class ServiceWrapper;
35  }
36 
38  {
39 
40  public:
41 
42  class Operate {
43  public:
44  Operate(const ServiceToken& iToken) :
46  {}
49  }
50 
51  //override operator new to stop use on heap?
52  private:
53  Operate(const Operate&); //stop default
54  const Operate& operator=(const Operate&); //stop default
56  };
57 
58  friend class edm::FwkImpl;
59  friend int main(int argc, char* argv[]);
60  friend class Operate;
61 
62  virtual ~ServiceRegistry();
63 
64  // ---------- const member functions ---------------------
65  template<class T>
66  T& get() const {
67  if(0 == manager_.get()) {
69  "Service"
70  " no ServiceRegistry has been set for this thread");
71  }
72  return manager_-> template get<T>();
73  }
74 
75  template<class T>
76  bool isAvailable() const {
77  if(0 == manager_.get()) {
79  "Service"
80  " no ServiceRegistry has been set for this thread");
81  }
82  return manager_-> template isAvailable<T>();
83  }
87  ServiceToken presentToken() const;
88  // ---------- static member functions --------------------
89  static ServiceRegistry& instance();
90 
91  // ---------- member functions ---------------------------
92 
93 
94  static ServiceToken createServicesFromConfig(const std::string& config);
95 
96  public: // Made public (temporarily) at the request of Emilio Meschi.
97  static ServiceToken createSet(std::vector<ParameterSet>&);
98  static ServiceToken createSet(std::vector<ParameterSet>&,
102  template<class T>
103  static ServiceToken createContaining(std::auto_ptr<T> iService){
104  std::vector<edm::ParameterSet> config;
105  boost::shared_ptr<serviceregistry::ServicesManager> manager( new serviceregistry::ServicesManager(config) );
106  boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
108  manager->put(wrapper);
109  return manager;
110  }
111  template<class T>
112  static ServiceToken createContaining(std::auto_ptr<T> iService,
113  ServiceToken iToken,
115  std::vector<edm::ParameterSet> config;
116  boost::shared_ptr<serviceregistry::ServicesManager> manager( new serviceregistry::ServicesManager(iToken,
117  iLegacy,
118  config) );
119  boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
121  manager->put(wrapper);
122  return manager;
123  }
125  template<class T>
126  static ServiceToken createContaining(boost::shared_ptr<serviceregistry::ServiceWrapper<T> > iWrapper) {
127  std::vector<edm::ParameterSet> config;
128  boost::shared_ptr<serviceregistry::ServicesManager> manager( new serviceregistry::ServicesManager(config) );
129  manager->put(iWrapper);
130  return manager;
131  }
132  template<class T>
134  ServiceToken iToken,
136  std::vector<edm::ParameterSet> config;
137  boost::shared_ptr<serviceregistry::ServicesManager> manager( new serviceregistry::ServicesManager(iToken,
138  iLegacy,
139  config) );
140  manager->put(iWrapper);
141  return manager;
142  }
143 
144 private:
145 
146  //returns old token
147  ServiceToken setContext(const ServiceToken& iNewToken);
148  void unsetContext(const ServiceToken& iOldToken);
149 
150  ServiceRegistry();
151  ServiceRegistry(const ServiceRegistry&); // stop default
152 
153  const ServiceRegistry& operator=(const ServiceRegistry&); // stop default
154 
155  // ---------- member data --------------------------------
156  boost::shared_ptr<serviceregistry::ServicesManager> manager_;
157  };
158 }
159 
160 #endif
ServiceToken setContext(const ServiceToken &iNewToken)
boost::shared_ptr< serviceregistry::ServicesManager > manager_
static ServiceToken createSet(std::vector< ParameterSet > &)
static ServiceToken createServicesFromConfig(const std::string &config)
static ServiceRegistry & instance()
static ServiceToken createContaining(std::auto_ptr< T > iService)
create a service token that holds the service defined by iService
void unsetContext(const ServiceToken &iOldToken)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:81
static ServiceToken createContaining(boost::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
const Operate & operator=(const Operate &)
Operate(const ServiceToken &iToken)
friend int main(int argc, char *argv[])
static ServiceToken createContaining(std::auto_ptr< T > iService, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
bool isAvailable() const
const ServiceRegistry & operator=(const ServiceRegistry &)
tuple config
Definition: cmsDriver.py:17
friend class edm::FwkImpl
static ServiceToken createContaining(boost::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper)
create a service token that holds the service held by iWrapper
ServiceToken presentToken() const
static HepMC::HEPEVT_Wrapper wrapper