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);
60 const G4String& directoryName, [[maybe_unused]]
const G4String& objectType)
const
62 if ( ! rfile )
return nullptr;
64 if ( directoryName ==
"" ) {
66 return &(rfile->dir());
69 Message(
kVL4,
"create",
"directory for " + objectType, directoryName);
71 auto directory = rfile->dir().mkdir(directoryName);
73 Warn(
"Cannot create directory " + directoryName,
fkClass,
"CreateDirectory");
77 Message(
kVL2,
"create",
"directory for " + objectType, directoryName);
87 G4int mainNumber)
const
91 auto ntupleFileName = ntupleDescription->
fFileName;
92 if ( ntupleFileName.size() ) {
102 if ( mainNumber > -1 ) {
108 return ntupleFileName;
116std::shared_ptr<G4RootFile>
120 std::shared_ptr<wroot::file>
file = std::make_shared<wroot::file>(
G4cout, fileName);
121 file->add_ziper(
'Z',compress_buffer);
124 if ( !
file->is_open() ) {
125 Warn(
"Cannot create file " + fileName,
fkClass,
"CreateFileImpl");
126 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
130 tools::wroot::directory* hdirectory
132 if ( ! hdirectory ) {
134 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
138 tools::wroot::directory* ndirectory
140 if ( ! ndirectory ) {
142 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
145 return std::make_shared<G4RootFile>(
file, hdirectory, ndirectory);
153 if ( !
file )
return false;
156 return std::get<0>(*file)->write(
n);
164 if ( !
file )
return false;
167 std::get<0>(*file)->close();
185 Warn(
"File " + fileName +
" already exists.",
fkClass,
"OpenFile");
192 Warn(
"Failed to create file " + fileName,
fkClass,
"OpenFile");
207 auto perThread =
true;
208 auto ntupleFileName =
GetNtupleFileName(ntupleDescription, perThread, mainNumber);
217 if ( mainNumber == -1 ) {
229 auto ntupleFileName =
GetNtupleFileName(ntupleDescription, perThread, mainNumber);
231 return GetTFile(ntupleFileName,
false);
240 if ( ntupleDescription->
fFile ) {
243 ntupleDescription->
fFile.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
static constexpr std::string_view fkClass
G4bool CloseNtupleFile(RootNtupleDescription *ntupleDescription)
virtual std::shared_ptr< G4RootFile > CreateFileImpl(const G4String &fileName) final
tools::wroot::directory * CreateDirectory(tools::wroot::file *rfile, const G4String &directoryName, const G4String &objectType) const
G4String GetNtupleFileName(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
virtual G4String GetFileType() const final
virtual G4bool CloseFileImpl(std::shared_ptr< G4RootFile > file) final
G4RootFileManager()=delete
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
virtual G4bool OpenFile(const G4String &fileName) final
virtual G4bool WriteFileImpl(std::shared_ptr< G4RootFile > file) final
std::shared_ptr< G4RootFile > CreateNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
std::shared_ptr< G4RootFile > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< G4RootFile > 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< G4RootFile > fFile
G4String GetTnFileName(const G4String &fileName, const G4String &fileType)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)
const char * name(G4int ptype)
std::shared_ptr< FT > fFile