Fork me on GitHub

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

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

first commit

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