8#include "GaudiKernel/IEventProcessor.h"
9#include "GaudiKernel/IAlgManager.h"
10#include "GaudiKernel/IOpaqueAddress.h"
11#include "GaudiKernel/IProperty.h"
12#include "GaudiKernel/ClassID.h"
13#include "GaudiKernel/IClassIDSvc.h"
14#include "GaudiKernel/IIncidentSvc.h"
15#include "GaudiKernel/ConcurrencyFlags.h"
17#include "EventInfo/EventInfo.h"
55 if(Gaudi::Concurrency::ConcurrencyFlags::numProcs()>0) {
61 return StatusCode::SUCCESS;
73 ATH_MSG_ERROR(
"Event number must be positive-definite; " << newnum <<
" is not allowed");
74 return StatusCode::FAILURE;
80 ATH_MSG_INFO(
"After " <<
m_nPass <<
" events we switch off HepMC3 warnings to avoid blowing up logs.");
81 HepMC3::Setup::set_print_warnings(
false);
87 if (
evtStore()->retrieve(oldmcEvtColl, key).isSuccess()){
96 return StatusCode::SUCCESS;
101 int inpRunNumber{-1};
105 ATH_CHECK(outputEvtInfoHandle.
record(std::make_unique<xAOD::EventInfo>(), std::make_unique<xAOD::EventAuxInfo>()));
107 outputEvtInfo = outputEvtInfoHandle.
ptr();
108 *outputEvtInfo = *inputEvtInfoHandle;
115 inpRunNumber = inputEvtInfoHandle->runNumber();
125 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
128 eventID->set_event_number(newnum);
132 return StatusCode::SUCCESS;
143 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
146 unsigned int run_number = pInputEvt->
event_ID()->run_number();
152 ATH_MSG_DEBUG(
"Copied run number into mc channel number: " << run_number);
155 return StatusCode::FAILURE;
168 unsigned int oldRunNumber = 0;
169 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
172 oldRunNumber = eventID->run_number();
182 return StatusCode::SUCCESS;
185 oldRunNumber = outputEvtInfo->
runNumber();
191 auto newChannelNumber =
193 auto oldChannelNumber =
196 const char* key =
"/Generation/Parameters";
207 if (collection->chanNum(
index) != oldChannelNumber) {
208 ATH_MSG_INFO(
"Not updating \"" << key <<
"\" on channel number "
209 << collection->chanNum(
index));
213 if (collection->fixChanNum(oldChannelNumber, newChannelNumber))
214 ATH_MSG_INFO(
"Updated \"" << key <<
"\" channel number from "
215 << oldChannelNumber <<
" to " << newChannelNumber);
217 ATH_MSG_ERROR(
"Channel number update from " << oldChannelNumber
218 <<
" to " << newChannelNumber <<
" on \"" << key
225 const char* key =
"/TagInfo";
235 for (
auto pair : *collection) {
237 if (
pair.second.exists(
"mc_channel_number")) {
239 pair.second[
"mc_channel_number"].setValue(
241 ATH_MSG_INFO(
"Updated \"" << key <<
"\" mc_channel_number"
243 }
catch (std::exception&) {
246 ATH_MSG_INFO(
"Updated \"" << key <<
"\" mc_channel_number"
248 }
catch (std::exception&) {
260 ATH_MSG_INFO(
"Could not retrieve \"" << key <<
"\" from MetaDataStore");
269 SmartIF<IEventProcessor> apm(serviceLocator()->service(
"AthMpEvtLoopMgr",
false));
274 apm = serviceLocator()->service(
"AthenaEventLoopMgr",
false);
284 return StatusCode::SUCCESS;
290 return StatusCode::SUCCESS;
295 if(inc.type()==AfterForkInc::type()) {
296 int nProcs= Gaudi::Concurrency::ConcurrencyFlags::numProcs();
297 const AfterForkInc* afInc =
dynamic_cast<const AfterForkInc*
>(&inc);
301 + (afInc->workerID() <= rem-1 ? 1 : 0);
304 ATH_MSG_ERROR(
"Failed to dyn-cast the incident to UpdateAfterFork!");
305 throw std::runtime_error(
"Wrong incident type handled by CountHepMC");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
This class provides general information about an event.
This class is a container for the payload of conditions data.
Handle class for reading a decoration on an object.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
static const std::string & type()
Incident type.
This class is a collection of AttributeLists where each one is associated with a channel number.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_mcWeightsKey
SG::ReadHandleKey< xAOD::EventInfo > m_inputEvtInfoKey
ServiceHandle< StoreGateSvc > m_metaDataStore
virtual StatusCode finalize() override
std::string m_inputKeyName
SG::WriteHandleKey< xAOD::EventInfo > m_outputEvtInfoKey
CountHepMC(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
virtual StatusCode initialize() override
virtual void handle(const Incident &inc) override
DataModel_detail::iterator< DataVector > iterator
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
EventID * event_ID()
the unique identification of the event.
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
This class represents the "type of event" where the type is given by one or more "characteristics".
void set_mc_channel_number(number_type chan)
Add in the MC generator channel number (aka gen run number).
number_type mc_channel_number() const
Access to the MC generator channel number (was used as run number for generator events).
void set_mc_event_number(uint64_t evt)
Add in the MC generator event number.
virtual StatusCode initialize() override
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
This class is a container for the payload of conditions data.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Handle class for reading a decoration on an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
void setEventNumber(uint64_t value)
Set the current event's event number.
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
void setMCEventWeights(const std::vector< float > &value)
Set the weights of all the MC events used in the simulation.
void setRunNumber(uint32_t value)
Set the current event's run number.
uint32_t runNumber() const
The current event's run number.
bool set_ll_event_number(HepMC3::GenEvent *e, long long int num)
HepMC3::GenEvent GenEvent
EventInfo_v1 EventInfo
Definition of the latest event info version.