source: trunk/Mars/mfileio/MWriteRootFile.h@ 20063

Last change on this file since 20063 was 19760, checked in by tbretz, 5 years ago
They are added to the ListOfCleanups. This is implemented as a THashTable. According to the root documentation, it is required to rehash the table whenever the name of an object in the table changes. This is now guranteed if name change happens via SetName
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
109 // MTask
110 Bool_t ReInit(MParList *pList);
111 void StreamPrimitive(std::ostream &out) const;
112
113 // Constructor
114 void Init(const char *name=0, const char *title=0);
115
116public:
117 MWriteRootFile();
118 MWriteRootFile(const Int_t comp,
119 const char *rule,
120 const Option_t *opt="RECREATE",
121 const char *ftitle="Untitled",
122 const char *name=NULL,
123 const char *title=NULL);
124 MWriteRootFile(const char *fname,
125 const Option_t *opt="RECREATE",
126 const char *ftitle="Untitled",
127 const Int_t comp=2,
128 const char *name=NULL,
129 const char *title=NULL);
130 ~MWriteRootFile();
131
132 void SetName(const char *name);
133
134 void AddContainer(const char *cname, const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
135 void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE, Long64_t max=-1);
136 void AddCopySource(const char *tname, const char *bname=NULL, Bool_t force=kTRUE);
137 void AddCopySource(const char *tname, Bool_t force)
138 {
139 AddCopySource(tname, NULL, force);
140 }
141
142 void AddTree(const char *name, Bool_t force=kTRUE)
143 {
144 AddContainer(Form("MReport%s", name), name, force);
145 AddContainer(Form("MTime%s", name), name, force);
146 }
147
148 void Print(Option_t *t=NULL) const;
149
150 Bool_t cd(const char *path=0);
151
152 void RecursiveRemove(TObject *obj);
153
154 static TString SubstituteName(const char *regexp, TString fname);
155
156 const char *GetFileName() const;
157
158 ClassDef(MWriteRootFile, 1) // Task to write data into a root file
159};
160
161#endif
Note: See TracBrowser for help on using the repository browser.