Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTreeWriter.cc@ b443089

ImprovedOutputFile Timing dual_readout llp
Last change on this file since b443089 was d7d2da3, checked in by pavel <pavel@…>, 11 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 2.2 KB
Line 
1
2/** \class ExRootTreeWriter
3 *
4 * Class handling output ROOT tree
5 *
6 * $Date: 2008-06-04 13:57:57 $
7 * $Revision: 1.1 $
8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "ExRootAnalysis/ExRootTreeWriter.h"
15#include "ExRootAnalysis/ExRootTreeBranch.h"
16
17#include "TROOT.h"
18#include "TFile.h"
19#include "TTree.h"
20#include "TClonesArray.h"
21
22#include <iostream>
23#include <stdexcept>
24#include <sstream>
25
26using namespace std;
27
28ExRootTreeWriter::ExRootTreeWriter(TFile *file, const char *treeName) :
29 fFile(file), fTree(0), fTreeName(treeName)
30{
31}
32
33//------------------------------------------------------------------------------
34
35ExRootTreeWriter::~ExRootTreeWriter()
36{
37 set<ExRootTreeBranch*>::iterator itBranches;
38 for(itBranches = fBranches.begin(); itBranches != fBranches.end(); ++itBranches)
39 {
40 delete (*itBranches);
41 }
42
43 if(fTree) delete fTree;
44}
45
46//------------------------------------------------------------------------------
47
48ExRootTreeBranch *ExRootTreeWriter::NewBranch(const char *name, TClass *cl)
49{
50 if(!fTree) fTree = NewTree();
51 ExRootTreeBranch *branch = new ExRootTreeBranch(name, cl, fTree);
52 fBranches.insert(branch);
53 return branch;
54}
55
56//------------------------------------------------------------------------------
57
58void ExRootTreeWriter::Fill()
59{
60 if(fTree) fTree->Fill();
61}
62
63//------------------------------------------------------------------------------
64
65void ExRootTreeWriter::Write()
66{
67 fFile = fTree ? fTree->GetCurrentFile() : 0;
68 if(fFile) fFile->Write();
69}
70
71//------------------------------------------------------------------------------
72
73void ExRootTreeWriter::Clear()
74{
75 set<ExRootTreeBranch*>::iterator itBranches;
76 for(itBranches = fBranches.begin(); itBranches != fBranches.end(); ++itBranches)
77 {
78 (*itBranches)->Clear();
79 }
80}
81
82//------------------------------------------------------------------------------
83
84TTree *ExRootTreeWriter::NewTree()
85{
86 if(!fFile) return 0;
87
88 TTree *tree = 0;
89 TDirectory *dir = gDirectory;
90
91 fFile->cd();
92 tree = new TTree(fTreeName, "Analysis tree");
93 dir->cd();
94
95 if(!tree)
96 {
97 throw runtime_error("can't create output ROOT tree");
98 }
99
100 tree->SetDirectory(fFile);
101 tree->SetAutoSave(10000000); // autosave when 10 MB written
102
103 return tree;
104}
Note: See TracBrowser for help on using the repository browser.