Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:45

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 GAUDIMP_TESSERIALIZER_H
0012 #define GAUDIMP_TESSERIALIZER_H
0013 
0014 #include "GaudiKernel/DataObject.h"
0015 #include "GaudiKernel/IAddressCreator.h"
0016 #include "GaudiKernel/IDataStoreAgent.h"
0017 
0018 // ROOT includes
0019 #include "TClass.h"
0020 
0021 // vector and string
0022 #include <map>
0023 #include <string>
0024 #include <typeindex>
0025 #include <vector>
0026 
0027 // forward declarations
0028 class IDataProviderSvc;
0029 struct IDataManagerSvc;
0030 class TBufferFile;
0031 class DataStoreItem;
0032 class IAddressCreator;
0033 
0034 /** A class to serialize/deserialize
0035     TES objects to and from a TBufferFile
0036     Author:  P. Mato
0037     Author:  E. Smith
0038     Version: 1.1
0039 */
0040 
0041 namespace GaudiMP {
0042   class GAUDI_API TESSerializer : virtual public IDataStoreAgent {
0043     typedef std::vector<DataStoreItem*> Items;
0044     typedef std::vector<std::string>    ItemNames;
0045     typedef std::vector<DataObject*>    Objects;
0046 
0047   public:
0048     /// Constructor
0049     TESSerializer( IDataProviderSvc* svc, IAddressCreator* ac );
0050 
0051     /// Dump TES contents listed in m_itemList/m_optItemList to a TBufferFile
0052     void dumpBuffer( TBufferFile& );
0053 
0054     /// Rebuild TES from items in a TBufferFile
0055     void loadBuffer( TBufferFile& );
0056 
0057     /// add an item to the TESSerializer's list (#notation)
0058     void addItem( const std::string& path );
0059 
0060     /// add an item to the TESSerializer's optional list (#notation)
0061     void addOptItem( const std::string& path );
0062 
0063     /// Analysis callback
0064     bool analyse( IRegistry* dir, int level ) override;
0065 
0066     /// print out the contents of m_itemList and m_optItemList (std::cout)
0067     void checkItems();
0068 
0069     virtual ~TESSerializer() {}
0070 
0071   protected:
0072     /// Add item to the list of items to be serialized (#notation)
0073     void addItem( Items& itms, const std::string& descriptor );
0074 
0075     /// Find single item identified by its path (exact match)
0076     DataStoreItem* findItem( const std::string& path );
0077 
0078   private:
0079     /// caching wrapper to TClass::GetClass
0080     TClass* getClass( DataObject* obj ) {
0081       auto& id  = typeid( *obj );
0082       auto  pos = m_classMap.find( id );
0083       if ( pos == end( m_classMap ) ) { return m_classMap[id] = TClass::GetClass( id ); }
0084       return pos->second;
0085     }
0086 
0087     /// TES pointer
0088     IDataProviderSvc* m_TES;
0089     /// TES pointer
0090     IDataManagerSvc* m_TESMgr;
0091     /// Vector of item names
0092     ItemNames m_itemNames;
0093     /// Vector of items to be saved to this stream (DataStoreItem ptrs)
0094     Items m_itemList;
0095     /// Vector of item names (std::strings)
0096     ItemNames m_optItemNames;
0097     /// Vector of optional items to be saved to this stream (DataStoreItem ptrs)
0098     Items m_optItemList;
0099     /// Current item while traversing the TES tree
0100     DataStoreItem* m_currentItem;
0101     /// Selected list of Objects to be serialized (DataObject ptrs)
0102     Objects m_objects;
0103 
0104     /// Map of gROOT class information
0105     std::map<std::type_index, TClass*> m_classMap;
0106     /// Boolean Flag as used by GaudiSvc/PersistencySvc/OutputStreamer
0107     bool m_verifyItems;
0108     /// Boolean Flag used to determine error tolerance
0109     bool m_strict;
0110     /// IAddress Creator for Opaque Addresses
0111     IAddressCreator* m_addressCreator;
0112   };
0113 } // namespace GaudiMP
0114 #endif