ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
LArSamples::PersistentAccessor Class Reference

#include <PersistentAccessor.h>

Inheritance diagram for LArSamples::PersistentAccessor:
Collaboration diagram for LArSamples::PersistentAccessor:

Public Member Functions

 PersistentAccessor (TTree &cellTree, TTree &eventTree, TTree *runTree, TFile *file)
 Constructor
More...
 
 PersistentAccessor (const TString &fileName)
 
 PersistentAccessor (const PersistentAccessor &)
 
PersistentAccessoroperator= (const PersistentAccessor &)
 
virtual ~PersistentAccessor ()
 
unsigned int historySize (unsigned int i) const
 
bool save () const
 
const TTree & cellTree () const
 
const TTree & eventTree () const
 
const TTree & runTree () const
 
TFile * file () const
 
TString fileName () const
 
const HistoryContainerhistoryContainer (unsigned int i) const
 
unsigned int nEvents () const
 
const EventDataeventData (unsigned int i) const
 
unsigned int nRuns () const
 
const RunDatarunData (unsigned int i) const
 
void add (HistoryContainer *cont)
 
void addEvent (EventData *eventData)
 
void addRun (RunData *runData)
 
HistoryContainercurrentContainer () const
 
int getCellEntry (unsigned int i) const
 

Static Public Member Functions

static PersistentAccessoropen (const TString &fileName)
 
static PersistentAccessormerge (const std::vector< const PersistentAccessor * > &accessors, const TString &fileName)
 
static PersistentAccessormerge (const std::vector< TString > &inputFiles, const TString &fileName)
 

Private Attributes

TTree * m_cellTree
 
TTree * m_eventTree
 
TTree * m_runTree
 
TFile * m_file
 
HistoryContainerm_historyCont
 
EventDatam_eventData
 
RunDatam_runData
 
std::map< unsigned int, const RunData * > m_runCache
 

Detailed Description

Definition at line 24 of file PersistentAccessor.h.

Constructor & Destructor Documentation

◆ PersistentAccessor() [1/3]

PersistentAccessor::PersistentAccessor ( TTree &  cellTree,
TTree &  eventTree,
TTree *  runTree,
TFile *  file 
)

Constructor

Definition at line 26 of file PersistentAccessor.cxx.

28  m_historyCont(nullptr), m_eventData(nullptr), m_runData(nullptr)
29 {
30  ClassCounts::incrementInstanceCount("PersistentAccessor");
31  m_cellTree->SetBranchAddress("history", &m_historyCont);
32  m_eventTree->SetBranchAddress("event", &m_eventData);
33  m_eventTree->LoadBaskets(); // loads the tree to memory
34  if (m_eventTree->MemoryFull(0)) {
35  cout << "WARNING: could not load all the baskets of the event tree into memory -- processing will be very slow." << endl;
36  cout << "Please check if the file you are loading is too large or corrupted." << endl;
37  }
38  if (m_runTree) {
39  m_runTree->SetBranchAddress("run", &m_runData);
40  m_runTree->LoadBaskets();
41  }
42 }

◆ PersistentAccessor() [2/3]

PersistentAccessor::PersistentAccessor ( const TString &  fileName)

Definition at line 45 of file PersistentAccessor.cxx.

46  : m_cellTree(nullptr), m_eventTree(nullptr), m_runTree(nullptr), m_file(nullptr),
47  m_historyCont(nullptr), m_eventData(nullptr), m_runData(nullptr)
48 {
49  ClassCounts::incrementInstanceCount("PersistentAccessor");
50  if (TString(fileName) != "") m_file = new TFile(fileName, "RECREATE");
51  if (m_file && !m_file->IsOpen()) { delete m_file; m_file = nullptr; }
52  m_cellTree = new TTree("cells", "");
53  m_eventTree = new TTree("events", "");
54  m_runTree = new TTree("runs", "");
55  m_cellTree->Branch("history", &m_historyCont, 32000, 0);
56  m_eventTree->Branch("event", &m_eventData, 32000, 0);
57  m_runTree->Branch("run", &m_runData, 32000, 0);
58  m_eventTree->SetAutoSave(0); // keep everything in memory
59  m_eventTree->SetAutoFlush(0); // keep everything in memory
60  m_runTree->SetAutoSave(0); // keep everything in memory
61  m_runTree->SetAutoFlush(0); // keep everything in memory
62 }

