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:
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
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:45
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:62
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:125
config
Definition: config.py:1
edm::ServiceToken
Definition: ServiceToken.h:42
edm::ServiceRegistry::~ServiceRegistry
virtual ~ServiceRegistry()
Definition: ServiceRegistry.cc:36
submitPVResolutionJobs.config
config
parse the configuration file
Definition: submitPVResolutionJobs.py:281
edm::ServiceRegistry::manager_
std::shared_ptr< serviceregistry::ServicesManager > manager_
Definition: ServiceRegistry.h:142
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:107
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:99
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:118
edm::ServiceRegistry
Definition: ServiceRegistry.h:38
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40
edm::ServiceRegistry::isAvailable
bool isAvailable() const
Definition: ServiceRegistry.h:72
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