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;
79 constexpr long long int max32 = std::pow(2, 31) - 1;
80 if (newnum >= max32) {
81 ATH_MSG_ERROR(
"Event number " << newnum <<
" exceeds 32bit limit. In HepMC2 it is not allowed.");
82 return StatusCode::FAILURE;
88 ATH_MSG_INFO(
"After " <<
m_nPass <<
" events we switch off HepMC3 warnings to avoid blowing up logs.");
89 HepMC3::Setup::set_print_warnings(
false);
97 if (
evtStore()->retrieve(oldmcEvtColl, key).isSuccess()){
100 HepMC::GenEvent* hepMC = *evt;
106 return StatusCode::SUCCESS;
111 int inpRunNumber{-1};
115 ATH_CHECK(outputEvtInfoHandle.
record(std::make_unique<xAOD::EventInfo>(), std::make_unique<xAOD::EventAuxInfo>()));
117 outputEvtInfo = outputEvtInfoHandle.
ptr();
118 *outputEvtInfo = *inputEvtInfoHandle;
125 inpRunNumber = inputEvtInfoHandle->runNumber();
135 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
138 eventID->set_event_number(newnum);
142 return StatusCode::SUCCESS;
153 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
156 unsigned int run_number = pInputEvt->
event_ID()->run_number();
162 ATH_MSG_DEBUG(
"Copied run number into mc channel number: " << run_number);
165 return StatusCode::FAILURE;
178 unsigned int oldRunNumber = 0;
179 if (
evtStore()->retrieve(pInputEvt).isSuccess()) {
182 oldRunNumber = eventID->run_number();
192 return StatusCode::SUCCESS;
195 oldRunNumber = outputEvtInfo->
runNumber();
201 auto newChannelNumber =
203 auto oldChannelNumber =
206 const char* key =
"/Generation/Parameters";
217 if (collection->chanNum(
index) != oldChannelNumber) {
218 ATH_MSG_INFO(
"Not updating \"" << key <<
"\" on channel number "
219 << collection->chanNum(
index));
223 if (collection->fixChanNum(oldChannelNumber, newChannelNumber))
224 ATH_MSG_INFO(
"Updated \"" << key <<
"\" channel number from "
225 << oldChannelNumber <<
" to " << newChannelNumber);
227 ATH_MSG_ERROR(
"Channel number update from " << oldChannelNumber
228 <<
" to " << newChannelNumber <<
" on \"" << key
235 const char* key =
"/TagInfo";
245 for (
auto pair : *collection) {
247 if (
pair.second.exists(
"mc_channel_number")) {
249 pair.second[
"mc_channel_number"].setValue(
251 ATH_MSG_INFO(
"Updated \"" << key <<
"\" mc_channel_number"
253 }
catch (std::exception&) {
256 ATH_MSG_INFO(
"Updated \"" << key <<
"\" mc_channel_number"
258 }
catch (std::exception&) {
270 ATH_MSG_INFO(
"Could not retrieve \"" << key <<
"\" from MetaDataStore");
279 SmartIF<IEventProcessor> apm(serviceLocator()->service(
"AthMpEvtLoopMgr",
false));
284 apm = serviceLocator()->service(
"AthenaEventLoopMgr",
false);
294 return StatusCode::SUCCESS;
300 return StatusCode::SUCCESS;
305 if(inc.type()==AfterForkInc::type()) {
306 int nProcs= Gaudi::Concurrency::ConcurrencyFlags::numProcs();
307 const AfterForkInc* afInc =
dynamic_cast<const AfterForkInc*
>(&inc);
311 + (afInc->workerID() <= rem-1 ? 1 : 0);
314 ATH_MSG_ERROR(
"Failed to dyn-cast the incident to UpdateAfterFork!");
315 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
virtual StatusCode execute() override
CountHepMC(const std::string &name, ISvcLocator *pSvcLocator)
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(HepMC::GenEvent *e, long long int num)
EventInfo_v1 EventInfo
Definition of the latest event info version.