10 #ifndef GGSROOTFILESERVICE_H_
11 #define GGSROOTFILESERVICE_H_
16 #include <unordered_map>
19 #include "ROOT/TBufferMerger.hxx"
21 #include "TObjString.h"
25 #include "G4GenericMessenger.hh"
27 #include "G4VPhysicalVolume.hh"
69 TFile *
GetFileForThisRun(
const std::filesystem::path &baseName,
const G4Run *run);
114 void SetSuffix(
const std::string &suffix) { _suffix = suffix; }
140 int StoreVolume(TFile *tFilePtr,
const std::string &detector,
const G4VPhysicalVolume *volume,
141 const G4ThreeVector &position,
int id);
169 std::filesystem::path _GetAbsolutePath(
const std::filesystem::path &baseName);
170 std::filesystem::path _AppendSuffixAndExt(
const std::filesystem::path &baseName,
const G4Run *run);
172 void _SetMultiFileMode();
175 void _FillDefaultEventsTrees();
180 const G4VPhysicalVolume *physVol;
181 G4ThreeVector position;
183 VolumeKey(
const std::string &volName,
const G4VPhysicalVolume *physVolPtr,
const G4ThreeVector &pos)
184 : name(volName), physVol(physVolPtr), position(pos) {}
185 bool operator==(
const VolumeKey &rhs)
const {
186 return (name == rhs.name && physVol == rhs.physVol && position == rhs.position);
189 friend struct std::hash<VolumeKey>;
192 friend struct std::hash<VolumeKey>;
195 typedef std::unordered_map<VolumeKey, G4int, std::hash<VolumeKey>>
197 typedef std::list<std::pair<std::string, HitVolMap>> HitDetMap;
201 std::filesystem::path absPath;
202 std::unique_ptr<ROOT::TBufferMerger> bufferMerger;
203 HitDetMap detectorsMap;
204 TClonesArray *detectorsArray;
209 std::shared_ptr<TFile> tFile;
210 TTree *defaultEventsTree;
214 std::vector<TFileInfo> tFilesInfo;
217 typedef std::list<FileInfo> FileInfoContainer;
219 FileInfoContainer _filesInfo;
222 std::filesystem::path _defaultOutBase;
223 bool _singleFileForMT;
227 G4GenericMessenger _messenger;
230 G4ThreadLocalStatic TFile *_currVolStorageTFile;
231 G4ThreadLocalStatic std::string _currDetVolName;
232 G4ThreadLocalStatic FileInfoContainer::iterator _currVolStorageFileInfo;
233 G4ThreadLocalStatic HitDetMap::iterator _currDetector;
void SetDefaultFileBase(const std::filesystem::path &newFileBase)
Sets the default file name.
OutputMode
Aliases for the different output modes.
OutputMode GetOutputMode()
Gets the ouptut mode.
Class to store detector informations.
int StoreVolume(TFile *tFilePtr, const std::string &detector, const G4VPhysicalVolume *volume, const G4ThreeVector &position, int id)
Set persistence for the specified volume.
TFile * GetFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
void CloseFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Closes the ROOT output file.
A multiplexer container for user actions.
Singleton for a centralized ROOT files management.
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void SetSuffix(const std::string &suffix)
Sets the suffix for file names.
void SetSimInfo(const GGSTSimInfo &simInfo)
Set the simulation info object to be saved on output files.
A class to store simulation informations.