remage
Simulation framework for HPGe-based experiments
 
Loading...
Searching...
No Matches
RMGOutputManager.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_OUTPUT_MANAGER_HH_
17#define _RMG_OUTPUT_MANAGER_HH_
18
19#include <atomic>
20#include <memory>
21#include <set>
22#include <vector>
23
24#include "G4AnalysisManager.hh"
25#include "G4GenericMessenger.hh"
26#include "G4Threading.hh"
27#include "globals.hh"
28
29#include "RMGLog.hh"
30
37class RMGOutputManager {
38
39 public:
40
41 RMGOutputManager();
42 ~RMGOutputManager() = default;
43
44 RMGOutputManager(RMGOutputManager const&) = delete;
45 RMGOutputManager& operator=(RMGOutputManager const&) = delete;
46 RMGOutputManager(RMGOutputManager&&) = delete;
47 RMGOutputManager& operator=(RMGOutputManager&&) = delete;
48
49 // getters
56 static RMGOutputManager* Instance() {
57 if (!fRMGOutputManager) fRMGOutputManager = new RMGOutputManager();
58 return fRMGOutputManager;
59 }
60
65 [[nodiscard]] bool IsPersistencyEnabled() const { return fIsPersistencyEnabled; }
70 const std::string& GetOutputFileName() { return fOutputFile; }
75 [[nodiscard]] bool HasOutputFileNameNone() const { return fOutputFile == OUTPUT_FILE_NONE; }
80 [[nodiscard]] bool HasOutputFileName() const {
81 return !fOutputFile.empty() && fOutputFile != OUTPUT_FILE_NONE;
82 }
83
87 [[nodiscard]] bool GetOutputOverwriteFiles() const { return fOutputOverwriteFiles; }
92 const std::string& GetOutputNtupleDirectory() { return fOutputNtupleDirectory; }
97 [[nodiscard]] bool GetOutputNtuplePerDetector() const { return fOutputNtuplePerDetector; }
102 [[nodiscard]] bool GetOutputNtupleUseVolumeName() const { return fOutputNtupleUseVolumeName; }
103
108 const std::map<int, std::pair<int, std::string>>& GetNtupleIDs() { return fNtupleIDs; }
113 std::set<std::string> GetAuxNtupleNames() {
114 std::set<std::string> nt_names;
115 for (auto const& [k, v] : fNtupleAuxIDs) nt_names.insert(k);
116 return nt_names;
117 }
118
119 // setters
124 void EnablePersistency(bool flag = true) { fIsPersistencyEnabled = flag; }
125
130 void SetOutputFileName(std::string filename) { fOutputFile = filename; }
135 void SetOutputOverwriteFiles(bool overwrite) { fOutputOverwriteFiles = overwrite; }
141 void SetOutputNtupleDirectory(std::string dir) { fOutputNtupleDirectory = dir; }
142
151 int RegisterNtuple(int det_uid, int ntuple_id, std::string table_name);
166 int det_uid,
167 std::string table_name,
168 std::string oscheme,
169 G4AnalysisManager* ana_man
170 );
184 std::string table_name,
185 std::string oscheme,
186 G4AnalysisManager* ana_man
187 );
193 int GetNtupleID(int det_uid) { return fNtupleIDs[det_uid].first; }
199 int GetAuxNtupleID(std::string det_uid) { return fNtupleAuxIDs[det_uid]; }
200
205 // NOLINTNEXTLINE(readability-make-member-function-const)
206 void ActivateOptionalOutputScheme(std::string name);
207
208 private:
209
210 static inline const std::string OUTPUT_FILE_NONE = "none";
211 std::string fOutputFile;
212 bool fIsPersistencyEnabled = true;
213 bool fOutputOverwriteFiles = false;
214 bool fOutputNtuplePerDetector = true;
215 bool fOutputNtupleUseVolumeName = false;
216 std::string fOutputNtupleDirectory = "stp";
217
228 static G4ThreadLocal std::map<int, std::pair<int, std::string>> fNtupleIDs;
229
241 static G4ThreadLocal std::map<std::string, int> fNtupleAuxIDs;
242
243 static RMGOutputManager* fRMGOutputManager;
244
245 // messenger stuff
246 std::unique_ptr<G4GenericMessenger> fOutputMessenger;
247 void DefineCommands();
248};
249
250#endif
251
252// vim: tabstop=2 shiftwidth=2 expandtab
Manages output operations including ntuple registration and persistent storage.
Definition RMGOutputManager.hh:37
int CreateAndRegisterNtuple(int det_uid, std::string table_name, std::string oscheme, G4AnalysisManager *ana_man)
Creates and registers a ntuple for a given detector.
Definition RMGOutputManager.cc:56
void ActivateOptionalOutputScheme(std::string name)
Activates an optional output scheme.
Definition RMGOutputManager.cc:85
void SetOutputOverwriteFiles(bool overwrite)
Configures whether output files should be overwritten.
Definition RMGOutputManager.hh:135
bool IsPersistencyEnabled() const
Checks if persistency is enabled.
Definition RMGOutputManager.hh:65
const std::string & GetOutputFileName()
Retrieves the output file name.
Definition RMGOutputManager.hh:70
void SetOutputFileName(std::string filename)
Sets the output file name.
Definition RMGOutputManager.hh:130
const std::map< int, std::pair< int, std::string > > & GetNtupleIDs()
Retrieves the set of registered ntuple detector identifiers.
Definition RMGOutputManager.hh:108
bool GetOutputNtupleUseVolumeName() const
Checks if volume names are used for output ntuple naming.
Definition RMGOutputManager.hh:102
bool GetOutputOverwriteFiles() const
Indicates whether output files should be overwritten.
Definition RMGOutputManager.hh:87
int CreateAndRegisterAuxNtuple(std::string table_name, std::string oscheme, G4AnalysisManager *ana_man)
Creates and registers an auxiliary ntuple.
Definition RMGOutputManager.cc:70
void EnablePersistency(bool flag=true)
Enables or disables output persistency.
Definition RMGOutputManager.hh:124
static RMGOutputManager * Instance()
Gets the singleton instance of RMGOutputManager.
Definition RMGOutputManager.hh:56
int GetNtupleID(int det_uid)
Gets the ntuple identifier for a given detector.
Definition RMGOutputManager.hh:193
void SetOutputNtupleDirectory(std::string dir)
Sets the directory for output ntuples.
Definition RMGOutputManager.hh:141
std::set< std::string > GetAuxNtupleNames()
Retrieves the set of registered auxiliary ntuple identifiers.
Definition RMGOutputManager.hh:113
bool GetOutputNtuplePerDetector() const
Checks if output ntuples are generated per detector.
Definition RMGOutputManager.hh:97
int GetAuxNtupleID(std::string det_uid)
Gets the auxiliary ntuple identifier for a given key.
Definition RMGOutputManager.hh:199
bool HasOutputFileNameNone() const
Checks if the output file name is set to "none".
Definition RMGOutputManager.hh:75
bool HasOutputFileName() const
Checks if a valid output file name is set.
Definition RMGOutputManager.hh:80
const std::string & GetOutputNtupleDirectory()
Gets the directory name for output ntuples.
Definition RMGOutputManager.hh:92
int RegisterNtuple(int det_uid, int ntuple_id, std::string table_name)
Registers an alreaday created ntuple for a given detector.
Definition RMGOutputManager.cc:49