CMS 3D CMS Logo

ServiceMaker.h
Go to the documentation of this file.
1 #ifndef FWCore_ServiceRegistry_ServiceMaker_h
2 #define FWCore_ServiceRegistry_ServiceMaker_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : ServiceMaker
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon Sep 5 13:33:00 EDT 2005
19 //
20 
21 // user include files
28 
29 // system include files
30 #include <memory>
31 #include <typeinfo>
32 
33 // forward declarations
34 
35 namespace edm {
36  class ActivityRegistry;
37  class ParameterSet;
38 
39  namespace serviceregistry {
40 
41  template <typename T, typename TConcrete>
42  struct MakerBase {
43  typedef T interface_t;
44  typedef TConcrete concrete_t;
45  };
46 
47  template <typename T, typename TConcrete = T>
48  struct AllArgsMaker : public MakerBase<T, TConcrete> {
49  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& iAR) const {
50  return std::make_unique<TConcrete>(iPS, iAR);
51  }
52  };
53 
54  template <typename T, typename TConcrete = T>
55  struct ParameterSetMaker : public MakerBase<T, TConcrete> {
56  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& /* iAR */) const {
57  return std::make_unique<TConcrete>(iPS);
58  }
59  };
60 
61  template <typename T, typename TConcrete = T>
62  struct NoArgsMaker : public MakerBase<T, TConcrete> {
63  std::unique_ptr<T> make(ParameterSet const& /* iPS */, ActivityRegistry& /* iAR */) const {
64  return std::make_unique<TConcrete>();
65  }
66  };
67 
68  template <typename T, typename TMaker = AllArgsMaker<T> >
69  class ServiceMaker : public ServiceMakerBase {
70  public:
72 
73  ServiceMaker(ServiceMaker const&) = delete;
74  ServiceMaker const& operator=(ServiceMaker const&) = delete;
75 
76  // ---------- const member functions ---------------------
77  std::type_info const& serviceType() const override { return typeid(T); }
78 
79  bool make(ParameterSet const& iPS, ActivityRegistry& iAR, ServicesManager& oSM) const override {
80  TMaker maker;
81  std::unique_ptr<T> pService(maker.make(iPS, iAR));
82  auto ptr = std::make_shared<ServiceWrapper<T> >(std::move(pService));
83  return oSM.put(ptr);
84  }
85 
86  bool saveConfiguration() const override {
87  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(nullptr));
88  }
89 
90  bool processWideService() const override {
91  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(nullptr));
92  }
93  };
94  } // namespace serviceregistry
95 } // namespace edm
96 
97 #define DEFINE_FWK_SERVICE(type) \
98  DEFINE_EDM_PLUGIN( \
99  edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, EDM_STRINGIZE(type)); \
100  DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
101 
102 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
103  typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete##__t; \
104  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, concrete##__t, #concrete); \
105  typedef maker::concrete_t concrete##___t; \
106  DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete##___t)
107 
108 #endif
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:49
bool put(std::shared_ptr< ServiceWrapper< T >> iPtr)
returns false if put fails because a service of this type already exists
ServiceMaker const & operator=(ServiceMaker const &)=delete
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:98
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:56
std::unique_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:63
std::type_info const & serviceType() const override
Definition: ServiceMaker.h:77
bool processWideService() const override
Definition: ServiceMaker.h:90
HLT enums.
bool saveConfiguration() const override
Definition: ServiceMaker.h:86
long double T
bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const override
Definition: ServiceMaker.h:79
def move(src, dest)
Definition: eostools.py:511
bool testSaveConfiguration(SaveConfiguration const *) const