The Gaudi Framework  v33r1 (b1225454)
RootDataConnection.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIROOT_ROOTDATACONNECTION_H
12 #define GAUDIROOT_ROOTDATACONNECTION_H
13 
14 // Framework include files
15 #include "GaudiKernel/ClassID.h"
17 #include "GaudiKernel/SmartIF.h"
19 #include <map>
20 #include <set>
21 #include <string>
22 #include <string_view>
23 #include <vector>
24 
25 #include "RootCnv/RootRefs.h"
26 #include "TFile.h"
27 #include "TTreePerfStats.h"
28 
29 // Forward declarations
30 class TTree;
31 class TClass;
32 class TBranch;
33 
34 class MsgStream;
35 class IRegistry;
36 class DataObject;
37 class IIncidentSvc;
38 
39 /*
40  * Gaudi namespace declaration
41  */
42 namespace Gaudi {
43 
55  private:
59  SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
60 
61  public:
64 
72  int cacheSize{0};
74  int learnEntries{0};
75 
77  RootConnectionSetup() = default;
78 
80  static StatusCode setCompression( std::string_view compression );
82  static int compression();
83 
85  void setMessageSvc( MsgStream* m );
87  MsgStream& msgSvc() const { return *m_msgSvc; }
88 
90  void setIncidentSvc( IIncidentSvc* m );
92  IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
93  };
94 
104  public:
105  enum class Status : StatusCode::code_t { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };
106 
119  ContainerSection() : start( -1 ), length( 0 ) {}
121  ContainerSection( int s, int l ) : start( s ), length( l ) {}
123  ContainerSection( const ContainerSection& s ) : start( s.start ), length( s.length ) {}
126  if ( this != &s ) {
127  start = s.start;
128  length = s.length;
129  }
130  return *this;
131  }
133  int start;
135  int length;
136  };
137 
152 
154  MsgStream& msgSvc() const { return m_setup->msgSvc(); }
155 
156  protected:
164  TTree* m_refs = nullptr;
185 
187  const std::string& empty() const;
188 
190  StatusCode saveRefs();
191 
192  public:
202  class Tool {
203  protected:
211 
214 
215  public:
216  TTree* refs() const { return c->m_refs; }
217  StringVec& dbs() const { return c->m_dbs; }
218  StringVec& conts() const { return c->m_conts; }
219  StringVec& links() const { return c->m_links; }
220  ParamMap& params() const { return c->m_params; }
221  MsgStream& msgSvc() const { return c->msgSvc(); }
222  const std::string& name() const { return c->m_name; }
223  Sections& sections() const { return c->m_sections; }
224  LinkSections& linkSections() const { return c->m_linkSects; }
225  MergeSections& mergeSections() const { return c->m_mergeSects; }
226 
228  virtual ~Tool() = default;
230  virtual TBranch* getBranch( std::string_view section, std::string_view n ) = 0;
232  virtual RootRef poolRef( size_t /* which */ ) const { return RootRef(); }
233 
235  virtual StatusCode readRefs() = 0;
237  virtual StatusCode saveRefs() = 0;
239  virtual int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry,
240  RootObjectRefs& refs ) = 0;
241  };
243  friend class Tool;
244 
246  Tool* makeTool();
247 
248  public:
250  RootDataConnection( const IInterface* own, std::string_view nam, std::shared_ptr<RootConnectionSetup> setup );
251 
253  TFile* file() const { return m_file.get(); }
255  bool isConnected() const override { return bool( m_file ); }
257  bool isWritable() const { return m_file && m_file->IsWritable(); }
259  Tool* tool() const { return m_tool.get(); }
261  const MergeSections& mergeSections() const { return m_mergeSects; }
263  const StringVec& mergeFIDs() const { return m_mergeFIDs; }
264 
266  void addClient( const IInterface* client );
268  size_t removeClient( const IInterface* client );
270  bool lookupClient( const IInterface* client ) const;
271 
273  void badWriteError( std::string_view msg ) const;
274 
276  std::pair<const RootRef*, const ContainerSection*> getMergeSection( std::string_view container, int entry ) const;
277 
279  void enableStatistics( std::string_view section );
281  void saveStatistics( std::string_view statisticsFile );
282 
284  int loadObj( std::string_view section, std::string_view cnt, unsigned long entry, DataObject*& pObj );
285 
287  int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs& refs );
288 
290  std::pair<int, unsigned long> saveObj( std::string_view section, std::string_view cnt, TClass* cl, DataObject* pObj,
291  int buff_siz, int split_lvl, bool fill_missing = false );
293  std::pair<int, unsigned long> save( std::string_view section, std::string_view cnt, TClass* cl, void* pObj,
294  int buff_siz, int split_lvl, bool fill_missing = false );
295 
297  StatusCode connectRead() override;
299  StatusCode connectWrite( IoType typ ) override;
301  StatusCode disconnect() override;
303  StatusCode read( void* const, size_t ) override { return StatusCode::FAILURE; }
305  StatusCode write( const void*, int ) override { return StatusCode::FAILURE; }
307  long long int seek( long long int, int ) override { return -1; }
308 
310  TTree* getSection( std::string_view sect, bool create = false );
311 
313  TBranch* getBranch( std::string_view section, std::string_view branch_name ) {
314  return m_tool->getBranch( section, branch_name );
315  }
317  TBranch* getBranch( std::string_view section, std::string_view branch_name, TClass* cl, void* ptr, int buff_siz,
318  int split_lvl );
319 
321  void makeRef( const IRegistry& pA, RootRef& ref );
323  void makeRef( std::string_view name, long clid, int tech, std::string_view db, std::string_view cnt, int entry,
324  RootRef& ref );
325 
327  int makeLink( std::string_view p );
328 
330  const std::string& getDb( int which ) const;
331 
333  const std::string& getCont( int which ) const {
334  return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
335  }
336 
338  const std::string& getLink( int which ) const {
339  return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
340  }
341  };
342 } // End namespace Gaudi
343 
345 
346 #endif // GAUDIROOT_ROOTDATACONNECTION_H
MergeSections m_mergeSects
Database section map for merged files.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
STL class.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
const MergeSections & mergeSections() const
Access merged data section inventory.
RootDataConnection::Sections Sections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
std::unique_ptr< Tool > m_tool
Tool * tool() const
Access tool.
MergeSections & mergeSections() const
long long int seek(long long int, int) override
Seek on the file described by ioDesc. Arguments as in ::seek()
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
std::map< std::string, ContainerSections, std::less<> > MergeSections
Definition of database section to handle merged files.
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
Clients m_clients
Client list.
RootDataConnection::StringVec StringVec
int start
The start entry of the section.
std::set< const IInterface * > Clients
Client set.
IIncidentSvc * incidentSvc() const
Retrieve incident service.
std::vector< std::string > StringVec
Type definition for string maps.
LinkSections & linkSections() const
const StringVec & mergeFIDs() const
Access merged FIDs.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
def start
Definition: IOTest.py:108
STL class.
RootDataConnection::ContainerSections ContainerSections
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
Definition: extractEvt.C:81
StringVec m_links
Map containing internal links names.
bool isConnected() const override
Check if connected to data source.
MsgStream & msgSvc() const
Allow access to printer service.
ParamMap m_params
Parameter map for file parameters.
STL class.
std::string loadSection
RootCnvSvc Property: Root data cache size.
StringVec m_mergeFIDs
Map containing merge FIDs.
Persistent reference object.
Definition: extractEvt.C:44
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:337
const std::string & getCont(int which) const
Access container name from saved index.
Helper class to facilitate an abstraction layer for reading POOL style files with this package.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
constexpr double m
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition of the basic interface.
Definition: IInterface.h:254
RootDataConnection::ParamMap ParamMap
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
const std::string & getLink(int which) const
Access link name from saved index.
StringVec m_conts
Map containing external container names.
Sections m_sections
Tree sections in TFile.
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
std::vector< std::string > StringVec
Type definition for string maps.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:32
std::vector< RootRef > LinkSections
Link sections definition.
RootDataConnection::MergeSections MergeSections
ContainerSection(int s, int l)
Initializing constructor.
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
MsgStream & msgSvc() const
Retrieve message service.
dictionary l
Definition: gaudirun.py:543
T get(T... args)
const std::string & name() const
T size(T... args)
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
RootDataConnection::ContainerSection ContainerSection
ABC describing basic data connection.
RootDataConnection::LinkSections LinkSections
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
T begin(T... args)
LinkSections m_linkSects
Database link sections.
def which(executable)
Definition: BaseTest.py:665
string s
Definition: gaudirun.py:328
constexpr static const auto FAILURE
Definition: StatusCode.h:101
ContainerSection(const ContainerSection &s)
Copy constructor.
std::map< std::string, TTree *, std::less<> > Sections
Definition of tree sections.
RootDataConnection * c
Pointer to containing data connection object.
TFile * file() const
Direct access to TFile structure.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
bool isWritable() const
Is the file writable?
StringVec m_dbs
Map containing external database file names (fids)
std::string m_empty
Buffer for empty string reference.
#define GAUDI_API
Definition: Kernel.h:81
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
Concrete implementation of the IDataConnection interface to access ROOT files.
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Internal helper class, which described a TBranch section in a ROOT file.
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:33
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:67