ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterSnapshot.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
9#include "CaloClusterMaker.h"
10
11// -------------------------------------------------------------
12// Constructor
13// -------------------------------------------------------------
15 const std::string& name,
16 const IInterface* parent):
17 AthAlgTool(type, name, parent),
18 m_outputKey("")
19{
20 declareInterface<CaloClusterCollectionProcessor> (this);
21 declareProperty("OutputName",m_outputKey);
23 declareProperty("SetCrossLinks",m_setCrossLinks=false);
24 declareProperty("FinalClusterContainerName", m_finalContName);
25
26}
27
28// -------------------------------------------------------------
29// Destructor
30// -------------------------------------------------------------
32= default;
33
35 ATH_CHECK(m_outputKey.initialize());
36 if (m_cellLinkOutputKey.key().empty()) {
37 m_cellLinkOutputKey = m_outputKey.key() + "_links";
38 }
39 ATH_CHECK(m_cellLinkOutputKey.initialize());
40 return StatusCode::SUCCESS;
41
42}
43
44
45StatusCode
46CaloClusterSnapshot::execute(const EventContext& ctx,
47 xAOD::CaloClusterContainer* clusColl) const
48{
49 ATH_MSG_DEBUG("Executing CaloClusterSnapshot");
50
52
54
55 CaloClusterStoreHelper::copyContainer(clusColl,outputColl.ptr());
56
57 if (m_setCrossLinks) {
58 const size_t nClusters=clusColl->size();
59 if (nClusters!=outputColl->size()) {
60 ATH_MSG_ERROR("After copy of container: Unequal number of entries! Original " << nClusters << ", copy " << outputColl->size());
61 return StatusCode::FAILURE;
62 }
63
64 //final cluster to snapshot:
66 ClusterLink_t outputEL (outputColl.name(), 0, ctx);
67 for (size_t i=0;i<nClusters;++i) {
68 (*clusColl)[i]->setSisterClusterLink(ClusterLink_t(outputEL, i));
69 }
70
71 //From snapshot to final cluster
72 if (m_setCrossLinks) {
73 ClusterLink_t finalEL (m_finalContName, 0, ctx);
74 if (finalEL.isValid()) {
75 for (size_t i=0;i<nClusters;++i) {
76 (*outputColl)[i]->setSisterClusterLink(ClusterLink_t(finalEL, i));
77 // std::cout << "Setting link to " << m_finalContName << ", index "<< i <<std::endl;
78 }
79 }
80 else {
81 ATH_MSG_DEBUG("Can't set element link from snapshot to final cluster, likely mismatch in the FinalClusterContainerName");
82 }
83 }
84 }
85
86
89 outputColl.ptr()));
90
91 return StatusCode::SUCCESS;
92}
93
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *) const override
Execute on an entire collection of clusters.
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_cellLinkOutputKey
virtual ~CaloClusterSnapshot() override
virtual StatusCode initialize() override
CaloClusterSnapshot(const std::string &type, const std::string &name, const IInterface *parent)
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputKey
static void copyContainer(const xAOD::CaloClusterContainer *oldColl, xAOD::CaloClusterContainer *newColl)
Deep copy of a cluster container.
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
size_type size() const noexcept
Returns the number of elements in the collection.
const std::string & name() const
Return the StoreGate ID for the referenced object.
pointer_type ptr()
Dereference the pointer.
ElementLink< xAOD::CaloClusterContainer > ClusterLink_t
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.