ATLAS Offline Software
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
18 #include "CaloCellFastCopyTool.h"
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 
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: ";
62  for (; itCalo < m_acceptedCalos.end(); ++itCalo) {
63  msg(MSG::DEBUG) << (int) (*itCalo) << "; ";
64  }
65  msg(MSG::DEBUG) << endmsg;
66  }
67 
69  ATH_MSG_DEBUG( "CaloCell hash max: " << m_hashMax);
70 
71  if (m_isFindCellFast) {
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);
80  if (acceptedSamplings[m_caloID->calo_sample(cellHash)]) {
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 {
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();
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 
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 
210 template <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 
227 template <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 
253 template <class CONTAINER>
255  (const CaloCellContainer* srcCont,
256  CONTAINER* destCont) const
257 {
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();
265  destCont->push_back_fast(cell->clone());
266  }
267 
268  destCont->resetLookUpTable();
269  return StatusCode::SUCCESS;
270 }
271 
272 
273 template <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 
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) ?
309  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast<CaloCellContainer>) :
310  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast<CaloCellContainer>);
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) ?
320  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast<CaloCellContainer>) :
321  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast<CaloCellContainer>);
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 
335  CaloConstCellContainer* destCont) const
336 {
337  using COPY_CONST_CELLS = StatusCode (CaloCellFastCopyTool::*)(const CaloCellContainer *, CaloConstCellContainer *) const;
338 
339  COPY_CONST_CELLS copyConstCells;
340  if (m_isFindCellFast) {
341  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
342  copyConstCells = (m_avoidDuplicates) ?
343  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast<CaloConstCellContainer>) :
344  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast<CaloConstCellContainer>);
345  } else {
346  copyConstCells = (m_avoidDuplicates) ?
349  }
350  } else {
351  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
352  copyConstCells = (m_avoidDuplicates) ?
353  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast<CaloConstCellContainer>) :
354  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast<CaloConstCellContainer>);
355  } else {
356  copyConstCells = (m_avoidDuplicates) ?
359  }
360  }
361 
362  return (this->*copyConstCells)(srcCont, destCont);
363 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloCellFastCopyTool::m_acceptedCalos
std::vector< CaloCell_ID::SUBCALO > m_acceptedCalos
Definition: CaloCellFastCopyTool.h:102
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast
StatusCode cloneAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:229
CaloCellFastCopyTool.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
REPORT_ERROR
#define REPORT_ERROR(SC)
Report an error.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:355
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
CaloCellFastCopyTool::m_isFindCellFast
Gaudi::Property< bool > m_isFindCellFast
Definition: CaloCellFastCopyTool.h:97
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellFastCopyTool::m_acceptedCellHashes
std::vector< IdentifierHash > m_acceptedCellHashes
Definition: CaloCellFastCopyTool.h:105
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
CaloCellFastCopyTool::dispatchCopyConst
StatusCode dispatchCopyConst(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:334
CaloCellFastCopyTool::m_srcCellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_srcCellContainerKey
Definition: CaloCellFastCopyTool.h:95
rootconvert.fName
string fName
Definition: rootconvert.py:5
ConstDataVector::end
iterator end() noexcept
Return an iterator pointing past the end of the collection.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CaloCellContainer::setHasCalo
void setHasCalo(const CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
Definition: CaloCellContainer.cxx:213
CaloConstCellContainer::resetLookUpTable
void resetLookUpTable()
reset look up table
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CaloCellFastCopyTool::dispatchCopy
StatusCode dispatchCopy(const CaloCellContainer *srcCont, CaloCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:300
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
CaloCellFastCopyTool::m_hashMax
IdentifierHash m_hashMax
Definition: CaloCellFastCopyTool.h:98
CaloCellFastCopyTool::m_cellsToBeCopied
std::vector< bool > m_cellsToBeCopied
Definition: CaloCellFastCopyTool.h:106
CaloCellFastCopyTool::m_acceptedSampleNames
Gaudi::Property< std::vector< std::string > > m_acceptedSampleNames
Definition: CaloCellFastCopyTool.h:101
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max() const
cell 'global' hash table max size
CaloCellFastCopyTool::m_caloID
const CaloCell_ID * m_caloID
Pointer to CaloID helper.
Definition: CaloCellFastCopyTool.h:99
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloCellFastCopyTool::viewAvoidingDuplicatesFindCellIsNotFast
StatusCode viewAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:186
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloConstCellContainer::push_back_fast
void push_back_fast(const CaloCell *cell)
reimplementation of push_back to gain speed in readin
CaloCellFastCopyTool::viewAvoidingDuplicatesFindCellIsFast
StatusCode viewAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:144
CaloSamplingHelper::getCalos
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.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:127
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloSamplingHelper.h
CaloCellFastCopyTool::initialize
virtual StatusCode initialize() override
Definition: CaloCellFastCopyTool.cxx:31
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast
StatusCode cloneNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:255
CaloCellFastCopyTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: CaloCellFastCopyTool.cxx:93
CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast
StatusCode cloneAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:275
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
CaloCellContainer::findCell
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
Definition: CaloCellContainer.cxx:345
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
CaloCellFastCopyTool::viewNotAvoidingDuplicatesFindCellIsNotFast
StatusCode viewNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:168
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCellFastCopyTool::viewNotAvoidingDuplicatesFindCellIsFast
StatusCode viewNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:128
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloConstCellContainer
CaloCellContainer that can accept const cell pointers.
Definition: CaloConstCellContainer.h:45
CaloConstCellContainer::setHasCalo
void setHasCalo(CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
CaloSamplingHelper::getSamplingId
static CaloSampling::CaloSample getSamplingId(const std::string &samplingName)
Returns the CaloSampling::CaloSample enumerator value.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:63
DEBUG
#define DEBUG
Definition: page_access.h:11
CaloCellFastCopyTool
Concrete tool for coping Calo cells.
Definition: CaloCellFastCopyTool.h:54
DataVector::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
CaloCellContainer::hasCalo
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
Definition: CaloCellContainer.cxx:209
CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast
StatusCode cloneNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:212
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloConstCellContainer.h
CaloCellContainer that can accept const cell pointers.
CaloCellFastCopyTool::m_avoidDuplicates
Gaudi::Property< bool > m_avoidDuplicates
Definition: CaloCellFastCopyTool.h:96
ConstDataVector::begin
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.