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

#include <MultiTreeAccessor.h>

Inheritance diagram for LArSamples::MultiTreeAccessor:
Collaboration diagram for LArSamples::MultiTreeAccessor:

Public Member Functions

 MultiTreeAccessor (const std::vector< const TreeAccessor * > &accessors)
 Constructor
More...
 
virtual ~MultiTreeAccessor ()
 
unsigned int nEvents () const
 
unsigned int nRuns () const
 
const EventDataeventData (unsigned int i) const
 
const RunDatarunData (unsigned int i) const
 
unsigned int historySize (unsigned int i) const
 
bool writeToFile (const TString &fileName) const
 
const TreeAccessoraccessor (unsigned int i) const
 
unsigned int nAccessors () const
 
std::vector< MultiTreeAccessor * > filterComponents (const FilterList &filterList, const DataTweaker &tweaker) const
 
virtual const HistorynewCellHistory (unsigned int i) const
 
virtual const HistorycellHistory (unsigned int i) const
 
virtual const CellInfocellInfo (unsigned int i) const
 
virtual unsigned int nChannels () const
 
virtual void resetCache () const
 
const CellInfocellInfoCache (unsigned int i) const
 
const Historypass (unsigned int i, const FilterParams &f) const
 
const HistorycellCache () const
 
unsigned int cachePos () const
 
void resetCellInfoCache ()
 

Static Public Member Functions

static MultiTreeAccessoropen (const std::vector< TString > &files)
 
static MultiTreeAccessoropenList (const TString &fileList)
 
static MultiTreeAccessoropenWild (const TString &wcName)
 

Protected Member Functions

const HistorygetCellHistory (unsigned int i) const
 
const CellInfogetCellInfo (unsigned int i) const
 

Private Attributes

std::vector< const TreeAccessor * > m_accessors
 
unsigned int m_pos
 
const Historym_cellCache
 
std::vector< CellInfo * > m_cellInfoCache
 

Detailed Description

Definition at line 27 of file MultiTreeAccessor.h.

Constructor & Destructor Documentation

◆ MultiTreeAccessor()

LArSamples::MultiTreeAccessor::MultiTreeAccessor ( const std::vector< const TreeAccessor * > &  accessors)
inline

Constructor

Definition at line 32 of file MultiTreeAccessor.h.

33  : m_accessors(accessors) { }

◆ ~MultiTreeAccessor()

MultiTreeAccessor::~MultiTreeAccessor ( )
virtual

Definition at line 95 of file MultiTreeAccessor.cxx.

96 {
97  for (const TreeAccessor* accessor : m_accessors)
98  delete accessor;
99 }

Member Function Documentation

◆ accessor()

const TreeAccessor& LArSamples::MultiTreeAccessor::accessor ( unsigned int  i) const
inline

Definition at line 51 of file MultiTreeAccessor.h.

51 { return *m_accessors[i]; }

◆ cachePos()

unsigned int LArSamples::AbsLArCells::cachePos ( ) const
inlineinherited

Definition at line 45 of file AbsLArCells.h.

45 { return m_pos; }

◆ cellCache()

const History* LArSamples::AbsLArCells::cellCache ( ) const
inlineinherited

Definition at line 44 of file AbsLArCells.h.

44 { return m_cellCache; }

◆ cellHistory()

const History * AbsLArCells::cellHistory ( unsigned int  i) const
virtualinherited

Reimplemented in LArSamples::Interface.

Definition at line 59 of file AbsLArCells.cxx.

60 {
61  if (m_pos == i) return m_cellCache;
62  resetCache();
63  const History* history = newCellHistory(i);
64  if (!history) return nullptr;
65  m_cellCache = history;
66  m_pos = i;
67  return m_cellCache;
68 }

◆ cellInfo()

const CellInfo * AbsLArCells::cellInfo ( unsigned int  i) const
virtualinherited

Definition at line 71 of file AbsLArCells.cxx.

