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

Last change on this file since 951 was 852, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 3.1 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
32class MRootFileBranch : public TObject
33{
34private:
35 MRootFileTree *fTree;
36 TBranch *fBranch;
37 MParContainer *fContainer;
38 TString *fContName;
39 TString *fTreeName;
40 TString *fTreeTitle;
41
42public:
43 MRootFileBranch(const char *cname, const char *tname=NULL, const char *ttitle=NULL)
44 : fTree(NULL), fBranch(NULL), fContainer(NULL)
45 {
46 fContName = new TString(cname);
47 fTreeName = tname ? new TString(tname) : NULL;
48 fTreeTitle = ttitle ? new TString(ttitle) : NULL;
49 }
50
51 MRootFileBranch(MParContainer *cont, const char *tname=NULL, const char *ttitle=NULL)
52 : fTree(NULL), fBranch(NULL), fContName(NULL)
53 {
54 fContainer = cont;
55 fTreeName = tname ? new TString(tname) : NULL;
56 fTreeTitle = ttitle ? new TString(ttitle) : NULL;
57 }
58
59 MRootFileTree *GetTree() const { return fTree; }
60 MParContainer *GetContainer() const { return fContainer; }
61 void *GetAddress() { return &fContainer; }
62 TBranch *GetBranch() const { return fBranch; }
63 const char *GetContName() const { return fContName ? (const char*)(*fContName) : NULL; }
64 const char *GetTreeName() const { return fTreeName ? (const char*)(*fTreeName) : NULL; }
65 const char *GetTreeTitle() const { return fTreeTitle ? (const char*)(*fTreeTitle) : NULL; }
66
67 void SetContainer(MParContainer *cont) { fContainer = cont; }
68 void SetTree(MRootFileTree *tree) { fTree = tree; }
69
70};
71
72class MWriteRootFile : public MWriteFile
73{
74private:
75 TFile *fOut;
76
77 TObjArray fBranches;
78 TObjArray fTrees;
79
80 void CheckAndWrite() const;
81 Bool_t IsFileOpen() const;
82 Bool_t GetContainer(MParList *pList);
83 const char *GetFileName() const;
84
85public:
86 MWriteRootFile(const char *fname,
87 const Option_t *opt="RECREATE",
88 const char *ftitle="Unnamed",
89 const Int_t comp=9,
90 const char *name=NULL,
91 const char *title=NULL);
92 ~MWriteRootFile();
93
94 void Print(Option_t *t=NULL);
95
96 void AddContainer(const char *cname,
97 const char *tname=NULL, const char *ttitle=NULL);
98 void AddContainer(MParContainer *cont,
99 const char *tname=NULL, const char *ttitle=NULL);
100
101 ClassDef(MWriteRootFile, 0) // Class to write one container to an ascii file
102};
103
104#endif
Note: See TracBrowser for help on using the repository browser.