The Gaudi Framework  v30r3 (a5ef0a68)
RootDataConnection.h
Go to the documentation of this file.
1 #ifndef GAUDIROOT_ROOTDATACONNECTION_H
2 #define GAUDIROOT_ROOTDATACONNECTION_H
3 
4 // Framework include files
5 #include "GaudiKernel/ClassID.h"
7 #include "GaudiKernel/SmartIF.h"
9 #include "boost/utility/string_ref.hpp"
10 #include <map>
11 #include <set>
12 #include <string>
13 #include <vector>
14 
15 #include "RootCnv/RootRefs.h"
16 #include "TFile.h"
17 #include "TTreePerfStats.h"
18 
19 // Forward declarations
20 class TTree;
21 class TClass;
22 class TBranch;
23 
24 class MsgStream;
25 class IRegistry;
26 class DataObject;
27 class IIncidentSvc;
28 
29 /*
30  * Gaudi namespace declaration
31  */
32 namespace Gaudi
33 {
34 
46  {
47  private:
51  SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
52 
53  public:
56 
58  StringVec cacheBranches;
60  StringVec vetoBranches;
64  int cacheSize;
67 
69  RootConnectionSetup() = default;
70 
72  static StatusCode setCompression( boost::string_ref compression );
74  static int compression();
75 
77  void setMessageSvc( MsgStream* m );
79  MsgStream& msgSvc() const { return *m_msgSvc; }
80 
82  void setIncidentSvc( IIncidentSvc* m );
84  IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
85  };
86 
96  {
97  public:
98  enum class Status : StatusCode::code_t { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };
99 
112  ContainerSection() : start( -1 ), length( 0 ) {}
114  ContainerSection( int s, int l ) : start( s ), length( l ) {}
116  ContainerSection( const ContainerSection& s ) : start( s.start ), length( s.length ) {}
119  {
120  if ( this != &s ) {
121  start = s.start;
122  length = s.length;
123  }
124  return *this;
125  }
127  int start;
129  int length;
130  };
131 
146 
148  MsgStream& msgSvc() const { return m_setup->msgSvc(); }
149 
150  protected:
158  TTree* m_refs = nullptr;
160  Sections m_sections;
162  StringVec m_dbs;
164  StringVec m_conts;
166  StringVec m_links;
168  StringVec m_mergeFIDs;
170  ParamMap m_params;
172  MergeSections m_mergeSects;
174  LinkSections m_linkSects;
176  Clients m_clients;
179 
181  const std::string& empty() const;
182 
184  StatusCode saveRefs();
185 
186  public:
196  class Tool
197  {
198  protected:
206 
209 
210  public:
211  TTree* refs() const { return c->m_refs; }
212  StringVec& dbs() const { return c->m_dbs; }
213  StringVec& conts() const { return c->m_conts; }
214  StringVec& links() const { return c->m_links; }
215  ParamMap& params() const { return c->m_params; }
216  MsgStream& msgSvc() const { return c->msgSvc(); }
217  const std::string& name() const { return c->m_name; }
218  Sections& sections() const { return c->m_sections; }
219  LinkSections& linkSections() const { return c->m_linkSects; }
220  MergeSections& mergeSections() const { return c->m_mergeSects; }
221 
223  virtual ~Tool() = default;
225  virtual TBranch* getBranch( boost::string_ref section, boost::string_ref n ) = 0;
227  virtual RootRef poolRef( size_t /* which */ ) const { return RootRef(); }
228 
230  virtual StatusCode readRefs() = 0;
232  virtual StatusCode saveRefs() = 0;
234  virtual int loadRefs( boost::string_ref section, boost::string_ref cnt, unsigned long entry,
235  RootObjectRefs& refs ) = 0;
236  };
238  friend class Tool;
239 
241  Tool* makeTool();
242 
243  public:
245  RootDataConnection( const IInterface* own, boost::string_ref nam, std::shared_ptr<RootConnectionSetup> setup );
246 
248  TFile* file() const { return m_file.get(); }
250  bool isConnected() const override { return bool( m_file ); }
252  bool isWritable() const { return m_file && m_file->IsWritable(); }
254  Tool* tool() const { return m_tool.get(); }
256  const MergeSections& mergeSections() const { return m_mergeSects; }
258  const StringVec& mergeFIDs() const { return m_mergeFIDs; }
259 
261  void addClient( const IInterface* client );
263  size_t removeClient( const IInterface* client );
265  bool lookupClient( const IInterface* client ) const;
266 
268  void badWriteError( boost::string_ref msg ) const;
269 
271  std::pair<const RootRef*, const ContainerSection*> getMergeSection( boost::string_ref container, int entry ) const;
272 
274  void enableStatistics( boost::string_ref section );
276  void saveStatistics( boost::string_ref statisticsFile );
277 
279  int loadObj( boost::string_ref section, boost::string_ref cnt, unsigned long entry, DataObject*& pObj );
280 
282  int loadRefs( boost::string_ref section, boost::string_ref cnt, unsigned long entry, RootObjectRefs& refs );
283 
285  std::pair<int, unsigned long> saveObj( boost::string_ref section, boost::string_ref cnt, TClass* cl,
286  DataObject* pObj, int buff_siz, int split_lvl, bool fill_missing = false );
288  std::pair<int, unsigned long> save( boost::string_ref section, boost::string_ref cnt, TClass* cl, void* pObj,
289  int buff_siz, int split_lvl, bool fill_missing = false );
290 
292  StatusCode connectRead() override;
294  StatusCode connectWrite( IoType typ ) override;
296  StatusCode disconnect() override;
298  StatusCode read( void* const, size_t ) override { return StatusCode::FAILURE; }
300  StatusCode write( const void*, int ) override { return StatusCode::FAILURE; }
302  long long int seek( long long int, int ) override { return -1; }
303 
305  TTree* getSection( boost::string_ref sect, bool create = false );
306 
308  TBranch* getBranch( boost::string_ref section, boost::string_ref branch_name )
309  {
310  return m_tool->getBranch( section, branch_name );
311  }
313  TBranch* getBranch( boost::string_ref section, boost::string_ref branch_name, TClass* cl, void* ptr, int buff_siz,
314  int split_lvl );
315 
317  void makeRef( const IRegistry& pA, RootRef& ref );
319  void makeRef( boost::string_ref name, long clid, int tech, boost::string_ref db, boost::string_ref cnt, int entry,
320  RootRef& ref );
321 
323  int makeLink( boost::string_ref p );
324 
326  const std::string& getDb( int which ) const;
327 
329  const std::string& getCont( int which ) const
330  {
331  return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
332  }
333 
335  const std::string& getLink( int which ) const
336  {
337  return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
338  }
339  };
340 } // End namespace Gaudi
341 
343 
344 #endif // GAUDIROOT_ROOTDATACONNECTION_H
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const
MergeSections m_mergeSects
Database section map for merged files.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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
std::string m_name
Connection name/identifier.
IoType
I/O Connection types.
TFile * file() const
Direct access to TFile structure.
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
bool isConnected() const override
Check if connected to data source.
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.
Clients m_clients
Client list.
RootDataConnection::StringVec StringVec
int start
The start entry of the section.
std::set< const IInterface * > Clients
Client set.
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:258
MsgStream & msgSvc() const
Retrieve message service.
const std::string & getLink(int which) const
Access link name from saved index.
std::vector< std::string > StringVec
Type definition for string maps.
int cacheSize
RootCnvSvc Property: Root data cache size.
STL class.
RootDataConnection::ContainerSections ContainerSections
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject...
Definition: RootRefs.h:60
StringVec m_links
Map containing internal links names.
ParamMap m_params
Parameter map for file parameters.
STL class.
std::string loadSection
RootCnvSvc Property: Root data cache size.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
StringVec m_mergeFIDs
Map containing merge FIDs.
MergeSections & mergeSections() const
Persistent reference object.
Definition: RootRefs.h:31
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
Helper class to facilitate an abstraction layer for reading POOL style files with this package...
int learnEntries
RootCnvSvc Property: ROOT cache learn entries.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr double m
Definition: SystemOfUnits.h:94
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition of the basic interface.
Definition: IInterface.h:277
RootDataConnection::ParamMap ParamMap
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
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.
start
Definition: IOTest.py:99
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:22
std::vector< RootRef > LinkSections
Link sections definition.
RootDataConnection::MergeSections MergeSections
const std::string & getCont(int which) const
Access container name from saved index.
Tool * tool() const
Access tool.
ContainerSection(int s, int l)
Initializing constructor.
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
dictionary l
Definition: gaudirun.py:440
const StringVec & mergeFIDs() const
Access merged FIDs.
T get(T...args)
TBranch * getBranch(boost::string_ref section, boost::string_ref branch_name)
Access data branch by name: Get existing branch in read only mode.
T size(T...args)
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
RootDataConnection::ContainerSection ContainerSection
bool isWritable() const
Is the file writable?
ABC describing basic data connection.
RootDataConnection::LinkSections LinkSections
IIncidentSvc * incidentSvc() const
Retrieve incident service.
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:571
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:253
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.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
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:104
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Concrete implementation of the IDataConnection interface to access ROOT files.
TTree * m_refs
Pointer to the reference tree.
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Helper functions to set/get the application return code.
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:23
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:54
LinkSections & linkSections() const