source: branches/removing_cpp11_features/mfileio/MWriteRootFile.h@ 19890

Last change on this file since 19890 was 17867, checked in by tbretz, 11 years ago
Added the possibility to limit the number of events written per branch per file.
File size: 4.8 KB
Line 
1#ifndef MARS_MWriteRootFile
2#define MARS_MWriteRootFile
3
4#ifndef MARS_MWriteFile
5#include "MWriteFile.h"
6#endif
7#ifndef ROOT_TObjArray
8#include <TObjArray.h>
9#endif
10#ifndef ROOT_TArrayL
11#include <TArrayL.h>
12#endif
13
14class TFile;
15class TTree;
16class TBranch;
17
18class MRootFileBranch : public TNamed
19{
20private:
21 TTree *fTree; //!
22 TBranch *fBranch; //!
23
24 MParContainer *fContainer;
25
26 Bool_t fMust;
27 Long64_t fMaxEntries;
28
29 void Init(const char *name, Bool_t must)
30 {
31 SetName(name?name:"");
32 fMust = must;
33 }
34
35public:
36 MRootFileBranch() : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0), fMaxEntries(0)
37 {
38 Init(NULL, kFALSE);
39 fTitle = "";
40 }
41
42 MRootFileBranch(const char *cname, const char *tname=NULL, Bool_t must=kFALSE, Long64_t max=-1)
43 : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0), fMaxEntries(max)
44 {
45 Init(tname, must);
46 fTitle = cname;
47 }
48
49 MRootFileBranch(MParContainer *cont, const char *tname=NULL, Bool_t must=kFALSE, Long64_t max=-1)
50 : fTree(NULL), fBranch(NULL), fMust(0), fMaxEntries(max)
51 {
52 Init(tname, must);
53 fTitle = "";
54 fContainer = cont;
55 }
56
57 TTree *GetTree() const { return fTree; }
58 MParContainer *GetContainer() const { return fContainer; }
59 void *GetAddress() { return &fContainer; }
60 TBranch *GetBranch() const { return fBranch; }
61 const char *GetContName() const { return fTitle; }
62 Bool_t MustHave() const { return fMust; }
63 Long64_t GetMaxEntries() const { return fMaxEntries; }
64
65 void SetContainer(MParContainer *cont) { fContainer = cont; }
66 void SetTree(TTree *tree) { fTree = tree; }
67 void SetBranch(TBranch *branch) { fBranch = branch; }
68
69 ClassDef(MRootFileBranch, 1) // Storage container for MWriteRootFile to store TBranch informations
70};
71
72class MWriteRootFile : public MWriteFile
73{
74private:
75 static const TString gsDefName;
76 static const TString gsDefTitle;
77
78 TFile *fOut; // Current file
79
80 TObjArray fBranches; // List of Branch setup (MRootFileBranch)
81 TObjArray fTrees; //! List of trees
82 TObjArray fCopies; // Branches and tree to copy
83
84 TString fSplitRule; // file splitting allowed if rule existing (done in ReInit)
85
86 enum {
87 kIsNotOwner = BIT(14), // MWriteRootFile is not owner of fOut
88 kFillTree = BIT(14),
89 kForced = BIT(14), // Used for flag in fCopies
90 // Be carefull these bits are already in use!
91 // TBranch::kAutoDelete = BIT(15)
92 // TBranchElement::kDeleteObject = BIT(16)
93 // TTree::kFriendLock = BIT(17)
94 kIsNewTree = BIT(23)
95 };
96
97 // File handling
98 void Close();
99 Bool_t ChangeFile(const char *fname);
100 TFile *OpenFile(const char *name, Option_t *option, const char *title, Int_t comp);
101 void CopyTree(TTree &t) const;
102 Bool_t MakeCopies(const char *oldname) const;
103
104 // MWrite
105 Bool_t CheckAndWrite();
106 Bool_t IsFileOpen() const;
107 Bool_t GetContainer(MParList *pList);
108 const char *GetFileName() const;
109
110 // MTask
111 Bool_t ReInit(MParList *pList);
112 void StreamPrimitive(std::ostream &out) const;
113
114 // Constructor
115 void Init(const char *name=0, const char *title=0);
116
117public:
118 MWriteRootFile();
119 MWriteRootFile(const Int_t comp,
120 const char *rule,
121 const Option_t *opt="RECREATE",
122 const char *ftitle="Untitled",
123 const char *name=NULL,
124 const char *title=NULL);
125 MWriteRootFile(const char *fname,
126 const Option_t *opt="RECREATE",
127 const char *ftitle="Untitled",
128 const Int_t comp=2,
129 const char *name=NULL,
130 const char *title=NULL);
131 ~MWriteRootFile();
132
133 void AddContainer(const char *cname, const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
134 void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
135 void AddCopySource(const char *tname, const char *bname=NULL, Bool_t force=kTRUE);
136 void AddCopySource(const char *tname, Bool_t force)
137 {
138 AddCopySource(tname, NULL, force);
139 }
140
141 void AddTree(const char *name, Bool_t force=kTRUE)
142 {
143 AddContainer(Form("MReport%s", name), name, force);
144 AddContainer(Form("MTime%s", name), name, force);
145 }
146
147 void Print(Option_t *t=NULL) const;
148
149 Bool_t cd(const char *path=0);
150
151 void RecursiveRemove(TObject *obj);
152
153 static TString SubstituteName(const char *regexp, TString fname);
154
155 ClassDef(MWriteRootFile, 1) // Task to write data into a root file
156};
157
158#endif
Note: See TracBrowser for help on using the repository browser.