ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataUtil/interface/TreeWriter.h
Revision: 1.8
Committed: Wed Jun 18 19:08:14 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.7: +10 -11 lines
Log Message:
Coding conventions.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: TreeWriter.h,v 1.7 2008/06/17 08:22:41 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
19 #ifndef DATATREE_TREEWRITER_H
20 #define DATATREE_TREEWRITER_H
21
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 class MyTree : public TTree
31 {
32 public:
33 MyTree(const char* name, const char* title, Int_t splitlevel = 99) :
34 TTree(name,title, splitlevel), fAutoFill(1) {}
35 Bool_t GetAutoFill() const { return fAutoFill; }
36 void SetAutoFill(Bool_t b) { fAutoFill = b; }
37 protected:
38 Bool_t fAutoFill; //!=true then fill automatically in TreeWriter (def=1)
39 };
40
41 class TreeWriter : public TNamed
42 {
43 public:
44 TreeWriter(const char *tname="MitTree", Bool_t doreset = kFALSE);
45 ~TreeWriter();
46
47 void AddBranch(const char *name, const char *cname,
48 void *obj, Int_t bsize, Int_t level);
49 void AddBranch(const char *name, void *obj, Int_t bsize, Int_t level);
50 void AddBranch(const char *name, const char *cname,
51 void *obj, Int_t bsize);
52 void AddBranch(const char *name, void *obj, Int_t bsize);
53 void AddBranch(const char *name, const char *cname,
54 void *obj);
55 void AddBranch(const char *name, void *obj);
56 void AddBranchToTree(const char *tname, const char *name, const char *cname,
57 void *obj, Int_t bsize, Int_t level);
58 void AddBranchToTree(const char *tname, const char *name, void *obj,
59 Int_t bsize, Int_t level);
60 void AddBranchToTree(const char *tname, const char *name, const char *cname,
61 void *obj, Int_t bsize);
62 void AddBranchToTree(const char *tname, const char *name, void *obj,
63 Int_t bsize);
64 void AddBranchToTree(const char *tname, const char *name, const char *cname,
65 void *obj);
66 void AddBranchToTree(const char *tname, const char *name, void *obj);
67 Bool_t BeginEvent(Bool_t doreset=kFALSE);
68 Bool_t EndEvent(Bool_t doreset=kFALSE);
69 const char *GetBaseURL() const {
70 return fBaseURL.IsNull() ? "." : fBaseURL; }
71 Int_t GetCompressLevel() const { return fCompressLevel; }
72 Long64_t GetEntries(const char *tn=0) const;
73 Long64_t GetFileSize() const {
74 return fFile != 0 ? fFile->GetEND() : 0; }
75 const TFile *GetFile() const { return fFile; }
76 const char *GetFileName() const {
77 return Form("%s_%03d.root", GetPrefix(), GetFileNumber()); }
78 UShort_t GetFileNumber() const { return fFileNumber; }
79 const char *GetFullName() const {
80 return Form("%s/%s", GetBaseURL(), GetFileName()); }
81 const char *GetPrefix() const { return fPrefix; }
82 const TTree *GetTree(const char *tn) const;
83 TTree *GetTree(const char *tn);
84 void Print(Option_t *option="") const;
85 void SetAutoFill(const char *tn, Bool_t b);
86 void SetBaseURL(const char *b) { fBaseURL = b; }
87 void SetCompressLevel(Int_t l) { fCompressLevel = l; }
88 void SetDefaultBrSize(Int_t s) { fDefBrSize=s; }
89 void SetDefaultSL(Int_t s) { fDefSL=s;}
90 void SetMaxSize(Long64_t s);
91 void SetPrefix(const char *p) { fPrefix = p; }
92 void StoreObject(const TObject *obj);
93
94 protected:
95 TString fBaseURL; // base url for tree storage
96 TString fPrefix; // prefix of file name
97 UShort_t fFileNumber; // current sequence number
98 Int_t fCompressLevel; // compression level used for TFile
99 Int_t fDefBrSize; // default buffer size for branches
100 Int_t fDefSL; // default split level for branches
101 Long64_t fMaxSize; // maximum file size for a file [Bytes]
102 const Long64_t fkMinFreeSpace; // minimum free space required for closing file
103 const Long64_t fkMinAvgSize; // minimum average entry size
104 Long64_t fEvtObjNum; // event object number offset (for TRef)
105 Bool_t fIsInit; // true if OpenFile() was called
106 Bool_t fDoObjNumReset; // true if obj. number resets automatically (def=0)
107 TFile *fFile; // file being written
108 TObjArray fTrees; // array of tree(s) being filled
109
110 mithep::MyTree *AddOrGetMyTree(const char *tn);
111 mithep::MyTree *GetMyTree(const char *tn);
112 Bool_t IsInit() const { return fIsInit; }
113 Bool_t IsFull() const;
114 void OpenFile();
115 void CloseFile();
116
117 private:
118 const char *CName(void *obj) const;
119
120 ClassDef(TreeWriter,0) // Tree writer class
121 };
122 }
123 #endif