ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataUtil/interface/TreeWriter.h
(Generate patch)

Comparing UserCode/MitAna/DataUtil/interface/TreeWriter.h (file contents):
Revision 1.2 by loizides, Tue May 27 19:59:54 2008 UTC vs.
Revision 1.3 by loizides, Mon Jun 2 08:58:52 2008 UTC

# Line 7 | Line 7
7   #include <TString.h>
8   #include <TFile.h>
9   #include <TTree.h>
10 + #include <TObjArray.h>
11  
12   //--------------------------------------------------------------------------------------------------
13   //
14   // TreeWriter
15   //
16   // Class implementing a tree writing infra structure. The class creates and maintaines
17 < // a tree with name "tname" as given in the constructor. The tree is stored in a file
18 < // or in multiple files if needed, where the file path name and maximum size can be
17 > // 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   // 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 < // structures.
22 > // 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   //
25   // Authors: C.Loizides
26   //
# Line 26 | Line 28
28  
29   namespace mithep
30   {
31 +  class MyTree : public TTree
32 +  {
33 +    public:
34 +      MyTree(const char* name, const char* title, Int_t splitlevel = 99) :
35 +         TTree(name,title, splitlevel), fAutoFill(1) {}
36 +      Bool_t GetAutoFill() const   { return fAutoFill; }
37 +      void   SetAutoFill(Bool_t b) { fAutoFill = b; }
38 +    protected:
39 +      Bool_t fAutoFill; //!=true then fill automatically in TreeWriter (def=1)
40 +  };
41 +
42    class TreeWriter : public TNamed
43    {
44      public:
45        TreeWriter(const char *tname="MitTree", Bool_t doreset = kFALSE);
46        ~TreeWriter();
47  
48 <      void                 AddBranch(const char *name, const char *cname, void *obj,
49 <                                     Int_t bsize, Int_t level);
50 <      void                 AddBranch(const char *name, const char *cname, void *obj,
51 <                                     Int_t bsize);
52 <      void                 AddBranch(const char *name, const char *cname, void *obj);
48 >      void                 AddBranch(const char *name, const char *cname,
49 >                                     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, const char *cname,
53 >                                     void *obj);
54 >      void                 AddBranchToTree(const char *tname, const char *name, const char *cname,
55 >                                           void *obj,  Int_t bsize, Int_t level);
56 >      void                 AddBranchToTree(const char *tname, const char *name, const char *cname,
57 >                                           void *obj, Int_t bsize);
58 >      void                 AddBranchToTree(const char *tname, const char *name, const char *cname,
59 >                                           void *obj);
60        Bool_t               BeginEvent(Bool_t doreset=kFALSE);
61        Bool_t               EndEvent(Bool_t doreset=kFALSE);
62 <      const char          *GetBaseURL()        const { return fBaseURL.IsNull() ? "." : fBaseURL; }  
63 <      Int_t                GetCompressLevel()  const { return fCompressLevel; }
64 <      Long64_t             GetEntries()        const { return fTree != 0 ? fTree->GetEntries() : 0; }
65 <      Long64_t             GetFileSize()       const { return fFile != 0 ? fFile->GetEND() : 0; }
66 <      const TFile         *GetFile()           const { return fFile; }
67 <      const char          *GetFileName()       const { return Form("%s_%03d.root",
68 <                                                                   GetPrefix(), GetFileNumber()); }
69 <      UShort_t             GetFileNumber()     const { return fFileNumber; }
70 <      const char          *GetFullName()       const { return Form("%s/%s",
71 <                                                                   GetBaseURL(), GetFileName()); }
72 <      const char          *GetPrefix()         const { return fPrefix; }  
73 <      void                 Print(Option_t *option="") const;
74 <      void                 SetBaseURL(const char *b) { fBaseURL = b; }
75 <      void                 SetCompressLevel(Int_t l) { fCompressLevel = l; }
76 <      void                 SetDefaultBrSize(Int_t s) { fDefBrSize=s; }
77 <      void                 SetDefaultSL(Int_t s)     { fDefSL=s;}
78 <      void                 SetPrefix(const char *p)  { fPrefix = p; }
62 >      const char          *GetBaseURL()                 const { return fBaseURL.IsNull() ? "." : fBaseURL; }  
63 >      Int_t                GetCompressLevel()           const { return fCompressLevel; }
64 >      Long64_t             GetEntries(const char *tn=0) const;
65 >      Long64_t             GetFileSize()                const { return fFile != 0 ? fFile->GetEND() : 0; }
66 >      const TFile         *GetFile()                    const { return fFile; }
67 >      const char          *GetFileName()                const { return Form("%s_%03d.root",
68 >                                                                            GetPrefix(), GetFileNumber()); }
69 >      UShort_t             GetFileNumber()              const { return fFileNumber; }
70 >      const char          *GetFullName()                const { return Form("%s/%s",
71 >                                                                            GetBaseURL(), GetFileName()); }
72 >      const char          *GetPrefix()                  const { return fPrefix; }  
73 >      const TTree         *GetTree(const char *tn)      const;
74 >      TTree               *GetTree(const char *tn);
75 >      void                 Print(Option_t *option="")   const;
76 >      void                 SetAutoFill(const char *tn, Bool_t b);
77 >      void                 SetBaseURL(const char *b)          { fBaseURL = b; }
78 >      void                 SetCompressLevel(Int_t l)          { fCompressLevel = l; }
79 >      void                 SetDefaultBrSize(Int_t s)          { fDefBrSize=s; }
80 >      void                 SetDefaultSL(Int_t s)              { fDefSL=s;}
81 >      void                 SetMaxSize(Long64_t s)             { fMaxSize=s; }
82 >      void                 SetPrefix(const char *p)           { fPrefix = p; }
83        void                 StoreObject(const TObject *obj);
60      void                 SetMaxSize(Long64_t s)    { fMaxSize=s; }
84  
85      protected:
86 <      TString              fBaseURL;          //base url for tree storage
87 <      TString              fPrefix;           //prefix of file name
88 <      UShort_t             fFileNumber;       //current sequence number
89 <      Int_t                fCompressLevel;    //compression level used for TFile
90 <      Int_t                fDefBrSize;        //default buffer size for branches
91 <      Int_t                fDefSL;            //default split level for branches
92 <      Long64_t             fMaxSize;          //maximum file size for a file [Bytes]
93 <      const Long64_t       fkMinFreeSpace;    //minimum free space required for closing file
94 <      const Long64_t       fkMinAvgSize;      //minimum average entry size
95 <      Long64_t             fEvtObjNum;        //event object number offset (for TRef)
96 <      Bool_t               fIsInit;           //true if OpenFile() was called
97 <      Bool_t               fDoObjNumReset;    //true if obj. number resets automatically (def=0)
98 <      TFile               *fFile;             //file being written
99 <      TTree               *fTree;             //tree being filled
100 <
101 <      Bool_t               IsInit()            const { return fIsInit; }
102 <      Bool_t               IsFull()            const;
86 >      TString              fBaseURL;            //base url for tree storage
87 >      TString              fPrefix;             //prefix of file name
88 >      UShort_t             fFileNumber;         //current sequence number
89 >      Int_t                fCompressLevel;      //compression level used for TFile
90 >      Int_t                fDefBrSize;          //default buffer size for branches
91 >      Int_t                fDefSL;              //default split level for branches
92 >      Long64_t             fMaxSize;            //maximum file size for a file [Bytes]
93 >      const Long64_t       fkMinFreeSpace;      //minimum free space required for closing file
94 >      const Long64_t       fkMinAvgSize;        //minimum average entry size
95 >      Long64_t             fEvtObjNum;          //event object number offset (for TRef)
96 >      Bool_t               fIsInit;             //true if OpenFile() was called
97 >      Bool_t               fDoObjNumReset;      //true if obj. number resets automatically (def=0)
98 >      TFile               *fFile;               //file being written
99 >      TObjArray            fTrees;              //array of tree(s) being filled
100 >
101 >      mithep::MyTree      *AddOrGetMyTree(const char *tn);
102 >      mithep::MyTree      *GetMyTree(const char *tn);
103 >      Bool_t               IsInit()                     const { return fIsInit; }
104 >      Bool_t               IsFull()                     const;
105        void                 OpenFile();
106        void                 CloseFile();
107  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines