ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellFastCopyTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * CaloCellFastCopyTool.cxx
7 *
8 * Created on: Oct 7, 2013
9 *
10 */
11
12// Athena includes
14
15// Calo includes
19#include "CaloGeoHelpers/CaloSampling.h"
21
22#include <algorithm>
23#include <string>
24
25
27// INITIALIZE:
28// The initialize method will create all the required algorithm objects
30
32
33 ATH_MSG_INFO( "In initialize ");
34
35 ATH_CHECK( detStore()->retrieve(m_caloID));
36 ATH_CHECK(m_srcCellContainerKey.initialize());
37 std::vector<bool> acceptedSamplings(m_caloID->Unknown, false);
38 std::vector<CaloSampling::CaloSample> acceptedSamples;
39
40 std::vector<std::string>::const_iterator fName = m_acceptedSampleNames.begin();
41 for (; fName != m_acceptedSampleNames.end(); ++fName) {
43 if (sampInd != CaloSampling::Unknown) {
44 acceptedSamplings[sampInd] = true;
45 acceptedSamples.push_back(sampInd);
46 }
47 }
48
50
51 if (msgLvl(MSG::DEBUG)) {
52
53 msg(MSG::DEBUG) << "Accepted calo samplings: ";
54 std::vector<CaloSampling::CaloSample>::iterator itSampling = acceptedSamples.begin();
55 for (; itSampling < acceptedSamples.end(); ++itSampling) {
56 msg(MSG::DEBUG) << (int) (*itSampling) << "; ";
57 }
58 msg(MSG::DEBUG) << endmsg;
59
60 msg(MSG::DEBUG) << "Accepted sub calos: ";
61 std::vector<CaloCell_ID::SUBCALO>::iterator itCalo = m_acceptedCalos.begin();
62 for (; itCalo < m_acceptedCalos.end(); ++itCalo) {
63 msg(MSG::DEBUG) << (int) (*itCalo) << "; ";
64 }
65 msg(MSG::DEBUG) << endmsg;
66 }
67
68 m_hashMax = m_caloID->calo_cell_hash_max();
69 ATH_MSG_DEBUG( "CaloCell hash max: " << m_hashMax);
70
71 if (m_isFindCellFast) {
72 for (IdentifierHash cellHash = 0; cellHash < m_hashMax; cellHash += 1) {
73 if (acceptedSamplings[m_caloID->calo_sample(cellHash)]) {
74 m_acceptedCellHashes.push_back(cellHash);
75 }
76 }
77 } else {
78 m_cellsToBeCopied.resize(m_hashMax, false);
79 for (IdentifierHash cellHash = 0; cellHash < m_hashMax; cellHash += 1) {
80 if (acceptedSamplings[m_caloID->calo_sample(cellHash)]) {
81 m_cellsToBeCopied[cellHash] = true;
82 }
83 }
84 }
85
86 ATH_MSG_DEBUG( "Number of accepted hashes: " << m_acceptedCellHashes.size() );
87
88
89 return StatusCode::SUCCESS;
90}
91
92
94 const EventContext& ctx) const
95{
96 // Retrieve source cell container
98
99 ATH_CHECK( dispatchCopy (srcCont.cptr(), theCont) );
100
101 std::vector<CaloCell_ID::SUBCALO>::const_iterator it = m_acceptedCalos.begin();
102 for (; it != m_acceptedCalos.end(); ++it) {
103 if (srcCont->hasCalo(*it)) theCont->setHasCalo(*it);
104 }
105
106 return StatusCode::SUCCESS;
107}
108
109
111 const EventContext& ctx) const
112{
113 // Retrieve source cell container
115
116 ATH_CHECK( dispatchCopyConst (srcCont.cptr(), theCont) );
117
118 std::vector<CaloCell_ID::SUBCALO>::const_iterator it = m_acceptedCalos.begin();
119 for (; it != m_acceptedCalos.end(); ++it) {
120 if (srcCont->hasCalo(*it)) theCont->setHasCalo(*it);
121 }
122
123 return StatusCode::SUCCESS;
124}
125
126
128 (const CaloCellContainer* srcCont,
129 CaloConstCellContainer* destCont) const
130{
131 const CaloCell* cell;
132 std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
133 for (; it != m_acceptedCellHashes.end(); ++it) {
134 cell = srcCont->findCell(*it);
135 if (cell) destCont->push_back_fast(cell);
136 }
137
138 destCont->resetLookUpTable();
139 return StatusCode::SUCCESS;
140}
141
142
144 (const CaloCellContainer* srcCont,
145 CaloConstCellContainer* destCont) const
146{
147 std::vector<bool> notInContainer(m_hashMax, true);
148 CaloCellContainer::const_iterator itCell = destCont->begin();
149 for (; itCell != destCont->end(); ++itCell) {
150 notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
151 }
152
153 const CaloCell* cell;
154 std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
155 for (; it != m_acceptedCellHashes.end(); ++it) {
156 if (notInContainer[*it]) {
157 cell = srcCont->findCell(*it);
158 if (cell) destCont->push_back_fast(cell);
159 }
160 }
161
162 destCont->resetLookUpTable();
163 return StatusCode::SUCCESS;
164}
165
166
168 (const CaloCellContainer* srcCont,
169 CaloConstCellContainer* destCont) const
170{
171 IdentifierHash cellHash;
172 const CaloCell* cell;
173 CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
174 for (; itSrcCell != srcCont->end(); ++itSrcCell) {
175 cell = (*itSrcCell);
176 cellHash = cell->caloDDE()->calo_hash();
177 if (m_cellsToBeCopied[cellHash])
178 destCont->push_back_fast(cell);
179 }
180 destCont->resetLookUpTable();
181 return StatusCode::SUCCESS;
182}
183
184
186 (const CaloCellContainer* srcCont,
187 CaloConstCellContainer* destCont) const
188{
189 std::vector<bool> notInContainer(m_hashMax, true);
190 CaloCellContainer::const_iterator itCell = destCont->begin();
191 for (; itCell != destCont->end(); ++itCell) {
192 notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
193 }
194
195 IdentifierHash cellHash;
196 const CaloCell* cell;
197 CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
198 for (; itSrcCell != srcCont->end(); ++itSrcCell) {
199 cell = (*itSrcCell);
200 cellHash = cell->caloDDE()->calo_hash();
201 if (m_cellsToBeCopied[cellHash] && notInContainer[cellHash])
202 destCont->push_back_fast(cell);
203 }
204
205 destCont->resetLookUpTable();
206 return StatusCode::SUCCESS;
207}
208
209
210template <class CONTAINER>
212 (const CaloCellContainer* srcCont,
213 CONTAINER* destCont) const
214{
215 const CaloCell* cell;
216 std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
217 for (; it != m_acceptedCellHashes.end(); ++it) {
218 cell = srcCont->findCell(*it);
219 if (cell) destCont->push_back_fast(cell->clone());
220 }
221
222 destCont->resetLookUpTable();
223 return StatusCode::SUCCESS;
224}
225
226
227template <class CONTAINER>
229 (const CaloCellContainer* srcCont,
230 CONTAINER* destCont) const
231{
232
233 std::vector<bool> notInContainer(m_hashMax, true);
234 CaloCellContainer::const_iterator itCell = destCont->begin();
235 for (; itCell != destCont->end(); ++itCell) {
236 notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
237 }
238
239 const CaloCell* cell;
240 std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
241 for (; it != m_acceptedCellHashes.end(); ++it) {
242 if (notInContainer[*it]) {
243 cell = srcCont->findCell(*it);
244 if (cell) destCont->push_back_fast(cell->clone());
245 }
246 }
247
248 destCont->resetLookUpTable();
249 return StatusCode::SUCCESS;
250}
251
252
253template <class CONTAINER>
255 (const CaloCellContainer* srcCont,
256 CONTAINER* destCont) const
257{
258 IdentifierHash cellHash;
259 const CaloCell* cell;
260 CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
261 for (; itSrcCell != srcCont->end(); ++itSrcCell) {
262 cell = (*itSrcCell);
263 cellHash = cell->caloDDE()->calo_hash();
264 if (m_cellsToBeCopied[cellHash])
265 destCont->push_back_fast(cell->clone());
266 }
267
268 destCont->resetLookUpTable();
269 return StatusCode::SUCCESS;
270}
271
272
273template <class CONTAINER>
275 (const CaloCellContainer* srcCont,
276 CONTAINER* destCont) const
277{
278 std::vector<bool> notInContainer(m_hashMax, true);
279 CaloCellContainer::const_iterator itCell = destCont->begin();
280 for (; itCell != destCont->end(); ++itCell) {
281 notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
282 }
283
284 IdentifierHash cellHash;
285 const CaloCell* cell;
286 CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
287 for (; itSrcCell != srcCont->end(); ++itSrcCell) {
288 cell = (*itSrcCell);
289 cellHash = cell->caloDDE()->calo_hash();
290 if (m_cellsToBeCopied[cellHash] && notInContainer[cellHash])
291 destCont->push_back_fast(cell->clone());
292 }
293
294 destCont->resetLookUpTable();
295 return StatusCode::SUCCESS;
296}
297
298
299
301 CaloCellContainer* destCont) const
302{
303 using COPY_CELLS = StatusCode (CaloCellFastCopyTool::*)(const CaloCellContainer *, CaloCellContainer *) const;
304
305 COPY_CELLS copyCells;
306 if (m_isFindCellFast) {
307 if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
308 copyCells = (m_avoidDuplicates) ?
311 }
312 else {
313 REPORT_ERROR(StatusCode::FAILURE) << "Can't copy to a non-const view container.";
314 return StatusCode::FAILURE;
315 }
316 }
317 else {
318 if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
319 copyCells = (m_avoidDuplicates) ?
322 }
323 else {
324 REPORT_ERROR(StatusCode::FAILURE) << "Can't copy to a non-const view container.";
325 return StatusCode::FAILURE;
326 }
327 }
328
329 return (this->*copyCells)(srcCont, destCont);
330}
331
332
333StatusCode
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
CaloCellContainer that can accept const cell pointers.
Helpers for checking error return status codes and reporting errors.
#define REPORT_ERROR(SC)
Report an error.
Container class for CaloCell.
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
void setHasCalo(const CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
Concrete tool for coping Calo cells.
Gaudi::Property< bool > m_avoidDuplicates
Gaudi::Property< std::vector< std::string > > m_acceptedSampleNames
StatusCode viewNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode cloneAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode dispatchCopy(const CaloCellContainer *srcCont, CaloCellContainer *destCont) const
std::vector< bool > m_cellsToBeCopied
const CaloCell_ID * m_caloID
Pointer to CaloID helper.
std::vector< CaloCell_ID::SUBCALO > m_acceptedCalos
StatusCode dispatchCopyConst(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
virtual StatusCode initialize() override
StatusCode cloneNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
std::vector< IdentifierHash > m_acceptedCellHashes
SG::ReadHandleKey< CaloCellContainer > m_srcCellContainerKey
StatusCode viewAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode cloneAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode cloneNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Gaudi::Property< bool > m_isFindCellFast
StatusCode viewAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
CaloCellContainer that can accept const cell pointers.
void setHasCalo(CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
void push_back_fast(const CaloCell *cell)
reimplementation of push_back to gain speed in readin
void resetLookUpTable()
reset look up table
static CaloSampling::CaloSample getSamplingId(const std::string &samplingName)
Returns the CaloSampling::CaloSample enumerator value.
static bool getCalos(const std::vector< CaloSampling::CaloSample > &theSamplings, std::vector< CaloCell_ID::SUBCALO > &theCalos)
Returns a list of sub-calos for a list of samplings.
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
This is a "hash" representation of an Identifier.
const_pointer_type cptr()
Dereference the pointer.
@ OWN_ELEMENTS
this data object owns its elements
MsgStream & msg
Definition testRead.cxx:32