ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellFastCopyTool Class Reference

Concrete tool for coping Calo cells. More...

#include <CaloCellFastCopyTool.h>

Inheritance diagram for CaloCellFastCopyTool:
Collaboration diagram for CaloCellFastCopyTool:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode process (CaloCellContainer *theCellContainer, const EventContext &ctx) const override
virtual StatusCode process (CaloConstCellContainer *theCellContainer, const EventContext &ctx) const override

Private Member Functions

StatusCode viewNotAvoidingDuplicatesFindCellIsFast (const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewAvoidingDuplicatesFindCellIsFast (const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewNotAvoidingDuplicatesFindCellIsNotFast (const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewAvoidingDuplicatesFindCellIsNotFast (const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
template<class CONTAINER>
StatusCode cloneNotAvoidingDuplicatesFindCellIsFast (const CaloCellContainer *srcCont, CONTAINER *destCont) const
template<class CONTAINER>
StatusCode cloneAvoidingDuplicatesFindCellIsFast (const CaloCellContainer *srcCont, CONTAINER *destCont) const
template<class CONTAINER>
StatusCode cloneNotAvoidingDuplicatesFindCellIsNotFast (const CaloCellContainer *srcCont, CONTAINER *destCont) const
template<class CONTAINER>
StatusCode cloneAvoidingDuplicatesFindCellIsNotFast (const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode dispatchCopy (const CaloCellContainer *srcCont, CaloCellContainer *destCont) const
StatusCode dispatchCopyConst (const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const

Private Attributes

SG::ReadHandleKey< CaloCellContainerm_srcCellContainerKey {this, "InputName", "AllCalo"}
Gaudi::Property< bool > m_avoidDuplicates {this, "AvoidDuplicates", false}
Gaudi::Property< bool > m_isFindCellFast {this, "IsFindCellFast", false}
IdentifierHash m_hashMax
const CaloCell_IDm_caloID = nullptr
 Pointer to CaloID helper.
Gaudi::Property< std::vector< std::string > > m_acceptedSampleNames {this, "includeSamplings", {}}
std::vector< CaloCell_ID::SUBCALOm_acceptedCalos
std::vector< IdentifierHashm_acceptedCellHashes
std::vector< bool > m_cellsToBeCopied

Detailed Description

Concrete tool for coping Calo cells.

CaloCellFastCopyTool to be used by CaloCellMaker algorithms. The tool copies Calo cells from an existing CaloCellContainer to the one processed by the CaloCellMaker algorithm. Properties of the tool: InputName - source cell container (default: "AllCalo") IncludeSamplings - name of CaloSampling to be copied into new CaloCellContainer AvoidDuplicates - indicates if this tool should avoid duplicates in new CaloCellContainer. IsFindCellFast - indicates if source CaloCellContainer find CaloCell fast (i.e. source CaloCellContainer is complete and ordered or has already initialized internal lookUpTable). In this case this tool can be very fast.

Definition at line 52 of file CaloCellFastCopyTool.h.

Member Function Documentation

◆ cloneAvoidingDuplicatesFindCellIsFast()

template<class CONTAINER>
StatusCode CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsFast ( const CaloCellContainer * srcCont,
CONTAINER * destCont ) const
private

Definition at line 228 of file CaloCellFastCopyTool.cxx.

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}
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
std::vector< IdentifierHash > m_acceptedCellHashes
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838

◆ cloneAvoidingDuplicatesFindCellIsNotFast()

template<class CONTAINER>
StatusCode CaloCellFastCopyTool::cloneAvoidingDuplicatesFindCellIsNotFast ( const CaloCellContainer * srcCont,
CONTAINER * destCont ) const
private

Definition at line 274 of file CaloCellFastCopyTool.cxx.

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}
std::vector< bool > m_cellsToBeCopied
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.

◆ cloneNotAvoidingDuplicatesFindCellIsFast()

template<class CONTAINER>
StatusCode CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsFast ( const CaloCellContainer * srcCont,
CONTAINER * destCont ) const
private

Definition at line 211 of file CaloCellFastCopyTool.cxx.

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}

◆ cloneNotAvoidingDuplicatesFindCellIsNotFast()

template<class CONTAINER>
StatusCode CaloCellFastCopyTool::cloneNotAvoidingDuplicatesFindCellIsNotFast ( const CaloCellContainer * srcCont,
CONTAINER * destCont ) const
private

Definition at line 254 of file CaloCellFastCopyTool.cxx.

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}

◆ dispatchCopy()

StatusCode CaloCellFastCopyTool::dispatchCopy ( const CaloCellContainer * srcCont,
CaloCellContainer * destCont ) const
private

Definition at line 300 of file CaloCellFastCopyTool.cxx.

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}
#define REPORT_ERROR(SC)
Report an error.
Gaudi::Property< bool > m_avoidDuplicates
StatusCode cloneAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode cloneNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode cloneAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
StatusCode cloneNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CONTAINER *destCont) const
Gaudi::Property< bool > m_isFindCellFast
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
::StatusCode StatusCode
StatusCode definition for legacy code.
@ OWN_ELEMENTS
this data object owns its elements

◆ dispatchCopyConst()

StatusCode CaloCellFastCopyTool::dispatchCopyConst ( const CaloCellContainer * srcCont,
CaloConstCellContainer * destCont ) const
private

