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 <string>
10 #include <vector>
11 #include <map>
12 #include <set>
13 
14 #include "TFile.h"
15 #include "TTreePerfStats.h"
16 #include "RootCnv/RootRefs.h"
17 
18 // Forward declarations
19 class TTree;
20 class TClass;
21 class TBranch;
22 
23 class MsgStream;
24 class IRegistry;
25 class DataObject;
26 class IIncidentSvc;
27 
28 /*
29  * Gaudi namespace declaration
30  */
31 namespace Gaudi {
32 
44  private:
48  SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
49 
50  public:
53 
55  StringVec cacheBranches;
57  StringVec vetoBranches;
61  int cacheSize;
64 
66  RootConnectionSetup() = default;
67 
69  static long setCompression(const std::string& compression);
71  static int compression();
72 
74  void setMessageSvc(MsgStream* m);
76  MsgStream& msgSvc() const { return *m_msgSvc; }
77 
79  void setIncidentSvc(IIncidentSvc* m);
81  IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
82  };
83 
93  public:
94 
95  enum { ROOT_READ_ERROR = 0x2,
96  ROOT_OPEN_ERROR = 0x4
97  };
98 
111  ContainerSection() : start(-1), length(0) {}
113  ContainerSection(int s, int l) : start(s), length(l) {}
115  ContainerSection(const ContainerSection& s) : start(s.start), length(s.length) {}
118  if ( this != &s ) {
119  start=s.start;
120  length=s.length;
121  }
122  return *this;
123  }
125  int start;
127  int length;
128  };
129 
144 
146  MsgStream& msgSvc() const { return m_setup->msgSvc(); }
147 
148 
149  protected:
157  TTree *m_refs = nullptr;
159  Sections m_sections;
161  StringVec m_dbs;
163  StringVec m_conts;
165  StringVec m_links;
167  StringVec m_mergeFIDs;
169  ParamMap m_params;
171  MergeSections m_mergeSects;
173  LinkSections m_linkSects;
175  Clients m_clients;
178 
180  const std::string& empty() const;
181 
183  StatusCode saveRefs();
184 
185  public:
195  class Tool {
196  protected:
204 
207  public:
208  TTree* refs() const { return c->m_refs; }
209  StringVec& dbs() const { return c->m_dbs; }
210  StringVec& conts() const { return c->m_conts; }
211  StringVec& links() const { return c->m_links; }
212  ParamMap& params() const { return c->m_params; }
213  MsgStream& msgSvc() const { return c->msgSvc(); }
214  const std::string& name() const { return c->m_name; }
215  Sections& sections() const { return c->m_sections; }
216  LinkSections& linkSections() const { return c->m_linkSects; }
217  MergeSections& mergeSections() const { return c->m_mergeSects; }
218 
220  virtual ~Tool() = default;
222  virtual TBranch* getBranch(const std::string& section, const std::string& n) = 0;
224  virtual RootRef poolRef(size_t /* which */) const { return RootRef(); }
225 
227  virtual StatusCode readRefs() = 0;
229  virtual StatusCode saveRefs() = 0;
231  virtual int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs) = 0;
232  };
234  friend class Tool;
235 
237  Tool* makeTool();
238 
239  public:
240 
244  ~RootDataConnection() override = default;
245 
247  TFile* file() const { return m_file.get(); }
249  bool isConnected() const override { return bool(m_file); }
251  bool isWritable() const { return m_file && m_file->IsWritable(); }
253  Tool* tool() const { return m_tool.get(); }
255  const MergeSections& mergeSections() const { return m_mergeSects; }
257  const StringVec& mergeFIDs() const { return m_mergeFIDs; }
258 
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(const std::string& msg) const;
269 
271  std::pair<const RootRef*,const ContainerSection*> getMergeSection(const std::string& container, int entry) const;
272 
274  void enableStatistics(const std::string& section);
276  void saveStatistics(const std::string& statisticsFile);
277 
279  int loadObj(const std::string& section, const std::string& cnt, unsigned long entry, DataObject*& pObj);
280 
282  int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs);
283 
285  std::pair<int,unsigned long> saveObj(const std::string& section,const std::string& cnt, TClass* cl, DataObject* pObj, int buff_siz, int split_lvl,bool fill_missing=false);
287  std::pair<int,unsigned long> save(const std::string& section,const std::string& cnt, TClass* cl, void* pObj, int buff_siz, int split_lvl,bool fill_missing=false);
288 
289 
291  StatusCode connectRead() override;
293  StatusCode connectWrite(IoType typ) override;
295  StatusCode disconnect() override;
297  StatusCode read(void* const, size_t) override { return StatusCode::FAILURE; }
299  StatusCode write(const void*, int) override { return StatusCode::FAILURE; }
301  long long int seek(long long int, int) override { return -1; }
302 
304  TTree* getSection(const std::string& sect, bool create=false);
305 
307  TBranch* getBranch(const std::string& section,const std::string& branch_name)
308  { return m_tool->getBranch(section,branch_name); }
310  TBranch* getBranch(const std::string& section, const std::string& branch_name, TClass* cl, void* ptr, int buff_siz, int split_lvl);
311 
313  void makeRef(IRegistry* pA, RootRef& ref);
315  void makeRef(const std::string& name, long clid, int tech, const std::string& db, const std::string& cnt, int entry, RootRef& ref);
316 
318  int makeLink(const std::string& p);
319 
321  const std::string& getDb(int which) const;
322 
324  const std::string& getCont(int which) const
325  { return (which>=0)&&(size_t(which)<m_conts.size()) ? *(m_conts.begin()+which) : empty(); }
326 
328  const std::string& getLink(int which) const
329  { return (which>=0)&&(size_t(which)<m_links.size()) ? *(m_links.begin()+which) : empty(); }
330  };
331 } // End namespace Gaudi
332 #endif // GAUDIROOT_ROOTDATACONNECTION_H
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.
TFile * file() const
Direct access to TFile structure.
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
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.
Clients m_clients
Client list.
RootDataConnection::StringVec StringVec
int start
The start entry of the section.
std::set< const IInterface * > Clients
Client set.
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.
RootDataConnection::ContainerSections ContainerSections
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject...
Definition: RootRefs.h:58
StringVec m_links
Map containing internal links names.
bool isConnected() const override
Check if connected to data source.
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:76
StringVec m_mergeFIDs
Map containing merge FIDs.
MergeSections & mergeSections() const
Persistent reference object.
Definition: RootRefs.h:30
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:26
constexpr double m
Definition: SystemOfUnits.h:93
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition of the basic interface.
Definition: IInterface.h:234
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
RootDataConnection::ParamMap ParamMap
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: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:421
const StringVec & mergeFIDs() const
Access merged FIDs.
T get(T...args)
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.
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
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:547
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:245
ContainerSection(const ContainerSection &s)
Copy constructor.
RootDataConnection * c
Pointer to containing data connection object.
std::map< std::string, ContainerSections > MergeSections
Definition of database section to handle merged files.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
StringVec m_dbs
Map containing external database file names (fids)
std::map< std::string, TTree * > Sections
Definition of tree sections.
std::string m_empty
Buffer for empty string reference.
#define GAUDI_API
Definition: Kernel.h:107
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:21
tuple start
Definition: IOTest.py:88
LinkSections & linkSections() const