Fork me on GitHub

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

Last change on this file since bdf9e2e was e5ea42e, checked in by Joschka Lingemann <joschka.lingemann@…>, 8 years ago

Fix override warnings.

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