Fork me on GitHub

source: svn/trunk/Utilities/ExRootAnalysis/src/ExRootTreeWriter.cc@ 229

Last change on this file since 229 was 220, checked in by Xavier Rouby, 16 years ago

include statements have been cleaned

File size: 2.0 KB
Line 
1
2/** \class ExRootTreeWriter
3 *
4 * Class handling output ROOT tree
5 *
6 * $Date: 2009-02-02 11:32:01 $
7 * $Revision: 1.2 $
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
21using namespace std;
22
23ExRootTreeWriter::ExRootTreeWriter(const TString &fileName, const TString &treeName)
24{
25 TDirectory *dir = gDirectory;
26 fNewFile = TFile::Open(fileName,"UPDATE");
27 fNewFile->cd();
28 fNewTree = new TTree(treeName, "Analysis tree");
29 dir->cd();
30
31 if(!fNewTree)
32 {
33 cout << "** ERROR: cannot create tree" << endl;
34 return;
35 }
36
37 fNewTree->SetAutoSave(10000000); // autosave when 10 MB written
38}
39
40//------------------------------------------------------------------------------
41
42ExRootTreeWriter::~ExRootTreeWriter()
43{
44 set<ExRootTreeBranch*>::iterator it_set;
45 for(it_set = fBranches.begin(); it_set != fBranches.end(); ++it_set)
46 {
47 delete (*it_set);
48 }
49
50 if(fNewTree) delete fNewTree;
51 if(fNewFile) delete fNewFile;
52}
53
54//------------------------------------------------------------------------------
55
56ExRootTreeBranch *ExRootTreeWriter::NewBranch(const TString &name, TClass *cl)
57{
58 ExRootTreeBranch *branch = new ExRootTreeBranch(name, cl, fNewTree);
59 fBranches.insert(branch);
60 return branch;
61}
62
63//------------------------------------------------------------------------------
64
65void ExRootTreeWriter::Fill()
66{
67 if(fNewTree) fNewTree->Fill();
68}
69
70//------------------------------------------------------------------------------
71
72void ExRootTreeWriter::Write()
73{
74 fNewFile = fNewTree ? fNewTree->GetCurrentFile() : 0;
75 if(fNewFile) fNewFile->Write();
76}
77
78//------------------------------------------------------------------------------
79
80void ExRootTreeWriter::Clear()
81{
82 set<ExRootTreeBranch*>::iterator it_set;
83 for(it_set = fBranches.begin(); it_set != fBranches.end(); ++it_set)
84 {
85 (*it_set)->Clear();
86 }
87}
88
89//------------------------------------------------------------------------------
90
Note: See TracBrowser for help on using the repository browser.