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 94 of file MultiTreeAccessor.cxx.

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

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 57 of file AbsLArCells.cxx.

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

◆ cellInfo()

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

Definition at line 69 of file AbsLArCells.cxx.

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

◆ cellInfoCache()

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

Definition at line 80 of file AbsLArCells.cxx.

81 {
82  return m_cellInfoCache[i];
83 }

◆ eventData()

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

Implements LArSamples::Accessor.

Definition at line 101 of file MultiTreeAccessor.cxx.

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

◆ filterComponents()

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

Definition at line 215 of file MultiTreeAccessor.cxx.

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

◆ getCellHistory()

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

Implements LArSamples::AbsLArCells.

Definition at line 155 of file MultiTreeAccessor.cxx.

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

◆ getCellInfo()

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

Reimplemented from LArSamples::AbsLArCells.

Definition at line 191 of file MultiTreeAccessor.cxx.

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

◆ historySize()

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

Implements LArSamples::Accessor.

Definition at line 143 of file MultiTreeAccessor.cxx.

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

◆ 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 125 of file MultiTreeAccessor.cxx.

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

◆ newCellHistory()

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

Definition at line 42 of file AbsLArCells.cxx.

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

◆ nRuns()

unsigned int MultiTreeAccessor::nRuns ( ) const
virtual

Implements LArSamples::Accessor.

Definition at line 134 of file MultiTreeAccessor.cxx.

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

◆ open()

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

Definition at line 25 of file MultiTreeAccessor.cxx.

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

◆ openList()

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

Definition at line 42 of file MultiTreeAccessor.cxx.

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

◆ openWild()

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

Definition at line 70 of file MultiTreeAccessor.cxx.

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

◆ pass()

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

Definition at line 97 of file AbsLArCells.cxx.

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

◆ resetCache()

void AbsLArCells::resetCache ( ) const
virtualinherited

Definition at line 32 of file AbsLArCells.cxx.

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

◆ resetCellInfoCache()

void AbsLArCells::resetCellInfoCache ( )
inherited

Definition at line 112 of file AbsLArCells.cxx.

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

◆ runData()

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

Implements LArSamples::Accessor.

Definition at line 113 of file MultiTreeAccessor.cxx.

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

◆ writeToFile()

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

Implements LArSamples::Accessor.

Definition at line 202 of file MultiTreeAccessor.cxx.

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

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:42
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:61
LArSamples::AbsLArCells::cellHistory
virtual const History * cellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:57
Data
@ Data
Definition: BaseObject.h:11
LArSamples::History
Definition: History.h:40
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:69
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:89
LArSamples::TreeAccessor::getCellHistory
const History * getCellHistory(unsigned int i) const
Definition: TreeAccessor.cxx:51
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:86
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:56
LArSamples::TreeAccessor::merge
static TreeAccessor * merge(const std::vector< const Accessor * > &accessors, const TString &fileName="")
Definition: TreeAccessor.cxx:73
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:80
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:90
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:294
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:32
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:100
LArSamples::History::eventData
const std::vector< const EventData * > & eventData() const
Definition: History.h:63
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:28
LArSamples::HistoryContainer::nDataContainers
unsigned int nDataContainers() const
Definition: HistoryContainer.h:40