remage
Simulation framework for HPGe-based experiments
 
Loading...
Searching...
No Matches
RMGRunAction.hh
1// Copyright (C) 2022 Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571>
2//
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the GNU Lesser General Public License as published by the Free
5// Software Foundation, either version 3 of the License, or (at your option) any
6// later version.
7//
8// This program is distributed in the hope that it will be useful, but WITHOUT
9// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11// details.
12//
13// You should have received a copy of the GNU Lesser General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#ifndef _RMG_RUN_ACTION_HH_
17#define _RMG_RUN_ACTION_HH_
18
19#include <filesystem>
20#include <memory>
21#include <vector>
22namespace fs = std::filesystem;
23
24#include "G4AnalysisManager.hh"
25#include "G4UserRunAction.hh"
26
27#include "RMGHardware.hh"
28#include "RMGVOutputScheme.hh"
29
30class G4Run;
31class RMGRun;
41
42 public:
43
45 RMGRunAction(bool persistency = false);
47 RMGRunAction(RMGMasterGenerator*, bool persistency = false);
48 ~RMGRunAction() = default;
49
50 RMGRunAction(RMGRunAction const&) = delete;
51 RMGRunAction& operator=(RMGRunAction const&) = delete;
52 RMGRunAction(RMGRunAction&&) = delete;
53 RMGRunAction& operator=(RMGRunAction&&) = delete;
54
62 G4Run* GenerateRun() override;
64 void BeginOfRunAction(const G4Run*) override;
66 void EndOfRunAction(const G4Run*) override;
67
69 [[nodiscard]] int GetCurrentRunPrintModulo() const { return fCurrentPrintModulo; }
70
72 [[nodiscard]] const auto& GetAllOutputDataFields() { return fOutputDataFields; }
75 for (auto& el : fOutputDataFields) el->ClearBeforeEvent();
76 }
77
78 private:
79
82 struct OutputFilePaths {
83 fs::path tmp;
84 fs::path original;
85 };
86
87 [[nodiscard]] OutputFilePaths BuildOutputFile() const;
88 [[nodiscard]] fs::path GetWorkerTmpPath(fs::path path, std::string extension) const;
89 void PostprocessOutputFile(int number_of_primaries) const;
90
91 RMGRun* fRMGRun = nullptr;
92 bool fIsPersistencyEnabled = false;
93 bool fIsAnaManInitialized = false;
94 RMGMasterGenerator* fRMGMasterGenerator = nullptr;
95 OutputFilePaths fCurrentOutputFile;
96
97 int fCurrentPrintModulo = -1;
98
99 std::vector<std::shared_ptr<RMGVOutputScheme>> fOutputDataFields;
100};
101
102#endif
103
104// vim: tabstop=2 shiftwidth=2 expandtab
Definition RMGMasterGenerator.hh:28
void SetupAnalysisManager()
Configure the Geant4 analysis manager and register all output ntuples.
Definition RMGRunAction.cc:57
RMGRunAction(bool persistency=false)
Construct a run action with no primary generator hook-up.
Definition RMGRunAction.cc:51
void BeginOfRunAction(const G4Run *) override
Open the output file, notify schemes, and record the run start time.
Definition RMGRunAction.cc:95
void ClearOutputDataFields()
Invoke RMGVOutputScheme::ClearBeforeEvent on every registered scheme.
Definition RMGRunAction.hh:74
const auto & GetAllOutputDataFields()
Output schemes registered on this thread.
Definition RMGRunAction.hh:72
void EndOfRunAction(const G4Run *) override
Close the output file and move the temporary worker file to its final path.
Definition RMGRunAction.cc:212
int GetCurrentRunPrintModulo() const
Print-modulo value chosen for the run currently being processed.
Definition RMGRunAction.hh:69
G4Run * GenerateRun() override
Allocate and return an RMGRun instance for the current run.
Definition RMGRunAction.cc:46
Per-run object extending G4Run with bookkeeping needed by remage.
Definition RMGRun.hh:29