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:
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
edm::ServiceRegistry::operator=
ServiceRegistry const & operator=(ServiceRegistry const &)=delete
edm::ServiceRegistry::FwkImpl
friend class edm::FwkImpl
Definition: ServiceRegistry.h:52
edm::ServiceRegistry::Operate::operator=
Operate const & operator=(Operate const &)=delete
cmsBatch.argv
argv
Definition: cmsBatch.py:279
edm::ServiceRegistry::Operate::~Operate
~Operate()
Definition: ServiceRegistry.h:43
dir2webdir.argc
argc
Definition: dir2webdir.py:39
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ServiceRegistry::get
T & get() const
Definition: ServiceRegistry.h:60
edm::ServiceRegistry::createSet
static ServiceToken createSet(std::vector< ParameterSet > &)
Definition: ServiceRegistry.cc:75
ServiceToken.h
wrapper
static HepMC::HEPEVT_Wrapper wrapper
Definition: BeamHaloProducer.cc:47
edm::errors::NotFound
Definition: EDMException.h:57
edm::ServiceRegistry::setContext
ServiceToken setContext(ServiceToken const &iNewToken)
Definition: ServiceRegistry.cc:52
edm::ServiceRegistry::Operate::oldToken_
ServiceToken oldToken_
Definition: ServiceRegistry.h:49
edm::ServiceRegistry::createContaining
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
Definition: ServiceRegistry.h:123
config
Definition: config.py:1
edm::ServiceToken
Definition: ServiceToken.h:40
edm::ServiceRegistry::~ServiceRegistry
virtual ~ServiceRegistry()
Definition: ServiceRegistry.cc:36
edm::ServiceRegistry::manager_
std::shared_ptr< serviceregistry::ServicesManager > manager_
Definition: ServiceRegistry.h:143
looper.config
config
Definition: looper.py:291
edm::ServiceRegistry::createServicesFromConfig
static ServiceToken createServicesFromConfig(std::unique_ptr< ParameterSet > params)
Definition: ServiceRegistry.cc:69
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
edm::ServiceRegistry::Operate::Operate
Operate(ServiceToken const &iToken)
Definition: ServiceRegistry.h:42
edm::ServiceRegistry::instance
static ServiceRegistry & instance()
Definition: ServiceRegistry.cc:90
edm::ServiceRegistry::createContaining
static ServiceToken createContaining(std::unique_ptr< T > iService, ServiceToken iToken, serviceregistry::ServiceLegacy iLegacy)
Definition: ServiceRegistry.h:105
eostools.move
def move(src, dest)
Definition: eostools.py:511
ServicesManager.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ServiceRegistry::createContaining
static ServiceToken createContaining(std::unique_ptr< T > iService)
create a service token that holds the service defined by iService
Definition: ServiceRegistry.h:97
ServiceLegacy.h
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
edm::ServiceRegistry::unsetContext
void unsetContext(ServiceToken const &iOldToken)
Definition: ServiceRegistry.cc:58
ParameterSet.h
edm::ServiceRegistry::createContaining
static ServiceToken createContaining(std::shared_ptr< serviceregistry::ServiceWrapper< T > > iWrapper)
create a service token that holds the service held by iWrapper
Definition: ServiceRegistry.h:116
edm::ServiceRegistry
Definition: ServiceRegistry.h:38
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40
edm::ServiceRegistry::isAvailable
bool isAvailable() const
Definition: ServiceRegistry.h:70
edm::ServiceRegistry::ServiceRegistry
ServiceRegistry()
Definition: ServiceRegistry.cc:30
edm::serviceregistry::ServiceLegacy
ServiceLegacy
Definition: ServiceLegacy.h:29
edm::serviceregistry::ServiceWrapper
Definition: ServiceRegistry.h:35
edm::ServiceRegistry::main
friend int main(int argc, char *argv[])
Definition: DMRtrends.cc:1052