72 {
73  const CellInfo* info = cellInfoCache(i);
74  if (info) return (info->isValid() ? new CellInfo(*info) : nullptr);
75  info = getCellInfo(i);
76  if (info) m_cellInfoCache[i] = new CellInfo(*info, false);
77  //m_cellInfoCache[i] = (info ? new CellInfo(*info, false) : new CellInfo());
78  return info;
79 }

◆ cellInfoCache()

const CellInfo * AbsLArCells::cellInfoCache ( unsigned int  i) const
inherited

Definition at line 82 of file AbsLArCells.cxx.

83 {
84  return m_cellInfoCache[i];
85 }

◆ eventData()

const EventData * MultiTreeAccessor::eventData ( unsigned int  i) const
virtual

Implements LArSamples::Accessor.

Definition at line 102 of file MultiTreeAccessor.cxx.

103 {
104  unsigned int nEventsSoFar = 0;
105  for (const TreeAccessor* accessor : m_accessors) {
106  unsigned int n = accessor->nEvents();
107  if (i < nEventsSoFar + n) return accessor->eventData(i - nEventsSoFar);
108  nEventsSoFar += n;
109  }
110  return nullptr;
111 }

◆ filterComponents()

std::vector< MultiTreeAccessor * > MultiTreeAccessor::filterComponents ( const FilterList filterList,
const DataTweaker tweaker 
) const

Definition at line 216 of file MultiTreeAccessor.cxx.

217 {
218  std::vector< std::vector<const TreeAccessor*> > filteredAccessors(filterList.size());
219 
220  for (unsigned int i = 0; i < nAccessors(); i++) {
221  const TreeAccessor* treeAcc = dynamic_cast<const TreeAccessor*>(&accessor(i));
222  cout << "Processing data " << i << " of " << nAccessors();
223  if (treeAcc) cout << " (fileName = " << treeAcc->fileName() << ")";
224  cout << endl;
225  FilterList thisFilterList;
226  //
227  for (unsigned int f = 0; f < filterList.size(); f++) {
228  std::string pathname = (string)filterList.fileName(f);
229  if( pathname.find("eos/atlas/") < pathname.length() ){
230  int nslashes = 0, slpos = 0;
231  for( int k1 = 0; k1 < (int)pathname.length(); k1++ ){
232  if( nslashes > 2 )break;
233  if( pathname[k1] != '/' )continue;
234  nslashes++;
235  slpos = k1;
236  }
237  pathname.resize( slpos );
238  }
239  TString thisFN = Form("%s_filter%d.root", pathname.c_str(), i );//filterList.fileName(f).Data(), i);
240  thisFilterList.add(filterList.filterParams(f), thisFN);
241  }
242  std::vector<TreeAccessor*> filteredTreeAccs = TreeAccessor::filter(accessor(i), thisFilterList, tweaker);
243  if (filteredTreeAccs.size() != filterList.size()) {
244  cout << "Filtering failed, exiting" << endl;
245  return std::vector<MultiTreeAccessor*>();
246  }
247  for (unsigned int f = 0; f < filteredTreeAccs.size(); f++) filteredAccessors[f].push_back(filteredTreeAccs[f]);
248  }
249 
250  std::vector<MultiTreeAccessor*> result;
251  for (unsigned int f = 0; f < filteredAccessors.size(); f++) result.push_back(new MultiTreeAccessor(filteredAccessors[f]));
252  return result;
253 }

◆ getCellHistory()

const History * MultiTreeAccessor::getCellHistory ( unsigned int  i) const
protectedvirtual

Implements LArSamples::AbsLArCells.

Definition at line 156 of file MultiTreeAccessor.cxx.

