ATLAS Offline Software
Loading...
Searching...
No Matches
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.
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
unsigned int historySizeSC (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 unsigned int nChannelsSC () 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 HistorygetSCHistory (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) { }
std::vector< const TreeAccessor * > m_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}
const TreeAccessor & accessor(unsigned int i) const

Member Function Documentation

◆ accessor()

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

Definition at line 52 of file MultiTreeAccessor.h.

52{ return *m_accessors[i]; }

◆ cachePos()

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

Definition at line 48 of file AbsLArCells.h.

48{ return m_pos; }

◆ cellCache()

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

Definition at line 47 of file AbsLArCells.h.

47{ return m_cellCache; }
const History * m_cellCache
Definition AbsLArCells.h:55

◆ 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}
virtual void resetCache() const
virtual const History * newCellHistory(unsigned int i) const

◆ 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}
std::vector< CellInfo * > m_cellInfoCache
Definition AbsLArCells.h:56
virtual const CellInfo * getCellInfo(unsigned int i) const
const CellInfo * cellInfoCache(unsigned int i) const

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

270{
271 std::vector< std::vector<const TreeAccessor*> > filteredAccessors(filterList.size());
272
273 for (unsigned int i = 0; i < nAccessors(); i++) {
274 const TreeAccessor* treeAcc = dynamic_cast<const TreeAccessor*>(&accessor(i));
275 cout << "Processing data " << i << " of " << nAccessors();
276 if (treeAcc) cout << " (fileName = " << treeAcc->fileName() << ")";
277 cout << endl;
278 FilterList thisFilterList;
279 //
280 for (unsigned int f = 0; f < filterList.size(); f++) {
281 std::string pathname = (string)filterList.fileName(f);
282 if( pathname.find("eos/atlas/") < pathname.length() ){
283 int nslashes = 0, slpos = 0;
284 for( int k1 = 0; k1 < (int)pathname.length(); k1++ ){
285 if( nslashes > 2 )break;
286 if( pathname[k1] != '/' )continue;
287 nslashes++;
288 slpos = k1;
289 }
290 pathname.resize( slpos );
291 }
292 TString thisFN = Form("%s_filter%d.root", pathname.c_str(), i );//filterList.fileName(f).Data(), i);
293 thisFilterList.add(filterList.filterParams(f), thisFN);
294 }
295 std::vector<TreeAccessor*> filteredTreeAccs = TreeAccessor::filter(accessor(i), thisFilterList, tweaker);
296 if (filteredTreeAccs.size() != filterList.size()) {
297 cout << "Filtering failed, exiting" << endl;
298 return std::vector<MultiTreeAccessor*>();
299 }
300 for (unsigned int f = 0; f < filteredTreeAccs.size(); f++) filteredAccessors[f].push_back(filteredTreeAccs[f]);
301 }
302
303 std::vector<MultiTreeAccessor*> result;
304 for (unsigned int f = 0; f < filteredAccessors.size(); f++) result.push_back(new MultiTreeAccessor(filteredAccessors[f]));
305 return result;
306}
void add(const FilterParams &params, const TString &fileName)
Definition FilterList.h:27
unsigned int size() const
Definition FilterList.h:29
const FilterParams & filterParams(unsigned int i) const
Definition FilterList.h:30
const TString & fileName(unsigned int i) const
Definition FilterList.h:31
unsigned int nAccessors() const
MultiTreeAccessor(const std::vector< const TreeAccessor * > &accessors)
Constructor.
static TreeAccessor * filter(const Accessor &accessor, const FilterParams &filterParams, const TString &fileName, const DataTweaker &tweaker)

◆ getCellHistory()

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

Implements LArSamples::AbsLArCells.

Definition at line 167 of file MultiTreeAccessor.cxx.

