1 |
// $Id: TreeWriter.h,v 1.1 2008/05/27 19:36:05 loizides Exp $
|
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 |
{
|
29 |
class TreeWriter : public TNamed
|
30 |
{
|
31 |
public:
|
32 |
TreeWriter(const char *tname="MitTree", Bool_t doreset = kFALSE);
|
33 |
~TreeWriter();
|
34 |
|
35 |
void AddBranch(const char *name, const char *cname, void *obj,
|
36 |
Int_t bsize, Int_t level);
|
37 |
void AddBranch(const char *name, const char *cname, void *obj,
|
38 |
Int_t bsize);
|
39 |
void AddBranch(const char *name, const char *cname, void *obj);
|
40 |
Bool_t BeginEvent(Bool_t doreset=kFALSE);
|
41 |
Bool_t EndEvent(Bool_t doreset=kFALSE);
|
42 |
const char *GetBaseURL() const { return fBaseURL.IsNull() ? "." : fBaseURL; }
|
43 |
Int_t GetCompressLevel() const { return fCompressLevel; }
|
44 |
Long64_t GetEntries() const { return fTree != 0 ? fTree->GetEntries() : 0; }
|
45 |
Long64_t GetFileSize() const { return fFile != 0 ? fFile->GetEND() : 0; }
|
46 |
const TFile *GetFile() const { return fFile; }
|
47 |
const char *GetFileName() const { return Form("%s_%03d.root",
|
48 |
GetPrefix(), GetFileNumber()); }
|
49 |
UShort_t GetFileNumber() const { return fFileNumber; }
|
50 |
const char *GetFullName() const { return Form("%s/%s",
|
51 |
GetBaseURL(), GetFileName()); }
|
52 |
const char *GetPrefix() const { return fPrefix; }
|
53 |
void Print(Option_t *option="") const;
|
54 |
void SetBaseURL(const char *b) { fBaseURL = b; }
|
55 |
void SetCompressLevel(Int_t l) { fCompressLevel = l; }
|
56 |
void SetDefaultBrSize(Int_t s) { fDefBrSize=s; }
|
57 |
void SetDefaultSL(Int_t s) { fDefSL=s;}
|
58 |
void SetPrefix(const char *p) { fPrefix = p; }
|
59 |
void StoreObject(const TObject *obj);
|
60 |
void SetMaxSize(Long64_t s) { fMaxSize=s; }
|
61 |
|
62 |
protected:
|
63 |
TString fBaseURL; //base url for tree storage
|
64 |
TString fPrefix; //prefix of file name
|
65 |
UShort_t fFileNumber; //current sequence number
|
66 |
Int_t fCompressLevel; //compression level used for TFile
|
67 |
Int_t fDefBrSize; //default buffer size for branches
|
68 |
Int_t fDefSL; //default split level for branches
|
69 |
Long64_t fMaxSize; //maximum file size for a file [Bytes]
|
70 |
const Long64_t fkMinFreeSpace; //minimum free space required for closing file
|
71 |
const Long64_t fkMinAvgSize; //minimum average entry size
|
72 |
Long64_t fEvtObjNum; //event object number offset (for TRef)
|
73 |
Bool_t fIsInit; //true if OpenFile() was called
|
74 |
Bool_t fDoObjNumReset; //true if obj. number resets automatically (def=0)
|
75 |
TFile *fFile; //file being written
|
76 |
TTree *fTree; //tree being filled
|
77 |
|
78 |
Bool_t IsInit() const { return fIsInit; }
|
79 |
Bool_t IsFull() const;
|
80 |
void OpenFile();
|
81 |
void CloseFile();
|
82 |
|
83 |
ClassDef(TreeWriter,0) // Tree writer class
|
84 |
};
|
85 |
|
86 |
} /*namespace mithep*/
|
87 |
|
88 |
#endif /*DATATREE_TREEWRITER_H*/
|