157 {
158  CellInfo* cellInfo = nullptr;
159  std::vector<const Data*> allData;
160  std::vector<const EventData*> allEventData;
161  for (const TreeAccessor* accessor : m_accessors) {
162  const History* thisHistory = accessor->getCellHistory(i);
163  if (!thisHistory) continue;
164  if (!cellInfo) {
165  cellInfo = new CellInfo(*thisHistory->cellInfo());
166  }
167  const std::vector<const EventData*>& thisEventData = thisHistory->eventData();
168  std::map<const EventData*, const EventData*> eventMap;
169  for (const EventData* event : thisEventData) {
170  if (eventMap.find(event) != eventMap.end()) continue;
171  EventData* newED = new EventData(*event);
172  eventMap[event] = newED;
173  allEventData.push_back(newED);
174  }
175 
176  for (unsigned int i = 0; i < thisHistory->nData(); i++) {
177  allData.push_back(new Data(*thisHistory->data(i), eventMap[thisHistory->data(i)->eventData()], nullptr, -1));
178  if (!cellInfo->shape(thisHistory->data(i)->gain())) {
179  const ShapeInfo* thisShape = thisHistory->cellInfo()->shape(thisHistory->data(i)->gain());
180  cellInfo->setShape(thisHistory->data(i)->gain(), thisShape ? new ShapeInfo(*thisShape) : nullptr);
181  }
182  }
183  delete thisHistory;
184  }
185  //data are copied from cellInfo into History member variable
186  auto * h = cellInfo ? new History(allData, *cellInfo, allEventData, i): nullptr;
187  delete cellInfo;
188  return h;
189 }

◆ getCellInfo()

const CellInfo * MultiTreeAccessor::getCellInfo ( unsigned int  i) const
protectedvirtual

Reimplemented from LArSamples::AbsLArCells.

Definition at line 192 of file MultiTreeAccessor.cxx.

193 {
194  resetCache();
195  for (const TreeAccessor* accessor : m_accessors) {
197  if (cont && cont->cellInfo()) return new CellInfo(*cont->cellInfo());
198  }
199  return nullptr;
200 }

◆ historySize()

unsigned int MultiTreeAccessor::historySize ( unsigned int  i) const
virtual

Implements LArSamples::Accessor.

Definition at line 144 of file MultiTreeAccessor.cxx.

145 {
146  resetCache();
147  unsigned int size = 0;
148  for (const TreeAccessor* accessor : m_accessors) {
150  if (cont) size += cont->nDataContainers();
151  }
152  return size;
153 }

◆ nAccessors()

unsigned int LArSamples::MultiTreeAccessor::nAccessors ( ) const
inline

Definition at line 52 of file MultiTreeAccessor.h.

52 { return m_accessors.size(); }

◆ nChannels()

virtual unsigned int LArSamples::AbsLArCells::nChannels ( ) const
inlinevirtualinherited

Reimplemented in LArSamples::MonitorBase.

Definition at line 34 of file AbsLArCells.h.

34 { return Definitions::nChannels; }

◆ nEvents()

unsigned int MultiTreeAccessor::nEvents ( ) const
virtual

Implements LArSamples::Accessor.

Definition at line 126 of file MultiTreeAccessor.cxx.

127 {
128  unsigned int n = 0;
129  for (const TreeAccessor* accessor : m_accessors)
130  n += accessor->nEvents();
131  return n;
132 }

◆ newCellHistory()

const History * AbsLArCells::newCellHistory ( unsigned int  i) const
virtualinherited

Definition at line 44 of file AbsLArCells.cxx.

45 {
46  const History* history = getCellHistory(i);
47  if (!history) return nullptr;
48  if (!m_cellInfoCache[i]) {
49  const CellInfo* ci=history->cellInfo();
50  if (ci) {
51  m_cellInfoCache[i]=new CellInfo(*ci,false);
52  }
53  }
54  // m_cellInfoCache[i] = (history->cellInfo() ? new CellInfo(*history->cellInfo(), false) : new CellInfo());
55  return history;
56 }

◆ nRuns()

unsigned int MultiTreeAccessor::nRuns ( ) const
virtual

Implements LArSamples::Accessor.

Definition at line 135 of file MultiTreeAccessor.cxx.

136 {
137  unsigned int n = 0;
138  for (const TreeAccessor* accessor : m_accessors)
139  n += accessor->nRuns();
140  return n;
141 }

◆ open()

