ATLAS Offline Software
Loading...
Searching...
No Matches
MergeTrackRecordCollTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
10 const std::string& name,
11 const IInterface* parent) :
12 PileUpToolBase(type, name, parent)
13{
14}
15
17{
18 ATH_MSG_DEBUG( "initialize()" );
19 ATH_CHECK( m_pMergeSvc.retrieve() );
20 ATH_CHECK( m_outputKey.initialize() );
21 return StatusCode::SUCCESS;
22}
23
24StatusCode MergeTrackRecordCollTool::prepareEvent(const EventContext& /*ctx*/, unsigned int nInputEvents)
25{
26 ATH_MSG_DEBUG ( "Calling prepareEvent()" );
27 ATH_MSG_DEBUG( "prepareEvent: there are " << nInputEvents << " subevents in this event.");
28 m_firstSubEvent=true;
29 return StatusCode::SUCCESS;
30}
31
33 SubEventIterator bSubEvents,
34 SubEventIterator eSubEvents)
35{
36 ATH_MSG_VERBOSE ( "processBunchXing()" );
37 //We are only interested in the TrackRecordCollection for the original event
38 if(m_firstSubEvent && bunchXing==0) {
39 if (bSubEvents != eSubEvents) {
40 const TrackRecordCollection* oldColl(nullptr);
41 if (m_pMergeSvc->retrieveSingleSubEvtData(m_trRecCollKey.value(), oldColl,
42 bunchXing, bSubEvents).isSuccess()) {
44 ATH_CHECK(outputCollection.record(std::make_unique<TrackRecordCollection>()));
45 if (!outputCollection.isValid()) {
46 ATH_MSG_ERROR("Could not record output TrackRecordCollection " << outputCollection.name() << " to store " << outputCollection.store());
47 return StatusCode::FAILURE;
48 }
49
50 for(const auto& trcit : *oldColl) {
51 outputCollection->push_back( TrackRecord(trcit) );
52 }
53 ATH_MSG_DEBUG( "processBunchXing: copied original event TrackRecordCollection" );
54 m_firstSubEvent=false;
55 }
56 else {
57 ATH_MSG_ERROR ( "processBunchXing: TimedTruthList is empty" );
58 }
59 }
60 else {
61 ATH_MSG_ERROR ( "processBunchXing: Can not find TimedTruthList" );
62 }
63 }
64
65 return StatusCode::SUCCESS;
66}
67
68StatusCode MergeTrackRecordCollTool::mergeEvent(const EventContext& /*ctx*/)
69{
70 //Nothing to do here;
71 return StatusCode::SUCCESS;
72}
73
74bool MergeTrackRecordCollTool::toProcess(int bunchXing) const
75{
76 //We are only interested in the TrackRecordCollection for the original event
77 //which should be in BC 0 !
78 return (bunchXing==0);
79}
80
81StatusCode MergeTrackRecordCollTool::processAllSubEvents(const EventContext& ctx)
82{
83 ATH_MSG_VERBOSE ( "processAllSubEvents()" );
84
86 TimedTruthList truthList;
87 if ( (m_pMergeSvc->retrieveSubEvtsData(m_trRecCollKey.value(), truthList)).isSuccess() ) {
88 if (truthList.begin() != truthList.end()) {
89 //FIXME we are forced to do a deep copy
90 const TrackRecordCollection &oldColl=*(truthList.begin())->second;
91
93 ATH_CHECK(outputCollection.record(std::make_unique<TrackRecordCollection>()));
94 if (!outputCollection.isValid()) {
95 ATH_MSG_ERROR("Could not record output TrackRecordCollection " << outputCollection.name() << " to store " << outputCollection.store());
96 return StatusCode::FAILURE;
97 }
98
99 for (const auto& trcit : oldColl) {
100 outputCollection->push_back( TrackRecord(trcit) );
101 }
102
103 ATH_MSG_DEBUG ( "processAllSubEvents: copied original event TrackRecordCollection" );
104 }
105 else {
106 ATH_MSG_ERROR ( "processAllSubEvents: TimedTruthList is empty" );
107 }
108 }
109 else {
110 ATH_MSG_ERROR ( "processAllSubEvents: Can not find TimedTruthList" );
111 }
112 return StatusCode::SUCCESS;
113}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition IPileUpTool.h:22
AtlasHitsVector< TrackRecord > TrackRecordCollection
virtual StatusCode processAllSubEvents(const EventContext &ctx) override final
Propagate the TrackRecordCollections to the output StoreGate.
virtual StatusCode processBunchXing(int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents) override final
called for each active bunch-crossing to process current SubEvents bunchXing is in ns
virtual StatusCode mergeEvent(const EventContext &ctx) override final
called at the end of the subevts loop.
SG::WriteHandleKey< TrackRecordCollection > m_outputKey
virtual StatusCode initialize() override final
Initialize tool.
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
MergeTrackRecordCollTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode prepareEvent(const EventContext &ctx, unsigned int nInputEvents) override final
called before the subevts loop.
virtual bool toProcess(int bunchXing) const override final
return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase...
PileUpToolBase(const std::string &type, const std::string &name, const IInterface *parent)
std::list< value_t > type
type of the collection of timed data object