Public Member Functions | Protected Attributes | List of all members
garana::TreeReader Class Referenceabstract

#include <TreeReader.h>

Inheritance diagram for garana::TreeReader:
garana::DetTree garana::DisplayTree garana::G4Tree garana::GenTree garana::HeaderTree garana::RecoTree garana::FlatDetTree garana::StructuredDetTree garana::FlatDisplayTree garana::StructuredDisplayTree garana::FlatG4Tree garana::StructuredG4Tree garana::FlatGenTree garana::StructuredGenTree garana::FlatRecoTree garana::StructuredRecoTree

Public Member Functions

virtual ~TreeReader ()
 
void SetupRead (TTree *tree)
 
TTree * GetInputTree ()
 
size_t NEntries () const
 
virtual void GetEntry (const UInt_t &ientry)
 
Int_t Event () const
 
const TObjArray * GetBranchList () const
 
void Fill ()
 
void Write ()
 
void CheckOpt (char opt)
 
bool BlockWrite () const
 
virtual bool SetBranchAddresses ()=0
 

Protected Attributes

const std::string treename
 
char fOpt = 'r'
 
TTree * fTreeIn = nullptr
 pointer to the analyzed TTree or TChain More...
 
UInt_t fCurrentEntry = UINT_MAX
 
TBranch * b_Event = nullptr
 
Int_t fEvent = -1
 event number for tree entry More...
 

Detailed Description

Definition at line 26 of file TreeReader.h.

Constructor & Destructor Documentation

virtual garana::TreeReader::~TreeReader ( )
inlinevirtual

Definition at line 30 of file TreeReader.h.

30 {};

Member Function Documentation

bool TreeReader::BlockWrite ( ) const

Definition at line 93 of file TreeReader.cxx.

93  {
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 }
QTextStream & endl(QTextStream &s)
void TreeReader::CheckOpt ( char  opt)

Definition at line 67 of file TreeReader.cxx.

67  {
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 }
opt
Definition: train.py:196
QTextStream & endl(QTextStream &s)
Int_t TreeReader::Event ( ) const

Definition at line 30 of file TreeReader.cxx.

30  {
31 
32  return fEvent;
33 }
Int_t fEvent
event number for tree entry
Definition: TreeReader.h:55
void TreeReader::Fill ( )

Definition at line 51 of file TreeReader.cxx.

51  {
52  if(BlockWrite())
53  return;
54 
55  fTreeIn->Fill();
56 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
bool BlockWrite() const
Definition: TreeReader.cxx:93
const TObjArray * TreeReader::GetBranchList ( ) const

Definition at line 47 of file TreeReader.cxx.

47  {
48  return fTreeIn->GetListOfBranches();
49 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
void TreeReader::GetEntry ( const UInt_t &  ientry = 0)
virtual

Reimplemented in garana::FlatGenTree, and garana::FlatG4Tree.

Definition at line 39 of file TreeReader.cxx.

39  {
40  if(ientry != fCurrentEntry) {
41  fCurrentEntry = ientry;
42  fTreeIn->GetEntry(ientry);
43  }
44  return;
45 }
UInt_t fCurrentEntry
Definition: TreeReader.h:52
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
TTree * TreeReader::GetInputTree ( )

Definition at line 26 of file TreeReader.cxx.

26  {
27  return fTreeIn;
28 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
size_t TreeReader::NEntries ( ) const

Definition at line 35 of file TreeReader.cxx.

35  {
36  return fTreeIn->GetEntries();
37 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
virtual bool garana::TreeReader::SetBranchAddresses ( )
pure virtual
void TreeReader::SetupRead ( TTree *  tree = 0)

Definition at line 6 of file TreeReader.cxx.

6  {
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 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
virtual bool SetBranchAddresses()=0
QTextStream & endl(QTextStream &s)
void TreeReader::Write ( )

Definition at line 58 of file TreeReader.cxx.

58  {
59  if(BlockWrite())
60  return;
61 
62  //fTreeIn->GetCurrentFile()->Write();
63  fTreeIn->Write();
64 }
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
bool BlockWrite() const
Definition: TreeReader.cxx:93

Member Data Documentation

TBranch* garana::TreeReader::b_Event = nullptr
protected

Definition at line 54 of file TreeReader.h.

UInt_t garana::TreeReader::fCurrentEntry = UINT_MAX
protected

Definition at line 52 of file TreeReader.h.

Int_t garana::TreeReader::fEvent = -1
protected

event number for tree entry

Definition at line 55 of file TreeReader.h.

char garana::TreeReader::fOpt = 'r'
protected

Definition at line 50 of file TreeReader.h.

TTree* garana::TreeReader::fTreeIn = nullptr
protected

pointer to the analyzed TTree or TChain

Definition at line 51 of file TreeReader.h.

const std::string garana::TreeReader::treename
protected

Definition at line 48 of file TreeReader.h.


The documentation for this class was generated from the following files: