RootDataConnection.h
Go to the documentation of this file.
1 // $Id: RootDataConnection.h,v 1.9 2010-09-17 09:00:12 frankb Exp $
2 #ifndef GAUDIROOT_ROOTDATACONNECTION_H
3 #define GAUDIROOT_ROOTDATACONNECTION_H
4 
5 // Framework include files
6 #include "GaudiKernel/ClassID.h"
7 #include "GaudiUtils/IIODataManager.h"
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <set>
12 
13 #include "TFile.h"
14 #include "RootCnv/RootRefs.h"
15 
16 // Forward declarations
17 class TTree;
18 class TClass;
19 class TBranch;
20 class TTreePerfStats;
21 
22 class MsgStream;
23 class IRegistry;
24 class DataObject;
25 class IIncidentSvc;
26 
27 /*
28  * Gaudi namespace declaration
29  */
30 namespace Gaudi {
31 
43  public:
45  typedef std::vector<std::string> StringVec;
46  protected:
48  virtual ~RootConnectionSetup();
50  int refCount;
55 
56  public:
58  StringVec cacheBranches;
60  StringVec vetoBranches;
62  std::string loadSection;
64  int cacheSize;
67 
71  void addRef();
73  void release();
74 
76  static long setCompression(const std::string& compression);
78  static int compression();
79 
81  void setMessageSvc(MsgStream* m);
83  MsgStream& msgSvc() const { return *m_msgSvc; }
84 
86  void setIncidentSvc(IIncidentSvc* m);
88  IIncidentSvc* incidentSvc() const { return m_incidentSvc; }
89  };
90 
100  public:
101 
102  enum { ROOT_READ_ERROR = 0x2,
103  ROOT_OPEN_ERROR = 0x4
104  };
105 
118  ContainerSection() : start(-1), length(0) {}
120  ContainerSection(int s, int l) : start(s), length(l) {}
122  ContainerSection(const ContainerSection& s) : start(s.start), length(s.length) {}
125  if ( this != &s ) {
126  start=s.start;
127  length=s.length;
128  }
129  return *this;
130  }
132  int start;
134  int length;
135  };
136 
138  typedef std::vector<std::string> StringVec;
140  typedef std::vector<std::pair<std::string,std::string> > ParamMap;
142  typedef std::map<std::string,TTree*> Sections;
144  typedef std::vector<ContainerSection> ContainerSections;
146  typedef std::map<std::string,ContainerSections> MergeSections;
148  typedef std::vector<RootRef> LinkSections;
150  typedef std::set<const IInterface*> Clients;
151 
153  MsgStream& msgSvc() const { return m_setup->msgSvc(); }
154 
155 
156  protected:
160  TTreePerfStats* m_statistics;
162  TFile* m_file;
164  TTree *m_refs;
166  Sections m_sections;
168  StringVec m_dbs;
170  StringVec m_conts;
172  StringVec m_links;
174  StringVec m_mergeFIDs;
176  ParamMap m_params;
178  MergeSections m_mergeSects;
180  LinkSections m_linkSects;
182  Clients m_clients;
184  std::string m_empty;
185 
187  const std::string& empty() const;
188 
190  StatusCode saveRefs();
191 
192  public:
202  class Tool {
203  protected:
211 
214  public:
215  TTree* refs() const { return c->m_refs; }
216  StringVec& dbs() const { return c->m_dbs; }
217  StringVec& conts() const { return c->m_conts; }
218  StringVec& links() const { return c->m_links; }
219  ParamMap& params() const { return c->m_params; }
220  MsgStream& msgSvc() const { return c->msgSvc(); }
221  const std::string& name() const { return c->m_name; }
222  Sections& sections() const { return c->m_sections; }
223  LinkSections& linkSections() const { return c->m_linkSects; }
224  MergeSections& mergeSections() const { return c->m_mergeSects; }
225 
227  virtual ~Tool() {}
229  virtual void release() { delete this; }
231  virtual TBranch* getBranch(const std::string& section, const std::string& n) = 0;
233  virtual RootRef poolRef(size_t /* which */) const { return RootRef(); }
234 
236  virtual StatusCode readRefs() = 0;
238  virtual StatusCode saveRefs() = 0;
240  virtual int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs) = 0;
241  } *m_tool;
242  friend class Tool;
243 
245  Tool* makeTool();
246 
247  public:
248 
250  RootDataConnection(const IInterface* own, const std::string& nam, RootConnectionSetup* setup);
252  virtual ~RootDataConnection();
253 
255  TFile* file() const { return m_file; }
257  virtual bool isConnected() const { return m_file != 0; }
259  bool isWritable() const { return m_file != 0 && m_file->IsWritable(); }
261  Tool* tool() const { return m_tool; }
263  const MergeSections& mergeSections() const { return m_mergeSects; }
265  const StringVec& mergeFIDs() const { return m_mergeFIDs; }
266 
267 
269  void addClient(const IInterface* client);
271  size_t removeClient(const IInterface* client);
273  bool lookupClient(const IInterface* client) const;
274 
276  void badWriteError(const std::string& msg) const;
277 
279  std::pair<const RootRef*,const ContainerSection*> getMergeSection(const std::string& container, int entry) const;
280 
282  void enableStatistics(const std::string& section);
284  void saveStatistics(const std::string& statisticsFile);
285 
287  int loadObj(const std::string& section, const std::string& cnt, unsigned long entry, DataObject*& pObj);
288 
290  int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs);
291 
293  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);
295  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);
296 
297 
299  virtual StatusCode connectRead();
301  virtual StatusCode connectWrite(IoType typ);
303  virtual StatusCode disconnect();
305  virtual StatusCode read(void* const, size_t) { return StatusCode::FAILURE; }
307  virtual StatusCode write(const void*, int) { return StatusCode::FAILURE; }
309  virtual long long int seek(long long int, int) { return -1; }
310 
312  TTree* getSection(const std::string& sect, bool create=false);
313 
315  TBranch* getBranch(const std::string& section,const std::string& branch_name)
316  { return m_tool->getBranch(section,branch_name); }
318  TBranch* getBranch(const std::string& section, const std::string& branch_name, TClass* cl, void* ptr, int buff_siz, int split_lvl);
319 
321  void makeRef(IRegistry* pA, RootRef& ref);
323  void makeRef(const std::string& name, long clid, int tech, const std::string& db, const std::string& cnt, int entry, RootRef& ref);
324 
326  int makeLink(const std::string& p);
327 
329  const std::string& getDb(int which) const;
330 
332  const std::string& getCont(int which) const
333  { return (which>=0)&&(size_t(which)<m_conts.size()) ? *(m_conts.begin()+which) : empty(); }
334 
336  const std::string& getLink(int which) const
337  { return (which>=0)&&(size_t(which)<m_links.size()) ? *(m_links.begin()+which) : empty(); }
338  };
339 } // End namespace Gaudi
340 #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.
virtual long long int seek(long long int, int)
Seek on the file described by ioDesc. Arguments as in ::seek()
RootDataConnection::Sections Sections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
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.
#define GAUDI_API
Definition: Kernel.h:108
virtual ~Tool()
Default destructor.
int refCount
Object refrfence count.
Clients m_clients
Client list.
TFile * m_file
Reference to ROOT file.
RootDataConnection::StringVec StringVec
int start
The start entry of the section.
TTreePerfStats * m_statistics
I/O read statistics from TTree.
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:72
StringVec m_links
Map containing internal links names.
ParamMap m_params
Parameter map for file parameters.
std::string loadSection
RootCnvSvc Property: Root data cache size.
StringVec m_mergeFIDs
Map containing merge FIDs.
MergeSections & mergeSections() const
Persistent reference object.
Definition: RootRefs.h:31
virtual void release()
Use releasePtr() helper to delete object.
virtual bool isConnected() const
Check if connected to data source.
TTree * m_refs
Pointer to the reference tree.
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:30
constexpr double m
Definition: SystemOfUnits.h:93
RootConnectionSetup * m_setup
Reference to the setup structure.
Definition of the basic interface.
Definition: IInterface.h:160
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:420
const StringVec & mergeFIDs() const
Access merged FIDs.
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
RootDataConnection::ContainerSection ContainerSection
bool isWritable() const
Is the file writable?
virtual StatusCode read(void *const, size_t)
Read root byte buffer from input stream.
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.
LinkSections m_linkSects
Database link sections.
def which(executable)
Definition: BaseTest.py:519
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:244
ContainerSection(const ContainerSection &s)
Copy constructor.
virtual StatusCode write(const void *, int)
Write root byte buffer to output stream.
MsgStream * m_msgSvc
Reference to message service.
std::map< std::string, ContainerSections > MergeSections
Definition of database section to handle merged files.
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.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
RootDataConnection * c
Pointer to containing data connection object.
Concrete implementation of the IDataConnection interface to access ROOT files.
Helper functions to set/get the application return code.
Definition: __init__.py:1
IIncidentSvc * m_incidentSvc
Reference to incident service.
Internal helper class, which described a TBranch section in a ROOT file.
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
tuple start
Definition: IOTest.py:88
LinkSections & linkSections() const