Definition at line 334 of file CaloCellFastCopyTool.cxx.

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) ?
345 } else {
346 copyConstCells = (m_avoidDuplicates) ?
349 }
350 } else {
351 if (destCont->ownPolicy() == SG::OWN_ELEMENTS) {
352 copyConstCells = (m_avoidDuplicates) ?
355 } else {
356 copyConstCells = (m_avoidDuplicates) ?
359 }
360 }
361
362 return (this->*copyConstCells)(srcCont, destCont);
363}
StatusCode viewNotAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewAvoidingDuplicatesFindCellIsNotFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewNotAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const
StatusCode viewAvoidingDuplicatesFindCellIsFast(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const

◆ initialize()

StatusCode CaloCellFastCopyTool::initialize ( )
overridevirtual

Definition at line 31 of file CaloCellFastCopyTool.cxx.

31 {
32
33 ATH_MSG_INFO( "In initialize ");
34
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)]) {
82 }
83 }
84 }
85
86 ATH_MSG_DEBUG( "Number of accepted hashes: " << m_acceptedCellHashes.size() );
87
88
89 return StatusCode::SUCCESS;
90}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Property< std::vector< std::string > > m_acceptedSampleNames
const CaloCell_ID * m_caloID
Pointer to CaloID helper.
std::vector< CaloCell_ID::SUBCALO > m_acceptedCalos
SG::ReadHandleKey< CaloCellContainer > m_srcCellContainerKey
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.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110
MsgStream & msg
Definition testRead.cxx:32

◆ process() [1/2]

StatusCode CaloCellFastCopyTool::process ( CaloCellContainer * theCellContainer,
const EventContext & ctx ) const
overridevirtual

Definition at line 93 of file CaloCellFastCopyTool.cxx.

95{
96 // Retrieve source cell container
97 SG::ReadHandle<CaloCellContainer> srcCont(m_srcCellContainerKey, ctx);
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}
StatusCode dispatchCopy(const CaloCellContainer *srcCont, CaloCellContainer *destCont) const

◆ process() [2/2]

StatusCode CaloCellFastCopyTool::process ( CaloConstCellContainer * theCellContainer,
const EventContext & ctx ) const
overridevirtual

Definition at line 110 of file CaloCellFastCopyTool.cxx.

112{
113 // Retrieve source cell container
114 SG::ReadHandle<CaloCellContainer> srcCont(m_srcCellContainerKey, ctx);
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}
StatusCode dispatchCopyConst(const CaloCellContainer *srcCont, CaloConstCellContainer *destCont) const

◆ viewAvoidingDuplicatesFindCellIsFast()

StatusCode CaloCellFastCopyTool::viewAvoidingDuplicatesFindCellIsFast ( const CaloCellContainer * srcCont,
CaloConstCellContainer * destCont ) const
private

Definition at line 143 of file CaloCellFastCopyTool.cxx.

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}
void push_back_fast(const CaloCell *cell)
reimplementation of push_back to gain speed in readin
void resetLookUpTable()
reset look up table
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.

◆ viewAvoidingDuplicatesFindCellIsNotFast()

StatusCode CaloCellFastCopyTool::viewAvoidingDuplicatesFindCellIsNotFast ( const CaloCellContainer * srcCont,
CaloConstCellContainer * destCont ) const
private

Definition at line 185 of file CaloCellFastCopyTool.cxx.

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}

◆ viewNotAvoidingDuplicatesFindCellIsFast()

StatusCode CaloCellFastCopyTool::viewNotAvoidingDuplicatesFindCellIsFast ( const CaloCellContainer * srcCont,
CaloConstCellContainer * destCont ) const
private

Definition at line 127 of file CaloCellFastCopyTool.cxx.

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}

◆ viewNotAvoidingDuplicatesFindCellIsNotFast()

StatusCode CaloCellFastCopyTool::viewNotAvoidingDuplicatesFindCellIsNotFast ( const CaloCellContainer * srcCont,
CaloConstCellContainer * destCont ) const
private

Definition at line 167 of file CaloCellFastCopyTool.cxx.

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}

Member Data Documentation

◆ m_acceptedCalos

std::vector<CaloCell_ID::SUBCALO> CaloCellFastCopyTool::m_acceptedCalos
private

Definition at line 102 of file CaloCellFastCopyTool.h.

◆ m_acceptedCellHashes

std::vector<IdentifierHash> CaloCellFastCopyTool::m_acceptedCellHashes
private

Definition at line 105 of file CaloCellFastCopyTool.h.

◆ m_acceptedSampleNames

Gaudi::Property<std::vector<std::string> > CaloCellFastCopyTool::m_acceptedSampleNames {this, "includeSamplings", {}}
private

Definition at line 101 of file CaloCellFastCopyTool.h.

101{this, "includeSamplings", {}};

◆ m_avoidDuplicates

Gaudi::Property<bool> CaloCellFastCopyTool::m_avoidDuplicates {this, "AvoidDuplicates", false}
private

Definition at line 96 of file CaloCellFastCopyTool.h.

96{this, "AvoidDuplicates", false};

◆ m_caloID

const CaloCell_ID* CaloCellFastCopyTool::m_caloID = nullptr
private

Pointer to CaloID helper.

Definition at line 99 of file CaloCellFastCopyTool.h.

◆ m_cellsToBeCopied

std::vector<bool> CaloCellFastCopyTool::m_cellsToBeCopied
private

Definition at line 106 of file CaloCellFastCopyTool.h.

◆ m_hashMax

IdentifierHash CaloCellFastCopyTool::m_hashMax
private

Definition at line 98 of file CaloCellFastCopyTool.h.

◆ m_isFindCellFast

Gaudi::Property<bool> CaloCellFastCopyTool::m_isFindCellFast {this, "IsFindCellFast", false}
private

Definition at line 97 of file CaloCellFastCopyTool.h.

97{this, "IsFindCellFast", false};

◆ m_srcCellContainerKey

SG::ReadHandleKey<CaloCellContainer> CaloCellFastCopyTool::m_srcCellContainerKey {this, "InputName", "AllCalo"}
private

Definition at line 95 of file CaloCellFastCopyTool.h.

95{this, "InputName", "AllCalo"};

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