ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataUtil/interface/TreeWriter.h
Revision: 1.15
Committed: Sun Mar 22 11:32:04 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, HEAD
Branch point for: Mit_025c_branch
Changes since 1.14: +3 -1 lines
Log Message:
Add Getters.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: TreeWriter.h,v 1.14 2009/03/15 11:17:04 loizides Exp $
3 //
4 // TreeWriter
5 //
6 // Class implementing a tree writing infrastructure. The class creates and maintaines
7 // a standard tree with name "tname" as given in the constructor. The tree is stored in
8 // a file or in multiple files if needed, where the file path name and maximum size can be
9 // specified. Using TreeWriter::AddBranch allows to add various branches to the tree.
10 // The user has to make sure that (s)he calls TreeWriter::BeginEvent and
11 // TreeWriter::EndEvent for every event before and after filling of the branch
12 // structures. Note that in addition to the standard tree one can create new
13 // tree(s) in the same file using the TreeWriter::AddBranchToTree member functions.
14 //
15 // Authors: C.Loizides
16 //--------------------------------------------------------------------------------------------------
17
18 #ifndef MITANA_DATAUTIL_TREEWRITER_H
19 #define MITANA_DATAUTIL_TREEWRITER_H
20
21 #include <string>
22 #include <TNamed.h>
23 #include <TString.h>
24 #include <TFile.h>
25 #include <TTree.h>
26 #include <TObjArray.h>
27
28 namespace mithep
29 {
30 using std::string;
31
32 class MyTree : public TTree
33 {
34 public:
35 MyTree(const char* name, const char* title, Int_t splitlevel = 99) :
36 TTree(name,title, splitlevel), fAutoFill(1) {}
37 Bool_t GetAutoFill() const { return fAutoFill; }
38 void SetAutoFill(Bool_t b) { fAutoFill = b; }
39
40 protected:
41 Bool_t fAutoFill; //!=true then fill automatically in TreeWriter (def=1)
42 };
43
44 class TreeWriter : public TNamed
45 {
46 public:
47 TreeWriter(const char *tname="MitTree", Bool_t doreset = kFALSE);
48 ~TreeWriter();
49
50 void AddBranch(const char *name, const char *cname,
51 void *obj, Int_t bsize, Int_t level);
52 void AddBranch(const string &name, const string &cname,
53 void *obj, Int_t bsize, Int_t level)
54 { AddBranch(name.c_str(),cname.c_str(),obj,bsize,level); }
55 void AddBranch(const char *name, void *obj, Int_t bsize, Int_t level);
56 void AddBranch(const string &name, void *obj, Int_t bsize, Int_t level)
57 { AddBranch(name.c_str(),obj,bsize,level); }
58 void AddBranch(const char *name, const char *cname,
59 void *obj, Int_t bsize);
60 void AddBranch(const string &name, const string &cname,
61 void *obj, Int_t bsize)
62 { AddBranch(name.c_str(),cname.c_str(),obj,bsize); }
63 void AddBranch(const char *name, void *obj, Int_t bsize);
64 void AddBranch(const string &name, void *obj, Int_t bsize)
65 { AddBranch(name.c_str(),obj, bsize); }
66 void AddBranch(const char *name, const char *cname, void *obj);
67 void AddBranch(const string &name, const string &cname, void *obj)
68 { AddBranch(name.c_str(),cname.c_str(),obj); }
69 void AddBranch(const char *name, void *obj);
70 void AddBranch(const string &name, void *obj)
71 { AddBranch(name.c_str(),obj); }
72 void AddBranchToTree(const char *tname, const char *name, const char *cname,
73 void *obj, Int_t bsize, Int_t level);
74 void AddBranchToTree(const string &tn, const string &n, const string &cn,
75 void *obj, Int_t bsize, Int_t level)
76 { AddBranchToTree(tn.c_str(),n.c_str(),cn.c_str(),obj,bsize,level); }
77 void AddBranchToTree(const char *tname, const char *name, void *obj,
78 Int_t bsize, Int_t level);
79 void AddBranchToTree(const string &tn, const string &n, void *obj,
80 Int_t bsize, Int_t level)
81 { AddBranchToTree(tn.c_str(),n.c_str(),obj,bsize,level); }
82 void AddBranchToTree(const char *tname, const char *name, const char *cname,
83 void *obj, Int_t bsize);
84 void AddBranchToTree(const string &tn, const string &n, const string &cn,
85 void *obj, Int_t bsize)
86 { AddBranchToTree(tn.c_str(),n.c_str(),cn.c_str(),obj,bsize); }
87 void AddBranchToTree(const char *tname, const char *name, void *obj,
88 Int_t bsize);
89 void AddBranchToTree(const string &tn, const string &n, void *obj,
90 Int_t bsize)
91 { AddBranchToTree(tn.c_str(),n.c_str(),obj,bsize); }
92 void AddBranchToTree(const char *tname, const char *name, const char *cname,
93 void *obj);
94 void AddBranchToTree(const string &tn, const string &n, const string &cn,
95 void *obj)
96 { AddBranchToTree(tn.c_str(),n.c_str(),cn.c_str(),obj); }
97 void AddBranchToTree(const char *tname, const char *name, void *obj);
98 void AddBranchToTree(const string &tn, const string &n, void *obj)
99 { AddBranchToTree(tn.c_str(),n.c_str(),obj); }
100 void AddTree(const char *tname);
101 void AddTree(const string &tname) { AddTree(tname.c_str()); }
102 Bool_t BeginEvent(Bool_t doreset=kFALSE);
103 void DoBranchRef(const char *tn);
104 Bool_t EndEvent(Bool_t doreset=kFALSE);
105 const char *GetBaseURL() const
106 { return fBaseURL.IsNull()?".":fBaseURL; }
107 Int_t GetCompressLevel() const { return fCompressLevel; }
108 Int_t GetDefaultBrSize() const { return fDefBrSize; }
109 Int_t GetDefaultSL() const { return fDefSL; }
110 Bool_t GetDoObjNumReset() const { return fDoObjNumReset; }
111 Bool_t GetDoBranchRef() const { return fDoBranchRef; }
112 Long64_t GetEntries(const char *tn=0) const;
113 Long64_t GetFileSize() const
114 { return fFile!=0?fFile->GetEND():0; }
115 const TFile *GetFile() const { return fFile; }
116 const char *GetFileName() const {
117 return Form("%s_%03d.root",GetPrefix(),GetFileNumber()); }
118 UShort_t GetFileNumber() const { return fFileNumber; }
119 const char *GetFullName() const {
120 return Form("%s/%s",GetBaseURL(),GetFileName()); }
121 const char *GetPrefix() const { return fPrefix; }
122 const TTree *GetTree(const char *tn=0) const;
123 TTree *GetTree(const char *tn=0);
124 const TTree *GetTree(const string &tn) const { return GetTree(tn.c_str()); }
125 TTree *GetTree(const string &tn) { return GetTree(tn.c_str()); }
126 void Print(Option_t *option="") const;
127 void SetAutoFill(const char *tn, Bool_t b);
128 void SetAutoFill(const string &tn, Bool_t b)
129 { SetAutoFill(tn.c_str(), b); }
130 void SetBaseURL(const char *b) { fBaseURL = b; }
131 void SetBaseURL(const string &b) { fBaseURL = b.c_str(); }
132 void SetCompressLevel(Int_t l) { fCompressLevel = l; }
133 void SetDefaultBrSize(Int_t s) { fDefBrSize=s; }
134 void SetDefaultSL(Int_t s) { fDefSL=s; }
135 void SetDoObjNumReset(Bool_t b) { fDoObjNumReset = b; }
136 void SetDoBranchRef(Bool_t b) { fDoBranchRef = b; }
137 void SetMaxSize(Long64_t s);
138 void SetPrefix(const char *p) { fPrefix = p; }
139 void SetPrefix(const string &p) { fPrefix = p.c_str(); }
140 void StoreObject(const TObject *obj);
141 void Terminate();
142
143 protected:
144 TString fBaseURL; //base url for tree storage
145 TString fPrefix; //prefix of file name
146 UShort_t fFileNumber; //current sequence number
147 Int_t fCompressLevel; //compression level used for TFile
148 Int_t fDefBrSize; //default buffer size for branches
149 Int_t fDefSL; //default split level for branches
150 Long64_t fMaxSize; //maximum file size for a file [Bytes]
151 const Long64_t fkMinFreeSpace; //minimum free space required for closing file
152 const Long64_t fkMinAvgSize; //minimum average entry size
153 Long64_t fEvtObjNum; //event object number offset (for TRef)
154 Bool_t fIsInit; //true if OpenFile() was called
155 Bool_t fDoObjNumReset; //true if obj. number resets automatically (def=0)
156 Bool_t fDoBranchRef; //true if BranchRef is called automatically (def=0)
157 TFile *fFile; //file being written
158 TObjArray fTrees; //array of tree(s) being filled
159
160 mithep::MyTree *AddOrGetMyTree(const char *tn);
161 mithep::MyTree *GetMyTree(const char *tn);
162 Bool_t IsInit() const { return fIsInit; }
163 Bool_t IsFull() const;
164 void OpenFile();
165 void CloseFile();
166
167 private:
168 const char *CName(void *obj) const;
169
170 ClassDef(TreeWriter, 0) // Tree writer class
171 };
172 }
173 #endif