◆ PersistentAccessor() [3/3]

LArSamples::PersistentAccessor::PersistentAccessor ( const PersistentAccessor )

◆ ~PersistentAccessor()

PersistentAccessor::~PersistentAccessor ( )
virtual

Definition at line 80 of file PersistentAccessor.cxx.

81 {
82  ClassCounts::decrementInstanceCount("PersistentAccessor");
84  run != m_runCache.end(); ++run)
85  delete run->second;
86  if (m_file)
87  delete m_file;
88  else {
89  delete m_cellTree;
90  delete m_eventTree;
91  delete m_runTree;
92  }
93  if (m_historyCont) delete m_historyCont;
94  if (m_eventData) delete m_eventData;
95  if (m_runData) delete m_runData;
96 }

Member Function Documentation

◆ add()

void PersistentAccessor::add ( HistoryContainer cont)

Definition at line 141 of file PersistentAccessor.cxx.

142 {
143  m_historyCont = cont;
144  m_cellTree->Fill();
145  m_historyCont = nullptr;
146 }

◆ addEvent()

void PersistentAccessor::addEvent ( EventData eventData)

Definition at line 149 of file PersistentAccessor.cxx.

150 {
152  m_eventTree->Fill();
153  m_eventData = nullptr;
154 }

◆ addRun()

void PersistentAccessor::addRun ( RunData runData)

Definition at line 157 of file PersistentAccessor.cxx.

158 {
159  m_runData = runData;
160  m_runTree->Fill();
161  m_runData = nullptr;
162 }

◆ cellTree()

const TTree& LArSamples::PersistentAccessor::cellTree ( ) const
inline

Definition at line 43 of file PersistentAccessor.h.

43 { return *m_cellTree; }

◆ currentContainer()

HistoryContainer* LArSamples::PersistentAccessor::currentContainer ( ) const
inline

Definition at line 62 of file PersistentAccessor.h.

62 { return m_historyCont; }

◆ eventData()

const EventData * PersistentAccessor::eventData ( unsigned int  i) const

Definition at line 113 of file PersistentAccessor.cxx.

114 {
115  if (i >= nEvents()) return nullptr;
116  m_eventTree->GetEntry(i);
118  return m_eventData;
119 }

◆ eventTree()

const TTree& LArSamples::PersistentAccessor::eventTree ( ) const
inline

Definition at line 44 of file PersistentAccessor.h.

44 { return *m_eventTree; }

◆ file()

TFile* LArSamples::PersistentAccessor::file ( ) const
inline

Definition at line 47 of file PersistentAccessor.h.

47 { return m_file; }

◆ fileName()

TString PersistentAccessor::fileName ( ) const

Definition at line 135 of file PersistentAccessor.cxx.

136 {
137  return (m_file ? m_file->GetName() : "");
138 }

◆ getCellEntry()

int LArSamples::PersistentAccessor::getCellEntry ( unsigned int  i) const
inline

Definition at line 67 of file PersistentAccessor.h.

67 { return m_cellTree->GetEntry(i); }

◆ historyContainer()

const HistoryContainer * PersistentAccessor::historyContainer ( unsigned int  i) const

Definition at line 99 of file PersistentAccessor.cxx.

100 {
101  m_cellTree->GetEntry(i);
102  return m_historyCont;
103 }

◆ historySize()

unsigned int PersistentAccessor::historySize ( unsigned int  i) const

Definition at line 106 of file PersistentAccessor.cxx.

