1 |
loizides |
1.1 |
// $Id: THITreeBase.h 4114 2007-06-14 13:25:51Z loizides $
|
2 |
|
|
|
3 |
|
|
#ifndef DATATREE_TREEWRITER_H
|
4 |
|
|
#define DATATREE_TREEWRITER_H
|
5 |
|
|
|
6 |
|
|
#include <TNamed.h>
|
7 |
|
|
#include <TString.h>
|
8 |
|
|
#include <TFile.h>
|
9 |
|
|
#include <TTree.h>
|
10 |
|
|
|
11 |
|
|
//--------------------------------------------------------------------------------------------------
|
12 |
|
|
//
|
13 |
|
|
// TreeWriter
|
14 |
|
|
//
|
15 |
|
|
// Class implementing a tree writing infra structure. The class creates and maintaines
|
16 |
|
|
// a tree with name "tname" as given in the constructor. The tree is stored in a file
|
17 |
|
|
// or in multiple files if needed, where the file path name and maximum size can be
|
18 |
|
|
// specified. Using TreeWriter::AddBranch allows to add various branches to the tree.
|
19 |
|
|
// The user has to make sure that (s)he calls TreeWriter::BeginEvent and
|
20 |
|
|
// TreeWriter::EndEvent for every event before and after filling of the branch
|
21 |
|
|
// structures.
|
22 |
|
|
//
|
23 |
|
|
// Authors: C.Loizides
|
24 |
|
|
//
|
25 |
|
|
//--------------------------------------------------------------------------------------------------
|
26 |
|
|
|
27 |
|
|
namespace mithep {
|
28 |
|
|
class TreeWriter : public TNamed
|
29 |
|
|
{
|
30 |
|
|
public:
|
31 |
|
|
TreeWriter(const char *tname="MitTree", Bool_t doreset = kFALSE);
|
32 |
|
|
~TreeWriter();
|
33 |
|
|
|
34 |
|
|
void AddBranch(const char *name, const char *cname, void *obj,
|
35 |
|
|
Int_t bsize, Int_t level);
|
36 |
|
|
void AddBranch(const char *name, const char *cname, void *obj,
|
37 |
|
|
Int_t bsize);
|
38 |
|
|
void AddBranch(const char *name, const char *cname, void *obj);
|
39 |
|
|
Bool_t BeginEvent(Bool_t doreset=kFALSE);
|
40 |
|
|
Bool_t EndEvent(Bool_t doreset=kFALSE);
|
41 |
|
|
const char *GetBaseURL() const { return fBaseURL.IsNull() ? "." : fBaseURL; }
|
42 |
|
|
Int_t GetCompressLevel() const { return fCompressLevel; }
|
43 |
|
|
Long64_t GetEntries() const { return fTree != 0 ? fTree->GetEntries() : 0; }
|
44 |
|
|
Long64_t GetFileSize() const { return fFile != 0 ? fFile->GetEND() : 0; }
|
45 |
|
|
const TFile *GetFile() const { return fFile; }
|
46 |
|
|
const char *GetFileName() const { return Form("%s_%03d.root",
|
47 |
|
|
GetPrefix(), GetFileNumber()); }
|
48 |
|
|
UShort_t GetFileNumber() const { return fFileNumber; }
|
49 |
|
|
const char *GetFullName() const { return Form("%s/%s",
|
50 |
|
|
GetBaseURL(), GetFileName()); }
|
51 |
|
|
const char *GetPrefix() const { return fPrefix; }
|
52 |
|
|
void Print(Option_t *option="") const;
|
53 |
|
|
void SetBaseURL(const char *b) { fBaseURL = b; }
|
54 |
|
|
void SetCompressLevel(Int_t l) { fCompressLevel = l; }
|
55 |
|
|
void SetDefaultBrSize(Int_t s) { fDefBrSize=s; }
|
56 |
|
|
void SetDefaultSL(Int_t s) { fDefSL=s;}
|
57 |
|
|
void SetPrefix(const char *p) { fPrefix = p; }
|
58 |
|
|
void StoreObject(const TObject *obj);
|
59 |
|
|
void SetMaxSize(Long64_t s) { fMaxSize=s; }
|
60 |
|
|
|
61 |
|
|
protected:
|
62 |
|
|
TString fBaseURL; //base url for tree storage
|
63 |
|
|
TString fPrefix; //prefix of file name
|
64 |
|
|
UShort_t fFileNumber; //current sequence number
|
65 |
|
|
Int_t fCompressLevel; //compression level used for TFile
|
66 |
|
|
Int_t fDefBrSize; //default buffer size for branches
|
67 |
|
|
Int_t fDefSL; //default split level for branches
|
68 |
|
|
Long64_t fMaxSize; //maximum file size for a file [Bytes]
|
69 |
|
|
const Long64_t fkMinFreeSpace; //minimum free space required for closing file
|
70 |
|
|
const Long64_t fkMinAvgSize; //minimum average entry size
|
71 |
|
|
Long64_t fEvtObjNum; //event object number offset (for TRef)
|
72 |
|
|
Bool_t fIsInit; //true if OpenFile() was called
|
73 |
|
|
Bool_t fDoObjNumReset; //true if obj. number resets automatically (def=0)
|
74 |
|
|
TFile *fFile; //file being written
|
75 |
|
|
TTree *fTree; //tree being filled
|
76 |
|
|
|
77 |
|
|
Bool_t IsInit() const { return fIsInit; }
|
78 |
|
|
Bool_t IsFull() const;
|
79 |
|
|
void OpenFile();
|
80 |
|
|
void CloseFile();
|
81 |
|
|
|
82 |
|
|
ClassDef(TreeWriter,0) // Tree writer class
|
83 |
|
|
};
|
84 |
|
|
|
85 |
|
|
} /*namespace mithep*/
|
86 |
|
|
|
87 |
|
|
#endif /*DATATREE_TREEWRITER_H*/
|