Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:08:58

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_DATASVC_H
0012 #define GAUDIKERNEL_DATASVC_H
0013 
0014 // Include files
0015 #include "GaudiKernel/DataStoreItem.h"
0016 #include "GaudiKernel/IConversionSvc.h"
0017 #include "GaudiKernel/IDataManagerSvc.h"
0018 #include "GaudiKernel/IDataProviderSvc.h"
0019 #include "GaudiKernel/IIncidentSvc.h"
0020 #include "GaudiKernel/RegistryEntry.h"
0021 #include "GaudiKernel/Service.h"
0022 #include "GaudiKernel/SmartIF.h"
0023 
0024 #include <string_view>
0025 
0026 // Forward declarations
0027 // Incident service
0028 class IIncidentSvc;
0029 // Generic address
0030 class IOpaqueAddress;
0031 // Generic interface to data object class
0032 class DataObject;
0033 // Data store agent
0034 class IDataStoreAgent;
0035 
0036 // Do not clutter global namespace for helpers...
0037 namespace DataSvcHelpers {
0038   // Map of objects where loading is inhibited
0039   class InhibitMap;
0040 } // namespace DataSvcHelpers
0041 
0042 /**
0043  * @class DataSvc DataSvc.h GaudiKernel/DataSvc.h
0044  *
0045  * Data service base class. A data service manages the transient data stores
0046  * and implements the IDataProviderSvc and IDataManagerSvc interfaces.
0047  *
0048  * @author Markus Frank
0049  * @author Sebastien Ponce
0050  * @version 1.0
0051  */
0052 class GAUDI_API DataSvc : public extends<Service, IDataProviderSvc, IDataManagerSvc> {
0053 
0054   /// Pointer to data loader service
0055   SmartIF<IConversionSvc> m_dataLoader = nullptr;
0056 
0057 protected:
0058   /// Pointer to incident service
0059   SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
0060 
0061   Gaudi::Property<CLID>        m_rootCLID{ this, "RootCLID", 110 /*CLID_Event*/, "CLID of root entry" };
0062   Gaudi::Property<std::string> m_rootName{ this, "RootName", "/Event", "name of root entry" };
0063 
0064 private:
0065   Gaudi::Property<bool>                     m_forceLeaves{ this, "ForceLeaves", false,
0066                                        "force creation of default leaves on registerObject" };
0067   Gaudi::Property<std::vector<std::string>> m_inhibitPathes{ this, "InhibitPathes", {}, "inhibited leaves" };
0068 
0069   Gaudi::Property<bool>        m_enableFaultHdlr{ this, "EnableFaultHandler", false,
0070                                            "enable incidents on data creation requests" };
0071   Gaudi::Property<std::string> m_faultName{ this, "DataFaultName", "DataFault", "Name of the data fault incident" };
0072 
0073   Gaudi::Property<bool>        m_enableAccessHdlr{ this, "EnableAccessHandler", false,
0074                                             "enable incidents on data access requests" };
0075   Gaudi::Property<std::string> m_accessName{ this, "DataAccessName", "DataAccess", "Name of the data access incident" };
0076 
0077   /// Items to be pre-loaded
0078   std::vector<DataStoreItem> m_preLoads;
0079 
0080 protected:
0081   /// Pointer to root entry
0082   std::unique_ptr<DataSvcHelpers::RegistryEntry> m_root;
0083 
0084 public:
0085   /// IDataManagerSvc: Accessor for root event CLID
0086   CLID rootCLID() const override;
0087 
0088   /// IDataManagerSvc: Accessor for root event name
0089   const std::string& rootName() const override;
0090 
0091   /// IDataManagerSvc: Register object address with the data store.
0092   StatusCode registerAddress( std::string_view fullPath, IOpaqueAddress* pAddress ) override;
0093 
0094   using IDataManagerSvc::registerAddress;
0095 
0096   /// IDataManagerSvc: Register object address with the data store.
0097   StatusCode registerAddress( IRegistry* parentObj, std::string_view objectPath, IOpaqueAddress* pAddress ) override;
0098 
0099   using IDataManagerSvc::unregisterAddress;
0100 
0101   /// IDataManagerSvc: Unregister object address from the data store.
0102   StatusCode unregisterAddress( std::string_view fullPath ) override;
0103 
0104   /// IDataManagerSvc: Unregister object address from the data store.
0105   StatusCode unregisterAddress( IRegistry* pParent, std::string_view objPath ) override;
0106 
0107   /** IDataManagerSvc: Explore the object store: retrieve all leaves attached
0108    *  to the object
0109    */
0110   StatusCode objectLeaves( const DataObject* pObject, std::vector<IRegistry*>& refLeaves ) override;
0111   /** IDataManagerSvc: Explore the object store: retrieve all leaves attached
0112    *  to the object
0113    */
0114   StatusCode objectLeaves( const IRegistry* pRegistry, std::vector<IRegistry*>& refLeaves ) override;
0115 
0116   /// IDataManagerSvc: Explore the object store: retrieve the object's parent
0117   StatusCode objectParent( const DataObject* pObject, IRegistry*& refpParent ) override;
0118   /// IDataManagerSvc: Explore the object store: retrieve the object's parent
0119   StatusCode objectParent( const IRegistry* pRegistry, IRegistry*& refpParent ) override;
0120 
0121   /** IDataManagerSvc: Remove all data objects below the sub tree identified
0122    *  by its full path name.
0123    */
0124   StatusCode clearSubTree( std::string_view sub_tree_path ) override;
0125 
0126   /** IDataManagerSvc: Remove all data objects below the sub tree identified
0127    *  by the object.
0128    */
0129   StatusCode clearSubTree( DataObject* pObject ) override;
0130 
0131   /// IDataManagerSvc: Remove all data objects in the data store.
0132   StatusCode clearStore() override;
0133 
0134   /** IDataManagerSvc: Analyze by traversing all data objects below the sub
0135    *  tree identified by its full path name.
0136    */
0137   StatusCode traverseSubTree( std::string_view sub_tree_path, IDataStoreAgent* pAgent ) override;
0138 
0139   /// IDataManagerSvc: Analyze by traversing all data objects below the sub tree
0140   StatusCode traverseSubTree( DataObject* pObject, IDataStoreAgent* pAgent ) override;
0141 
0142   /// IDataManagerSvc: Analyze by traversing all data objects in the data store.
0143   StatusCode traverseTree( IDataStoreAgent* pAgent ) override;
0144 
0145   /** Initialize data store for new event by giving new event path and root
0146       object. Takes care to clear the store before reinitializing it  */
0147   StatusCode setRoot( std::string root_name, DataObject* pRootObj ) override;
0148 
0149   /** Initialize data store for new event by giving new event path and root
0150       object. Does not clear the store before reinitializing it. This could
0151       lead to errors and should be handle with care. Use setRoot if unsure */
0152   virtual StatusCode i_setRoot( std::string root_name, DataObject* pRootObj );
0153 
0154   /** Initialize data store for new event by giving new event path and address
0155       of root object. Takes care to clear the store before reinitializing it */
0156   StatusCode setRoot( std::string root_path, IOpaqueAddress* pRootAddr ) override;
0157 
0158   /** Initialize data store for new event by giving new event path and address
0159    *  of root object. Does not clear the store before reinitializing it. This
0160    *  could lead to errors and should be handle with care. Use setRoot if unsure
0161    */
0162   virtual StatusCode i_setRoot( std::string root_path, IOpaqueAddress* pRootAddr );
0163 
0164   /** IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the
0165    *  service and optionally a data provider
0166    */
0167   StatusCode setDataLoader( IConversionSvc* svc, IDataProviderSvc* dpsvc = nullptr ) override;
0168 
0169   /// Add an item to the preload list
0170   StatusCode addPreLoadItem( const DataStoreItem& item ) override;
0171 
0172   /// Remove an item from the preload list
0173   StatusCode removePreLoadItem( const DataStoreItem& item ) override;
0174 
0175   /// Clear the preload list
0176   StatusCode resetPreLoad() override;
0177 
0178   /** Execute one level of preloading and recursively load until the
0179       final level is reached.
0180       @param   depth        current level of loading from requested parent
0181       @param   load_depth   maximum level of object loading
0182       @param   pObject      pointer to next level root object
0183       @return  Status code indicating success or failure.
0184   */
0185   virtual StatusCode preLoad( int depth, int load_depth, DataObject* pObject );
0186 
0187   /// load all preload items of the list
0188   StatusCode preLoad() override;
0189 
0190   using IDataProviderSvc::registerObject;
0191 
0192   /// Register object with the data store.
0193   StatusCode registerObject( std::string_view parentPath, std::string_view objPath, DataObject* pObject ) override;
0194 
0195   /// Register object with the data store.
0196   StatusCode registerObject( DataObject* parentObj, std::string_view objPath, DataObject* pObject ) override;
0197 
0198   /// Unregister object from the data store.
0199   StatusCode unregisterObject( std::string_view fullPath ) override;
0200 
0201   /// Unregister object from the data store.
0202   StatusCode unregisterObject( DataObject* pObject ) override;
0203 
0204   /// Unregister object from the data store.
0205   StatusCode unregisterObject( DataObject* pObject, std::string_view objectPath ) override;
0206 
0207   using IDataProviderSvc::retrieveObject;
0208 
0209   /// Retrieve object from data store.
0210   StatusCode retrieveObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
0211 
0212   using IDataProviderSvc::findObject;
0213 
0214   /// Find object identified by its full path in the data store.
0215   StatusCode findObject( std::string_view fullPath, DataObject*& pObject ) override;
0216 
0217   /// Find object identified by its full path in the data store.
0218   StatusCode findObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
0219 
0220   using IDataProviderSvc::linkObject;
0221 
0222   /// Add a link to another object.
0223   StatusCode linkObject( IRegistry* from, std::string_view objPath, DataObject* to ) override;
0224 
0225   /// Add a link to another object.
0226   StatusCode linkObject( std::string_view fullPath, DataObject* to ) override;
0227 
0228   using IDataProviderSvc::unlinkObject;
0229 
0230   /// Remove a link to another object.
0231   StatusCode unlinkObject( IRegistry* from, std::string_view objPath ) override;
0232 
0233   /// Remove a link to another object.
0234   StatusCode unlinkObject( DataObject* fromObj, std::string_view objPath ) override;
0235 
0236   /// Remove a link to another object.
0237   StatusCode unlinkObject( std::string_view fullPath ) override;
0238 
0239   /// Update object identified by its directory entry.
0240   StatusCode updateObject( IRegistry* pDirectory ) override;
0241 
0242   /// Update object.
0243   StatusCode updateObject( DataObject* toUpdate ) override;
0244 
0245   /// Service initialization
0246   StatusCode initialize() override;
0247 
0248   /// Service initialization
0249   StatusCode reinitialize() override;
0250 
0251   /// Service initialization
0252   StatusCode finalize() override;
0253 
0254   /// inherit contructor
0255   using extends::extends;
0256 
0257   /// copy constructor disabled
0258   DataSvc( const DataSvc& ) = delete;
0259   /// Fake assignment operator (never implemented).
0260   DataSvc& operator=( const DataSvc& ) = delete;
0261 
0262 protected:
0263   /// Check if root path is valid
0264   bool checkRoot() { return 0 != m_root; }
0265 
0266   /** Retrieve customizable data loader according to registry entry to be
0267    *  retrieved
0268    */
0269   virtual IConversionSvc* getDataLoader( IRegistry* pReg );
0270 
0271   /// Create default objects in case forced creation of leaves is requested
0272   virtual DataObject* createDefaultObject() const;
0273 
0274   /** Invoke Persistency service to create transient object from its
0275    *  persistent representation
0276    */
0277   virtual StatusCode loadObject( IRegistry* pNode );
0278 
0279   /** Invoke Persistency service to create transient object from its
0280    *  persistent representation
0281    */
0282   virtual StatusCode loadObject( IConversionSvc* pLoader, IRegistry* pNode );
0283 
0284   /// Retrieve registry entry from store
0285   StatusCode retrieveEntry( DataSvcHelpers::RegistryEntry* pNode, std::string_view path,
0286                             DataSvcHelpers::RegistryEntry*& pEntry );
0287   /** Invoke data fault handling if enabled
0288    * @param pReg  [IN]   Pointer to missing registry entry
0289    * @param path  [IN]   Sub-path of requested object from pReg
0290    *
0291    * @return Object corresponding to the specified leaf
0292    */
0293   DataObject* handleDataFault( IRegistry* pReg, std::string_view path = "" );
0294 
0295 private:
0296   StatusCode  i_retrieveEntry( DataSvcHelpers::RegistryEntry* parentObj, std::string_view path,
0297                                DataSvcHelpers::RegistryEntry*& pEntry );
0298   DataObject* i_handleDataFault( IRegistry* pReg, std::string_view path = std::string_view{} );
0299 };
0300 #endif // GAUDIKERNEL_DATASVC_H