MultiTreeAccessor * MultiTreeAccessor::open ( const std::vector< TString > &  files)
static

Definition at line 26 of file MultiTreeAccessor.cxx.

27 {
28  std::vector<const TreeAccessor*> accessors;
29  for (const TString& fileName : files) {
31  if (!accessor) {
32  cout << "Skipping invalid file " << fileName << endl;
33  continue;
34  }
35  accessors.push_back(accessor);
36  }
37 
38  if (accessors.empty()) return nullptr;
39  return new MultiTreeAccessor(accessors);
40 }

◆ openList()

MultiTreeAccessor * MultiTreeAccessor::openList ( const TString &  fileList)
static

Definition at line 43 of file MultiTreeAccessor.cxx.

44 {
45  std::ifstream f(fileList);
46  if (!f) {
47  cout << "file " << fileList << " not accessible" << endl;
48  return nullptr;
49  }
50 
51  std::string fileName;
52  unsigned int i = 0;
53 
54  std::vector<const TreeAccessor*> accessors;
55 
56  while (f >> fileName) {
58  if (!accessor) {
59  cout << "Skipping invalid file " << fileName << endl;
60  continue;
61  }
62  cout << std::setw(2) << ++i << " - " << fileName << endl;
63  accessors.push_back(accessor);
64  }
65 
66  if (accessors.empty()) return nullptr;
67  return new MultiTreeAccessor(accessors);
68 }

◆ openWild()

MultiTreeAccessor * MultiTreeAccessor::openWild ( const TString &  wcName)
static

Definition at line 71 of file MultiTreeAccessor.cxx.

72 {
73  // Piggyback on TChain wildcarding feature...
74  TChain chain("");
75  chain.Add(wcName);
76 
77  std::vector<const TreeAccessor*> accessors;
78 
79  for (int i = 0; i < chain.GetListOfFiles()->GetEntries(); i++) {
80  std::string fileName = chain.GetListOfFiles()->At(i)->GetTitle();
82  if (!accessor) {
83  cout << "Skipping invalid file " << fileName << endl;
84  continue;
85  }
86  cout << std::setw(2) << i+1 << " - " << fileName << " , nEvents = " << accessor->nEvents() << ", nRuns = " << accessor->nRuns() << endl;
87  accessors.push_back(accessor);
88  }
89 
90  if (accessors.empty()) return nullptr;
91  return new MultiTreeAccessor(accessors);
92 }

◆ pass()

const History * AbsLArCells::pass ( unsigned int  i,
const FilterParams f 
) const
inherited

Definition at line 99 of file AbsLArCells.cxx.

100 {
101  //std::cout << "Called AbsLArCells with hash " << i << std::endl;
102  if (!f.passHash(i)) return nullptr;
103  const CellInfo* info = cellInfo(i);
104  if (!info) {
105  return nullptr;
106  }
107  //std::cout << "Called AbsLArCells::pass on a cell belonging to " << Id::str(info->calo()) << std::endl;
108  bool result = f.passCell(*info);
109  delete info;
110  return result ? cellHistory(i) : nullptr;
111 }

◆ resetCache()

void AbsLArCells::resetCache ( ) const
virtualinherited

Definition at line 34 of file AbsLArCells.cxx.

35 {
36  if (m_cellCache) {
37  delete m_cellCache;
38  m_cellCache = nullptr;
39  }
40  m_pos = nChannels() + 1;
41 }

◆ resetCellInfoCache()

void AbsLArCells::resetCellInfoCache ( )
inherited

Definition at line 114 of file AbsLArCells.cxx.

115 {
116  unsigned int i = 0;
118  cellInfo != m_cellInfoCache.end(); ++cellInfo, i++)
119  if (*cellInfo) {
120  delete *cellInfo;
121  *cellInfo = 0;
122  }
123 }

◆ runData()

const RunData * MultiTreeAccessor::runData ( unsigned int  i) const
virtual

Implements LArSamples::Accessor.

Definition at line 114 of file MultiTreeAccessor.cxx.