107 {
108  const HistoryContainer* cont = historyContainer(i);
109  return (cont ? cont->nDataContainers() : 0);
110 }

◆ merge() [1/2]

PersistentAccessor * PersistentAccessor::merge ( const std::vector< const PersistentAccessor * > &  accessors,
const TString &  fileName 
)
static

Definition at line 181 of file PersistentAccessor.cxx.

183 {
185  unsigned int size = 0;
186  CellInfo* info = nullptr;
187 
188  int evtIndex = 0, runIndex = 0;
189  std::map<std::pair<int, int>, int> evtMap;
190  std::map<int, int> runMap;
191  std::map< std::pair<const PersistentAccessor*, int>, int > evtAccMap;
192 
193  cout << "Merging runs" << endl;
194  for (const PersistentAccessor* accessor : accessors) {
195  if (!accessor) {
196  cout << "Cannot merge: one of the inputs is null!" << endl;
197  delete newAcc;
198  return nullptr;
199  }
200  for (unsigned int i = 0; i < accessor->nRuns(); i++) {
201  int run = accessor->runData(i)->run();
202  if (runMap.find(run) != runMap.end()) continue;
203  runMap[run] = runIndex;
204  RunData* newRun = new RunData(*accessor->runData(i));
205  newAcc->addRun(newRun);
206  delete newRun;
207  runIndex++;
208  }
209  }
210 
211  cout << "Merging events" << endl;
212  unsigned int nEventsTotal = 0, iEvt = 0;
213  for (const PersistentAccessor* accessor : accessors) {
214  nEventsTotal += accessor->nEvents();
215  }
216  for (const PersistentAccessor* accessor : accessors) {
217  for (unsigned int i = 0; i < accessor->nEvents(); i++) {
218  iEvt++;
219  if (iEvt % 100000 == 0) cout << "Merging event " << iEvt << "/" << nEventsTotal << endl;
220  std::pair<int, int> evtId(accessor->eventData(i)->run(), accessor->eventData(i)->event());
221  std::pair<const PersistentAccessor*, int> evtAccId(accessor, i);
222  if (evtMap.find(evtId) != evtMap.end()) {
223  cout << "ERROR: Skipping duplicate entry for run " << accessor->eventData(i)->run() << ", event " << accessor->eventData(i)->event() << endl;
224  continue;
225  }
226  evtAccMap[evtAccId] = evtIndex;
227  evtMap[evtId] = evtIndex;
228  std::map<int, int>::const_iterator idx = runMap.find(accessor->eventData(i)->run());
229  int newRunIndex = (idx == runMap.end() ? -999 : idx->second);
230  //cout << "Storing eventData for run " << accessor->eventData(i)->run() << " at index " << newRunIndex << " instead of " << accessor->eventData(i)->runIndex() << endl;
231  EventData* newEvent = new EventData(*accessor->eventData(i), newRunIndex);
232  newAcc->addEvent(newEvent);
233  delete newEvent;
234  evtIndex++;
235  }
236  }
237 
238  for (unsigned int i = 0; i < Definitions::nChannels; i++) {
239  if (i % 10000 == 0) {
240  cout << "Merging channel " << i << "/" << Definitions::nChannels << " (current size = " << size << ")" << endl;
241  //ClassCounts::printCountsTable();
242  }
243  HistoryContainer* newHistory = nullptr;
244  for (const PersistentAccessor* accessor : accessors) {
245  const HistoryContainer* history = accessor->historyContainer(i);
246  if (!history || !history->isValid()) continue;
247  if (!newHistory) {
248  info = new CellInfo(*history->cellInfo());
249  newHistory = new HistoryContainer(info);
250  }
251  for (unsigned int j = 0; j < history->nDataContainers(); j++) {
252  DataContainer* newDC = new DataContainer(*history->dataContainer(j));
253  std::map<std::pair<const PersistentAccessor*, int>, int>::const_iterator newIndex
254  = evtAccMap.find(std::make_pair(accessor, history->dataContainer(j)->eventIndex()));
255  if (newIndex == evtAccMap.end()) cout << "Event not found for cell " << i << ", data " << j << "." << endl;
256  newDC->setEventIndex(newIndex != evtAccMap.end() ? newIndex->second : -1);
257  newHistory->add(newDC);
258  if (!info->shape(history->dataContainer(j)->gain())) {
259  const ShapeInfo* shape = history->cellInfo()->shape(history->dataContainer(j)->gain());
260  if (!shape)
261  cout << "Shape not filled for hash = " << i << ", index = " << j << ", gain = " << history->dataContainer(j)->gain() << endl;
262  info->setShape(history->dataContainer(j)->gain(), (shape ? new ShapeInfo(*shape) : nullptr));
263  }
264  }
265  }
266  if (newHistory) size += newHistory->nDataContainers();
267  newAcc->add(newHistory);
268  delete newHistory;
269  }
270 
271  cout << "Merging done, final size = " << size << endl;
272  newAcc->save();
273  return newAcc;
274 }

