Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:09:04

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2021 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_REGISTRYENTRY_H
0012 #define GAUDIKERNEL_REGISTRYENTRY_H
0013 
0014 // Framework include files
0015 #include "GaudiKernel/IRegistry.h"
0016 #include "GaudiKernel/Kernel.h"
0017 #include "GaudiKernel/StatusCode.h"
0018 
0019 // STL include files
0020 #include <string_view>
0021 #include <vector>
0022 
0023 // Forward declarations
0024 class DataSvc;
0025 // DP add this fwd decl for thread safety
0026 class TsDataSvc;
0027 class DataObject;
0028 class IDataProviderSvc;
0029 class IOpaqueAddress;
0030 class IDataStoreAgent;
0031 
0032 namespace DataSvcHelpers {
0033   /**
0034    * @class RegistryEntry RegistryEntry.h GaudiKernel/RegistryEntry.h
0035    *
0036    * Definition of an entry in the transient data store.
0037    *
0038    * The RegistryEntry represents an entry of the transient data store.
0039    * The object holds the recipe how to retrieve objects from the persistent
0040    * world (member IOpaqueAddress) as well as the backward link to the
0041    * parent entry and the leaves.
0042    *
0043    * @author Markus Frank
0044    * @author Sebastien Ponce
0045    */
0046   class GAUDI_API RegistryEntry final : public IRegistry {
0047   private:
0048     /// Definition of datastore type
0049     typedef std::vector<IRegistry*> Store;
0050 
0051   public:
0052     friend class ::DataSvc;
0053     // DP add friend class: the thread safe version of the DataSvc
0054     friend class ::TsDataSvc;
0055     /// Iterator definition
0056     typedef Store::const_iterator Iterator;
0057 
0058   private:
0059     /// Reference counter
0060     unsigned long m_refCount = 0;
0061     /// Is the link soft or hard?
0062     bool m_isSoft = false;
0063     /// String containing full path of the object (volatile)
0064     std::string m_fullpath;
0065     /// Path name
0066     std::string m_path;
0067     /// Pointer to parent
0068     RegistryEntry* m_pParent = nullptr;
0069     /// Pointer to opaque address (load info)
0070     IOpaqueAddress* m_pAddress = nullptr;
0071     /// Pointer to object
0072     DataObject* m_pObject = nullptr;
0073     /// Pointer to hosting transient store
0074     IDataProviderSvc* m_pDataProviderSvc = nullptr;
0075     /// Store of leaves
0076     Store m_store;
0077 
0078   private:
0079     /** The following entries serve two aspects:
0080       1) They are faster for recursive calls, because they are non-virtual
0081       2) They can be re-used for the non-const entry points using a
0082          const_cast of the result.
0083     */
0084     /// Recursive helper to assemble the full path name of the entry
0085     void assemblePath( std::string& buffer ) const;
0086     /// Internal method to retrieve data directory
0087     IRegistry* i_find( const IRegistry* pDirectory ) const;
0088     /// Internal method to retrieve data directory
0089     RegistryEntry* i_find( std::string_view path ) const;
0090     /// Internal method to locate object entry
0091     RegistryEntry* i_find( const DataObject* pObject ) const;
0092     /// Internal method to create entries
0093     RegistryEntry* i_create( std::string name );
0094     /// Internal method to add entries
0095     long i_add( RegistryEntry* entry );
0096     /// Set new parent pointer
0097     void setParent( RegistryEntry* pParent );
0098     /// Set the transient data store
0099     void setDataSvc( IDataProviderSvc* s ) { m_pDataProviderSvc = s; }
0100     /// Pointer to parent registry entry
0101     RegistryEntry* parentEntry() { return m_pParent; }
0102     /// Find identified leaf in this registry node
0103     RegistryEntry* findLeaf( std::string_view path ) const { return i_find( path ); }
0104     /// Find identified leaf in this registry node
0105     RegistryEntry* findLeaf( const DataObject* key ) const { return i_find( key ); }
0106     /// Initialize link as hard link
0107     void makeHard( DataObject* pObject );
0108     /// Initialize link as hard link
0109     void makeHard( IOpaqueAddress* pAddress );
0110     /// Initialize link as soft link
0111     void makeSoft( DataObject* pObject );
0112     /// Initialize link as soft link
0113     void makeSoft( IOpaqueAddress* pAddress );
0114 
0115   public:
0116     /// Standard Constructor
0117     RegistryEntry( std::string path, RegistryEntry* parent = nullptr );
0118     /// Standard Destructor
0119     ~RegistryEntry() override;
0120     /// IInterface implementation: Reference the object
0121     unsigned long release() override;
0122     /// IInterface implementation: Dereference the object
0123     unsigned long addRef() override { return ++m_refCount; }
0124     /// Retrieve name of the entry
0125     const std::string& name() const override { return m_path; }
0126     /// Full identifier (or key)
0127     const std::string& identifier() const override { return m_fullpath; }
0128     /// Retrieve pointer to Transient Store
0129     IDataProviderSvc* dataSvc() const override { return m_pDataProviderSvc; }
0130     /// Retrive object behind the link
0131     DataObject* object() const override { return m_pObject; }
0132     /// Retrieve opaque storage address
0133     IOpaqueAddress* address() const override { return m_pAddress; }
0134     /// Pointer to parent directory entry
0135     IRegistry* parent() const { return m_pParent; }
0136     /// Is the link soft or hard
0137     bool isSoft() const { return m_isSoft; }
0138     /// Access the leaves of the object
0139     const Store& leaves() const { return m_store; }
0140     /// Return the size of the container(=number of objects)
0141     size_t size() const { return m_store.size(); }
0142     /// Simple check if the Container is empty
0143     bool isEmpty() const { return m_store.size() == 0; }
0144     /// Return starting point for container iteration
0145     Iterator begin() const { return m_store.begin(); }
0146     /// Return end elemtn if the container
0147     Iterator end() const { return m_store.end(); }
0148     /// Try to find an object identified by its pointer
0149     IRegistry* find( const IRegistry* obj ) const { return i_find( obj ); }
0150     /// Try to find an object identified by its relative name to the directory
0151     IRegistry* find( std::string_view path ) const { return i_find( path ); }
0152     /// Set/Update Opaque address
0153     void setAddress( IOpaqueAddress* pAddress ) override;
0154     /// Set/Update object address
0155     void setObject( DataObject* obj );
0156 
0157     /// Add entry to data store
0158     StatusCode add( std::string name, DataObject* pObject, bool is_soft = false );
0159     /// Add entry to data store
0160     StatusCode add( std::string name, IOpaqueAddress* pAddress, bool is_soft = false );
0161     /// Remove an entry from the store
0162     StatusCode remove( std::string_view name );
0163     /// Add object to the container
0164     long add( IRegistry* obj );
0165     /// Remove an object from the container
0166     long remove( IRegistry* obj );
0167     /// Delete all contained elements
0168     long deleteElements();
0169     /// traverse data tree
0170     StatusCode traverseTree( IDataStoreAgent* pAgent, int level = 0 );
0171   };
0172 } // namespace DataSvcHelpers
0173 #endif // GAUDIKERNEL_REGISTRYENTRY_H