| 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 | // TBranchElement::kDeleteObject = BIT(16)
|
|---|
| 86 | kIsNewTree = BIT(17)
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 | public:
|
|---|
| 90 | MWriteRootFile();
|
|---|
| 91 | MWriteRootFile(const char *fname,
|
|---|
| 92 | const Option_t *opt="RECREATE",
|
|---|
| 93 | const char *ftitle="Untitled",
|
|---|
| 94 | const Int_t comp=9,
|
|---|
| 95 | const char *name=NULL,
|
|---|
| 96 | const char *title=NULL);
|
|---|
| 97 | ~MWriteRootFile();
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | void AddContainer(const char *cname,
|
|---|
| 101 | const char *tname=NULL, const char *ttitle=NULL);
|
|---|
| 102 | void AddContainer(MParContainer *cont,
|
|---|
| 103 | const char *tname=NULL, const char *ttitle=NULL);
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | void Print(Option_t *t=NULL) const;
|
|---|
| 107 |
|
|---|
| 108 | ClassDef(MWriteRootFile, 1) // Task to write data into a root file
|
|---|
| 109 | };
|
|---|
| 110 |
|
|---|
| 111 | #endif
|
|---|