Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
genie::evtlib::OnDemandRecordList Class Reference

#include <EvtLibRecordList.h>

Inheritance diagram for genie::evtlib::OnDemandRecordList:
genie::evtlib::IEvtLibRecordList

Public Member Functions

 OnDemandRecordList (TTree *tree, const std::string &prettyName)
 
virtual ~OnDemandRecordList ()
 
const EvtLibRecordGetRecord (float E) const override
 
- Public Member Functions inherited from genie::evtlib::IEvtLibRecordList
virtual ~IEvtLibRecordList ()
 

Protected Member Functions

void LoadIndex () const
 

Protected Attributes

TTree * fTree
 
std::string fPrettyName
 
RecordLoaderfLoader
 
std::vector< std::pair< float, int > > fEnergies
 
EvtLibRecord fRecord
 

Detailed Description

Definition at line 84 of file EvtLibRecordList.h.

Constructor & Destructor Documentation

genie::evtlib::OnDemandRecordList::OnDemandRecordList ( TTree *  tree,
const std::string prettyName 
)

Definition at line 118 of file EvtLibRecordList.cxx.

virtual genie::evtlib::OnDemandRecordList::~OnDemandRecordList ( )
inlinevirtual

Definition at line 88 of file EvtLibRecordList.h.

88 {delete fLoader;}

Member Function Documentation

const EvtLibRecord * genie::evtlib::OnDemandRecordList::GetRecord ( float  E) const
overridevirtual

Implements genie::evtlib::IEvtLibRecordList.

Definition at line 146 of file EvtLibRecordList.cxx.

147  {
148  if(fEnergies.empty()){
149  LoadIndex();
150  // The loader must be created after the indices are loaded, because they
151  // both want to set branch addresses in the TTree, and we ultimately need
152  // the loader's to be active.
153  fLoader = new RecordLoader(fTree);
154  }
155 
156  auto it = std::lower_bound(fEnergies.begin(), fEnergies.end(),
157  std::make_pair(E, 0));
158  if(it == fEnergies.end()) return 0;
159 
160  fRecord = fLoader->GetRecord(it->second);
161 
162  return &fRecord;
163  }
EvtLibRecord GetRecord(int i) const
std::vector< std::pair< float, int > > fEnergies
void genie::evtlib::OnDemandRecordList::LoadIndex ( ) const
protected

Definition at line 124 of file EvtLibRecordList.cxx.

125  {
126  std::cout << "Loading index to " << fPrettyName;
127 
128  float Enu;
129  fTree->SetBranchAddress("Enu", &Enu);
130 
131  const int N = fTree->GetEntries();
132  fEnergies.reserve(N);
133 
134  for(int i = 0; i < N; ++i){
135  if(i%(N/8) == 0) std::cout << "." << std::flush;
136  fTree->GetEntry(i);
137 
138  fEnergies.emplace_back(Enu, i);
139  } // end for i
140  std::cout << std::endl;
141 
142  std::sort(fEnergies.begin(), fEnergies.end());
143  }
QTextStream & flush(QTextStream &s)
std::vector< std::pair< float, int > > fEnergies
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::vector<std::pair<float, int> > genie::evtlib::OnDemandRecordList::fEnergies
mutableprotected

Definition at line 98 of file EvtLibRecordList.h.

RecordLoader* genie::evtlib::OnDemandRecordList::fLoader
mutableprotected

Definition at line 96 of file EvtLibRecordList.h.

std::string genie::evtlib::OnDemandRecordList::fPrettyName
protected

Definition at line 95 of file EvtLibRecordList.h.

EvtLibRecord genie::evtlib::OnDemandRecordList::fRecord
mutableprotected

Definition at line 100 of file EvtLibRecordList.h.

TTree* genie::evtlib::OnDemandRecordList::fTree
protected

Definition at line 94 of file EvtLibRecordList.h.


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