CMS 3D CMS Logo

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> class ServiceWrapper;
35  }
36 
38  public:
39 
40  class Operate {
41  public:
42  Operate(ServiceToken const& iToken) :
43  oldToken_(ServiceRegistry::instance().setContext(iToken)) {}
46  }
47 
48  //override operator new to stop use on heap?
49  private:
50  Operate(Operate const&) = delete; //stop default
51  Operate const& operator=(Operate const&) = delete; //stop default
53  };
54 
55  friend class edm::FwkImpl;
56  friend int main(int argc, char* argv[]);
57  friend class Operate;
58 
59  virtual ~ServiceRegistry();
60 
61  // ---------- const member functions ---------------------
62  template<typename T>
63  T& get() const {
64  if(nullptr == manager_.get()) {
66  "Service"
67  " no ServiceRegistry has been set for this thread");
68  }
69  return manager_-> template get<T>();
70  }
71 
72  template<typename T>
73  bool isAvailable() const {
74  if(nullptr == manager_.get()) {
76  "Service"
77  " no ServiceRegistry has been set for this thread");
78  }
79  return manager_-> template isAvailable<T>();
80  }
84  ServiceToken presentToken() const;
85  // ---------- static member functions --------------------
86  static ServiceRegistry& instance();
87 
88  // ---------- member functions ---------------------------
89 
90  static ServiceToken createServicesFromConfig(std::string const& config);
91 
92  public: // Made public (temporarily) at the request of Emilio Meschi.
93  static ServiceToken createSet(std::vector<ParameterSet>&);
94  static ServiceToken createSet(std::vector<ParameterSet>&,
97  bool associate = true);
99  template<typename T>
100  static ServiceToken createContaining(std::unique_ptr<T> iService){
101  std::vector<edm::ParameterSet> config;
102  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
103  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
104  manager->put(wrapper);
105  return manager;
106  }
107  template<typename T>
108  static ServiceToken createContaining(std::unique_ptr<T> iService,
109  ServiceToken iToken,
111  std::vector<edm::ParameterSet> config;
112  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
113  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
114  manager->put(wrapper);
115  return manager;
116  }
118  template<typename T>
120  std::vector<edm::ParameterSet> config;
121  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
122  manager->put(iWrapper);
123  return manager;
124  }
125  template<typename T>
127  ServiceToken iToken,
129  std::vector<edm::ParameterSet> config;
130  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
131  manager->put(iWrapper);
132  return manager;
133  }
134 
135 private:
136  //returns old token
137  ServiceToken setContext(ServiceToken const& iNewToken);
138  void unsetContext(ServiceToken const& iOldToken);
139 
140  ServiceRegistry();
141  ServiceRegistry(ServiceRegistry const&) = delete; // stop default
142 
143  ServiceRegistry const& operator=(ServiceRegistry const&) = delete; // stop default
144 
145  // ---------- member data --------------------------------
146  std::shared_ptr<serviceregistry::ServicesManager> manager_;
147  };
148 }
149 
150 #endif
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)
static PFTauRenderPlugin instance
Definition: config.py:1
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
config
Definition: looper.py:289
void unsetContext(ServiceToken const &iOldToken)
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)
bool isAvailable() const
HLT enums.
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
long double T
def move(src, dest)
Definition: eostools.py:511
std::shared_ptr< serviceregistry::ServicesManager > manager_
static HepMC::HEPEVT_Wrapper wrapper