| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
42 class GAUDI_API RootConnectionSetup {
43 public:
45 typedef std::vector<std::string> StringVec;
46 protected:
48 virtual ~RootConnectionSetup();
50 int refCount;
52 MsgStream* m_msgSvc;
54 IIncidentSvc* m_incidentSvc;
55
56 public:
58 StringVec cacheBranches;
60 StringVec vetoBranches;
62 std::string loadSection;
64 int cacheSize;
66 int learnEntries;
67
69 RootConnectionSetup();
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
99 class GAUDI_API RootDataConnection : virtual public Gaudi::IDataConnection {
100 public:
101
102 enum { ROOT_READ_ERROR = 0x2,
103 ROOT_OPEN_ERROR = 0x4
104 };
105
116 struct ContainerSection {
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) {}
124 ContainerSection& operator=(const ContainerSection& s) {
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:
158 RootConnectionSetup* m_setup;
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:
204 typedef RootDataConnection::StringVec StringVec;
205 typedef RootDataConnection::ParamMap ParamMap;
206 typedef RootDataConnection::Sections Sections;
207 typedef RootDataConnection::MergeSections MergeSections;
208 typedef RootDataConnection::LinkSections LinkSections;
209 typedef RootDataConnection::ContainerSection ContainerSection;
210 typedef RootDataConnection::ContainerSections ContainerSections;
211
213 RootDataConnection* c;
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