ATLAS Offline Software
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) :
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 
24 StatusCode 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 
69 {
70  //Nothing to do here;
71  return StatusCode::SUCCESS;
72 }
73 
74 bool 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 
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 }
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
MergeTrackRecordCollTool::processAllSubEvents
virtual StatusCode processAllSubEvents(const EventContext &ctx) override final
Propagate the TrackRecordCollections to the output StoreGate.
Definition: MergeTrackRecordCollTool.cxx:81
MergeTrackRecordCollTool.h
AtlasHitsVector
Definition: AtlasHitsVector.h:33
MergeTrackRecordCollTool::toProcess
virtual bool toProcess(int bunchXing) const override final
return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase...
Definition: MergeTrackRecordCollTool.cxx:74
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MergeTrackRecordCollTool::initialize
virtual StatusCode initialize() override final
Initialize tool.
Definition: MergeTrackRecordCollTool.cxx:16
MergeTrackRecordCollTool::mergeEvent
virtual StatusCode mergeEvent(const EventContext &ctx) override final
called at the end of the subevts loop.
Definition: MergeTrackRecordCollTool.cxx:68
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
MergeTrackRecordCollTool::MergeTrackRecordCollTool
MergeTrackRecordCollTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MergeTrackRecordCollTool.cxx:9
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MergeTrackRecordCollTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: MergeTrackRecordCollTool.h:50
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MergeTrackRecordCollTool::m_outputKey
SG::WriteHandleKey< TrackRecordCollection > m_outputKey
Definition: MergeTrackRecordCollTool.h:52
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PileUpToolBase
Definition: PileUpToolBase.h:18
postInclude.outputCollection
outputCollection
Definition: postInclude.SortInput.py:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
MergeTrackRecordCollTool::processBunchXing
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
Definition: MergeTrackRecordCollTool.cxx:32
MergeTrackRecordCollTool::prepareEvent
virtual StatusCode prepareEvent(const EventContext &ctx, unsigned int nInputEvents) override final
called before the subevts loop.
Definition: MergeTrackRecordCollTool.cxx:24
MergeTrackRecordCollTool::m_firstSubEvent
bool m_firstSubEvent
Definition: MergeTrackRecordCollTool.h:53
TrackRecord
Definition: TrackRecord.h:10
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MergeTrackRecordCollTool::m_trRecCollKey
StringProperty m_trRecCollKey
Definition: MergeTrackRecordCollTool.h:51
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22