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