ATLAS Offline Software
CopyTrackCollection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CopyTrackCollection.h"
6 
7 
8 CopyTrackCollection::CopyTrackCollection(const std::string &name, ISvcLocator *pSvcLocator)
9  : AthReentrantAlgorithm(name, pSvcLocator) { }
10 
12 {
13  ATH_MSG_DEBUG("Initializing...");
14 
15  // Check and initialize keys
16  ATH_CHECK( m_inputKey.initialize() );
17  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_inputKey);
18  ATH_CHECK( m_outputKey.initialize() );
19  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode CopyTrackCollection::execute(const EventContext& ctx) const
25 {
26  ATH_MSG_DEBUG("execute() begin");
27  // Reading the input container
28  ATH_MSG_VERBOSE("Retrieving input container");
29 
30  SG::ReadHandle<TrackCollection> inputContainer(m_inputKey, ctx);
31  if (!inputContainer.isValid()) {
32  ATH_MSG_ERROR("Could not get pileup TrackCollection " << inputContainer.name() << " from store " << inputContainer.store());
33  return StatusCode::FAILURE;
34  }
35  ATH_MSG_DEBUG("Found pileup TrackCollection " << inputContainer.name() << " in store " << inputContainer.store());
36 
37  // Creating output container
38  SG::WriteHandle<TrackCollection> outputContainer(m_outputKey, ctx);
39  ATH_CHECK(outputContainer.record(std::make_unique<TrackCollection>()));
40  if (!outputContainer.isValid()) {
41  ATH_MSG_ERROR("Could not record output TrackCollection " << outputContainer.name() << " to store " << outputContainer.store());
42  return StatusCode::FAILURE;
43  }
44  ATH_MSG_DEBUG("Recorded output TrackCollection container " << outputContainer.name() << " in store " << outputContainer.store());
45 
46  // Copy pileup tracks
47  for (const Trk::Track* track : *inputContainer) {
48  outputContainer->push_back(new Trk::Track(*track));
49  }
50 
51  ATH_MSG_DEBUG("execute() end");
52  return StatusCode::SUCCESS;
53 }
CopyTrackCollection::initialize
virtual StatusCode initialize() override
Definition: CopyTrackCollection.cxx:11
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
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
CopyTrackCollection::m_inputKey
SG::ReadHandleKey< TrackCollection > m_inputKey
Definition: CopyTrackCollection.h:21
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
CopyTrackCollection::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CopyTrackCollection.cxx:24
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CopyTrackCollection.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
CopyTrackCollection::CopyTrackCollection
CopyTrackCollection(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CopyTrackCollection.cxx:8
CopyTrackCollection::m_outputKey
SG::WriteHandleKey< TrackCollection > m_outputKey
Definition: CopyTrackCollection.h:22