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 
72  ServiceMaker(ServiceMaker const&) = delete;
73  ServiceMaker const& operator=(ServiceMaker const&) = delete;
74 
75  // ---------- const member functions ---------------------
76  std::type_info const& serviceType() const override { return typeid(T); }
77 
78  bool make(ParameterSet const& iPS, ActivityRegistry& iAR, ServicesManager& oSM) const override {
79  TMaker maker;
80  std::unique_ptr<T> pService(maker.make(iPS, iAR));
81  auto ptr = std::make_shared<ServiceWrapper<T> >(std::move(pService));
82  return oSM.put(ptr);
83  }
84 
85  bool saveConfiguration() const override {
86  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(nullptr));
87  }
88 
89  bool processWideService() const override {
90  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(nullptr));
91  }
92  };
93  } // namespace serviceregistry
94 } // namespace edm
95 
96 #define DEFINE_FWK_SERVICE(type) \
97  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, #type); \
98  DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
99 
100 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
101  typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete##_##_t; \
102  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, concrete##_##_t, #concrete); \
103  typedef maker::concrete_t concrete##_##_##_t; \
104  DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete##_##_##_t)
105 
106 #endif
ServicePluginFactory.h
edm::serviceregistry::ServicesManager::put
bool put(std::shared_ptr< ServiceWrapper< T >> iPtr)
returns false if put fails because a service of this type already exists
Definition: ServicesManager.h:127
edm::serviceregistry::ParameterSetMaker
Definition: ServiceMaker.h:54
edm::serviceregistry::ServiceMaker::make
bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const override
Definition: ServiceMaker.h:78
edm::serviceregistry::ServiceMaker
Definition: ServiceMaker.h:68
ActivityRegistry
edm::serviceregistry::ServiceMakerBase::testSaveConfiguration
bool testSaveConfiguration(SaveConfiguration const *) const
Definition: ServiceMakerBase.h:58
edm::serviceregistry::ServiceMakerBase
Definition: ServiceMakerBase.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::serviceregistry::ServicesManager
Definition: ServicesManager.h:44
edm::serviceregistry::ServiceMaker::serviceType
std::type_info const & serviceType() const override
Definition: ServiceMaker.h:76
edm::service::isProcessWideService
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:98
ParameterSetDescriptionFillerPluginFactory.h
edm::serviceregistry::AllArgsMaker
Definition: ServiceMaker.h:47
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
edm::serviceregistry::MakerBase::interface_t
T interface_t
Definition: ServiceMaker.h:42
edm::serviceregistry::ServiceMaker::ServiceMaker
ServiceMaker()
Definition: ServiceMaker.h:70
ServiceWrapper.h
edm::ParameterSet
Definition: ParameterSet.h:47
edm::serviceregistry::ServiceMaker::processWideService
bool processWideService() const override
Definition: ServiceMaker.h:89
ParameterSet
Definition: Functions.h:16
edm::serviceregistry::ServiceMaker::operator=
ServiceMaker const & operator=(ServiceMaker const &)=delete
ServiceMakerBase.h
edm::serviceregistry::NoArgsMaker
Definition: ServiceMaker.h:61
edm::serviceregistry::ParameterSetMaker::make
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:55
edm::serviceregistry::MakerBase
Definition: ServiceMaker.h:41
edm::serviceregistry::ServiceMaker::saveConfiguration
bool saveConfiguration() const override
Definition: ServiceMaker.h:85
edm::serviceregistry::MakerBase::concrete_t
TConcrete concrete_t
Definition: ServiceMaker.h:43
eostools.move
def move(src, dest)
Definition: eostools.py:511
ServicesManager.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::serviceregistry::NoArgsMaker::make
std::unique_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:62
edm::serviceregistry::AllArgsMaker::make
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:48