34#include "tools/wroot/file"
35#include "tools/wroot/to"
46 fH1FileManager = std::make_shared<G4RootHnFileManager<histo::h1d>>(
this);
47 fH2FileManager = std::make_shared<G4RootHnFileManager<histo::h2d>>(
this);
48 fH3FileManager = std::make_shared<G4RootHnFileManager<histo::h3d>>(
this);
49 fP1FileManager = std::make_shared<G4RootHnFileManager<histo::p1d>>(
this);
50 fP2FileManager = std::make_shared<G4RootHnFileManager<histo::p2d>>(
this);
58tools::wroot::directory* G4RootFileManager::CreateDirectory(
59 tools::wroot::file* rfile,
60 const G4String& directoryName, [[maybe_unused]]
const G4String& objectType)
const
62 if (rfile ==
nullptr)
return nullptr;
64 if ( directoryName ==
"" ) {
66 return &(rfile->dir());
69 Message(
kVL4,
"create",
"directory for " + objectType, directoryName);
71 auto directory = rfile->dir().mkdir(directoryName);
72 if (directory ==
nullptr) {
73 Warn(
"Cannot create directory " + directoryName, fkClass,
"CreateDirectory");
76 Message(
kVL2,
"create",
"directory for " + objectType, directoryName);
82G4String G4RootFileManager::GetNtupleFileName(
85 G4int mainNumber)
const
89 auto ntupleFileName = ntupleDescription->
GetFileName();
90 if (ntupleFileName.size() != 0u) {
101 if ( mainNumber > -1 ) {
107 return ntupleFileName;
115std::shared_ptr<G4RootFile>
119 std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(
G4cout, fileName);
120 file->add_ziper(
'Z',toolx::compress_buffer);
123 if ( ! file->is_open() ) {
124 Warn(
"Cannot create file " + fileName, fkClass,
"CreateFileImpl");
125 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
129 tools::wroot::directory* hdirectory
131 if (hdirectory ==
nullptr) {
133 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
137 tools::wroot::directory* ndirectory
139 if (ndirectory ==
nullptr) {
141 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
144 return std::make_shared<G4RootFile>(file, hdirectory, ndirectory);
153 return (file ==
nullptr) ? false :
true;
162 if (file ==
nullptr)
return false;
166 std::get<0>(*file)->write(n);
169 std::get<0>(*file)->close();
187 Warn(
"File " + fileName +
" already exists.", fkClass,
"OpenFile");
194 Warn(
"Failed to create file " + fileName, fkClass,
"OpenFile");
209 auto perThread =
true;
210 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
212 auto file =
GetTFile(ntupleFileName,
false);
219 if ( mainNumber == -1 ) {
220 ntupleDescription->
SetFile(file);
231 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
233 return GetTFile(ntupleFileName,
false);
243 auto ntupleFileName = GetNtupleFileName(ntupleDescription,
true, mainNumber);
247 ntupleDescription->
GetFile().reset();
std::tuple< std::shared_ptr< tools::wroot::file >, tools::wroot::directory *, tools::wroot::directory * > G4RootFile
G4GLOB_DLL std::ostream G4cout
G4int GetCompressionLevel() const
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
const G4AnalysisManagerState & fState
std::shared_ptr< G4RootFile > CreateFileImpl(const G4String &fileName) final
G4bool CloseNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
G4bool CloseFileImpl(std::shared_ptr< G4RootFile > file) final
G4RootFileManager()=delete
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
G4bool OpenFile(const G4String &fileName) final
G4bool WriteFileImpl(std::shared_ptr< G4RootFile > file) final
std::shared_ptr< G4RootFile > CreateNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
G4String GetFileType() const final
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< G4RootFile > fFile
G4String GetTnFileName(const G4String &fileName, const G4String &fileType, G4int cycle=0)
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName, G4int cycle=0)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)