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

File Contents

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