ATLAS Offline Software
CaloCellFastCopyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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 // CONSTRUCTOR:
29 
31  const std::string& name, const IInterface* parent)
32  : base_class(type, name, parent)
33  , m_srcCellContainerKey("AllCalo")
34  , m_avoidDuplicates(false)
35  , m_isFindCellFast(false)
36  , m_caloID(nullptr)
37 {
39  declareProperty("IncludeSamplings", m_acceptedSampleNames);
40  declareProperty("AvoidDuplicates", m_avoidDuplicates);
41  declareProperty("IsFindCellFast", m_isFindCellFast);
42 }
43 
45 // INITIALIZE:
46 // The initialize method will create all the required algorithm objects
48 
50 
51  ATH_MSG_INFO( "In initialize ");
52 
55  std::vector<bool> acceptedSamplings(m_caloID->Unknown, false);
56  std::vector<CaloSampling::CaloSample> acceptedSamples;
57 
58  std::vector<std::string>::const_iterator fName = m_acceptedSampleNames.begin();
59  for (; fName != m_acceptedSampleNames.end(); ++fName) {
61  if (sampInd != CaloSampling::Unknown) {
62  acceptedSamplings[sampInd] = true;
63  acceptedSamples.push_back(sampInd);
64  }
65  }
66 
68 
69  if (msgLvl(MSG::DEBUG)) {
70 
71  msg(MSG::DEBUG) << "Accepted calo samplings: ";
72  std::vector<CaloSampling::CaloSample>::iterator itSampling = acceptedSamples.begin();
73  for (; itSampling < acceptedSamples.end(); ++itSampling) {
74  msg(MSG::DEBUG) << (int) (*itSampling) << "; ";
75  }
76  msg(MSG::DEBUG) << endmsg;
77 
78  msg(MSG::DEBUG) << "Accepted sub calos: ";
80  for (; itCalo < m_acceptedCalos.end(); ++itCalo) {
81  msg(MSG::DEBUG) << (int) (*itCalo) << "; ";
82  }
83  msg(MSG::DEBUG) << endmsg;
84  }
85 
87  ATH_MSG_DEBUG( "CaloCell hash max: " << m_hashMax);
88 
89  if (m_isFindCellFast) {
91  if (acceptedSamplings[m_caloID->calo_sample(cellHash)]) {
92  m_acceptedCellHashes.push_back(cellHash);
93  }
94  }
95  } else {
96  m_cellsToBeCopied.resize(m_hashMax, false);
98  if (acceptedSamplings[m_caloID->calo_sample(cellHash)]) {
100  }
101  }
102  }
103 
104  ATH_MSG_DEBUG( "Number of accepted hashes: " << m_acceptedCellHashes.size() );
105 
106 
107  return StatusCode::SUCCESS;
108 }
109 
110 
112  const EventContext& ctx) const
113 {
114  // Retrieve source cell container
116 
117  ATH_CHECK( dispatchCopy (srcCont.cptr(), theCont) );
118 
119  std::vector<CaloCell_ID::SUBCALO>::const_iterator it = m_acceptedCalos.begin();
120  for (; it != m_acceptedCalos.end(); ++it) {
121  if (srcCont->hasCalo(*it)) theCont->setHasCalo(*it);
122  }
123 
124  return StatusCode::SUCCESS;
125 }
126 
127 
129  const EventContext& ctx) const
130 {
131  // Retrieve source cell container
133 
134  ATH_CHECK( dispatchCopyConst (srcCont.cptr(), theCont) );
135 
136  std::vector<CaloCell_ID::SUBCALO>::const_iterator it = m_acceptedCalos.begin();
137  for (; it != m_acceptedCalos.end(); ++it) {
138  if (srcCont->hasCalo(*it)) theCont->setHasCalo(*it);
139  }
140 
141  return StatusCode::SUCCESS;
142 }
143 
144 
146  (const CaloCellContainer* srcCont,
147  CaloConstCellContainer* destCont) const
148 {
149  const CaloCell* cell;
150  std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
151  for (; it != m_acceptedCellHashes.end(); ++it) {
152  cell = srcCont->findCell(*it);
153  if (cell) destCont->push_back_fast(cell);
154  }
155 
156  destCont->resetLookUpTable();
157  return StatusCode::SUCCESS;
158 }
159 
160 
162  (const CaloCellContainer* srcCont,
163  CaloConstCellContainer* destCont) const
164 {
165  std::vector<bool> notInContainer(m_hashMax, true);
166  CaloCellContainer::const_iterator itCell = destCont->begin();
167  for (; itCell != destCont->end(); ++itCell) {
168  notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
169  }
170 
171  const CaloCell* cell;
172  std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
173  for (; it != m_acceptedCellHashes.end(); ++it) {
174  if (notInContainer[*it]) {
175  cell = srcCont->findCell(*it);
176  if (cell) destCont->push_back_fast(cell);
177  }
178  }
179 
180  destCont->resetLookUpTable();
181  return StatusCode::SUCCESS;
182 }
183 
184 
186  (const CaloCellContainer* srcCont,
187  CaloConstCellContainer* destCont) const
188 {
190  const CaloCell* cell;
191  CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
192  for (; itSrcCell != srcCont->end(); ++itSrcCell) {
193  cell = (*itSrcCell);
194  cellHash = cell->caloDDE()->calo_hash();
196  destCont->push_back_fast(cell);
197  }
198  destCont->resetLookUpTable();
199  return StatusCode::SUCCESS;
200 }
201 
202 
204  (const CaloCellContainer* srcCont,
205  CaloConstCellContainer* destCont) const
206 {
207  std::vector<bool> notInContainer(m_hashMax, true);
208  CaloCellContainer::const_iterator itCell = destCont->begin();
209  for (; itCell != destCont->end(); ++itCell) {
210  notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
211  }
212 
214  const CaloCell* cell;
215  CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
216  for (; itSrcCell != srcCont->end(); ++itSrcCell) {
217  cell = (*itSrcCell);
218  cellHash = cell->caloDDE()->calo_hash();
219  if (m_cellsToBeCopied[cellHash] && notInContainer[cellHash])
220  destCont->push_back_fast(cell);
221  }
222 
223  destCont->resetLookUpTable();
224  return StatusCode::SUCCESS;
225 }
226 
227 
228 template <class CONTAINER>
230  (const CaloCellContainer* srcCont,
231  CONTAINER* destCont) const
232 {
233  const CaloCell* cell;
234  std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
235  for (; it != m_acceptedCellHashes.end(); ++it) {
236  cell = srcCont->findCell(*it);
237  if (cell) destCont->push_back_fast(cell->clone());
238  }
239 
240  destCont->resetLookUpTable();
241  return StatusCode::SUCCESS;
242 }
243 
244 
245 template <class CONTAINER>
247  (const CaloCellContainer* srcCont,
248  CONTAINER* destCont) const
249 {
250 
251  std::vector<bool> notInContainer(m_hashMax, true);
252  CaloCellContainer::const_iterator itCell = destCont->begin();
253  for (; itCell != destCont->end(); ++itCell) {
254  notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
255  }
256 
257  const CaloCell* cell;
258  std::vector<IdentifierHash>::const_iterator it = m_acceptedCellHashes.begin();
259  for (; it != m_acceptedCellHashes.end(); ++it) {
260  if (notInContainer[*it]) {
261  cell = srcCont->findCell(*it);
262  if (cell) destCont->push_back_fast(cell->clone());
263  }
264  }
265 
266  destCont->resetLookUpTable();
267  return StatusCode::SUCCESS;
268 }
269 
270 
271 template <class CONTAINER>
273  (const CaloCellContainer* srcCont,
274  CONTAINER* destCont) const
275 {
277  const CaloCell* cell;
278  CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
279  for (; itSrcCell != srcCont->end(); ++itSrcCell) {
280  cell = (*itSrcCell);
281  cellHash = cell->caloDDE()->calo_hash();
283  destCont->push_back_fast(cell->clone());
284  }
285 
286  destCont->resetLookUpTable();
287  return StatusCode::SUCCESS;
288 }
289 
290 
291 template <class CONTAINER>
293  (const CaloCellContainer* srcCont,
294  CONTAINER* destCont) const
295 {
296  std::vector<bool> notInContainer(m_hashMax, true);
297  CaloCellContainer::const_iterator itCell = destCont->begin();
298  for (; itCell != destCont->end(); ++itCell) {
299  notInContainer[(*itCell)->caloDDE()->calo_hash()] = false;
300  }
301 
303  const CaloCell* cell;
304  CaloCellContainer::const_iterator itSrcCell = srcCont->begin();
305  for (; itSrcCell != srcCont->end(); ++itSrcCell) {
306  cell = (*itSrcCell);
307  cellHash = cell->caloDDE()->calo_hash();
308  if (m_cellsToBeCopied[cellHash] && notInContainer[cellHash])
309  destCont->push_back_fast(cell->clone());
310  }
311 
312  destCont->resetLookUpTable();
313  return StatusCode::SUCCESS;
314 }
315 
316 
317 
319  CaloCellContainer* destCont) const
320 {
321  using COPY_CELLS = StatusCode (CaloCellFastCopyTool::*)(const CaloCellContainer *, CaloCellContainer *) const;
322 
323  COPY_CELLS copyCells;
324  if (m_isFindCellFast) {
325  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
326  copyCells = (m_avoidDuplicates) ?
327  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast<CaloCellContainer>) :
328  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast<CaloCellContainer>);
329  }
330  else {
331  REPORT_ERROR(StatusCode::FAILURE) << "Can't copy to a non-const view container.";
332  return StatusCode::FAILURE;
333  }
334  }
335  else {
336  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
337  copyCells = (m_avoidDuplicates) ?
338  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast<CaloCellContainer>) :
339  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast<CaloCellContainer>);
340  }
341  else {
342  REPORT_ERROR(StatusCode::FAILURE) << "Can't copy to a non-const view container.";
343  return StatusCode::FAILURE;
344  }
345  }
346 
347  return (this->*copyCells)(srcCont, destCont);
348 }
349 
350 
353  CaloConstCellContainer* destCont) const
354 {
355  using COPY_CONST_CELLS = StatusCode (CaloCellFastCopyTool::*)(const CaloCellContainer *, CaloConstCellContainer *) const;
356 
357  COPY_CONST_CELLS copyConstCells;
358  if (m_isFindCellFast) {
359  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
360  copyConstCells = (m_avoidDuplicates) ?
361  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast<CaloConstCellContainer>) :
362  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast<CaloConstCellContainer>);
363  } else {
364  copyConstCells = (m_avoidDuplicates) ?
367  }
368  } else {
369  if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
370  copyConstCells = (m_avoidDuplicates) ?
371  (&CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast<CaloConstCellContainer>) :
372  (&CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast<CaloConstCellContainer>);
373  } else {
374  copyConstCells = (m_avoidDuplicates) ?
377  }
378  }
379 
380  return (this->*copyConstCells)(srcCont, destCont);
381 }
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:106
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast
StatusCode cloneAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:247
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
CaloCellFastCopyTool::m_isFindCellFast
bool m_isFindCellFast
Definition: CaloCellFastCopyTool.h:101
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellFastCopyTool::m_acceptedCellHashes
std::vector< IdentifierHash > m_acceptedCellHashes
Definition: CaloCellFastCopyTool.h:109
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
CaloCellFastCopyTool::dispatchCopyConst
StatusCode dispatchCopyConst(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:352
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloCellFastCopyTool::m_srcCellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_srcCellContainerKey
Definition: CaloCellFastCopyTool.h:99
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:70
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:423
CaloCellFastCopyTool::dispatchCopy
StatusCode dispatchCopy(const CaloCellContainer *srcCont, CaloCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:318
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:102
CaloCellFastCopyTool::m_cellsToBeCopied
std::vector< bool > m_cellsToBeCopied
Definition: CaloCellFastCopyTool.h:110
CaloCellFastCopyTool::m_caloID
const CaloCell_ID * m_caloID
Pointer to CaloID helper.
Definition: CaloCellFastCopyTool.h:103
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:204
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:162
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:129
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloSamplingHelper.h
CaloCellFastCopyTool::initialize
virtual StatusCode initialize() override
Definition: CaloCellFastCopyTool.cxx:49
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:273
CaloCellFastCopyTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: CaloCellFastCopyTool.cxx:111
CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast
StatusCode cloneAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Definition: CaloCellFastCopyTool.cxx:293
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:186
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloCellFastCopyTool::m_acceptedSampleNames
std::vector< std::string > m_acceptedSampleNames
Definition: CaloCellFastCopyTool.h:105
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCellFastCopyTool::viewNotAvoidingDuplicatesFindCellIsFast
StatusCode viewNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
Definition: CaloCellFastCopyTool.cxx:146
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
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.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloSamplingHelper::getSamplingId
static CaloSampling::CaloSample getSamplingId(const std::string &samplingName)
Returns the CaloSampling::CaloSample enumerator value.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:61
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.
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
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:230
IdentifierHash
Definition: IdentifierHash.h:38
CaloConstCellContainer.h
CaloCellContainer that can accept const cell pointers.
ConstDataVector::begin
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
CaloCellFastCopyTool::CaloCellFastCopyTool
CaloCellFastCopyTool(const std::string &type, const std::string &name, const IInterface *parent)
AthAlgTool constructor.
Definition: CaloCellFastCopyTool.cxx:30
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
CaloCellFastCopyTool::m_avoidDuplicates
bool m_avoidDuplicates
Definition: CaloCellFastCopyTool.h:100
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size