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>
36  }
37 
39  public:
40  class Operate {
41  public:
42  Operate(ServiceToken const& iToken) : oldToken_(ServiceRegistry::instance().setContext(iToken)) {}
44 
45  //override operator new to stop use on heap?
46  private:
47  Operate(Operate const&) = delete; //stop default
48  Operate const& operator=(Operate const&) = delete; //stop default
50  };
51 
52  friend class edm::FwkImpl;
53  friend int main(int argc, char* argv[]);
54  friend class Operate;
55 
56  virtual ~ServiceRegistry();
57 
58  // ---------- const member functions ---------------------
59  template <typename T>
60  T& get() const {
61  if (nullptr == manager_.get()) {
63  "Service"
64  " no ServiceRegistry has been set for this thread");
65  }
66  return manager_->template get<T>();
67  }
68 
69  template <typename T>
70  bool isAvailable() const {
71  if (nullptr == manager_.get()) {
73  "Service"
74  " no ServiceRegistry has been set for this thread");
75  }
76  return manager_->template isAvailable<T>();
77  }
81  ServiceToken presentToken() const;
82  // ---------- static member functions --------------------
83  static ServiceRegistry& instance();
84 
85  // ---------- member functions ---------------------------
86 
87  static ServiceToken createServicesFromConfig(std::unique_ptr<ParameterSet> params);
88 
89  public: // Made public (temporarily) at the request of Emilio Meschi.
90  static ServiceToken createSet(std::vector<ParameterSet>&);
91  static ServiceToken createSet(std::vector<ParameterSet>&,
94  bool associate = true);
96  template <typename T>
97  static ServiceToken createContaining(std::unique_ptr<T> iService) {
98  std::vector<edm::ParameterSet> config;
99  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
100  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
101  manager->put(wrapper);
102  return manager;
103  }
104  template <typename T>
105  static ServiceToken createContaining(std::unique_ptr<T> iService,
106  ServiceToken iToken,
108  std::vector<edm::ParameterSet> config;
109  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
110  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
111  manager->put(wrapper);
112  return manager;
113  }
115  template <typename T>
117  std::vector<edm::ParameterSet> config;
118  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
119  manager->put(iWrapper);
120  return manager;
121  }
122  template <typename T>
124  ServiceToken iToken,
126  std::vector<edm::ParameterSet> config;
127  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
128  manager->put(iWrapper);
129  return manager;
130  }
131 
132  private:
133  //returns old token
134  ServiceToken setContext(ServiceToken const& iNewToken);
135  void unsetContext(ServiceToken const& iOldToken);
136 
137  ServiceRegistry();
138  ServiceRegistry(ServiceRegistry const&) = delete; // stop default
139 
140  ServiceRegistry const& operator=(ServiceRegistry const&) = delete; // stop default
141 
142  // ---------- member data --------------------------------
143  std::shared_ptr<serviceregistry::ServicesManager> manager_;
144  };
145 } // namespace edm
146 
147 #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
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
config
Definition: looper.py:291
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