168{
169 CellInfo* cellInfo = nullptr;
170 std::vector<const Data*> allData;
171 std::vector<const EventData*> allEventData;
172 for (const TreeAccessor* accessor : m_accessors) {
173 const History* thisHistory = accessor->getCellHistory(i);
174 if (!thisHistory) continue;
175 if (!cellInfo) {
176 cellInfo = new CellInfo(*thisHistory->cellInfo());
177 }
178 const std::vector<const EventData*>& thisEventData = thisHistory->eventData();
179 std::map<const EventData*, const EventData*> eventMap;
180 for (const EventData* event : thisEventData) {
181 if (eventMap.find(event) != eventMap.end()) continue;
182 EventData* newED = new EventData(*event);
183 eventMap[event] = newED;
184 allEventData.push_back(newED);
185 }
186
187 for (unsigned int j = 0; j < thisHistory->nData(); j++) {
188 allData.push_back(new Data(*thisHistory->data(j), eventMap[thisHistory->data(j)->eventData()], nullptr, -1));
189 if (!cellInfo->shape(thisHistory->data(j)->gain())) {
190 const ShapeInfo* thisShape = thisHistory->cellInfo()->shape(thisHistory->data(j)->gain());
191 cellInfo->setShape(thisHistory->data(j)->gain(), thisShape ? new ShapeInfo(*thisShape) : nullptr);
192 }
193 }
194 delete thisHistory;
195 }
196 //data are copied from cellInfo into History member variable
197 auto * h = cellInfo ? new History(allData, *cellInfo, allEventData, i): nullptr;
198 delete cellInfo;
199 return h;
200}
@ Data
Definition BaseObject.h:11
virtual const CellInfo * cellInfo(unsigned int i) const
const ShapeInfo * shape(CaloGain::CaloGain gain) const
Definition CellInfo.cxx:78
const EventData * eventData() const
Definition Data.h:95
CaloGain::CaloGain gain() const
Definition Data.h:85
const std::vector< const EventData * > & eventData() const
Definition History.h:58
const CellInfo * cellInfo() const
Definition History.h:56
const Data * data(unsigned int i) const
Definition History.cxx:91
unsigned int nData() const
Definition History.h:51

◆ getCellInfo()

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

Reimplemented from LArSamples::AbsLArCells.

Definition at line 245 of file MultiTreeAccessor.cxx.

246{
247 resetCache();
248 for (const TreeAccessor* accessor : m_accessors) {
249 const HistoryContainer* cont = accessor->historyContainer(i);
250 if (cont && cont->cellInfo()) return new CellInfo(*cont->cellInfo());
251 }
252 return nullptr;
253}
const CellInfo * cellInfo() const

◆ getSCHistory()

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

Implements LArSamples::AbsLArCells.

Definition at line 202 of file MultiTreeAccessor.cxx.

203{
204 std::unique_ptr<CellInfo> cellInfo{};
205 std::vector<const Data*> allData;
206 std::vector<const EventData*> allEventData;
207 for (const TreeAccessor* accessor : m_accessors) {
208 //cout << "---> Getting history for a treeAccessor..." << endl;
209 const History* thisHistory = accessor->getSCHistory(i);
210 //cout << "---> done Getting history for a treeAccessor..." << endl;
211 if (!thisHistory) continue;
212 if (!cellInfo) {
213 cellInfo = std::make_unique<CellInfo>(*thisHistory->cellInfo());
214 //cout << "---> done new cell info" << endl;
215 }
216 //cout << "---> Creating new event data N = " << thisHistory->eventData().size() << endl;
217 const std::vector<const EventData*>& thisEventData = thisHistory->eventData();
218 std::map<const EventData*, const EventData*> eventMap;
219 for (const EventData* event : thisEventData) {
220 if (eventMap.find(event) != eventMap.end()) continue;
221 EventData* newED = new EventData(*event);
222 eventMap[event] = newED;
223 allEventData.push_back(newED);
224 }
225 //cout << "---> Creating new data N = " << thisHistory->nData() << endl;
226
227 for (unsigned int ii = 0; ii < thisHistory->nData(); ii++) {
228 //cout << "------> Creating new data " << i << endl;
229 allData.push_back(new Data(*thisHistory->data(ii), eventMap[thisHistory->data(ii)->eventData()], nullptr, -1));
230 //cout << "------> done Creating new data " << i << endl;
231 if (!cellInfo->shape(thisHistory->data(ii)->gain())) {
232 const ShapeInfo* thisShape = thisHistory->cellInfo()->shape(thisHistory->data(ii)->gain());
233 cellInfo->setShape(thisHistory->data(ii)->gain(), thisShape ? new ShapeInfo(*thisShape) : nullptr);
234 }
235 //cout << "------> done shape " << i << endl;
236 }
237 //cout << "---> done Creating new data, deleting treeAcc history" << endl;
238 delete thisHistory;
239 }
240 //cout << "--->returning new history..." << endl;
241 return (cellInfo ? new History(allData, *cellInfo, allEventData, i) : nullptr);
242}

