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 |
|
---|
11 | class TFile;
|
---|
12 | class TTree;
|
---|
13 | class TBranch;
|
---|
14 |
|
---|
15 | class MRootFileBranch : public TNamed
|
---|
16 | {
|
---|
17 | private:
|
---|
18 | TTree *fTree; //!
|
---|
19 | TBranch *fBranch; //!
|
---|
20 |
|
---|
21 | MParContainer *fContainer;
|
---|
22 | TString fContName;
|
---|
23 |
|
---|
24 | void Init(const char *name, const char *title)
|
---|
25 | {
|
---|
26 | SetName(name?name:"");
|
---|
27 | SetTitle(title?title:"");
|
---|
28 | }
|
---|
29 |
|
---|
30 | public:
|
---|
31 | MRootFileBranch() : fTree(NULL), fBranch(NULL), fContainer(NULL)
|
---|
32 | {
|
---|
33 | Init(NULL, NULL);
|
---|
34 | fContName = "";
|
---|
35 | }
|
---|
36 |
|
---|
37 | MRootFileBranch(const char *cname, const char *tname=NULL, const char *ttitle=NULL)
|
---|
38 | : fTree(NULL), fBranch(NULL), fContainer(NULL)
|
---|
39 | {
|
---|
40 | Init(tname, ttitle);
|
---|
41 | fContName = cname;
|
---|
42 | }
|
---|
43 |
|
---|
44 | MRootFileBranch(MParContainer *cont, const char *tname=NULL, const char *ttitle=NULL)
|
---|
45 | : fTree(NULL), fBranch(NULL), fContName("")
|
---|
46 | {
|
---|
47 | Init(tname, ttitle);
|
---|
48 | fContainer = cont;
|
---|
49 | }
|
---|
50 |
|
---|
51 | TTree *GetTree() const { return fTree; }
|
---|
52 | MParContainer *GetContainer() const { return fContainer; }
|
---|
53 | void *GetAddress() { return &fContainer; }
|
---|
54 | TBranch *GetBranch() const { return fBranch; }
|
---|
55 | const char *GetContName() const { return fContName; }
|
---|
56 |
|
---|
57 | void SetContainer(MParContainer *cont) { fContainer = cont; }
|
---|
58 | void SetTree(TTree *tree) { fTree = tree; }
|
---|
59 | void SetBranch(TBranch *branch) { fBranch = branch; }
|
---|
60 |
|
---|
61 | ClassDef(MRootFileBranch, 1) // Storage container for MWriteRootFile to store TBranch informations
|
---|
62 | };
|
---|
63 |
|
---|
64 | class MWriteRootFile : public MWriteFile
|
---|
65 | {
|
---|
66 | private:
|
---|
67 | TFile *fOut;
|
---|
68 |
|
---|
69 | TObjArray fBranches;
|
---|
70 | TObjArray fTrees; //!
|
---|
71 |
|
---|
72 | //UInt_t fNumEvents; //! Number of events written in a run
|
---|
73 |
|
---|
74 | void CheckAndWrite() const;
|
---|
75 | Bool_t IsFileOpen() const;
|
---|
76 | Bool_t GetContainer(MParList *pList);
|
---|
77 | const char *GetFileName() const;
|
---|
78 |
|
---|
79 | void StreamPrimitive(ofstream &out) const;
|
---|
80 | //Bool_t ReInit(MParList *pList);
|
---|
81 |
|
---|
82 | enum {
|
---|
83 | kFillTree = BIT(14),
|
---|
84 | // TBranch::kAutoDelete = BIT(15)
|
---|
85 | kIsNewTree = BIT(16)
|
---|
86 | };
|
---|
87 |
|
---|
88 | public:
|
---|
89 | MWriteRootFile();
|
---|
90 | MWriteRootFile(const char *fname,
|
---|
91 | const Option_t *opt="RECREATE",
|
---|
92 | const char *ftitle="Untitled",
|
---|
93 | const Int_t comp=9,
|
---|
94 | const char *name=NULL,
|
---|
95 | const char *title=NULL);
|
---|
96 | ~MWriteRootFile();
|
---|
97 |
|
---|
98 |
|
---|
99 | void AddContainer(const char *cname,
|
---|
100 | const char *tname=NULL, const char *ttitle=NULL);
|
---|
101 | void AddContainer(MParContainer *cont,
|
---|
102 | const char *tname=NULL, const char *ttitle=NULL);
|
---|
103 |
|
---|
104 |
|
---|
105 | void Print(Option_t *t=NULL) const;
|
---|
106 |
|
---|
107 | ClassDef(MWriteRootFile, 1) // Task to write data into a root file
|
---|
108 | };
|
---|
109 |
|
---|
110 | #endif
|
---|