1 |
|
---|
2 | /** \class ExRootTreeWriter
|
---|
3 | *
|
---|
4 | * Class handling output ROOT tree
|
---|
5 | *
|
---|
6 | * $Date: 2009-02-05 13:37:32 $
|
---|
7 | * $Revision: 1.3 $
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * \author S. Ovyn - UCL, Louvain-la-Neuve
|
---|
11 | *
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "ExRootTreeWriter.h"
|
---|
15 | #include "ExRootTreeBranch.h"
|
---|
16 |
|
---|
17 | #include "TFile.h"
|
---|
18 | #include "TTree.h"
|
---|
19 | #include <iostream>
|
---|
20 | #include <iomanip>
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | ExRootTreeWriter::ExRootTreeWriter(const TString &fileName, const TString &treeName)
|
---|
25 | {
|
---|
26 | TDirectory *dir = gDirectory;
|
---|
27 | fNewFile = TFile::Open(fileName,"UPDATE");
|
---|
28 | fNewFile->cd();
|
---|
29 | fNewTree = new TTree(treeName, "Analysis tree");
|
---|
30 | dir->cd();
|
---|
31 |
|
---|
32 | if(!fNewTree)
|
---|
33 | {
|
---|
34 | cerr <<"** ERROR: cannot create tree **"<< endl;
|
---|
35 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | fNewTree->SetAutoSave(10000000); // autosave when 10 MB written
|
---|
39 | }
|
---|
40 |
|
---|
41 | //------------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | ExRootTreeWriter::~ExRootTreeWriter()
|
---|
44 | {
|
---|
45 | set<ExRootTreeBranch*>::iterator it_set;
|
---|
46 | for(it_set = fBranches.begin(); it_set != fBranches.end(); ++it_set)
|
---|
47 | {
|
---|
48 | delete (*it_set);
|
---|
49 | }
|
---|
50 |
|
---|
51 | if(fNewTree) delete fNewTree;
|
---|
52 | if(fNewFile) delete fNewFile;
|
---|
53 | }
|
---|
54 |
|
---|
55 | //------------------------------------------------------------------------------
|
---|
56 |
|
---|
57 | ExRootTreeBranch *ExRootTreeWriter::NewBranch(const TString &name, TClass *cl)
|
---|
58 | {
|
---|
59 | ExRootTreeBranch *branch = new ExRootTreeBranch(name, cl, fNewTree);
|
---|
60 | fBranches.insert(branch);
|
---|
61 | return branch;
|
---|
62 | }
|
---|
63 |
|
---|
64 | //------------------------------------------------------------------------------
|
---|
65 |
|
---|
66 | void ExRootTreeWriter::Fill()
|
---|
67 | {
|
---|
68 | if(fNewTree) fNewTree->Fill();
|
---|
69 | }
|
---|
70 |
|
---|
71 | //------------------------------------------------------------------------------
|
---|
72 |
|
---|
73 | void ExRootTreeWriter::Write()
|
---|
74 | {
|
---|
75 | fNewFile = fNewTree ? fNewTree->GetCurrentFile() : 0;
|
---|
76 | if(fNewFile) fNewFile->Write();
|
---|
77 | }
|
---|
78 |
|
---|
79 | //------------------------------------------------------------------------------
|
---|
80 |
|
---|
81 | void ExRootTreeWriter::Clear()
|
---|
82 | {
|
---|
83 | set<ExRootTreeBranch*>::iterator it_set;
|
---|
84 | for(it_set = fBranches.begin(); it_set != fBranches.end(); ++it_set)
|
---|
85 | {
|
---|
86 | (*it_set)->Clear();
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | //------------------------------------------------------------------------------
|
---|
91 |
|
---|