115 {
116  unsigned int nRunsSoFar = 0;
117  for (const TreeAccessor* accessor : m_accessors) {
118  unsigned int n = accessor->nRuns();
119  if (i < nRunsSoFar + n) return accessor->runData(i - nRunsSoFar);
120  nRunsSoFar += n;
121  }
122  return nullptr;
123 }

◆ writeToFile()

bool MultiTreeAccessor::writeToFile ( const TString &  fileName) const
virtual

Implements LArSamples::Accessor.

Definition at line 203 of file MultiTreeAccessor.cxx.

204 {
205  std::vector<const Accessor*> accessors;
206  for (unsigned int i = 0; i < m_accessors.size(); i++)
207  accessors.push_back(m_accessors[i]);
208  cout << "Merging data..." << endl;
209  TreeAccessor* singleContainer = TreeAccessor::merge(accessors, fileName);
210  if (!singleContainer) return false;
211  delete singleContainer;
212  return true;
213 }

Member Data Documentation

◆ m_accessors

std::vector<const TreeAccessor*> LArSamples::MultiTreeAccessor::m_accessors
private

Definition at line 63 of file MultiTreeAccessor.h.

◆ m_cellCache

const History* LArSamples::AbsLArCells::m_cellCache
mutableprivateinherited

Definition at line 52 of file AbsLArCells.h.

◆ m_cellInfoCache

std::vector<CellInfo*> LArSamples::AbsLArCells::m_cellInfoCache
mutableprivateinherited

Definition at line 53 of file AbsLArCells.h.

◆ m_pos

unsigned int LArSamples::AbsLArCells::m_pos
mutableprivateinherited

