34#include "toolx/hdf5/h2file"
35#include "toolx/hdf5/group_exists"
46 fH1RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h1d>>(
this);
47 fH2RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h2d>>(
this);
48 fH3RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h3d>>(
this);
49 fP1RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::p1d>>(
this);
50 fP2RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::p2d>>(
this);
58hid_t G4Hdf5RFileManager::OpenRFile(
const G4String& fileName,
67 hid_t newFile = H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
69 Warn(
"Cannot open file " + name, fkClass,
"OpenRFile");
84hid_t G4Hdf5RFileManager::OpenDirectory(hid_t file,
const G4String& directoryName)
86 Message(
kVL4,
"open",
"read directory", directoryName);
88 auto directory = toolx_H5Gopen(file, directoryName);
89 if ( directory < 0 ) {
90 Warn(
"Cannot open directory " + directoryName, fkClass,
"OpenDirectory");
93 Message(
kVL2,
"open",
"read directory", directoryName);
98hid_t G4Hdf5RFileManager::GetRDirectory(
const G4String& directoryType,
104 auto rfile =
GetRFile(fileName, isPerThread);
105 if (rfile ==
nullptr) {
107 if ( OpenRFile(fileName, isPerThread) < 0 )
return kInvalidId;
108 rfile =
GetRFile(fileName, isPerThread);
111 auto isHistograms = (directoryType ==
"histograms");
115 if ( isHistograms ) {
116 directory = std::get<1>(*rfile);
118 directory = std::get<2>(*rfile);
125 auto newDirName = dirName;
126 if ( newDirName ==
"" ) {
129 newDirName = fgkDefaultDirectoryName;
131 newDirName += directoryType;
135 directory = OpenDirectory(std::get<0>(*rfile), newDirName);
138 if ( isHistograms ) {
139 std::get<1>(*rfile) = directory;
141 std::get<2>(*rfile) = directory;
158 auto it = fRFiles.find(name);
159 if (it != fRFiles.end()) {
160 return &(it->second);
169 return GetRDirectory(
"histograms", fileName, dirName, isPerThread);
176 return GetRDirectory(
"ntuples", fileName, dirName, isPerThread);
183 for (
auto [key, rfile] : fRFiles ) {
185 ::H5Gclose(std::get<1>(rfile));
188 ::H5Gclose(std::get<2>(rfile));
191 ::H5Fclose(std::get<0>(rfile));
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4Hdf5File * GetRFile(const G4String &fileName, G4bool isPerThread)
hid_t GetNtupleRDirectory(const G4String &fileName, const G4String &dirName, G4bool isPerThread)
hid_t GetHistoRDirectory(const G4String &fileName, const G4String &dirName, G4bool isPerThread)
G4Hdf5RFileManager()=delete
std::shared_ptr< G4VTHnRFileManager< tools::histo::h2d > > fH2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::p2d > > fP2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h3d > > fH3RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::p1d > > fP1RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h1d > > fH1RFileManager
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
const char * name(G4int ptype)