diff --git a/include/SimCore/ReSimulator.h b/include/SimCore/ReSimulator.h index 4dd02b7..7ecf2b4 100644 --- a/include/SimCore/ReSimulator.h +++ b/include/SimCore/ReSimulator.h @@ -26,6 +26,13 @@ class ReSimulator : public SimulatorBase { void produce(framework::Event& event) override; private: + /** + * Check if an event should be skipped during resimulation + * + * @param[in] event handle to the current event being processed + */ + bool skip(framework::Event& event) const; + /** * List of events in the input files that should be resimulated if * `resimulate_all_events` is false. @@ -35,7 +42,7 @@ class ReSimulator : public SimulatorBase { * @note: If an event in `events_to_resimulate_` is not part of the * input file, it will be ignored. */ - std::vector> events_to_resimulate_; + std::vector> events_to_resimulate_; /** * Whether to resimulate all events in the input files diff --git a/src/SimCore/ReSimulator.cxx b/src/SimCore/ReSimulator.cxx index be04d03..e31ec59 100644 --- a/src/SimCore/ReSimulator.cxx +++ b/src/SimCore/ReSimulator.cxx @@ -8,7 +8,9 @@ void ReSimulator::configure(framework::config::Parameters& parameters) { parameters.getParameter("resimulate_all_events"); if (!resimulate_all_events_) { care_about_run_ = parameters.getParameter("care_about_run"); - auto configured_events{parameters.getParameter>("events_to_resimulate", {})}; + auto configured_events{ + parameters.getParameter>( + "events_to_resimulate", {})}; if (configured_events.size() == 0) { EXCEPTION_RAISE( "ReSimNoEvents", @@ -17,10 +19,8 @@ void ReSimulator::configure(framework::config::Parameters& parameters) { "the events_to_resimulate parameter?\n"); } for (const auto& run_event : configured_events) { - events_to_resimulate_.emplace_back( - run_event.getParameter("run"), - run_event.getParameter("event") - ); + events_to_resimulate_.emplace_back(run_event.getParameter("run"), + run_event.getParameter("event")); } } } @@ -29,24 +29,14 @@ void ReSimulator::produce(framework::Event& event) { /* numEventsBegan_++; */ auto& eventHeader{event.getEventHeader()}; const auto eventNumber{eventHeader.getEventNumber()}; - if (!resimulate_all_events_) { - auto found_event_to_resim = std::find_if( - std::begin(events_to_resimulate_), std::end(events_to_resimulate_), - [&](const std::pair& run_event) -> bool { - bool runs_match = true; - if (care_about_run_) runs_match = (event.getEventHeader().getRun() == run_event.first); - return eventNumber == run_event.second and runs_match; - } - ); - if (found_event_to_resim == std::end(events_to_resimulate_)) { - if (verbosity_ > 1) { - std::cout << "Skipping event: " << eventNumber - << " since it wasn't part of the requested events..." - << std::endl; - } - this->abortEvent(); // get out of processors loop - return; + if (skip(event)) { + if (verbosity_ > 1) { + std::cout << "Skipping event: " << eventNumber + << " since it wasn't part of the requested events..." + << std::endl; } + this->abortEvent(); // get out of processors loop + return; } if (verbosity_ > 0) { std::cout << "Resimulating " << eventNumber << std::endl; @@ -78,5 +68,28 @@ void ReSimulator::produce(framework::Event& event) { runManager_->TerminateOneEvent(); } +bool ReSimulator::skip(framework::Event& event) const { + /** + * If we are configured to simply resimulate all events, this + * function always returns false. + */ + if (resimulate_all_events_) return false; + /** + * Otherwise, we check the event number + * (and also its run number if we care_about_run_) + * against the list of run/event pairs that we are + * interested in re-simulating. + */ + auto found_event_to_resim = std::find_if( + std::begin(events_to_resimulate_), std::end(events_to_resimulate_), + [&](const std::pair& run_event) -> bool { + bool runs_match = true; + if (care_about_run_) + runs_match = (event.getEventHeader().getRun() == run_event.first); + return event.getEventNumber() == run_event.second and runs_match; + }); + return (found_event_to_resim == std::end(events_to_resimulate_)); +} + } // namespace simcore DECLARE_PRODUCER_NS(simcore, ReSimulator)