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
27 
28 // system include files
29 #include <memory>
30 #include <typeinfo>
31 
32 // forward declarations
33 
34 namespace edm {
35  class ActivityRegistry;
36  class ParameterSet;
37 
38  namespace serviceregistry {
39 
40  template <typename T, typename TConcrete>
41  struct MakerBase {
42  typedef T interface_t;
43  typedef TConcrete concrete_t;
44  };
45 
46  template <typename T, typename TConcrete = T>
47  struct AllArgsMaker : public MakerBase<T, TConcrete> {
48  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& iAR) const {
49  return std::make_unique<TConcrete>(iPS, iAR);
50  }
51  };
52 
53  template <typename T, typename TConcrete = T>
54  struct ParameterSetMaker : public MakerBase<T, TConcrete> {
55  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& /* iAR */) const {
56  return std::make_unique<TConcrete>(iPS);
57  }
58  };
59 
60  template <typename T, typename TConcrete = T>
61  struct NoArgsMaker : public MakerBase<T, TConcrete> {
62  std::unique_ptr<T> make(ParameterSet const& /* iPS */, ActivityRegistry& /* iAR */) const {
63  return std::make_unique<TConcrete>();
64  }
65  };
66 
67  template <typename T, typename TMaker = AllArgsMaker<T> >
68  class ServiceMaker : public ServiceMakerBase {
69  public:
71  //virtual ~ServiceMaker();
72 
73  // ---------- const member functions ---------------------
74  std::type_info const& serviceType() const override { return typeid(T); }
75 
76  bool make(ParameterSet const& iPS, ActivityRegistry& iAR, ServicesManager& oSM) const override {
77  TMaker maker;
78  std::unique_ptr<T> pService(maker.make(iPS, iAR));
79  auto ptr = std::make_shared<ServiceWrapper<T> >(std::move(pService));
80  return oSM.put(ptr);
81  }
82 
83  bool saveConfiguration() const override {
84  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(nullptr));
85  }
86 
87  bool processWideService() const override {
88  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(nullptr));
89  }
90 
91  // ---------- static member functions --------------------
92 
93  // ---------- member functions ---------------------------
94 
95  private:
96  ServiceMaker(ServiceMaker const&) = delete; // stop default
97 
98  ServiceMaker const& operator=(ServiceMaker const&) = delete; // stop default
99 
100  // ---------- member data --------------------------------
101  };
102  } // namespace serviceregistry
103 } // namespace edm
104 
105 #define DEFINE_FWK_SERVICE(type) \
106  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, #type); \
107  DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
108 
109 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
110  typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete##_##_t; \
111  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, concrete##_##_t, #concrete); \
112  typedef maker::concrete_t concrete##_##_##_t; \
113  DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete##_##_##_t)
114 
115 #endif
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:48
bool put(std::shared_ptr< ServiceWrapper< T >> iPtr)
returns false if put fails because a service of this type already exists
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:99
bool testSaveConfiguration(SaveConfiguration const *) const
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:55
bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const override
Definition: ServiceMaker.h:76
bool processWideService() const override
Definition: ServiceMaker.h:87
bool saveConfiguration() const override
Definition: ServiceMaker.h:83
HLT enums.
long double T
std::unique_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:62
def move(src, dest)
Definition: eostools.py:511
std::type_info const & serviceType() const override
Definition: ServiceMaker.h:74