ATLAS Offline Software
Loading...
Searching...
No Matches
AbsLArCells.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
11
12#include <iostream>
13using std::cout;
14using std::endl;
15
16using namespace LArSamples;
17
18
19//std::vector<CellInfo*> AbsLArCells::m_cellInfoCache(Definitions::nChannels,nullptr);
20
22 m_pos(nChannels() + 1),
23 m_cellCache(nullptr),
24 m_cellInfoCache(nChannels(),nullptr)
25{ }
26
32
33
35{
36 if (m_cellCache) {
37 delete m_cellCache;
38 m_cellCache = nullptr;
39 }
40 m_pos = nChannels() + 1;
41}
42
43
44const History* AbsLArCells::newCellHistory(unsigned int i) const
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}
57
58
59const History* AbsLArCells::cellHistory(unsigned int i) const
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}
69
70
71const CellInfo* AbsLArCells::cellInfo(unsigned int i) const
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}
80
81
82const CellInfo* AbsLArCells::cellInfoCache(unsigned int i) const
83{
84 return m_cellInfoCache[i];
85}
86
87
88const CellInfo* AbsLArCells::getCellInfo(unsigned int i) const
89{
90 const History* history = this->getCellHistory(i);
91 if (!history) return nullptr;
92 if (!history->cellInfo()) { delete history; return nullptr; }
93 CellInfo* info = new CellInfo(*history->cellInfo());
94 delete history;
95 return info;
96}
97
98
99const History* AbsLArCells::pass(unsigned int i, const FilterParams& f) const
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}
112
113
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}
const History * m_cellCache
Definition AbsLArCells.h:55
virtual unsigned int nChannels() const
Definition AbsLArCells.h:34
std::vector< CellInfo * > m_cellInfoCache
Definition AbsLArCells.h:56
virtual const CellInfo * getCellInfo(unsigned int i) const
const History * pass(unsigned int i, const FilterParams &f) const
virtual const History * cellHistory(unsigned int i) const
virtual void resetCache() const
virtual const History * newCellHistory(unsigned int i) const
virtual const History * getCellHistory(unsigned int i) const =0
const CellInfo * cellInfoCache(unsigned int i) const
virtual const CellInfo * cellInfo(unsigned int i) const
const CellInfo * cellInfo() const
Definition History.h:56