File indexing completed on 2025-01-30 10:07:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_IUPDATEMANAGERSVC_H
0012 #define GAUDIKERNEL_IUPDATEMANAGERSVC_H 1
0013
0014
0015
0016 #include <string>
0017 #include <typeinfo>
0018
0019
0020 #include "GaudiKernel/IInterface.h"
0021
0022
0023 class DataObject;
0024 class ValidDataObject;
0025 class IUpdateManagerSvc;
0026 class IDataProviderSvc;
0027 class IDetDataSvc;
0028 namespace Gaudi {
0029 class Time;
0030 }
0031
0032
0033
0034
0035
0036
0037
0038
0039 class BaseObjectMemberFunction {
0040 public:
0041
0042 virtual ~BaseObjectMemberFunction() = default;
0043
0044 virtual StatusCode operator()() const = 0;
0045
0046 virtual BaseObjectMemberFunction* makeCopy() const = 0;
0047
0048 virtual const std::type_info& type() const = 0;
0049
0050 virtual bool match( BaseObjectMemberFunction* ) const = 0;
0051
0052 virtual DataObject* castToDataObject() const = 0;
0053 virtual ValidDataObject* castToValidDataObject() const = 0;
0054 virtual void* castToVoid() const = 0;
0055 };
0056
0057
0058
0059
0060
0061
0062
0063
0064 template <class CallerClass>
0065 class ObjectMemberFunction final : public BaseObjectMemberFunction {
0066 public:
0067
0068 typedef StatusCode ( CallerClass::*MemberFunctionType )();
0069
0070
0071
0072 StatusCode operator()() const override {
0073 return m_memberFunction ? ( m_instance->*m_memberFunction )() : StatusCode::SUCCESS;
0074 }
0075
0076
0077
0078 BaseObjectMemberFunction* makeCopy() const override {
0079 return new ObjectMemberFunction{ m_instance, m_memberFunction };
0080 }
0081
0082
0083 const std::type_info& type() const override { return typeid( CallerClass ); }
0084
0085
0086 bool match( BaseObjectMemberFunction* bmf ) const override {
0087 if ( bmf == (BaseObjectMemberFunction*)this ) return true;
0088 if ( type() == bmf->type() ) {
0089 ObjectMemberFunction* mf = dynamic_cast<ObjectMemberFunction*>( bmf );
0090 return m_instance == mf->m_instance && m_memberFunction == mf->m_memberFunction;
0091 }
0092 return false;
0093 }
0094
0095
0096 DataObject* castToDataObject() const override { return dynamic_cast<DataObject*>( m_instance ); }
0097
0098
0099 ValidDataObject* castToValidDataObject() const override { return dynamic_cast<ValidDataObject*>( m_instance ); }
0100
0101
0102 void* castToVoid() const override { return dynamic_cast<void*>( m_instance ); }
0103
0104 protected:
0105
0106 ObjectMemberFunction( CallerClass* instance, const MemberFunctionType& mf )
0107 : m_instance( instance ), m_memberFunction( mf ) {}
0108
0109
0110 CallerClass* m_instance;
0111
0112
0113 MemberFunctionType m_memberFunction;
0114
0115 friend class IUpdateManagerSvc;
0116 };
0117
0118
0119
0120
0121
0122
0123
0124
0125 class BasePtrSetter {
0126 public:
0127
0128 virtual ~BasePtrSetter() = default;
0129
0130 virtual void set( DataObject* ) = 0;
0131
0132 virtual bool isNull() = 0;
0133 };
0134
0135
0136
0137
0138
0139
0140
0141
0142 class GAUDI_API IUpdateManagerSvc : virtual public IInterface {
0143 private:
0144
0145
0146
0147
0148 template <class ActualType>
0149 class PtrSetter final : public BasePtrSetter {
0150 public:
0151 using dest_type = ActualType;
0152 PtrSetter( dest_type*& dest ) : m_storage( &dest ) { *m_storage = nullptr; }
0153 void set( DataObject* obj ) override { *m_storage = dynamic_cast<dest_type*>( obj ); }
0154 bool isNull() override { return *m_storage == nullptr; }
0155
0156 private:
0157
0158 dest_type** m_storage;
0159 };
0160
0161 public:
0162
0163 DeclareInterfaceID( IUpdateManagerSvc, 2, 0 );
0164
0165
0166 virtual IDataProviderSvc* dataProvider() const = 0;
0167
0168
0169 virtual IDetDataSvc* detDataSvc() const = 0;
0170
0171
0172
0173
0174
0175
0176
0177 template <class CallerClass>
0178 inline void registerCondition( CallerClass* instance, const std::string& condition = "",
0179 typename ObjectMemberFunction<CallerClass>::MemberFunctionType mf = nullptr ) {
0180 i_registerCondition( condition, new ObjectMemberFunction{ instance, mf } );
0181 }
0182
0183 template <class CallerClass, class CondType>
0184 inline void registerCondition( CallerClass* instance, const std::string& condition,
0185 typename ObjectMemberFunction<CallerClass>::MemberFunctionType mf,
0186 CondType*& condPtrDest ) {
0187 i_registerCondition( condition, new ObjectMemberFunction{ instance, mf }, new PtrSetter{ condPtrDest } );
0188 }
0189
0190
0191 template <class CallerClass>
0192 inline void registerCondition( CallerClass* instance, const char* condition,
0193 typename ObjectMemberFunction<CallerClass>::MemberFunctionType mf = nullptr ) {
0194 i_registerCondition( std::string( condition ), new ObjectMemberFunction{ instance, mf } );
0195 }
0196
0197
0198
0199
0200 template <class CallerClass, class ObjectClass>
0201 inline void registerCondition( CallerClass* instance, ObjectClass* obj,
0202 typename ObjectMemberFunction<CallerClass>::MemberFunctionType mf = nullptr ) {
0203 i_registerCondition( dynamic_cast<void*>( obj ), new ObjectMemberFunction{ instance, mf } );
0204 }
0205
0206
0207
0208
0209 template <class CallerClass>
0210 inline void unregister( CallerClass* instance ) {
0211 i_unregister( dynamic_cast<void*>( instance ) );
0212 }
0213
0214
0215
0216 template <class CallerClass>
0217 inline void invalidate( CallerClass* instance ) {
0218 i_invalidate( dynamic_cast<void*>( instance ) );
0219 }
0220
0221
0222
0223 virtual bool getValidity( const std::string path, Gaudi::Time& since, Gaudi::Time& until,
0224 bool path_to_db = false ) = 0;
0225
0226
0227
0228
0229
0230 virtual void setValidity( const std::string path, const Gaudi::Time& since, const Gaudi::Time& until,
0231 bool path_to_db = false ) = 0;
0232
0233
0234 virtual StatusCode newEvent() = 0;
0235
0236
0237
0238 virtual StatusCode newEvent( const Gaudi::Time& ) = 0;
0239
0240
0241
0242 template <class CallerClass>
0243 inline StatusCode update( CallerClass* instance ) {
0244 return i_update( dynamic_cast<void*>( instance ) );
0245 }
0246
0247
0248 virtual void dump() = 0;
0249
0250
0251 virtual void acquireLock() = 0;
0252
0253 virtual void releaseLock() = 0;
0254
0255
0256
0257
0258 virtual void purge() = 0;
0259
0260
0261
0262
0263
0264 class PythonHelper;
0265
0266 protected:
0267
0268 virtual void i_registerCondition( const std::string& condition, BaseObjectMemberFunction* mf,
0269 BasePtrSetter* ptr_dest = nullptr ) = 0;
0270 virtual void i_registerCondition( void* obj, BaseObjectMemberFunction* mf ) = 0;
0271 virtual StatusCode i_update( void* instance ) = 0;
0272 virtual void i_unregister( void* instance ) = 0;
0273 virtual void i_invalidate( void* instance ) = 0;
0274
0275 friend class PythonHelper;
0276 };
0277 #endif