ATLAS Offline Software
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 
7 #include "CaloClusterSnapshot.h"
9 #include "CaloClusterMaker.h"
10 
11 // -------------------------------------------------------------
12 // Constructor
13 // -------------------------------------------------------------
15  const std::string& name,
16  const IInterface* parent):
18  m_outputKey("")
19 {
20  declareInterface<CaloClusterCollectionProcessor> (this);
21  declareProperty("OutputName",m_outputKey);
22  declareProperty("CellLinkName",m_cellLinkOutputKey);
23  declareProperty("SetCrossLinks",m_setCrossLinks=false);
24  declareProperty("FinalClusterContainerName", m_finalContName);
25 
26 }
27 
28 // -------------------------------------------------------------
29 // Destructor
30 // -------------------------------------------------------------
32 = default;
33 
36  if (m_cellLinkOutputKey.key().empty()) {
37  m_cellLinkOutputKey = m_outputKey.key() + "_links";
38  }
40  return StatusCode::SUCCESS;
41 
42 }
43 
44 
46 CaloClusterSnapshot::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 
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
CaloClusterMaker.h
CaloClusterSnapshot::CaloClusterSnapshot
CaloClusterSnapshot(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloClusterSnapshot.cxx:14
CaloClusterSnapshot.h
CaloClusterStoreHelper::AddContainerWriteHandle
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
Definition: CaloClusterStoreHelper.cxx:53
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
CaloClusterSnapshot::m_finalContName
std::string m_finalContName
Definition: CaloClusterSnapshot.h:34
CaloClusterSnapshot::m_setCrossLinks
bool m_setCrossLinks
Definition: CaloClusterSnapshot.h:32
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloClusterSnapshot::initialize
virtual StatusCode initialize() override
Definition: CaloClusterSnapshot.cxx:34
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ClusterLink_t
ElementLink< xAOD::CaloClusterContainer > ClusterLink_t
Definition: egammaTruthAssociationAlg.cxx:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloClusterStoreHelper::copyContainer
static void copyContainer(const xAOD::CaloClusterContainer *oldColl, xAOD::CaloClusterContainer *newColl)
Deep copy of a cluster container.
Definition: CaloClusterStoreHelper.cxx:91
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloClusterSnapshot::m_cellLinkOutputKey
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_cellLinkOutputKey
Definition: CaloClusterSnapshot.h:30
CaloClusterSnapshot::~CaloClusterSnapshot
virtual ~CaloClusterSnapshot() override
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloClusterSnapshot::m_outputKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputKey
Definition: CaloClusterSnapshot.h:29
CaloClusterSnapshot::execute
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *) const override
Execute on an entire collection of clusters.
Definition: CaloClusterSnapshot.cxx:46