34#include "tools/wroot/file"
35#include "tools/wroot/to"
51 fH1FileManager = std::make_shared<G4RootHnFileManager<histo::h1d>>(
this);
52 fH2FileManager = std::make_shared<G4RootHnFileManager<histo::h2d>>(
this);
53 fH3FileManager = std::make_shared<G4RootHnFileManager<histo::h3d>>(
this);
54 fP1FileManager = std::make_shared<G4RootHnFileManager<histo::p1d>>(
this);
55 fP2FileManager = std::make_shared<G4RootHnFileManager<histo::p2d>>(
this);
67tools::wroot::directory* G4RootFileManager::CreateDirectory(
68 std::shared_ptr<tools::wroot::file> rfile,
75 if ( ! rfile )
return nullptr;
77 if ( directoryName ==
"" ) {
79 return &(rfile->dir());
83 if ( fState.GetVerboseL4() )
85 ->Message(
"create",
"directory for " + objectType, directoryName);
88 auto directory = rfile->dir().mkdir(directoryName);
92 <<
"cannot create directory " << directoryName;
99 if ( fState.GetVerboseL2() )
100 fState.GetVerboseL2()
101 ->Message(
"create",
"directory for " + objectType, directoryName);
108G4String G4RootFileManager::GetNtupleFileName(
111 G4int mainNumber)
const
115 auto ntupleFileName = ntupleDescription->
fFileName;
116 if ( ntupleFileName.size() ) {
126 if ( mainNumber > -1 ) {
132 return ntupleFileName;
140std::shared_ptr<G4RootFile>
144 std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(
G4cout, fileName);
145 file->add_ziper(
'Z',compress_buffer);
148 if ( ! file->is_open() ) {
150 description <<
" " <<
"Cannot create file " << fileName;
153 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
157 tools::wroot::directory* hdirectory
159 if ( ! hdirectory ) {
161 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
165 tools::wroot::directory* ndirectory
167 if ( ! ndirectory ) {
169 return std::make_shared<G4RootFile>(
nullptr,
nullptr,
nullptr);
172 return std::make_shared<G4RootFile>(file, hdirectory, ndirectory);
180 if ( ! file )
return false;
183 return std::get<0>(*file)->write(n);
191 if ( ! file )
return false;
194 std::get<0>(*file)->close();
213 description <<
"File " << fileName <<
" already exists.";
223 description <<
"Failed to create file " << fileName;
240 auto perThread =
true;
241 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
243 auto file =
GetTFile(ntupleFileName,
false);
250 if ( mainNumber == -1 ) {
251 ntupleDescription->
fFile = file;
262 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
264 return GetTFile(ntupleFileName,
false);
271 auto finalResult =
true;
273 if ( ntupleDescription->
fFile ) {
276 ntupleDescription->
fFile.reset();
278 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
280 finalResult = result && finalResult;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
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
const G4AnalysisManagerState & fState
G4bool CloseNtupleFile(RootNtupleDescription *ntupleDescription)
virtual std::shared_ptr< G4RootFile > CreateFileImpl(const G4String &fileName) final
virtual ~G4RootFileManager()
virtual G4String GetFileType() const final
G4RootFileManager(const G4AnalysisManagerState &state)
virtual G4bool CloseFileImpl(std::shared_ptr< G4RootFile > file) final
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< 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< G4RootFile > fFile
G4String GetTnFileName(const G4String &fileName, const G4String &fileType)
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)
std::shared_ptr< TF > fFile