ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataUtil/interface/TreeWriter.h
Revision: 1.12
Committed: Mon Dec 1 17:39:20 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.11: +5 -3 lines
Log Message:
Added AddTree and DoBranchRef

File Contents

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