CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 // user include files
26 
27 // system include files
28 #include <vector>
29 
30 // forward declarations
31 namespace edm {
32  class FwkImpl;
33  namespace serviceregistry {
34  template <typename T>
36  }
37 
39  public:
40  class Operate {
41  public:
43  Operate(Operate const&) = delete; //stop default
44  Operate const& operator=(Operate const&) = delete; //stop default
46 
47  //override operator new to stop use on heap?
48  private:
50  };
51 
52  friend class edm::FwkImpl;
53  friend int main(int argc, char* argv[]);
54  friend class Operate;
55 
56  ServiceRegistry(ServiceRegistry const&) = delete; // stop default
57  ServiceRegistry const& operator=(ServiceRegistry const&) = delete; // stop default
58  virtual ~ServiceRegistry();
59 
60  // ---------- const member functions ---------------------
61  template <typename T>
62  T& get() const {
63  if (nullptr == manager_.get()) {
65  "Service"
66  " no ServiceRegistry has been set for this thread");
67  }
68  return manager_->template get<T>();
69  }
70 
71  template <typename T>
72  bool isAvailable() const {
73  if (nullptr == manager_.get()) {
75  "Service"
76  " no ServiceRegistry has been set for this thread");
77  }
78  return manager_->template isAvailable<T>();
79  }
83  ServiceToken presentToken() const;
84  // ---------- static member functions --------------------
85  static ServiceRegistry& instance();
86 
87  // ---------- member functions ---------------------------
88 
89  static ServiceToken createServicesFromConfig(std::unique_ptr<ParameterSet> params);
90 
91  public: // Made public (temporarily) at the request of Emilio Meschi.
92  static ServiceToken createSet(std::vector<ParameterSet>&);
93  static ServiceToken createSet(std::vector<ParameterSet>&,
96  bool associate = true);
98  template <typename T>
99  static ServiceToken createContaining(std::unique_ptr<T> iService) {
100  std::vector<edm::ParameterSet> config;
101  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
102  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
103  manager->put(wrapper);
104  return manager;
105  }
106  template <typename T>
107  static ServiceToken createContaining(std::unique_ptr<T> iService,
108  ServiceToken iToken,
110  std::vector<edm::ParameterSet> config;
111  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
112  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
113  manager->put(wrapper);
114  return manager;
115  }
117  template <typename T>
119  std::vector<edm::ParameterSet> config;
120  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
121  manager->put(iWrapper);
122  return manager;
123  }
124  template <typename T>
126  ServiceToken iToken,
128  std::vector<edm::ParameterSet> config;
129  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
130  manager->put(iWrapper);
131  return manager;
132  }
133 
134  private:
135  //returns old token
136  ServiceToken setContext(ServiceToken const& iNewToken);
137  void unsetContext(ServiceToken const& iOldToken);
138 
139  ServiceRegistry();
140 
141  // ---------- member data --------------------------------
142  std::shared_ptr<serviceregistry::ServicesManager> manager_;
143  };
144 } // namespace edm
145 
146 #endif
ServiceToken setContext(ServiceToken const &iNewToken)
static ServiceToken createServicesFromConfig(std::unique_ptr< ParameterSet > params)
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper)
create a service token that holds the service held by iWrapper
static ServiceToken createContaining(std::unique_ptr< T > iService, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
Operate const & operator=(Operate const &)=delete
ServiceToken presentToken() const
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
void unsetContext(ServiceToken const &iOldToken)
ServiceRegistry const & operator=(ServiceRegistry const &)=delete
def move
Definition: eostools.py:511
static ServiceRegistry & instance()
static ServiceToken createContaining(std::unique_ptr< T > iService)
create a service token that holds the service defined by iService
Operate(ServiceToken const &iToken)
friend int main(int argc, char *argv[])
Definition: DMRtrends.cc:1053
static ServiceToken createSet(std::vector< ParameterSet > &)
tuple argc
Definition: dir2webdir.py:39
bool isAvailable() const
tuple config
parse the configuration file
friend class edm::FwkImpl
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
long double T
std::shared_ptr< serviceregistry::ServicesManager > manager_
static HepMC::HEPEVT_Wrapper wrapper