ATLAS Offline Software
EventInfoCnvAlg.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 
6 // System include(s):
7 #include <memory>
8 
9 // Gaudi/Athena include(s):
11 #include "GaudiKernel/ConcurrencyFlags.h"
12 
13 // EDM include(s):
14 #include "EventInfo/EventInfo.h"
20 
21 // Local include(s):
22 #include "EventInfoCnvAlg.h"
23 
24 namespace xAODMaker {
25 
27  ISvcLocator* svcLoc )
28  : AthReentrantAlgorithm( name, svcLoc ),
29  m_cnvTool( "xAODMaker::EventInfoCnvTool/EventInfoCnvTool", this ) {
30 
31  declareProperty( "AODKey", m_aodKey = "" );
32  declareProperty( "xAODKey", m_xaodKey = "EventInfo" );
33  declareProperty( "PileupKey", m_pileupKey = "PileupEventInfo" );
34  declareProperty( "CnvTool", m_cnvTool );
35  }
36 
38 
39  // Greet the user:
40  ATH_MSG_INFO( "Initializing " << name() );
41  ATH_MSG_DEBUG( " AOD Key: " << m_aodKey );
42  ATH_MSG_DEBUG( "xAOD Key: " << m_xaodKey.key() );
43 
44  // Retrieve the converter tool:
45  CHECK( m_cnvTool.retrieve() );
46 
49  CHECK( m_pileupKey.initialize(SG::AllowEmpty) );
50 
51  // Return gracefully:
52  return StatusCode::SUCCESS;
53  }
54 
55  StatusCode EventInfoCnvAlg::execute (const EventContext& ctx) const {
56 
57  // Check if anything needs to be done:
58  // FIXME: Job configuration should be fixed so we don't need this test.
59  if( evtStore()->contains< xAOD::EventInfo >( m_xaodKey.key() ) ) {
60  ATH_MSG_WARNING( "xAOD::EventInfo with key \"" << m_xaodKey.key()
61  << "\" is already in StoreGate; "
62  << "EventInfoCnvAlg should not be scheduled.");
63  return StatusCode::SUCCESS;
64  }
65 
66  // Retrieve the AOD object:
67  // FIXME: Use a ReadHandle.
68  const EventInfo* aod = nullptr;
69  if( m_aodKey.empty() ) {
70  // If key has not been set, do a keyless retrieve instead.
71  // This is not standard behavior, but is for compatibility
72  // with existing configurations.
73  CHECK( evtStore()->retrieve( aod ) );
74  } else {
76  aod = ei.cptr();
77  }
78 
79  // Create the xAOD object(s):
80  auto ei = std::make_unique<xAOD::EventInfo>();
81  auto ei_aux = std::make_unique<xAOD::EventAuxInfo>();
82  ei->setStore (ei_aux.get());
83 
84  // Check if this is a PileUpEventInfo object:
85  const PileUpEventInfo* paod =
86  dynamic_cast< const PileUpEventInfo* >( aod );
87  if( paod ) {
88  // Create an EventInfoContainer for the pileup events:
89  auto puei = std::make_unique<xAOD::EventInfoContainer>();
90  auto puei_aux = std::make_unique<xAOD::EventInfoAuxContainer>();
91  puei->setStore (puei_aux.get());
92 
93  // Sub-events for the main EventInfo object:
94  std::vector< xAOD::EventInfo::SubEvent > subEvents;
95 
96  // A convenience type declaration:
98 
99  // Create xAOD::EventInfo objects for each pileup EventInfo object:
102  for( ; pu_itr != pu_end; ++pu_itr ) {
103  // Create a new xAOD object:
104  xAOD::EventInfo* ei = new xAOD::EventInfo();
105  puei->push_back( ei );
106  // Fill it with information:
107  CHECK( m_cnvTool->convert( pu_itr->pSubEvt, ei, true, false, ctx ) );
108  // And now add a sub-event to the temporary list:
110  switch (pu_itr->type()) {
113  break;
116  break;
119  break;
122  break;
125  break;
128  break;
129  default:
130  break;
131  }
132  subEvents.emplace_back( pu_itr->time(),
133  pu_itr->index(),
134  type,
135  EiLink( m_pileupKey.key(),
136  puei->size() -
137  1 ) );
138  }
139 
140  // And now update the main EventInfo object with the sub-events:
141  ei->setSubEvents( subEvents );
142 
143  // Record PU objects.
145  CHECK( puei_h.record (std::move(puei), std::move(puei_aux)) );
146  }
147 
148  // Do the translation:
149  CHECK( m_cnvTool->convert( aod, ei.get(), false, true, ctx ) );
150 
151  // Record EI objects.
153  CHECK( ei_h.record (std::move(ei), std::move (ei_aux)) );
154 
155  // Return gracefully:
156  return StatusCode::SUCCESS;
157  }
158 
159 } // namespace xAODMaker
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODMaker::EventInfoCnvAlg::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: EventInfoCnvAlg.cxx:37
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition: IEventInfoCnvTool.h:17
xAODMaker::EventInfoCnvAlg::m_xaodKey
SG::WriteHandleKey< xAOD::EventInfo > m_xaodKey
Key for the output object.
Definition: EventInfoCnvAlg.h:48
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PileUpTimeEventIndex::Cavern
@ Cavern
Definition: PileUpTimeEventIndex.h:18
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
PileUpEventInfo.h
This class provides information about an overlaid event. It extends EventInfo with a list of sub-evts...
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::EventInfo_v1::HighPtMinimumBias
@ HighPtMinimumBias
High pT Minimum bias pileup event.
Definition: EventInfo_v1.h:270
xAOD::EventInfo_v1::MinimumBias
@ MinimumBias
(Low pT) Minimum bias pileup event
Definition: EventInfo_v1.h:267
EventInfoAuxContainer.h
xAOD::EventInfo_v1::PileUpType
PileUpType
Enumerator describing the types of pileup events.
Definition: EventInfo_v1.h:264
xAOD::EventInfo_v1::ZeroBias
@ ZeroBias
Zero bias pileup event.
Definition: EventInfo_v1.h:271
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAODMaker
Definition: StoreGateSvc.h:72
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
EventInfoContainer.h
EventInfoCnvAlg.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PileUpTimeEventIndex::MinimumBias
@ MinimumBias
Definition: PileUpTimeEventIndex.h:17
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
PileUpEventInfo::beginSubEvt
SubEvent::iterator beginSubEvt()
Definition: PileUpEventInfo.h:131
xAODMaker::EventInfoCnvAlg::m_aodKey
SG::ReadHandleKey< EventInfo > m_aodKey
Key for the input object If blank, we do a keyless retrieve from SG instead!
Definition: EventInfoCnvAlg.h:46
xAODMaker::EventInfoCnvAlg::m_pileupKey
SG::WriteHandleKey< xAOD::EventInfoContainer > m_pileupKey
For pileup.
Definition: EventInfoCnvAlg.h:51
xAODMaker::EventInfoCnvAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition: EventInfoCnvAlg.cxx:55
PileUpTimeEventIndex::HaloGas
@ HaloGas
Definition: PileUpTimeEventIndex.h:19
xAOD::EventInfo_v1::Unknown
@ Unknown
Type not known/specified.
Definition: EventInfo_v1.h:265
PileUpTimeEventIndex::ZeroBias
@ ZeroBias
Definition: PileUpTimeEventIndex.h:21
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
xAOD::EventInfo_v1::HaloGas
@ HaloGas
Halo-gas non-collision background.
Definition: EventInfo_v1.h:269
PileUpTimeEventIndex::Signal
@ Signal
Definition: PileUpTimeEventIndex.h:16
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
xAODMaker::EventInfoCnvAlg::EventInfoCnvAlg
EventInfoCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: EventInfoCnvAlg.cxx:26
EventAuxInfo.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
errorcheck.h
Helpers for checking error return status codes and reporting errors.
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::EventInfo_v1::Signal
@ Signal
The signal event.
Definition: EventInfo_v1.h:266
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
PileUpEventInfo
This class provides information about an overlaid event. It extends EventInfo with a list of sub-evts...
Definition: PileUpEventInfo.h:37
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PileUpEventInfo::SubEvent::const_iterator
std::list< SubEvent >::const_iterator const_iterator
Definition: PileUpEventInfo.h:97
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::EventInfo_v1::Cavern
@ Cavern
Cavern background pileup event.
Definition: EventInfo_v1.h:268
xAODMaker::EventInfoCnvAlg::m_cnvTool
ToolHandle< IEventInfoCnvTool > m_cnvTool
Handle to the converter tool.
Definition: EventInfoCnvAlg.h:54
PileUpTimeEventIndex::HighPtMinimumBias
@ HighPtMinimumBias
Definition: PileUpTimeEventIndex.h:20
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
PileUpEventInfo::endSubEvt
SubEvent::iterator endSubEvt()
Definition: PileUpEventInfo.h:132