Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions k4Gen/src/components/GenEventFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ StatusCode GenEventFilter::initialize() {

StatusCode GenEventFilter::execute(const EventContext& evtCtx) const {
const edm4hep::MCParticleCollection* inParticles = m_inColl.get();

if (m_nEventsSeen == m_nEventsSeenMax) {
debug() << "Maximum number of " << m_nEventsSeenMax.value()
<< " seen events reached!" << endmsg;

StatusCode sc = m_eventProcessor->stopRun();
if (sc.isFailure()) {
error() << "Error when attempting to stop event processing! Aborting..."
<< endmsg;
return sc;
}

m_incidentSvc->fireIncident(Incident(name(), IncidentType::AbortEvent));

return StatusCode::SUCCESS;
}

m_nEventsSeen++;

if (!(*m_filterRulePtr)(inParticles)) {
Expand Down
8 changes: 8 additions & 0 deletions k4Gen/src/components/GenEventFilter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef GENERATION_GENEVENTFILTER_H
#define GENERATION_GENEVENTFILTER_H

// std
#include <limits>

// Gaudi
#include "GaudiKernel/Algorithm.h"
class IProperty;
Expand Down Expand Up @@ -48,6 +51,11 @@ class GenEventFilter : public Gaudi::Algorithm {
Gaudi::Property<std::string> m_filterRulePath{
this, "filterRulePath", "", "Path to the filter rule file"};

/// Maximum number of events seen
Gaudi::Property<unsigned int> m_nEventsSeenMax{
this, "nEventsSeenMax", std::numeric_limits<unsigned int>::max(),
"Limit the number of events seen"};

/// Targeted number of events.
mutable std::atomic<unsigned int> m_nEventsTarget;
/// Keep track of how many events were already accepted.
Expand Down