Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
put check on if an event should be skipped into its own function
Browse files Browse the repository at this point in the history
this is helpful isolation and makes it easier to document how an event
ends up being re-simulated
  • Loading branch information
tomeichlersmith committed Nov 20, 2023
1 parent 447d577 commit 5398819
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
9 changes: 8 additions & 1 deletion include/SimCore/ReSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<std::pair<int,int>> events_to_resimulate_;
std::vector<std::pair<int, int>> events_to_resimulate_;

/**
* Whether to resimulate all events in the input files
Expand Down
57 changes: 35 additions & 22 deletions src/SimCore/ReSimulator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ void ReSimulator::configure(framework::config::Parameters& parameters) {
parameters.getParameter<bool>("resimulate_all_events");
if (!resimulate_all_events_) {
care_about_run_ = parameters.getParameter<bool>("care_about_run");
auto configured_events{parameters.getParameter<std::vector<framework::config::Parameters>>("events_to_resimulate", {})};
auto configured_events{
parameters.getParameter<std::vector<framework::config::Parameters>>(
"events_to_resimulate", {})};
if (configured_events.size() == 0) {
EXCEPTION_RAISE(
"ReSimNoEvents",
Expand All @@ -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<int>("run"),
run_event.getParameter<int>("event")
);
events_to_resimulate_.emplace_back(run_event.getParameter<int>("run"),
run_event.getParameter<int>("event"));
}
}
}
Expand All @@ -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<int,int>& 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;
Expand Down Expand Up @@ -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<int, int>& 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)

0 comments on commit 5398819

Please sign in to comment.