GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
Inheritance graph
[legend]
Collaboration diagram for genie::evtlib::OnDemandRecordList:
Collaboration graph
[legend]

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.

119  : fTree(tree), fPrettyName(prettyName), fLoader(0)
120  {
121  }
virtual genie::evtlib::OnDemandRecordList::~OnDemandRecordList ( )
inlinevirtual

Definition at line 88 of file EvtLibRecordList.h.

References fLoader.

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.

References fEnergies, fLoader, fRecord, fTree, genie::evtlib::RecordLoader::GetRecord(), and LoadIndex().

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.

References fEnergies, fPrettyName, and fTree.

Referenced by GetRecord().

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  }
std::vector< std::pair< float, int > > fEnergies

Member Data Documentation

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

Definition at line 98 of file EvtLibRecordList.h.

Referenced by GetRecord(), and LoadIndex().

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

Definition at line 96 of file EvtLibRecordList.h.

Referenced by GetRecord(), and ~OnDemandRecordList().

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

Definition at line 95 of file EvtLibRecordList.h.

Referenced by LoadIndex().

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

Definition at line 100 of file EvtLibRecordList.h.

Referenced by GetRecord().

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

Definition at line 94 of file EvtLibRecordList.h.

Referenced by GetRecord(), and LoadIndex().


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