◆ merge() [2/2]

PersistentAccessor * PersistentAccessor::merge ( const std::vector< TString > &  inputFiles,
const TString &  fileName 
)
static

Definition at line 277 of file PersistentAccessor.cxx.

278 {
279  std::vector<const PersistentAccessor*> accessors;
280  for (const TString& inputFile : inputFiles) {
282  if (!accessor) {
283  cout << "ERROR : could not open file " << inputFile << endl;
284  return nullptr;
285  }
286  accessors.push_back(accessor);
287  }
289  for (const PersistentAccessor* accessor : accessors) {
290  delete accessor;
291  }
292  return result;
293 }

◆ nEvents()

unsigned int LArSamples::PersistentAccessor::nEvents ( ) const
inline

Definition at line 52 of file PersistentAccessor.h.

52 { return m_eventTree->GetEntries(); }

◆ nRuns()

unsigned int LArSamples::PersistentAccessor::nRuns ( ) const
inline

Definition at line 55 of file PersistentAccessor.h.

55 { return m_runTree->GetEntries(); }

◆ open()

PersistentAccessor * PersistentAccessor::open ( const TString &  fileName)
static

Definition at line 65 of file PersistentAccessor.cxx.

66 {
67  TFile* file = TFile::Open(fileName);
68  if (!file) return nullptr;
69  if (!file->IsOpen()) { delete file; return nullptr; }
70  TTree* cellTree = (TTree*)file->Get("cells");
71  if (!cellTree) return nullptr;
72  TTree* eventTree = (TTree*)file->Get("events");
73  if (!eventTree) return nullptr;
74  TTree* runTree = (TTree*)file->Get("runs");
76  return accessor;
77 }

◆ operator=()

PersistentAccessor& LArSamples::PersistentAccessor::operator= ( const PersistentAccessor )

◆ runData()

const RunData * PersistentAccessor::runData ( unsigned int  i) const

Definition at line 122 of file PersistentAccessor.cxx.

123 {
124  if (i >= nRuns()) return nullptr;
125  std::map<unsigned int, const RunData*>::const_iterator cache = m_runCache.find(i);
126  if (cache != m_runCache.end()) return cache->second;
127 
128  m_runTree->GetEntry(i);
129  RunData* newRunData = new RunData(*m_runData);
130  m_runCache[m_eventData->runIndex()] = newRunData;
131  return newRunData;
132 }

◆ runTree()

const TTree& LArSamples::PersistentAccessor::runTree ( ) const
inline

Definition at line 45 of file PersistentAccessor.h.

45 { return *m_runTree; }

◆ save()

bool PersistentAccessor::save ( ) const

Definition at line 165 of file PersistentAccessor.cxx.

