HeaderTree.cxx
Go to the documentation of this file.
1 /*
2  * HeaderTree.cxx
3  *
4  * Created on: Feb 9, 2021
5  * Author: chilgenb
6  */
7 
9 
10 using namespace garana;
11 
14 {
15  SetupRead(tree);
16 }
17 
19 {
20  CheckOpt(opt);//sets TreeReader::fOpt
21 
22  if(fOpt=='r'){
23  SetupRead(tree);
24  }
25  else {
26  fTreeIn = tree;
28  }
29 }//
30 
31 
32 const std::string* const HeaderTree::TreeType() const {
33 
34  fTreeIn->GetEntry(0);
35  //std::cout << "trying tree type, " << fTreeType << std::endl;
36  try{
37 
38  if(fTreeTypePtr->compare("structured")!=0 && fTreeTypePtr->compare("flat")!=0)
39  throw fTreeTypePtr;
40 
41  }
42  catch(std::string* type){
43  std::cerr << "HeaderTree::TreeType: tree type is not set." << '\n';
44  }
45 
46  return fTreeTypePtr;
47 }
48 
49 
50 Int_t const& HeaderTree::Run() const {
51  fTreeIn->GetEntry(0);
52  return fRun;
53 }
54 
55 Int_t const& HeaderTree::SubRun() const {
56  fTreeIn->GetEntry(0);
57  return fSubRun;
58 }
59 
60 Int_t const& HeaderTree::POT() const {
61  fTreeIn->GetEntry(0);
62  return fPOT;
63 }
64 
65 Int_t const& HeaderTree::NSpills() const {
66  fTreeIn->GetEntry(0);
67  return fNSpills;
68 }
69 
71  fTreeIn->GetEntry(0);
72  return fGeometry;
73 }
74 
75 TLorentzVector* const& HeaderTree::TpcCenter() const {
76  fTreeIn->GetEntry(0);
77  return fTpcCenter;
78 }
79 
81 
82  if(fOpt=='r'){
83  fTreeIn->SetBranchAddress("Run", &fRun, &b_Run );
84  fTreeIn->SetBranchAddress("SubRun", &fSubRun, &b_SubRun );
85  fTreeIn->SetBranchAddress("TreeType", &fTreeTypePtr, &b_TreeType );
86  fTreeIn->SetBranchAddress("POT", &fPOT, &b_POT );
87  fTreeIn->SetBranchAddress("NSpills", &fNSpills, &b_NSpills );
88  fTreeIn->SetBranchAddress("Geometry", &fGeometryPtr, &b_Geometry );
89  fTreeIn->SetBranchAddress("TpcCenter", &fTpcCenter, &b_TpcCenter);
90  }
91 
92  if(fOpt=='w'){
93  fTreeIn->Branch("Run", &fRun, "Run/I" );
94  fTreeIn->Branch("SubRun", &fSubRun, "SubRun/I" );
95  fTreeIn->Branch("TreeType", &fTreeType );
96  fTreeIn->Branch("POT", &fPOT, "POT/I" );
97  fTreeIn->Branch("NSpills", &fNSpills, "NSpills/I" );
98  fTreeIn->Branch("Geometry", &fGeometry );
99  fTreeIn->Branch("TpcCenter", &fTpcCenter );
100  }
101 
102  return true;
103 }
104 
105 void HeaderTree::SetRun(const Int_t run) {
106  std::cout << "SetRun called" << std::endl;
107  if(BlockWrite())
108  return;
109 
110  fRun = run;
111  std::cout << "set run = " << fRun << std::endl;
112 }
113 
114 void HeaderTree::SetSubRun(const Int_t subrun) {
115  if(BlockWrite())
116  return;
117  fSubRun = subrun;
118 }
119 
121  if(BlockWrite())
122  return;
123  fTreeType = type;
125 }
126 
127 //TODO implement other setters
std::string const & Geometry() const
Definition: HeaderTree.cxx:70
TLorentzVector *const & TpcCenter() const
Definition: HeaderTree.cxx:75
Int_t const & SubRun() const
Definition: HeaderTree.cxx:55
TBranch * b_TreeType
Definition: HeaderTree.h:53
std::string string
Definition: nybbler.cc:12
opt
Definition: train.py:196
void SetSubRun(const Int_t subrun)
Definition: HeaderTree.cxx:114
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
TBranch * b_Run
Definition: HeaderTree.h:51
Int_t const & POT() const
Definition: HeaderTree.cxx:60
std::string fGeometry
Definition: HeaderTree.h:45
bool SetBranchAddresses() override
Definition: HeaderTree.cxx:80
void CheckOpt(char opt)
Definition: TreeReader.cxx:67
TLorentzVector * fTpcCenter
Definition: HeaderTree.h:44
Int_t const & NSpills() const
Definition: HeaderTree.cxx:65
const std::string *const TreeType() const
Definition: HeaderTree.cxx:32
TBranch * b_NSpills
Definition: HeaderTree.h:56
TBranch * b_Geometry
Definition: HeaderTree.h:57
std::string * fGeometryPtr
Definition: HeaderTree.h:48
TBranch * b_POT
Definition: HeaderTree.h:55
std::string * fTreeTypePtr
Definition: HeaderTree.h:47
bool BlockWrite() const
Definition: TreeReader.cxx:93
std::string fTreeType
Definition: HeaderTree.h:46
void SetupRead(TTree *tree)
Definition: TreeReader.cxx:6
Int_t const & Run() const
Definition: HeaderTree.cxx:50
static QCString type
Definition: declinfo.cpp:672
void SetRun(const Int_t run)
Definition: HeaderTree.cxx:105
void SetTreeType(std::string type)
Definition: HeaderTree.cxx:120
TBranch * b_SubRun
Definition: HeaderTree.h:52
TBranch * b_TpcCenter
Definition: HeaderTree.h:54
QTextStream & endl(QTextStream &s)