The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 "Gaudi/Property.h"
16 #include "GaudiKernel/ClassID.h"
18 #include "GaudiKernel/SmartIF.h"
20 #include <map>
21 #include <set>
22 #include <string>
23 #include <string_view>
24 #include <vector>
25 
26 #include "RootCnv/RootRefs.h"
27 #include "TFile.h"
28 #include "TTreePerfStats.h"
29 
30 // Forward declarations
31 class TTree;
32 class TClass;
33 class TBranch;
34 
35 class MsgStream;
36 class IRegistry;
37 class DataObject;
38 class IIncidentSvc;
39 
40 /*
41  * Gaudi namespace declaration
42  */
43 namespace Gaudi {
44 
56  private:
60  SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
61 
62  public:
65 
73  int cacheSize{ 0 };
75  int learnEntries{ 0 };
76 
77  Gaudi::Property<bool> produceReproducibleFiles{ "ProduceReproducibleFiles", true,
78  "configure output files to be more reproducible" };
79 
81  RootConnectionSetup() = default;
82 
84  static StatusCode setCompression( std::string_view compression );
86  static int compression();
87 
89  void setMessageSvc( MsgStream* m );
91  MsgStream& msgSvc() const { return *m_msgSvc; }
92 
94  void setIncidentSvc( IIncidentSvc* m );
96  IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
97  };
98 
108  public:
109  enum class Status : StatusCode::code_t { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };
110 
123  ContainerSection() : start( -1 ), length( 0 ) {}
125  ContainerSection( int s, int l ) : start( s ), length( l ) {}
127  ContainerSection( const ContainerSection& s ) : start( s.start ), length( s.length ) {}
130  if ( this != &s ) {
131  start = s.start;
132  length = s.length;
133  }
134  return *this;
135  }
137  int start;
139  int length;
140  };
141 
156 
158  MsgStream& msgSvc() const { return m_setup->msgSvc(); }
159 
160  protected:
168  TTree* m_refs = nullptr;
189 
191  const std::string& empty() const;
192 
195 
196  public:
206  class Tool {
207  protected:
215 
218 
219  public:
220  TTree* refs() const { return c->m_refs; }
221  StringVec& dbs() const { return c->m_dbs; }
222  StringVec& conts() const { return c->m_conts; }
223  StringVec& links() const { return c->m_links; }
224  ParamMap& params() const { return c->m_params; }
225  MsgStream& msgSvc() const { return c->msgSvc(); }
226  const std::string& name() const { return c->m_name; }
227  Sections& sections() const { return c->m_sections; }
228  LinkSections& linkSections() const { return c->m_linkSects; }
229  MergeSections& mergeSections() const { return c->m_mergeSects; }
230 
232  virtual ~Tool() = default;
234  virtual TBranch* getBranch( std::string_view section, std::string_view n ) = 0;
236  virtual RootRef poolRef( size_t /* which */ ) const { return RootRef(); }
237 
239  virtual StatusCode readRefs() = 0;
241  virtual StatusCode saveRefs() = 0;
243  virtual int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry,
244  RootObjectRefs& refs ) = 0;
245  };
247  friend class Tool;
248 
250  Tool* makeTool();
251 
252  public:
254  RootDataConnection( const IInterface* own, std::string_view nam, std::shared_ptr<RootConnectionSetup> setup );
255 
257  TFile* file() const { return m_file.get(); }
259  bool isConnected() const override { return bool( m_file ); }
261  bool isWritable() const { return m_file && m_file->IsWritable(); }
263  Tool* tool() const { return m_tool.get(); }
265  const MergeSections& mergeSections() const { return m_mergeSects; }
267  const StringVec& mergeFIDs() const { return m_mergeFIDs; }
268 
270  void addClient( const IInterface* client );
272  size_t removeClient( const IInterface* client );
274  bool lookupClient( const IInterface* client ) const;
275 
277  void badWriteError( std::string_view msg ) const;
278 
280  std::pair<const RootRef*, const ContainerSection*> getMergeSection( std::string_view container, int entry ) const;
281 
283  void enableStatistics( std::string_view section );
285  void saveStatistics( std::string_view statisticsFile );
286 
288  int loadObj( std::string_view section, std::string_view cnt, unsigned long entry, DataObject*& pObj );
289 
291  int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs& refs );
292 
294  std::pair<int, unsigned long> saveObj( std::string_view section, std::string_view cnt, TClass* cl, DataObject* pObj,
295  int minBufferSize, int maxBufferSize, int approxEventsPerBasket,
296  int split_lvl, bool fill_missing = false );
298  std::pair<int, unsigned long> save( std::string_view section, std::string_view cnt, TClass* cl, void* pObj,
299  int minBufferSize, int maxBufferSize, int approxEventsPerBasket, int split_lvl,
300  bool fill_missing = false );
301 
303  StatusCode connectRead() override;
305  StatusCode connectWrite( IoType typ ) override;
307  StatusCode disconnect() override;
309  StatusCode read( void* const, size_t ) override { return StatusCode::FAILURE; }
311  StatusCode write( const void*, int ) override { return StatusCode::FAILURE; }
313  long long int seek( long long int, int ) override { return -1; }
314 
316  TTree* getSection( std::string_view sect, bool create = false );
317 
319  TBranch* getBranch( std::string_view section, std::string_view branch_name ) {
320  return m_tool->getBranch( section, branch_name );
321  }
323  TBranch* getBranch( std::string_view section, std::string_view branch_name, TClass* cl, void* ptr, int buff_siz,
324  int split_lvl );
325 
327  void makeRef( const IRegistry& pA, RootRef& ref );
329  void makeRef( std::string_view name, long clid, int tech, std::string_view db, std::string_view cnt, int entry,
330  RootRef& ref );
331 
333  int makeLink( std::string_view p );
334 
336  const std::string& getDb( int which ) const;
337 
339  const std::string& getCont( int which ) const {
340  return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
341  }
342 
344  const std::string& getLink( int which ) const {
345  return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
346  }
347  };
348 } // End namespace Gaudi
349 
351 
352 #endif // GAUDIROOT_ROOTDATACONNECTION_H
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection()
Default constructor.
Definition: RootDataConnection.h:123
Gaudi::RootDataConnection::mergeFIDs
const StringVec & mergeFIDs() const
Access merged FIDs.
Definition: RootDataConnection.h:267
Gaudi::RootDataConnection::isConnected
bool isConnected() const override
Check if connected to data source.
Definition: RootDataConnection.h:259
Gaudi::RootDataConnection::ContainerSection::length
int length
The length of the section.
Definition: RootDataConnection.h:139
std::string
STL class.
std::shared_ptr
STL class.
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:186
Gaudi::RootDataConnection::Tool::readRefs
virtual StatusCode readRefs()=0
Read references section when opening data file.
Gaudi::RootDataConnection::Tool::dbs
StringVec & dbs() const
Definition: RootDataConnection.h:221
Gaudi::RootConnectionSetup::cacheBranches
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
Definition: RootDataConnection.h:67
Gaudi::RootDataConnection::Sections
std::map< std::string, TTree *, std::less<> > Sections
Definition of tree sections.
Definition: RootDataConnection.h:147
Gaudi::RootDataConnection::Tool::MergeSections
RootDataConnection::MergeSections MergeSections
Definition: RootDataConnection.h:211
Gaudi::IDataConnection
Definition: IIODataManager.h:34
std::pair
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< std::string >
std::vector::size
T size(T... args)
ClassID.h
Gaudi::RootDataConnection::getLink
const std::string & getLink(int which) const
Access link name from saved index.
Definition: RootDataConnection.h:344
Gaudi::RootDataConnection::read
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Definition: RootDataConnection.h:309
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::RootDataConnection::Tool::conts
StringVec & conts() const
Definition: RootDataConnection.h:222
Gaudi::RootDataConnection::m_file
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Definition: RootDataConnection.h:166
Gaudi::RootDataConnection::isWritable
bool isWritable() const
Is the file writable?
Definition: RootDataConnection.h:261
Gaudi::RootDataConnection::Tool::msgSvc
MsgStream & msgSvc() const
Definition: RootDataConnection.h:225
std::unique_ptr::get
T get(T... args)
Gaudi::RootDataConnection::Tool::ContainerSection
RootDataConnection::ContainerSection ContainerSection
Definition: RootDataConnection.h:213
Gaudi::RootDataConnection::tool
Tool * tool() const
Access tool.
Definition: RootDataConnection.h:263
IIODataManager.h
Gaudi::RootDataConnection::ContainerSection
Definition: RootDataConnection.h:121
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:180
Gaudi::RootDataConnection::Tool::c
RootDataConnection * c
Pointer to containing data connection object.
Definition: RootDataConnection.h:217
gaudirun.c
c
Definition: gaudirun.py:525
Gaudi::RootDataConnection::ContainerSection::operator=
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
Definition: RootDataConnection.h:129
IRegistry
Definition: IRegistry.h:32
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:67
Gaudi::RootConnectionSetup::msgSvc
MsgStream & msgSvc() const
Retrieve message service.
Definition: RootDataConnection.h:91
Gaudi::RootDataConnection::Tool::name
const std::string & name() const
Definition: RootDataConnection.h:226
IOTest.start
start
Definition: IOTest.py:108
Gaudi::RootDataConnection::m_dbs
StringVec m_dbs
Map containing external database file names (fids)
Definition: RootDataConnection.h:172
Gaudi::RootDataConnection::saveRefs
StatusCode saveRefs()
Internal helper to save/update reference tables.
Gaudi::RootDataConnection::Tool::LinkSections
RootDataConnection::LinkSections LinkSections
Definition: RootDataConnection.h:212
Gaudi::RootObjectRefs
Definition: RootRefs.h:68
Gaudi::RootDataConnection
Definition: RootDataConnection.h:107
Gaudi::RootConnectionSetup::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:64
IIncidentSvc.h
SmartIF.h
Gaudi::RootDataConnection::ParamMap
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
Definition: RootDataConnection.h:145
Gaudi::RootDataConnection::m_linkSects
LinkSections m_linkSects
Database link sections.
Definition: RootDataConnection.h:184
Gaudi::RootDataConnection::ContainerSections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
Definition: RootDataConnection.h:149
StatusCode
Definition: StatusCode.h:65
Gaudi::RootDataConnection::m_mergeFIDs
StringVec m_mergeFIDs
Map containing merge FIDs.
Definition: RootDataConnection.h:178
Gaudi::RootDataConnection::m_setup
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Definition: RootDataConnection.h:162
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
Gaudi::RootDataConnection::Tool::sections
Sections & sections() const
Definition: RootDataConnection.h:227
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:739
Gaudi::RootDataConnection::m_mergeSects
MergeSections m_mergeSects
Database section map for merged files.
Definition: RootDataConnection.h:182
Gaudi::RootDataConnection::getCont
const std::string & getCont(int which) const
Access container name from saved index.
Definition: RootDataConnection.h:339
Gaudi::RootDataConnection::LinkSections
std::vector< RootRef > LinkSections
Link sections definition.
Definition: RootDataConnection.h:153
Gaudi::RootConnectionSetup::m_msgSvc
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition: RootDataConnection.h:58
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:164
Gaudi::RootRef
Definition: RootRefs.h:40
Gaudi::RootDataConnection::Tool::links
StringVec & links() const
Definition: RootDataConnection.h:223
Gaudi::RootDataConnection::ContainerSection::start
int start
The start entry of the section.
Definition: RootDataConnection.h:137
Gaudi::RootDataConnection::write
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
Definition: RootDataConnection.h:311
Gaudi::RootDataConnection::Tool::loadRefs
virtual int loadRefs(std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs &refs)=0
Load references object.
SmartIF< IIncidentSvc >
Gaudi::RootDataConnection::file
TFile * file() const
Direct access to TFile structure.
Definition: RootDataConnection.h:257
std::map
STL class.
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:246
Gaudi::RootDataConnection::Tool::mergeSections
MergeSections & mergeSections() const
Definition: RootDataConnection.h:229
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:174
Gaudi::RootDataConnection::Status
Status
Definition: RootDataConnection.h:109
MsgStream
Definition: MsgStream.h:34
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::RootDataConnection::Tool::saveRefs
virtual StatusCode saveRefs()=0
Save references section when closing data file.
Gaudi::RootDataConnection::Tool::Sections
RootDataConnection::Sections Sections
Definition: RootDataConnection.h:210
Gaudi::RootDataConnection::Tool::params
ParamMap & params() const
Definition: RootDataConnection.h:224
Gaudi::RootDataConnection::Tool::poolRef
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
Definition: RootDataConnection.h:236
Gaudi::RootDataConnection::Tool::StringVec
RootDataConnection::StringVec StringVec
Definition: RootDataConnection.h:208
Gaudi::RootDataConnection::seek
long long int seek(long long int, int) override
Seek on the file described by ioDesc. Arguments as in ::seek()
Definition: RootDataConnection.h:313
STATUSCODE_ENUM_DECL
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:286
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
Gaudi::RootConnectionSetup
Definition: RootDataConnection.h:55
Gaudi::RootDataConnection::Tool::refs
TTree * refs() const
Definition: RootDataConnection.h:220
RootRefs.h
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(const ContainerSection &s)
Copy constructor.
Definition: RootDataConnection.h:127
gaudirun.l
dictionary l
Definition: gaudirun.py:580
Gaudi::RootDataConnection::Tool::linkSections
LinkSections & linkSections() const
Definition: RootDataConnection.h:228
Gaudi::RootConnectionSetup::RootConnectionSetup
RootConnectionSetup()=default
Standard constructor.
std::vector::begin
T begin(T... args)
Gaudi::RootDataConnection::Tool::getBranch
virtual TBranch * getBranch(std::string_view section, std::string_view n)=0
Access data branch by name: Get existing branch in read only mode.
IInterface
Definition: IInterface.h:237
Gaudi::RootDataConnection::mergeSections
const MergeSections & mergeSections() const
Access merged data section inventory.
Definition: RootDataConnection.h:265
DataObject
Definition: DataObject.h:40
Gaudi::RootDataConnection::Tool::~Tool
virtual ~Tool()=default
Default destructor.
Gaudi::RootDataConnection::m_links
StringVec m_links
Map containing internal links names.
Definition: RootDataConnection.h:176
Gaudi::RootDataConnection::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:143
compareRootHistos.ref
ref
Definition: compareRootHistos.py:27
Gaudi::RootDataConnection::MergeSections
std::map< std::string, ContainerSections, std::less<> > MergeSections
Definition of database section to handle merged files.
Definition: RootDataConnection.h:151
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::RootConnectionSetup::incidentSvc
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Definition: RootDataConnection.h:96
Gaudi::RootConnectionSetup::loadSection
std::string loadSection
RootCnvSvc Property: Root data cache size.
Definition: RootDataConnection.h:71
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(int s, int l)
Initializing constructor.
Definition: RootDataConnection.h:125
Gaudi::RootDataConnection::Tool::ContainerSections
RootDataConnection::ContainerSections ContainerSections
Definition: RootDataConnection.h:214
IIncidentSvc
Definition: IIncidentSvc.h:33
Gaudi::RootDataConnection::m_sections
Sections m_sections
Tree sections in TFile.
Definition: RootDataConnection.h:170
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:319
Gaudi::RootDataConnection::Clients
std::set< const IInterface * > Clients
Client set.
Definition: RootDataConnection.h:155
std::unique_ptr< MsgStream >
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:158
Gaudi::RootConnectionSetup::vetoBranches
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
Definition: RootDataConnection.h:69
std::set< const IInterface * >
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Property< bool >
Gaudi::RootDataConnection::m_empty
std::string m_empty
Buffer for empty string reference.
Definition: RootDataConnection.h:188
Property.h
Gaudi::RootDataConnection::Tool
Definition: RootDataConnection.h:206
Gaudi::RootDataConnection::Tool::ParamMap
RootDataConnection::ParamMap ParamMap
Definition: RootDataConnection.h:209