166 {
167  if (!m_file) return 0;
168  m_file->cd();
169  cout << "Writing " << m_runTree->GetEntries() << " run(s)..." << endl;
170  m_runTree->Write();
171  cout << "Writing " << m_eventTree->GetEntries() << " event(s)..." << endl;
172  m_eventTree->Write();
173  cout << "Writing " << m_cellTree->GetEntries() << " cell(s)..." << endl;
174  m_cellTree->Write();
175  m_file->Flush();
176  cout << "Writing done!" << endl;
177  return true;
178 }

Member Data Documentation

◆ m_cellTree

TTree* LArSamples::PersistentAccessor::m_cellTree
private

Definition at line 71 of file PersistentAccessor.h.

◆ m_eventData

EventData* LArSamples::PersistentAccessor::m_eventData
mutableprivate

Definition at line 74 of file PersistentAccessor.h.

◆ m_eventTree

TTree * LArSamples::PersistentAccessor::m_eventTree
private

Definition at line 71 of file PersistentAccessor.h.

◆ m_file

TFile* LArSamples::PersistentAccessor::m_file
mutableprivate

Definition at line 72 of file PersistentAccessor.h.

◆ m_historyCont

HistoryContainer* LArSamples::PersistentAccessor::m_historyCont
mutableprivate

Definition at line 73 of file PersistentAccessor.h.

◆ m_runCache

std::map<unsigned int, const RunData*> LArSamples::PersistentAccessor::m_runCache
mutableprivate

Definition at line 76 of file PersistentAccessor.h.

◆ m_runData

RunData* LArSamples::PersistentAccessor::m_runData
mutableprivate

Definition at line 75 of file PersistentAccessor.h.

◆ m_runTree

TTree * LArSamples::PersistentAccessor::m_runTree
private

Definition at line 71 of file PersistentAccessor.h.


