ATLAS Offline Software
Loading...
Searching...
No Matches
TreeReader Class Reference

#include <TreeReader.h>

Collaboration diagram for TreeReader:

Public Member Functions

 TreeReader ()
virtual ~TreeReader ()
 TreeReader (TTree *n)
void SetTree (TTree *n)
double GetVariable (const char *c, int entry=-2)
int GetEntry (int entry=-1)
int GetEntries ()
TTree * GetTree ()
void Restart ()

Private Attributes

TTree * m_tree
int m_currentEntry = 0
int m_entries
bool m_isChain = false
int m_currentTree = 0
std::map< std::string, TTreeFormula * > m_formulae

Detailed Description

Definition at line 29 of file TreeReader.h.

Constructor & Destructor Documentation

◆ TreeReader() [1/2]

TreeReader::TreeReader ( )

Definition at line 26 of file TreeReader.cxx.

27{
28 // Default constructor.
29 m_isChain = false;
30 m_currentTree = -1;
31 m_tree = nullptr;
32 m_currentEntry = -1;
33 m_entries = -1;
34}
TTree * m_tree
Definition TreeReader.h:33
int m_currentTree
Definition TreeReader.h:37
int m_entries
Definition TreeReader.h:35
bool m_isChain
Definition TreeReader.h:36
int m_currentEntry
Definition TreeReader.h:34

◆ ~TreeReader()

TreeReader::~TreeReader ( )
virtual

Definition at line 36 of file TreeReader.cxx.

37{
38 m_formulae.clear();
39}
std::map< std::string, TTreeFormula * > m_formulae
Definition TreeReader.h:38

◆ TreeReader() [2/2]

TreeReader::TreeReader ( TTree * n)

Definition at line 43 of file TreeReader.cxx.

45{
46 // Constructor.
47 m_tree = nullptr;
48 m_entries = -1;
49 SetTree(n);
50}
void SetTree(TTree *n)

Member Function Documentation

◆ GetEntries()

int TreeReader::GetEntries ( )
inline

Definition at line 50 of file TreeReader.h.

50{ return m_entries ; }

◆ GetEntry()

int TreeReader::GetEntry ( int entry = -1)

Definition at line 102 of file TreeReader.cxx.

104{
105 // Read a given entry in the buffer (-1 -> next entry).
106 // Return kFALSE if not found.
107 // entry += 1;
108 if(m_entries==0) return 0;
109 if(entry==-1) entry = m_currentEntry+1;
110 if(entry<m_entries)
111 {
112 int entryNumber = m_tree->GetEntryNumber(entry);
113 if (entryNumber < 0) return 0;
114 Long64_t localEntry = m_tree->LoadTree(entryNumber);
115 if (localEntry < 0) return 0;
117 if(m_isChain) // check file change in chain
118 {
119 int I = static_cast<TChain*>(m_tree)->GetTreeNumber();
120 if(I!=m_currentTree)
121 {
123 //fManager->Clear();
124 std::map<std::string, TTreeFormula*>::iterator itr = m_formulae.begin();
125 std::map<std::string, TTreeFormula*>::iterator itrE= m_formulae.end();
126 TTreeFormula* dummy = m_formulae["__DUMMY__"];
127 for(;itr!=itrE;++itr)
128 {
129 if(itr->second!=dummy) itr->second->Notify(); //itr->second->UpdateFormulaLeaves();
130 }
131 }
132 }
133 return 1;
134 }
135 return 0;
136}
#define I(x, y, z)
Definition MD5.cxx:116

◆ GetTree()

TTree * TreeReader::GetTree ( )
inline

Definition at line 51 of file TreeReader.h.

51{ return m_tree ; }

◆ GetVariable()

double TreeReader::GetVariable ( const char * c,
int entry = -2 )

Definition at line 69 of file TreeReader.cxx.

71{
72 // Get vaviable.
73 // Return variable for a given entry (<0 -> current entry).
74 if(entry>=0 && entry!=m_currentEntry) this->GetEntry(entry);
75 std::string s = c;
76 TTreeFormula *f = m_formulae[s];
77 if(!f)
78 {
79 f = new TTreeFormula(c,c,m_tree);
80 f->SetQuickLoad(kTRUE);
81 // fManager->Add(f);
82 // fManager->Sync();
83 if(f->GetNdim()!=1) //invalid fomula
84 {
85 delete f;
86 f = m_formulae["__DUMMY__"];
87 std::cout << "in [TreeReader] : " << s << " is not valid -> return 0" << std::endl;
88 }
89 // else {f->Notify();}
90 m_formulae[s] = f;
91 }
92 if(f == m_formulae["__DUMMY__"]) return 0;
93 int valid = f->GetNdata() ;
94 if(!valid) return 0;
95 // std::cout << "Evaluating formula : " << s << std::flush;
96 // std::cout << " " << f->EvalInstance(0) << std::endl;
97 return f->EvalInstance(0);
98}
int GetEntry(int entry=-1)
list valid
Definition calibdata.py:44

◆ Restart()

void TreeReader::Restart ( )
inline

Definition at line 52 of file TreeReader.h.

52{m_currentEntry = -1;}

◆ SetTree()

void TreeReader::SetTree ( TTree * n)

Definition at line 53 of file TreeReader.cxx.

55{
56 // check for null pointer BEFORE trying to use it
57 if(!n) return;
58 // Set tree.
59 m_tree = n;
60 m_currentEntry = -1;
61 m_formulae.clear();
62 m_formulae["__DUMMY__"] = new TTreeFormula("__DUMMY__","0",m_tree);
63 m_isChain = (n->IsA() == TClass::GetClass("TChain"));
64 m_currentTree = 0;
65 m_entries = (int) m_tree->GetEntries();
66}

Member Data Documentation

◆ m_currentEntry

int TreeReader::m_currentEntry = 0
private

Definition at line 34 of file TreeReader.h.

◆ m_currentTree

int TreeReader::m_currentTree = 0
private

Definition at line 37 of file TreeReader.h.

◆ m_entries

int TreeReader::m_entries
private

Definition at line 35 of file TreeReader.h.

◆ m_formulae

std::map<std::string, TTreeFormula*> TreeReader::m_formulae
private

Definition at line 38 of file TreeReader.h.

◆ m_isChain

bool TreeReader::m_isChain = false
private

Definition at line 36 of file TreeReader.h.

◆ m_tree

TTree* TreeReader::m_tree
private

Definition at line 33 of file TreeReader.h.


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