Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
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 "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 
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
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection()
Default constructor.
Definition: RootDataConnection.h:119
Gaudi::RootDataConnection::mergeFIDs
const StringVec & mergeFIDs() const
Access merged FIDs.
Definition: RootDataConnection.h:263
Gaudi::RootDataConnection::isConnected
bool isConnected() const override
Check if connected to data source.
Definition: RootDataConnection.h:255
Gaudi::RootDataConnection::ContainerSection::length
int length
The length of the section.
Definition: RootDataConnection.h:135
std::string
STL class.
std::shared_ptr
STL class.
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:182
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:217
Gaudi::RootConnectionSetup::cacheBranches
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
Definition: RootDataConnection.h:66
Gaudi::RootDataConnection::Sections
std::map< std::string, TTree *, std::less<> > Sections
Definition of tree sections.
Definition: RootDataConnection.h:143
Gaudi::RootDataConnection::Tool::MergeSections
RootDataConnection::MergeSections MergeSections
Definition: RootDataConnection.h:207
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:338
Gaudi::RootDataConnection::read
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Definition: RootDataConnection.h:303
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::RootDataConnection::Tool::conts
StringVec & conts() const
Definition: RootDataConnection.h:218
Gaudi::RootDataConnection::m_file
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Definition: RootDataConnection.h:162
Gaudi::RootDataConnection::isWritable
bool isWritable() const
Is the file writable?
Definition: RootDataConnection.h:257
Gaudi::RootDataConnection::Tool::msgSvc
MsgStream & msgSvc() const
Definition: RootDataConnection.h:221
std::unique_ptr::get
T get(T... args)
Gaudi::RootDataConnection::Tool::ContainerSection
RootDataConnection::ContainerSection ContainerSection
Definition: RootDataConnection.h:209
Gaudi::RootDataConnection::tool
Tool * tool() const
Access tool.
Definition: RootDataConnection.h:259
IIODataManager.h
Gaudi::RootDataConnection::ContainerSection
Definition: RootDataConnection.h:117
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:176
Gaudi::RootDataConnection::Tool::c
RootDataConnection * c
Pointer to containing data connection object.
Definition: RootDataConnection.h:213
gaudirun.c
c
Definition: gaudirun.py:525
Gaudi::RootDataConnection::ContainerSection::operator=
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
Definition: RootDataConnection.h:125
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:87
Gaudi::RootDataConnection::Tool::name
const std::string & name() const
Definition: RootDataConnection.h:222
Gaudi::RootDataConnection::m_dbs
StringVec m_dbs
Map containing external database file names (fids)
Definition: RootDataConnection.h:168
Gaudi::RootDataConnection::saveRefs
StatusCode saveRefs()
Internal helper to save/update reference tables.
Gaudi::RootDataConnection::Tool::LinkSections
RootDataConnection::LinkSections LinkSections
Definition: RootDataConnection.h:208
Gaudi::RootObjectRefs
Definition: RootRefs.h:68
Gaudi::RootDataConnection
Definition: RootDataConnection.h:103
Gaudi::RootConnectionSetup::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:63
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:141
Gaudi::RootDataConnection::m_linkSects
LinkSections m_linkSects
Database link sections.
Definition: RootDataConnection.h:180
Gaudi::RootDataConnection::ContainerSections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
Definition: RootDataConnection.h:145
TimingHistograms.name
name
Definition: TimingHistograms.py:25
StatusCode
Definition: StatusCode.h:65
Gaudi::RootDataConnection::m_mergeFIDs
StringVec m_mergeFIDs
Map containing merge FIDs.
Definition: RootDataConnection.h:174
Gaudi::RootDataConnection::m_setup
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Definition: RootDataConnection.h:158
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
Gaudi::RootDataConnection::Tool::sections
Sections & sections() const
Definition: RootDataConnection.h:223
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:745
Gaudi::RootDataConnection::m_mergeSects
MergeSections m_mergeSects
Database section map for merged files.
Definition: RootDataConnection.h:178
Gaudi::RootDataConnection::getCont
const std::string & getCont(int which) const
Access container name from saved index.
Definition: RootDataConnection.h:333
Gaudi::RootDataConnection::LinkSections
std::vector< RootRef > LinkSections
Link sections definition.
Definition: RootDataConnection.h:149
Gaudi::RootConnectionSetup::m_msgSvc
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition: RootDataConnection.h:57
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:160
Gaudi::RootRef
Definition: RootRefs.h:40
Gaudi::RootDataConnection::Tool::links
StringVec & links() const
Definition: RootDataConnection.h:219
Gaudi::RootDataConnection::ContainerSection::start
int start
The start entry of the section.
Definition: RootDataConnection.h:133
Gaudi::RootDataConnection::write
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
Definition: RootDataConnection.h:305
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 >
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:28
Gaudi::RootDataConnection::file
TFile * file() const
Direct access to TFile structure.
Definition: RootDataConnection.h:253
std::map
STL class.
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:242
Gaudi::RootDataConnection::Tool::mergeSections
MergeSections & mergeSections() const
Definition: RootDataConnection.h:225
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:170
Gaudi::RootDataConnection::Status
Status
Definition: RootDataConnection.h:105
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:235
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:206
Gaudi::RootDataConnection::Tool::params
ParamMap & params() const
Definition: RootDataConnection.h:220
Gaudi::RootDataConnection::Tool::poolRef
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
Definition: RootDataConnection.h:232
Gaudi::RootDataConnection::Tool::StringVec
RootDataConnection::StringVec StringVec
Definition: RootDataConnection.h:204
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:307
STATUSCODE_ENUM_DECL
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:286
Gaudi::RootConnectionSetup
Definition: RootDataConnection.h:54
Gaudi::RootDataConnection::Tool::refs
TTree * refs() const
Definition: RootDataConnection.h:216
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:123
gaudirun.l
dictionary l
Definition: gaudirun.py:580
Gaudi::RootDataConnection::Tool::linkSections
LinkSections & linkSections() const
Definition: RootDataConnection.h:224
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:261
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:172
Gaudi::RootDataConnection::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:139
Gaudi::RootDataConnection::MergeSections
std::map< std::string, ContainerSections, std::less<> > MergeSections
Definition of database section to handle merged files.
Definition: RootDataConnection.h:147
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::RootConnectionSetup::incidentSvc
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Definition: RootDataConnection.h:92
Gaudi::RootConnectionSetup::loadSection
std::string loadSection
RootCnvSvc Property: Root data cache size.
Definition: RootDataConnection.h:70
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(int s, int l)
Initializing constructor.
Definition: RootDataConnection.h:121
Gaudi::RootDataConnection::Tool::ContainerSections
RootDataConnection::ContainerSections ContainerSections
Definition: RootDataConnection.h:210
IIncidentSvc
Definition: IIncidentSvc.h:33
Gaudi::RootDataConnection::m_sections
Sections m_sections
Tree sections in TFile.
Definition: RootDataConnection.h:166
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:313
Gaudi::RootDataConnection::Clients
std::set< const IInterface * > Clients
Client set.
Definition: RootDataConnection.h:151
std::unique_ptr< MsgStream >
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:154
IOTest.start
def start
Definition: IOTest.py:113
Gaudi::RootConnectionSetup::vetoBranches
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
Definition: RootDataConnection.h:68
std::set< const IInterface * >
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::RootDataConnection::m_empty
std::string m_empty
Buffer for empty string reference.
Definition: RootDataConnection.h:184
Gaudi::RootDataConnection::Tool
Definition: RootDataConnection.h:202
Gaudi::RootDataConnection::Tool::ParamMap
RootDataConnection::ParamMap ParamMap
Definition: RootDataConnection.h:205