source: trunk/MagicSoft/Mars/mbase/MWriteRootFile.h@ 991

Last change on this file since 991 was 969, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 3.3 KB
Line 
1#ifndef MWRITEROOTFILE_H
2#define MWRITEROOTFILE_H
3
4#ifndef MWriteFile_H
5#include "MWriteFile.h"
6#endif
7#ifndef ROOT_TObjArray
8#include <TObjArray.h>
9#endif
10
11class TFile;
12class TTree;
13class TBranch;
14
15class MRootFileTree : public TObject
16{
17private:
18 TTree *fTree;
19 Bool_t fWriteFlag;
20 ULong_t fNumEntries;
21
22public:
23 MRootFileTree(TTree *tree) : fTree(tree), fWriteFlag(kFALSE), fNumEntries(0) {}
24 TTree *GetTree() const { return fTree; }
25 Bool_t HasWriteFlag() const { return fWriteFlag; }
26 ULong_t GetNumEntries() const { return fNumEntries; }
27 void operator++(int) { fNumEntries++; }
28 void SetWriteFlag() { fWriteFlag = kTRUE; }
29 void DelWriteFlag() { fWriteFlag = kFALSE; }
30
31 ClassDef(MRootFileTree, 0) // Storage container for MWriteRootFile to store Tree informations
32};
33
34class MRootFileBranch : public TObject
35{
36private:
37 MRootFileTree *fTree;
38 TBranch *fBranch;
39 MParContainer *fContainer;
40 TString *fContName;
41 TString *fTreeName;
42 TString *fTreeTitle;
43
44public:
45 MRootFileBranch(const char *cname, const char *tname=NULL, const char *ttitle=NULL)
46 : fTree(NULL), fBranch(NULL), fContainer(NULL)
47 {
48 fContName = new TString(cname);
49 fTreeName = tname ? new TString(tname) : NULL;
50 fTreeTitle = ttitle ? new TString(ttitle) : NULL;
51 }
52
53 MRootFileBranch(MParContainer *cont, const char *tname=NULL, const char *ttitle=NULL)
54 : fTree(NULL), fBranch(NULL), fContName(NULL)
55 {
56 fContainer = cont;
57 fTreeName = tname ? new TString(tname) : NULL;
58 fTreeTitle = ttitle ? new TString(ttitle) : NULL;
59 }
60
61 MRootFileTree *GetTree() const { return fTree; }
62 MParContainer *GetContainer() const { return fContainer; }
63 void *GetAddress() { return &fContainer; }
64 TBranch *GetBranch() const { return fBranch; }
65 const char *GetContName() const { return fContName ? (const char*)(*fContName) : NULL; }
66 const char *GetTreeName() const { return fTreeName ? (const char*)(*fTreeName) : NULL; }
67 const char *GetTreeTitle() const { return fTreeTitle ? (const char*)(*fTreeTitle) : NULL; }
68
69 void SetContainer(MParContainer *cont) { fContainer = cont; }
70 void SetTree(MRootFileTree *tree) { fTree = tree; }
71
72 ClassDef(MRootFileBranch, 0) // Storage container for MWriteRootFile to store TBranch informations
73};
74
75class MWriteRootFile : public MWriteFile
76{
77private:
78 TFile *fOut;
79
80 TObjArray fBranches;
81 TObjArray fTrees;
82
83 void CheckAndWrite() const;
84 Bool_t IsFileOpen() const;
85 Bool_t GetContainer(MParList *pList);
86 const char *GetFileName() const;
87
88public:
89 MWriteRootFile(const char *fname,
90 const Option_t *opt="RECREATE",
91 const char *ftitle="Unnamed",
92 const Int_t comp=9,
93 const char *name=NULL,
94 const char *title=NULL);
95 ~MWriteRootFile();
96
97 void Print(Option_t *t=NULL);
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 ClassDef(MWriteRootFile, 0) // Class to write one container to a root file
105};
106
107#endif
Note: See TracBrowser for help on using the repository browser.