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
27 
28 // system include files
29 #include <vector>
30 
31 // forward declarations
32 namespace edm {
33  class FwkImpl;
34  namespace serviceregistry {
35  template <typename T>
37  }
38 
40  public:
41  class Operate {
42  public:
44  Operate(Operate const&) = delete; //stop default
45  Operate const& operator=(Operate const&) = delete; //stop default
47 
48  //override operator new to stop use on heap?
49  private:
51  };
52 
53  friend class edm::FwkImpl;
54  friend int main(int argc, char* argv[]);
55  friend class Operate;
56 
57  ServiceRegistry(ServiceRegistry const&) = delete; // stop default
58  ServiceRegistry const& operator=(ServiceRegistry const&) = delete; // stop default
59  virtual ~ServiceRegistry();
60 
61  // ---------- const member functions ---------------------
62  template <typename T>
63  T& get() const {
64  if (nullptr == manager_.get()) {
65  auto demangled = typeDemangle(typeid(T).name());
67  "No ServiceRegistry has been set for this thread. Tried to get a Service ",
68  demangled.c_str());
69  }
70  return manager_->template get<T>();
71  }
72 
73  template <typename T>
74  bool isAvailable() const {
75  if (nullptr == manager_.get()) {
76  auto demangled = typeDemangle(typeid(T).name());
78  "No ServiceRegistry has been set for this thread. Tried to ask availability of a Service ",
79  demangled.c_str());
80  }
81  return manager_->template isAvailable<T>();
82  }
86  ServiceToken presentToken() const;
87  // ---------- static member functions --------------------
88  static ServiceRegistry& instance();
89 
90  // ---------- member functions ---------------------------
91 
92  static ServiceToken createServicesFromConfig(std::unique_ptr<ParameterSet> params);
93 
94  public: // Made public (temporarily) at the request of Emilio Meschi.
95  static ServiceToken createSet(std::vector<ParameterSet>&);
96  static ServiceToken createSet(std::vector<ParameterSet>&,
99  bool associate = true);
101  template <typename T>
102  static ServiceToken createContaining(std::unique_ptr<T> iService) {
103  std::vector<edm::ParameterSet> config;
104  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
105  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
106  manager->put(wrapper);
107  return manager;
108  }
109  template <typename T>
110  static ServiceToken createContaining(std::unique_ptr<T> iService,
111  ServiceToken iToken,
112  bool iOverrideIfServiceInToken) {
113  std::vector<edm::ParameterSet> config;
114  auto manager =
115  std::make_shared<serviceregistry::ServicesManager>(iToken, serviceregistry::kOverlapIsError, config);
116  auto wrapper = std::make_shared<serviceregistry::ServiceWrapper<T> >(std::move(iService));
117  manager->put(wrapper, iOverrideIfServiceInToken);
118  return manager;
119  }
121  template <typename T>
123  std::vector<edm::ParameterSet> config;
124  auto manager = std::make_shared<serviceregistry::ServicesManager>(config);
125  manager->put(iWrapper);
126  return manager;
127  }
128  template <typename T>
130  ServiceToken iToken,
132  std::vector<edm::ParameterSet> config;
133  auto manager = std::make_shared<serviceregistry::ServicesManager>(iToken, iLegacy, config);
134  manager->put(iWrapper);
135  return manager;
136  }
137 
138  private:
139  //returns old token
140  ServiceToken setContext(ServiceToken const& iNewToken);
141  void unsetContext(ServiceToken const& iOldToken);
142 
143  ServiceRegistry();
144 
145  // ---------- member data --------------------------------
146  std::shared_ptr<serviceregistry::ServicesManager> manager_;
147  };
148 } // namespace edm
149 
150 #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
Operate const & operator=(Operate const &)=delete
static ServiceToken createContaining(std::unique_ptr< T > iService, ServiceToken iToken, bool iOverrideIfServiceInToken)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:85
void unsetContext(ServiceToken const &iOldToken)
ServiceRegistry const & operator=(ServiceRegistry const &)=delete
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: DiMuonVmerge.cc:73
static ServiceToken createSet(std::vector< ParameterSet > &)
demangled
Definition: symbols.py:70
std::string typeDemangle(char const *mangledName)
bool isAvailable() const
HLT enums.
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
friend class edm::FwkImpl
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
long double T
ServiceToken presentToken() const
def move(src, dest)
Definition: eostools.py:511
std::shared_ptr< serviceregistry::ServicesManager > manager_
static HepMC::HEPEVT_Wrapper wrapper