Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:37

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