| 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 | TString fContName;
|
|---|
| 26 |
|
|---|
| 27 | Bool_t fMust;
|
|---|
| 28 |
|
|---|
| 29 | void Init(const char *name, Bool_t must)
|
|---|
| 30 | {
|
|---|
| 31 | SetName(name?name:"");
|
|---|
| 32 | fMust = must;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | public:
|
|---|
| 36 | MRootFileBranch() : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0)
|
|---|
| 37 | {
|
|---|
| 38 | Init(NULL, kFALSE);
|
|---|
| 39 | fContName = "";
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | MRootFileBranch(const char *cname, const char *tname=NULL, Bool_t must=kFALSE)
|
|---|
| 43 | : fTree(NULL), fBranch(NULL), fContainer(NULL), fMust(0)
|
|---|
| 44 | {
|
|---|
| 45 | Init(tname, must);
|
|---|
| 46 | fContName = cname;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | MRootFileBranch(MParContainer *cont, const char *tname=NULL, Bool_t must=kFALSE)
|
|---|
| 50 | : fTree(NULL), fBranch(NULL), fContName(""), fMust(0)
|
|---|
| 51 | {
|
|---|
| 52 | Init(tname, must);
|
|---|
| 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 fContName; }
|
|---|
| 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 |
|
|---|
| 81 | TString fSplitRule; // file splitting allowed if rule existing (done in ReInit)
|
|---|
| 82 |
|
|---|
| 83 | enum {
|
|---|
| 84 | kFillTree = BIT(14),
|
|---|
| 85 | // Be carefull these bits are already in use!
|
|---|
| 86 | // TBranch::kAutoDelete = BIT(15)
|
|---|
| 87 | // TBranchElement::kDeleteObject = BIT(16)
|
|---|
| 88 | kIsNewTree = BIT(17)
|
|---|
| 89 | };
|
|---|
| 90 |
|
|---|
| 91 | // File handling
|
|---|
| 92 | void Close();
|
|---|
| 93 | TString GetNewFileName(const char *fname) const;
|
|---|
| 94 | Bool_t ChangeFile(const char *fname);
|
|---|
| 95 |
|
|---|
| 96 | // MWrite
|
|---|
| 97 | Bool_t CheckAndWrite();
|
|---|
| 98 | Bool_t IsFileOpen() const;
|
|---|
| 99 | Bool_t GetContainer(MParList *pList);
|
|---|
| 100 | const char *GetFileName() const;
|
|---|
| 101 |
|
|---|
| 102 | // MTask
|
|---|
| 103 | Bool_t ReInit(MParList *pList);
|
|---|
| 104 | void StreamPrimitive(ofstream &out) const;
|
|---|
| 105 |
|
|---|
| 106 | // Constructor
|
|---|
| 107 | void Init(const char *name=0, const char *title=0);
|
|---|
| 108 |
|
|---|
| 109 | public:
|
|---|
| 110 | MWriteRootFile();
|
|---|
| 111 | MWriteRootFile(const Int_t comp,
|
|---|
| 112 | const char *rule,
|
|---|
| 113 | const Bool_t overwrite=kTRUE,
|
|---|
| 114 | const char *ftitle="Untitled",
|
|---|
| 115 | const char *name=NULL,
|
|---|
| 116 | const char *title=NULL);
|
|---|
| 117 | MWriteRootFile(const char *fname,
|
|---|
| 118 | const Option_t *opt="RECREATE",
|
|---|
| 119 | const char *ftitle="Untitled",
|
|---|
| 120 | const Int_t comp=2,
|
|---|
| 121 | const char *name=NULL,
|
|---|
| 122 | const char *title=NULL);
|
|---|
| 123 | ~MWriteRootFile();
|
|---|
| 124 |
|
|---|
| 125 | void AddContainer(const char *cname, const char *tname=NULL, Bool_t must=kTRUE);
|
|---|
| 126 | void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE);
|
|---|
| 127 |
|
|---|
| 128 | void Print(Option_t *t=NULL) const;
|
|---|
| 129 |
|
|---|
| 130 | Bool_t cd(const char *path=0);
|
|---|
| 131 |
|
|---|
| 132 | ClassDef(MWriteRootFile, 1) // Task to write data into a root file
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | #endif
|
|---|