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