Skip to content

Commit

Permalink
preserve user-defined print modulo
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu committed Apr 26, 2024
1 parent 8278caf commit dac1443
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/RMGRunAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RMGRunAction : public G4UserRunAction {
void BeginOfRunAction(const G4Run*) override;
void EndOfRunAction(const G4Run*) override;

inline int GetCurrentRunPrintModulo() const const const { return fCurrentPrintModulo; }

inline auto& GetOutputDataFields(RMGHardware::DetectorType d_type) {
return fOutputDataFields.at(d_type);
}
Expand All @@ -62,6 +64,8 @@ class RMGRunAction : public G4UserRunAction {
bool fIsAnaManInitialized = false;
RMGMasterGenerator* fRMGMasterGenerator = nullptr;

int fCurrentPrintModulo = -1;

std::map<RMGHardware::DetectorType, std::unique_ptr<RMGVOutputScheme>> fOutputDataFields;
};

Expand Down
2 changes: 1 addition & 1 deletion src/RMGEventAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RMGEventAction::RMGEventAction(RMGRunAction* run_action) : fRunAction(run_action

void RMGEventAction::BeginOfEventAction(const G4Event* event) {

auto print_modulo = RMGManager::Instance()->GetPrintModulo();
auto print_modulo = fRunAction->GetCurrentRunPrintModulo();
if ((event->GetEventID() + 1) % print_modulo == 0) {

auto current_run = dynamic_cast<const RMGRun*>(G4RunManager::GetRunManager()->GetCurrentRun());
Expand Down
11 changes: 4 additions & 7 deletions src/RMGRunAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ void RMGRunAction::BeginOfRunAction(const G4Run*) {

auto g4manager = G4RunManager::GetRunManager();
auto tot_events = g4manager->GetNumberOfEventsToBeProcessed();
if (manager->GetPrintModulo() <= 0 and tot_events >= 100)
manager->SetPrintModulo(tot_events / 10);
else if (tot_events < 100) manager->SetPrintModulo(100);

fCurrentPrintModulo = manager->GetPrintModulo();
if (fCurrentPrintModulo <= 0 and tot_events >= 100) fCurrentPrintModulo = tot_events / 10;
else if (tot_events < 100) fCurrentPrintModulo = 100;
}

void RMGRunAction::EndOfRunAction(const G4Run*) {
Expand Down Expand Up @@ -203,10 +204,6 @@ void RMGRunAction::EndOfRunAction(const G4Run*) {
G4AnalysisManager::Instance()->Write();
G4AnalysisManager::Instance()->CloseFile();
}

// reset print modulo
// TODO: if it's user specified, it shouldn't be reset
RMGManager::Instance()->SetPrintModulo(-1);
}

// vim: tabstop=2 shiftwidth=2 expandtab

0 comments on commit dac1443

Please sign in to comment.