TreeReader.cxx
Go to the documentation of this file.
1 
3 
4 using namespace garana;
5 
6 void TreeReader::SetupRead(TTree* tree=0){
7 
8  fTreeIn = tree;
9  fOpt = 'r';
10 
11  try{
12  if(!fTreeIn)
13  throw fTreeIn;
14 
15  if(!SetBranchAddresses())
16  throw false;
17  }
18  catch(TTree* t){
19  std::cerr << "TreeReader::SetupRead error: input tree not valid" << std::endl;
20  }
21  catch(bool set){
22  std::cerr << "TreeReader::SetupRead error: failed to set branch addresses" << std::endl;
23  }
24 }
25 
27  return fTreeIn;
28 }
29 
30 Int_t TreeReader::Event() const {
31 
32  return fEvent;
33 }
34 
35 size_t TreeReader::NEntries() const {
36  return fTreeIn->GetEntries();
37 }
38 
39 void TreeReader::GetEntry(const UInt_t& ientry=0) {
40  if(ientry != fCurrentEntry) {
41  fCurrentEntry = ientry;
42  fTreeIn->GetEntry(ientry);
43  }
44  return;
45 }
46 
47 const TObjArray* TreeReader::GetBranchList() const {
48  return fTreeIn->GetListOfBranches();
49 }
50 
52  if(BlockWrite())
53  return;
54 
55  fTreeIn->Fill();
56 }
57 
59  if(BlockWrite())
60  return;
61 
62  //fTreeIn->GetCurrentFile()->Write();
63  fTreeIn->Write();
64 }
65 
66 //checks read/write option and sets usable value
68  switch(opt) {
69  case('W') :
70  fOpt = 'w';
71  return;
72 
73  case('R') :
74  fOpt = 'r';
75  return;
76 
77  case('w') :
78  fOpt = 'w';
79  return;
80  case('r') :
81  fOpt = 'r';
82  return;
83 
84  default :
85  std::cerr << "WARNING(TreeReader): Unknown option specified '"
86  << opt << "'. Option should be 'R'/'r' (read-only)"
87  << " or 'W'/'w' (write). Setting option to read-only."
88  << std::endl;
89  fOpt = 'r';
90  }
91 }
92 
94  if(fOpt!='w') {
95  std::cerr << "WARNING(TreeReader): Write method invoked for read-only accessor - "
96  << " ignoring method call..." << std::endl;
97  return true;
98  }
99  return false;
100 }
101 
102 
UInt_t fCurrentEntry
Definition: TreeReader.h:52
opt
Definition: train.py:196
TTree * GetInputTree()
Definition: TreeReader.cxx:26
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
void CheckOpt(char opt)
Definition: TreeReader.cxx:67
bool BlockWrite() const
Definition: TreeReader.cxx:93
Int_t Event() const
Definition: TreeReader.cxx:30
void SetupRead(TTree *tree)
Definition: TreeReader.cxx:6
const TObjArray * GetBranchList() const
Definition: TreeReader.cxx:47
virtual bool SetBranchAddresses()=0
virtual void GetEntry(const UInt_t &ientry)
Definition: TreeReader.cxx:39
Int_t fEvent
event number for tree entry
Definition: TreeReader.h:55
size_t NEntries() const
Definition: TreeReader.cxx:35
QTextStream & endl(QTextStream &s)