◆ 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) {
149 const HistoryContainer* cont = accessor->historyContainer(i);
150 if (cont) size += cont->nDataContainers();
151 }
152 return size;
153}
unsigned int nDataContainers() const

◆ historySizeSC()

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

Implements LArSamples::Accessor.

Definition at line 155 of file MultiTreeAccessor.cxx.

156{
157 resetCache();
158 unsigned int size = 0;
159 for (const TreeAccessor* accessor : m_accessors) {
160 const HistoryContainer* cont = accessor->historyContainerSC(i);
161 if (cont) size += cont->nDataContainers();
162 }
163 return size;
164}

◆ nAccessors()

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

Definition at line 53 of file MultiTreeAccessor.h.

53{ 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.

◆ nChannelsSC()

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

Definition at line 35 of file AbsLArCells.h.

◆ 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}
virtual const History * getCellHistory(unsigned int i) const =0

◆ 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) {
30 const TreeAccessor* accessor = TreeAccessor::open(fileName);
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}
static TreeAccessor * open(const TString &fileName)
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50

◆ 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) {
57 const TreeAccessor* accessor = TreeAccessor::open(fileName.c_str());
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();
81 const TreeAccessor* accessor = TreeAccessor::open(fileName.c_str());
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}
TGraphErrors * GetEntries(TH2F *histo)

◆ 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}
virtual const History * cellHistory(unsigned int i) const

◆ 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}
virtual unsigned int nChannels() const
Definition AbsLArCells.h:34

◆ resetCellInfoCache()

void AbsLArCells::resetCellInfoCache ( )
inherited

Definition at line 114 of file AbsLArCells.cxx.

115{
116 unsigned int i = 0;
117 for (std::vector<CellInfo*>::iterator cellInfo = m_cellInfoCache.begin();
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 256 of file MultiTreeAccessor.cxx.

257{
258 std::vector<const Accessor*> accessors;
259 for (unsigned int i = 0; i < m_accessors.size(); i++)
260 accessors.push_back(m_accessors[i]);
261 cout << "Merging data..." << endl;
262 TreeAccessor* singleContainer = TreeAccessor::merge(accessors, fileName);
263 if (!singleContainer) return false;
264 delete singleContainer;
265 return true;
266}
static TreeAccessor * merge(const std::vector< const Accessor * > &accessors, const TString &fileName="")

Member Data Documentation

◆ m_accessors

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

Definition at line 65 of file MultiTreeAccessor.h.

◆ m_cellCache

const History* LArSamples::AbsLArCells::m_cellCache
mutableprivateinherited

Definition at line 55 of file AbsLArCells.h.

◆ m_cellInfoCache

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

Definition at line 56 of file AbsLArCells.h.

◆ m_pos

unsigned int LArSamples::AbsLArCells::m_pos
mutableprivateinherited

Definition at line 54 of file AbsLArCells.h.


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