The documentation for this class was generated from the following files:
grepfile.info
info
Definition: grepfile.py:38
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
get_generator_info.result
result
Definition: get_generator_info.py:21
LArSamples::EventData::setRunData
void setRunData(const RunData *runData)
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:75
LArSamples::PersistentAccessor::m_cellTree
TTree * m_cellTree
Definition: PersistentAccessor.h:71
LArSamples::DataContainer::gain
CaloGain::CaloGain gain() const
Definition: DataContainer.h:54
LArSamples::PersistentAccessor::runData
const RunData * runData(unsigned int i) const
Definition: PersistentAccessor.cxx:122
Epos_Base_Fragment.inputFiles
string inputFiles
Definition: Epos_Base_Fragment.py:18
LArSamples::HistoryContainer::dataContainer
const DataContainer * dataContainer(unsigned int i) const
Definition: HistoryContainer.h:41
LArSamples::PersistentAccessor
Definition: PersistentAccessor.h:24
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
LArSamples::EventData::runIndex
int runIndex() const
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:53
LArSamples::PersistentAccessor::runTree
const TTree & runTree() const
Definition: PersistentAccessor.h:45
LArSamples::ShapeInfo
Definition: ShapeInfo.h:24
LArSamples::PersistentAccessor::eventData
const EventData * eventData(unsigned int i) const
Definition: PersistentAccessor.cxx:113
LArSamples::PersistentAccessor::addEvent
void addEvent(EventData *eventData)
Definition: PersistentAccessor.cxx:149
LArSamples::PersistentAccessor::file
TFile * file() const
Definition: PersistentAccessor.h:47
LArSamples::PersistentAccessor::add
void add(HistoryContainer *cont)
Definition: PersistentAccessor.cxx:141
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LArSamples::RunData
Definition: RunData.h:21
LArSamples::PersistentAccessor::PersistentAccessor
PersistentAccessor(TTree &cellTree, TTree &eventTree, TTree *runTree, TFile *file)
Constructor
Definition: PersistentAccessor.cxx:26
LArSamples::Definitions::nChannels
static const unsigned int nChannels
Definition: Definitions.h:14
LArSamples::PersistentAccessor::nEvents
unsigned int nEvents() const
Definition: PersistentAccessor.h:52
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArSamples::CellInfo::shape
const ShapeInfo * shape(CaloGain::CaloGain gain) const
Definition: CellInfo.cxx:78
LArSamples::ClassCounts::decrementInstanceCount
void decrementInstanceCount() const
Definition: LArCafJobs/LArCafJobs/ClassCounts.h:33
LArSamples::HistoryContainer::isValid
bool isValid() const
Definition: HistoryContainer.cxx:52
LArSamples::PersistentAccessor::m_file
TFile * m_file
Definition: PersistentAccessor.h:72
ITk::EventData
InDet::SiSpacePointsSeedMakerEventData EventData
Definition: ITkSiSpacePointsSeedMaker.h:63
run
Definition: run.py:1
LArSamples::PersistentAccessor::m_historyCont
HistoryContainer * m_historyCont
Definition: PersistentAccessor.h:73
LArSamples::PersistentAccessor::m_eventData
EventData * m_eventData
Definition: PersistentAccessor.h:74
LArSamples::PersistentAccessor::open
static PersistentAccessor * open(const TString &fileName)
Definition: PersistentAccessor.cxx:65
LArSamples::PersistentAccessor::nRuns
unsigned int nRuns() const
Definition: PersistentAccessor.h:55
LArSamples::PersistentAccessor::cellTree
const TTree & cellTree() const
Definition: PersistentAccessor.h:43
LArSamples::ClassCounts::incrementInstanceCount
void incrementInstanceCount() const
Definition: LArCafJobs/LArCafJobs/ClassCounts.h:32
LArSamples::PersistentAccessor::m_runTree
TTree * m_runTree
Definition: PersistentAccessor.h:71
LArSamples::PersistentAccessor::m_eventTree
TTree * m_eventTree
Definition: PersistentAccessor.h:71
LArSamples::CellInfo
Definition: CellInfo.h:31
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
LArSamples::HistoryContainer::cellInfo
const CellInfo * cellInfo() const
Definition: HistoryContainer.h:43
LArSamples::PersistentAccessor::save
bool save() const
Definition: PersistentAccessor.cxx:165
LArSamples::DataContainer
Definition: DataContainer.h:25
LArSamples::PersistentAccessor::m_runData
RunData * m_runData
Definition: PersistentAccessor.h:75
LArSamples::HistoryContainer
Definition: HistoryContainer.h:29
LArSamples::DataContainer::eventIndex
int eventIndex() const
Definition: DataContainer.h:64
LArSamples::HistoryContainer::add
void add(const DataContainer *data)
append data (takes ownership)
Definition: HistoryContainer.h:46
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
LArSamples::PersistentAccessor::eventTree
const TTree & eventTree() const
Definition: PersistentAccessor.h:44
xAODRootTest.accessors
dictionary accessors
Definition: xAODRootTest.py:67
LArSamples::PersistentAccessor::addRun
void addRun(RunData *runData)
Definition: PersistentAccessor.cxx:157
LArSamples::PersistentAccessor::m_runCache
std::map< unsigned int, const RunData * > m_runCache
Definition: PersistentAccessor.h:76
LArSamples::PersistentAccessor::historyContainer
const HistoryContainer * historyContainer(unsigned int i) const
Definition: PersistentAccessor.cxx:99
LArSamples::PersistentAccessor::merge
static PersistentAccessor * merge(const std::vector< const PersistentAccessor * > &accessors, const TString &fileName)
Definition: PersistentAccessor.cxx:181
LArSamples::EventData
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:29
LArSamples::PersistentAccessor::fileName
TString fileName() const
Definition: PersistentAccessor.cxx:135
LArSamples::DataContainer::setEventIndex
void setEventIndex(int index)
Definition: DataContainer.h:92
LArSamples::HistoryContainer::nDataContainers
unsigned int nDataContainers() const
Definition: HistoryContainer.h:40