35#include "toolx/hdf5/h2file"
52 fH1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h1d>>(
this);
53 fH2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h2d>>(
this);
54 fH3FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h3d>>(
this);
55 fP1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p1d>>(
this);
56 fP2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p2d>>(
this);
64hid_t G4Hdf5FileManager::CreateDirectory(hid_t& file,
73 auto newDirectoryName = directoryName;
74 if ( newDirectoryName ==
"" ) {
75 newDirectoryName = fgkDefaultDirectoryName;
76 newDirectoryName +=
"_";
77 newDirectoryName += objectType;
80 Message(
kVL4,
"create",
"directory for " + objectType, newDirectoryName);
85 auto directory = toolx_H5Gcreate(file, newDirectoryName, 0);
89 if ( directory < 0 ) {
90 Warn(
"Cannot create directory " + directoryName,
91 fkClass,
"CreateDirectory");
96 auto result = toolx::hdf5::write_atb(directory,
"type",
"directory");
98 Warn(
"Write_atb class failed for " + directoryName,
99 fkClass,
"CreateDirectory");
104 Message(
kVL2,
"create",
"directory for " + objectType, newDirectoryName, success);
113 auto ntupleFileName = ntupleDescription->
GetFileName();
114 if (ntupleFileName.size() != 0u) {
122 return ntupleFileName;
133 hid_t file = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
138 Warn(
"::H5Fcreate failed " + fileName, fkClass,
"CreateFileImpl");
139 return std::make_shared<G4Hdf5File>(-1, -1, -1);
143 if(!toolx::hdf5::write_header(file)) {
144 Warn(
"toolx::hdf5::write_header() failed for " + fileName,
145 fkClass,
"CreateFileImpl");
146 return std::make_shared<G4Hdf5File>(-1, -1, -1);
152 if ( hdirectory < 0 ) {
154 return std::make_shared<G4Hdf5File>(-1, -1, -1);
160 if ( ndirectory < 0 ) {
162 return std::make_shared<G4Hdf5File>(-1, -1, -1);
165 return std::make_shared<G4Hdf5File>(file, hdirectory, ndirectory);
178 if ( ! file )
return false;
182 ::H5Gclose(std::get<1>(*file));
183 ::H5Gclose(std::get<2>(*file));
184 ::H5Fclose(std::get<0>(*file));
203 Warn(
"File " + fileName +
" already exists.", fkClass,
"OpenFile");
210 Warn(
"Failed to create file " + fileName, fkClass,
"OpenFile");
225 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
227 auto file =
GetTFile(ntupleFileName,
false);
231 ntupleDescription->
SetFile(file);
233 return (ntupleDescription->
GetFile() !=
nullptr);
241 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
246 ntupleDescription->
GetFile().reset();
256 return std::get<1>(*
fFile);
264 return std::get<2>(*
fFile);
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
#define G4MUTEX_INITIALIZER
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
G4bool CloseFileImpl(std::shared_ptr< G4Hdf5File > file) final
G4String GetFileType() const final
hid_t GetNtupleDirectory() const
G4bool OpenFile(const G4String &fileName) final
G4bool CreateNtupleFile(Hdf5NtupleDescription *ntupleDescription)
std::shared_ptr< G4Hdf5File > CreateFileImpl(const G4String &fileName) final
hid_t GetHistoDirectory() const
G4bool CloseNtupleFile(Hdf5NtupleDescription *ntupleDescription)
G4bool WriteFileImpl(std::shared_ptr< G4Hdf5File > file) final
G4Hdf5FileManager()=delete
std::shared_ptr< FT > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< FT > CreateTFile(const G4String &fileName)
void SetFile(std::shared_ptr< FT > file)
G4bool GetHasFill() const
std::shared_ptr< FT > GetFile() const
G4String GetFileName() const
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::h1d > > fH1FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager
G4String fNtupleDirectoryName
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager
void LockDirectoryNames()
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager
G4String fHistoDirectoryName
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
std::shared_ptr< G4Hdf5File > fFile
G4String GetTnFileName(const G4String &fileName, const G4String &fileType, G4int cycle=0)
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)