Converter.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_CONVERTER_H
2 #define GAUDIKERNEL_CONVERTER_H
3 
4 // generic experiment headers
7 #include "GaudiKernel/IService.h"
11 
12 // Forward declarations
13 class IMessageSvc;
14 class IRegistry;
15 
24 class GAUDI_API Converter : public implements<IConverter> {
25 public:
26 #ifndef __REFLEX__
29 #endif
30 
32  StatusCode initialize() override;
33 
35  StatusCode finalize() override;
36 
38  StatusCode setDataProvider(IDataProviderSvc* svc) override;
39 
41  SmartIF<IDataProviderSvc>& dataProvider() const override;
42 
44  StatusCode setConversionSvc(IConversionSvc* svc) override;
45 
47  SmartIF<IConversionSvc>& conversionSvc() const override;
48 
50  StatusCode setAddressCreator(IAddressCreator* creator) override;
51 
53  SmartIF<IAddressCreator>& addressCreator() const override;
54 
56  const CLID& objType() const override;
57 
59  // MSF: Masked to generate compiler error due to interface change
60  virtual long i_repSvcType() const;
61 
63  StatusCode createObj(IOpaqueAddress* pAddress,DataObject*& refpObject) override;
64 
66  StatusCode fillObjRefs(IOpaqueAddress* pAddress, DataObject* pObject) override;
67 
69  StatusCode updateObj(IOpaqueAddress* pAddress, DataObject* refpObject) override;
70 
72  StatusCode updateObjRefs(IOpaqueAddress* pAddress, DataObject* pObject) override;
73 
75  StatusCode createRep(DataObject* pObject, IOpaqueAddress*& refpAddress) override;
76 
78  StatusCode fillRepRefs(IOpaqueAddress* pAddress,DataObject* pObject) override;
79 
81  StatusCode updateRep(IOpaqueAddress* pAddress, DataObject* pObject) override;
82 
84  StatusCode updateRepRefs(IOpaqueAddress* pAddress, DataObject* pObject) override;
85 
87  Converter(long storage_type, const CLID& class_type, ISvcLocator* svc = 0);
88 
90  template <class T>
91  StatusCode service( const std::string& name, T*& psvc, bool createIf = false ) const {
92  return service_i(name, createIf, T::interfaceID(), (void**)&psvc);
93  }
94 
96  template <class T>
97  StatusCode service( const std::string& type, const std::string& name, T*& psvc) const {
98  return service_i(type, name, T::interfaceID(), (void**)&psvc);
99  }
100 
102  SmartIF<IService> service(const std::string& name, const bool createIf = true) const;
103 
104 protected:
105 
107  ~Converter() override = default;
108 
110  SmartIF<ISvcLocator>& serviceLocator() const;
112  SmartIF<IMessageSvc>& msgSvc() const;
113  // Obsoleted name, kept due to the backwards compatibility
114  SmartIF<IMessageSvc>& messageService() const;
116  SmartIF<IDataManagerSvc>& dataManager() const;
117 
118 private:
119 
136 
138  StatusCode service_i(const std::string& svcName,
139  bool createIf,
140  const InterfaceID& iid,
141  void** ppSvc) const;
142  StatusCode service_i(const std::string& svcType,
143  const std::string& svcName,
144  const InterfaceID& iid,
145  void** ppSvc) const;
146 };
147 
148 
149 // Identified class for converters' factories
150 class GAUDI_API ConverterID final{
151 public:
152  ConverterID( long stype, CLID clid ) : m_stype(stype), m_clid(clid) {}
153  inline bool operator ==(const ConverterID& id) const {
154  return m_stype == id.m_stype && m_clid == id.m_clid;
155  }
156 private:
158  long m_stype;
160 };
161 
163  return s << "CNV_" << id.m_stype << "_" << id.m_clid;
164 }
165 
166 
167 #ifndef GAUDI_NEW_PLUGIN_SERVICE
168 template <class T>
169 class CnvFactory final {
170 public:
171 #ifndef __REFLEX__
172  template <typename S, typename... Args>
173  static typename S::ReturnType create(Args&&... a1) {
174  return new T(std::forward<Args>(a1)...);
175  }
176 #endif
177 };
178 
179 // Macro to declare component factories
180 #define DECLARE_CONVERTER_FACTORY(x) \
181  DECLARE_FACTORY_WITH_CREATOR_AND_ID(x, CnvFactory< x >, \
182  ConverterID(x::storageType(), x::classID()), Converter::Factory)
183 #define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x) \
184  DECLARE_CONVERTER_FACTORY(n::x)
185 
186 #else
187 
188 // Macro to declare component factories
189 #define DECLARE_CONVERTER_FACTORY(x) \
190  DECLARE_COMPONENT_WITH_ID(x, ConverterID(x::storageType(), x::classID()))
191 #define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x) \
192  DECLARE_CONVERTER_FACTORY(n::x)
193 
194 #endif
195 
196 #endif // GAUDIKERNEL_CONVERTER_H
SmartIF< IAddressCreator > m_addressCreator
Pointer to the address creation service interface.
Definition: Converter.h:125
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference.
Definition: Converter.h:133
Base class used to implement the interfaces.
Definition: implements.h:9
def initialize()
Definition: AnalysisTest.py:12
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
The data converters are responsible to translate data from one representation into another...
Definition: IConverter.h:57
CLID m_clid
Definition: Converter.h:159
SmartIF< IDataManagerSvc > m_dataManager
Pointer to data manager service.
Definition: Converter.h:129
IAddressCreator interface definition.
std::ostream & operator<<(std::ostream &s, const ConverterID &id)
Definition: Converter.h:162
SmartIF< IMessageSvc > m_messageSvc
MessageSvc reference.
Definition: Converter.h:135
static S::ReturnType create(Args &&...a1)
Definition: Converter.h:173
long m_stype
Definition: Converter.h:158
Data provider interface definition.
STL class.
SmartIF< IConversionSvc > m_conversionSvc
Pointer to the connected conversion service.
Definition: Converter.h:131
Interface ID class.
Definition: IInterface.h:30
long m_storageType
Storage type.
Definition: Converter.h:121
string type
Definition: gaudirun.py:151
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
Definition: Allocator.h:249
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode service(const std::string &name, T *&psvc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Converter.h:91
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
const CLID m_classType
Class type the converter can handle.
Definition: Converter.h:123
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
ConverterID(long stype, CLID clid)
Definition: Converter.h:152
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Converter base class.
Definition: Converter.h:24
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
string s
Definition: gaudirun.py:245
Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
Definition: Converter.h:28
StatusCode service(const std::string &type, const std::string &name, T *&psvc) const
Access a service by name, type creating it if it doesn't already exist.
Definition: Converter.h:97
Opaque address interface definition.
#define GAUDI_API
Definition: Kernel.h:107
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
STL class.
SmartIF< IDataProviderSvc > m_dataProvider
Pointer to data provider service.
Definition: Converter.h:127