ATLAS Offline Software
InDetSDOOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
9 InDetSDOOverlay::InDetSDOOverlay(const std::string &name, ISvcLocator *pSvcLocator) :
10  AthReentrantAlgorithm(name, pSvcLocator) { }
11 
13 {
14  ATH_MSG_DEBUG("Initializing...");
15 
16  if (m_signalInputKey.key().empty()) {
17  ATH_MSG_ERROR("Missing signal input SDO key.");
18  return StatusCode::FAILURE;
19  }
20 
21  if (m_outputKey.key().empty()) {
22  ATH_MSG_ERROR("Missing output SDO key.");
23  return StatusCode::FAILURE;
24  }
25 
26  // Check and initialize keys
28  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
30  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
32  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
33 
34  return StatusCode::SUCCESS;
35 }
36 
37 StatusCode InDetSDOOverlay::execute(const EventContext& ctx) const
38 {
39  ATH_MSG_DEBUG("execute() begin");
40 
41  // Reading the input containers
42  ATH_MSG_VERBOSE("Retrieving input containers");
43 
44  const InDetSimDataCollection *bkgContainerPtr = nullptr;
45  if (!m_bkgInputKey.key().empty()) {
47  if (!bkgContainer.isValid()) {
48  ATH_MSG_ERROR("Could not get background InDetSimDataCollection container " << bkgContainer.name() << " from store " << bkgContainer.store());
49  return StatusCode::FAILURE;
50  }
51  bkgContainerPtr = bkgContainer.cptr();
52 
53  ATH_MSG_DEBUG("Found background InDetSimDataCollection container " << bkgContainer.name() << " in store " << bkgContainer.store());
54  }
55 
57  if (!signalContainer.isValid()) {
58  ATH_MSG_ERROR("Could not get signal InDetSimDataCollection container " << signalContainer.name() << " from store " << signalContainer.store());
59  return StatusCode::FAILURE;
60  }
61  ATH_MSG_DEBUG("Found signal InDetSimDataCollection container " << signalContainer.name() << " in store " << signalContainer.store());
62 
63  // Creating output RDO container
65  ATH_CHECK(outputContainer.record(std::make_unique<InDetSimDataCollection>()));
66  if (!outputContainer.isValid()) {
67  ATH_MSG_ERROR("Could not record output InDetSimDataCollection container " << outputContainer.name() << " to store " << outputContainer.store());
68  return StatusCode::FAILURE;
69  }
70  ATH_MSG_DEBUG("Recorded output InDetSimDataCollection container " << outputContainer.name() << " in store " << outputContainer.store());
71 
72  // Copy over signal SDO
73  ATH_MSG_VERBOSE("Inserting signal SDO, size = " << signalContainer->size());
74  outputContainer->insert(signalContainer->begin(), signalContainer->end());
75 
76  // Merge with background
77  if (!m_bkgInputKey.key().empty()) {
78  ATH_MSG_VERBOSE("Inserting background SDO, size = " << bkgContainerPtr->size());
79 
80  for (const auto &entry : *bkgContainerPtr) {
81  auto it = outputContainer->find(entry.first);
82  if (it != outputContainer->end()) {
83  // merge necessary
84  const InDetSimData &outSimData = it->second;
85  std::vector<InDetSimData::Deposit> depositsVector(outSimData.getdeposits());
86  depositsVector.insert(depositsVector.end(), entry.second.getdeposits().begin(), entry.second.getdeposits().end());
87 
88  it->second = InDetSimData(depositsVector);
89  } else {
90  outputContainer->insert(entry);
91  }
92  }
93  }
94 
95  ATH_MSG_VERBOSE("Output SDO size " << outputContainer->size());
96 
97  ATH_MSG_DEBUG("execute() end");
98  return StatusCode::SUCCESS;
99 }
InDetSDOOverlay::InDetSDOOverlay
InDetSDOOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetSDOOverlay.cxx:9
InDetSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition: InDetSimData.h:74
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
skel.it
it
Definition: skel.GENtoEVGEN.py:423
InDetSimDataCollection
Definition: InDetSimDataCollection.h:25
InDetSDOOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: InDetSDOOverlay.cxx:37
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
InDetSDOOverlay.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
InDetSimData
Definition: InDetSimData.h:42
InDetSimData.h
InDetSDOOverlay::initialize
virtual StatusCode initialize() override
Definition: InDetSDOOverlay.cxx:12
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDetSDOOverlay::m_bkgInputKey
SG::ReadHandleKey< InDetSimDataCollection > m_bkgInputKey
Definition: InDetSDOOverlay.h:20
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetSDOOverlay::m_signalInputKey
SG::ReadHandleKey< InDetSimDataCollection > m_signalInputKey
Definition: InDetSDOOverlay.h:21
SG::WriteHandle< InDetSimDataCollection >
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
InDetSDOOverlay::m_outputKey
SG::WriteHandleKey< InDetSimDataCollection > m_outputKey
Definition: InDetSDOOverlay.h:22