35#include "tools/hdf5/h2file"
48const G4String G4Hdf5FileManager::fgkDefaultDirectoryName =
"default";
56 fH1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h1d>>(
this);
57 fH2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h2d>>(
this);
58 fH3FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h3d>>(
this);
59 fP1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p1d>>(
this);
60 fP2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p2d>>(
this);
72hid_t G4Hdf5FileManager::CreateDirectory(hid_t& file,
78 if ( file < 0 )
return false;
81 auto newDirectoryName = directoryName;
82 if ( newDirectoryName ==
"" ) {
83 newDirectoryName = fgkDefaultDirectoryName;
84 newDirectoryName +=
"_";
85 newDirectoryName += objectType;
91 ->
Message(
"create",
"directory for " + objectType, newDirectoryName);
98 auto directory = tools_H5Gcreate(file, newDirectoryName, 0);
102 if ( directory < 0 ) {
105 <<
"cannot create directory " << directoryName;
106 G4Exception(
"G4Hdf5FileManager::CreateDirectory()",
112 auto result = hdf5::write_atb(directory,
"type",
"directory");
116 <<
"write_atb class failed for " << directoryName;
117 G4Exception(
"G4Hdf5FileManager::CreateDirectory()",
126 ->
Message(
"create",
"directory for " + objectType, newDirectoryName, success);
136 auto ntupleFileName = ntupleDescription->
fFileName;
137 if ( ntupleFileName.size() ) {
144 return ntupleFileName;
155 hid_t file = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
161 description <<
" " <<
"::H5Fcreate failed " << fileName;
162 G4Exception(
"G4Hdf5AnalysisManager::CreateFileImpl()",
164 return std::make_shared<G4Hdf5File>(-1, -1, -1);
168 if(!tools::hdf5::write_header(file)) {
170 description <<
" " <<
"tools::hdf5::write_header() failed for " << fileName;
171 G4Exception(
"G4Hdf5AnalysisManager::CreateFileImpl()",
173 return std::make_shared<G4Hdf5File>(-1, -1, -1);
179 if ( hdirectory < 0 ) {
181 return std::make_shared<G4Hdf5File>(-1, -1, -1);
187 if ( ndirectory < 0 ) {
189 return std::make_shared<G4Hdf5File>(-1, -1, -1);
192 return std::make_shared<G4Hdf5File>(file, hdirectory, ndirectory);
205 if ( ! file )
return false;
209 ::H5Gclose(std::get<1>(*file));
210 ::H5Gclose(std::get<2>(*file));
211 ::H5Fclose(std::get<0>(*file));
232 <<
"File " << fileName <<
" already exists.";
242 description <<
"Failed to create file " << fileName;
259 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
261 auto file =
GetTFile(ntupleFileName,
false);
265 ntupleDescription->
fFile = file;
267 return (ntupleDescription->
fFile !=
nullptr);
275 if ( ! ntupleDescription->
fFile )
return true;
278 ntupleDescription->
fFile.reset();
281 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
292 return std::get<1>(*
fFile);
300 return std::get<2>(*
fFile);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
#define G4MUTEX_INITIALIZER
const G4AnalysisVerbose * GetVerboseL2() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisManagerState & fState
virtual G4bool CloseFileImpl(std::shared_ptr< G4Hdf5File > file) final
virtual G4String GetFileType() const final
hid_t GetNtupleDirectory() const
virtual G4bool OpenFile(const G4String &fileName) final
G4bool CreateNtupleFile(Hdf5NtupleDescription *ntupleDescription)
G4Hdf5FileManager(const G4AnalysisManagerState &state)
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
std::shared_ptr< FT > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< FT > 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
G4bool fLockDirectoryNames
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)
std::shared_ptr< TF > fFile