Definition at line 51 of file AbsLArCells.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
LArSamples::AbsLArCells::m_pos
unsigned int m_pos
Definition: AbsLArCells.h:51
get_generator_info.result
result
Definition: get_generator_info.py:21
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
LArSamples::AbsLArCells::newCellHistory
virtual const History * newCellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:44
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArSamples::CellInfo::setShape
bool setShape(CaloGain::CaloGain gain, ShapeInfo *shape)
Definition: CellInfo.cxx:90
LArSamples::History::cellInfo
const CellInfo * cellInfo() const
Definition: History.h:56
LArSamples::AbsLArCells::cellHistory
virtual const History * cellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:59
Data
@ Data
Definition: BaseObject.h:11
LArSamples::History
Definition: History.h:35
LArSamples::AbsLArCells::m_cellInfoCache
std::vector< CellInfo * > m_cellInfoCache
Definition: AbsLArCells.h:53
LArSamples::FilterList::filterParams
const FilterParams & filterParams(unsigned int i) const
Definition: FilterList.h:30
LArSamples::AbsLArCells::cellInfo
virtual const CellInfo * cellInfo(unsigned int i) const
Definition: AbsLArCells.cxx:71
CscCalibQuery.fileList
fileList
Definition: CscCalibQuery.py:330
LArSamples::MultiTreeAccessor::nAccessors
unsigned int nAccessors() const
Definition: MultiTreeAccessor.h:52
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:4019
LArSamples::ShapeInfo
Definition: ShapeInfo.h:24
LArSamples::FilterList::add
void add(const FilterParams &params, const TString &fileName)
Definition: FilterList.h:27
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LArSamples::History::data
const Data * data(unsigned int i) const
Definition: History.cxx:91
LArSamples::TreeAccessor::getCellHistory
const History * getCellHistory(unsigned int i) const
Definition: TreeAccessor.cxx:53
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
LArSamples::Definitions::nChannels
static const unsigned int nChannels
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/Definitions.h:14
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
LArSamples::AbsLArCells::getCellInfo
virtual const CellInfo * getCellInfo(unsigned int i) const
Definition: AbsLArCells.cxx:88
LArSamples::CellInfo::shape
const ShapeInfo * shape(CaloGain::CaloGain gain) const
Definition: CellInfo.cxx:78
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
LArSamples::MultiTreeAccessor::MultiTreeAccessor
MultiTreeAccessor(const std::vector< const TreeAccessor * > &accessors)
Constructor
Definition: MultiTreeAccessor.h:32
hist_file_dump.f
f
Definition: hist_file_dump.py:135
ITk::EventData
InDet::SiSpacePointsSeedMakerEventData EventData
Definition: ITkSiSpacePointsSeedMaker.h:63
LArSamples::AbsLArCells::getCellHistory
virtual const History * getCellHistory(unsigned int i) const =0
LArSamples::History::nData
unsigned int nData() const
Definition: History.h:51
LArSamples::TreeAccessor::merge
static TreeAccessor * merge(const std::vector< const Accessor * > &accessors, const TString &fileName="")
Definition: TreeAccessor.cxx:75
LArSamples::TreeAccessor::nRuns
unsigned int nRuns() const
Definition: TreeAccessor.h:66
LArSamples::TreeAccessor::eventData
const EventData * eventData(unsigned int i) const
Definition: TreeAccessor.h:64
LArSamples::FilterList
Definition: FilterList.h:21
LArSamples::AbsLArCells::cellInfoCache
const CellInfo * cellInfoCache(unsigned int i) const
Definition: AbsLArCells.cxx:82
LArSamples::MultiTreeAccessor
Definition: MultiTreeAccessor.h:27
LArSamples::FilterList::fileName
const TString & fileName(unsigned int i) const
Definition: FilterList.h:31
LArSamples::AbsLArCells::m_cellCache
const History * m_cellCache
Definition: AbsLArCells.h:52
LArSamples::Data::gain
CaloGain::CaloGain gain() const
Definition: Data.h:85
LArSamples::CellInfo
Definition: CellInfo.h:31
LArSamples::HistoryContainer::cellInfo
const CellInfo * cellInfo() const
Definition: HistoryContainer.h:43
LArSamples::TreeAccessor::filter
static TreeAccessor * filter(const Accessor &accessor, const FilterParams &filterParams, const TString &fileName, const DataTweaker &tweaker)
Definition: TreeAccessor.cxx:296
LArSamples::HistoryContainer
Definition: HistoryContainer.h:29
LArSamples::TreeAccessor::runData
const RunData * runData(unsigned int i) const
Definition: TreeAccessor.h:67
LArSamples::AbsLArCells::resetCache
virtual void resetCache() const
Definition: AbsLArCells.cxx:34
LArSamples::MultiTreeAccessor::accessor
const TreeAccessor & accessor(unsigned int i) const
Definition: MultiTreeAccessor.h:51
xAODRootTest.accessors
dictionary accessors
Definition: xAODRootTest.py:73
LArSamples::PersistentAccessor::historyContainer
const HistoryContainer * historyContainer(unsigned int i) const
Definition: PersistentAccessor.cxx:99
LArSamples::Data::eventData
const EventData * eventData() const
Definition: Data.h:95
LArSamples::History::eventData
const std::vector< const EventData * > & eventData() const
Definition: History.h:58
LArSamples::TreeAccessor
Definition: TreeAccessor.h:32
LArSamples::FilterList::size
unsigned int size() const
Definition: FilterList.h:29
LArSamples::TreeAccessor::nEvents
unsigned int nEvents() const
Definition: TreeAccessor.h:63
LArSamples::EventData
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:29
LArSamples::PersistentAccessor::fileName
TString fileName() const
Definition: PersistentAccessor.cxx:135
LArSamples::AbsLArCells::nChannels
virtual unsigned int nChannels() const
Definition: AbsLArCells.h:34
LArSamples::MultiTreeAccessor::m_accessors
std::vector< const TreeAccessor * > m_accessors
Definition: MultiTreeAccessor.h:63
LArSamples::TreeAccessor::open
static TreeAccessor * open(const TString &fileName)
Definition: TreeAccessor.cxx:30
LArSamples::HistoryContainer::nDataContainers
unsigned int nDataContainers() const
Definition: HistoryContainer.h:40