35#include "tools/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);
70 if (
file < 0 )
return false;
73 auto newDirectoryName = directoryName;
74 if ( newDirectoryName ==
"" ) {
76 newDirectoryName +=
"_";
77 newDirectoryName += objectType;
80 Message(
kVL4,
"create",
"directory for " + objectType, newDirectoryName);
85 auto directory = tools_H5Gcreate(
file, newDirectoryName, 0);
89 if ( directory < 0 ) {
90 Warn(
"Cannot create directory " + directoryName,
96 auto result = hdf5::write_atb(directory,
"type",
"directory");
98 Warn(
"Write_atb class failed for " + directoryName,
104 Message(
kVL2,
"create",
"directory for " + objectType, newDirectoryName, success);
113 auto ntupleFileName = ntupleDescription->
fFileName;
114 if ( ntupleFileName.size() ) {
121 return ntupleFileName;
132 hid_t
file = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
137 Warn(
"::H5Fcreate failed " + fileName,
fkClass,
"CreateFileImpl");
138 return std::make_shared<G4Hdf5File>(-1, -1, -1);
142 if(!tools::hdf5::write_header(
file)) {
143 Warn(
"tools::hdf5::write_header() failed for " + fileName,
145 return std::make_shared<G4Hdf5File>(-1, -1, -1);
151 if ( hdirectory < 0 ) {
153 return std::make_shared<G4Hdf5File>(-1, -1, -1);
159 if ( ndirectory < 0 ) {
161 return std::make_shared<G4Hdf5File>(-1, -1, -1);
164 return std::make_shared<G4Hdf5File>(
file, hdirectory, ndirectory);
177 if ( !
file )
return false;
181 ::H5Gclose(std::get<1>(*
file));
182 ::H5Gclose(std::get<2>(*
file));
183 ::H5Fclose(std::get<0>(*
file));
202 Warn(
"File " + fileName +
" already exists.",
fkClass,
"OpenFile");
209 Warn(
"Failed to create file " + fileName,
fkClass,
"OpenFile");
232 return (ntupleDescription->
fFile !=
nullptr);
240 if ( ntupleDescription->
fFile ==
nullptr )
return true;
243 ntupleDescription->
fFile.reset();
257 return std::get<1>(*
fFile);
265 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
G4String GetNtupleFileName(Hdf5NtupleDescription *ntupleDescription)
virtual G4bool CloseFileImpl(std::shared_ptr< G4Hdf5File > file) final
hid_t CreateDirectory(hid_t &file, const G4String &directoryName, const G4String &objectType)
static constexpr std::string_view fkClass
virtual G4String GetFileType() const final
hid_t GetNtupleDirectory() const
virtual G4bool OpenFile(const G4String &fileName) final
G4bool CreateNtupleFile(Hdf5NtupleDescription *ntupleDescription)
static const G4String fgkDefaultDirectoryName
virtual std::shared_ptr< G4Hdf5File > CreateFileImpl(const G4String &fileName) final
hid_t GetHistoDirectory() const
G4bool CloseNtupleFile(Hdf5NtupleDescription *ntupleDescription)
virtual G4bool WriteFileImpl(std::shared_ptr< G4Hdf5File > file) final
G4Hdf5FileManager()=delete
std::shared_ptr< G4Hdf5File > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< G4Hdf5File > CreateTFile(const G4String &fileName)
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
virtual G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
std::shared_ptr< G4Hdf5File > fFile
G4String GetTnFileName(const G4String &fileName, const G4String &fileType)
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
const char * name(G4int ptype)
std::shared_ptr< FT > fFile