Fork me on GitHub

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

Last change on this file since 724 was 247, checked in by severine ovyn, 16 years ago

cerr ok

File size: 2.1 KB
RevLine 
[3]1
2/** \class ExRootTreeWriter
3 *
4 * Class handling output ROOT tree
5 *
[247]6 * $Date: 2009-02-05 13:37:32 $
7 * $Revision: 1.3 $
[3]8 *
9 *
10 * \author S. Ovyn - UCL, Louvain-la-Neuve
11 *
12 */
13
[220]14#include "ExRootTreeWriter.h"
15#include "ExRootTreeBranch.h"
[3]16
17#include "TFile.h"
18#include "TTree.h"
19#include <iostream>
[247]20#include <iomanip>
[3]21
22using namespace std;
23
24ExRootTreeWriter::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 {
[247]34 cerr <<"** ERROR: cannot create tree **"<< endl;
[3]35 return;
36 }
37
38 fNewTree->SetAutoSave(10000000); // autosave when 10 MB written
39}
40
41//------------------------------------------------------------------------------
42
43ExRootTreeWriter::~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
57ExRootTreeBranch *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
66void ExRootTreeWriter::Fill()
67{
68 if(fNewTree) fNewTree->Fill();
69}
70
71//------------------------------------------------------------------------------
72
73void ExRootTreeWriter::Write()
74{
75 fNewFile = fNewTree ? fNewTree->GetCurrentFile() : 0;
76 if(fNewFile) fNewFile->Write();
77}
78
79//------------------------------------------------------------------------------
80
81void 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
Note: See TracBrowser for help on using the repository browser.