34 #include "tools/wroot/file"
40 using namespace G4Analysis;
46 fHistoDirectory(nullptr),
47 fNtupleDirectory(nullptr),
50 fMainNtupleDirectories(),
63 G4bool G4RootFileManager::OpenNtupleFiles()
65 auto finalResult =
true;
67 for (
auto i = 0; i < fNofNtupleFiles; i++ ) {
78 auto rfile = std::make_shared<tools::wroot::file>(
G4cout,
name);
79 rfile->add_ziper(
'Z', tools::compress_buffer);
82 if ( ! rfile->is_open() ) {
84 description <<
" " <<
"Cannot open file " <<
name;
93 tools::wroot::directory* directory = &rfile->dir();
100 G4Exception(
"G4RootFileManager::OpenNtupleFiles()",
102 directory = &fFile->dir();
106 fNtupleFiles.push_back(rfile);
107 fMainNtupleDirectories.push_back(directory);
129 if ( fState.GetVerboseL4() )
130 fState.GetVerboseL4()->Message(
"write",
"file", fileName);
134 auto result = rfile->write(n);
137 if ( fState.GetVerboseL1() )
138 fState.GetVerboseL1()->Message(
"write",
"file", fileName,
result);
153 if ( fState.GetVerboseL4() )
154 fState.GetVerboseL4()->Message(
"close",
"file", fileName);
160 if ( fState.GetVerboseL1() )
161 fState.GetVerboseL1()->Message(
"close",
"file", fileName,
true);
181 fFile = std::make_shared<tools::wroot::file>(
G4cout,
name);
182 fFile->add_ziper(
'Z',tools::compress_buffer);
185 if ( ! fFile->is_open() ) {
187 description <<
" " <<
"Cannot open file " << fileName;
212 auto finalResult =
true;
215 finalResult = finalResult &&
result;
218 for (
auto ntupleFile : fNtupleFiles ) {
220 finalResult = finalResult &&
result;
228 auto finalResult =
true;
231 finalResult = finalResult &&
result;
234 for (
auto ntupleFile : fNtupleFiles ) {
236 finalResult = finalResult &&
result;
250 fHistoDirectory = &(fFile->dir());
261 if ( ! fHistoDirectory ) {
265 G4Exception(
"G4RootFileManager::CreateHistoDirectory()",
284 fNtupleDirectory = &(fFile->dir());
295 if ( ! fNtupleDirectory ) {
299 G4Exception(
"G4RootFileManager::CreateNtupleDirectory()",
314 std::shared_ptr<tools::wroot::file>
317 if ( index==0 && ( ! fNtupleFiles.size() ) )
return fFile;
319 if ( index < 0 || index >=
G4int(fNtupleFiles.size()) ) {
320 G4String inFunction =
"G4RootFileManager::GetNtupleFile()";
322 description <<
" " <<
"ntuple file " << index <<
" does not exist.";
327 return fNtupleFiles[index];
331 tools::wroot::directory*
334 if ( index==0 && ( ! fMainNtupleDirectories.size() ) )
return fNtupleDirectory;
336 if ( index < 0 || index >=
G4int(fMainNtupleDirectories.size()) ) {
337 G4String inFunction =
"G4RootFileManager::GetMainNtupleDirectory()";
339 description <<
" " <<
"main ntuple directory " << index <<
" does not exist.";
344 return fMainNtupleDirectories[index];
G4double G4ParticleHPJENDLHEData::G4double result
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4bool CreateNtupleDirectory()
const G4AnalysisManagerState & fState
G4bool fLockHistoDirectoryName
G4int GetCompressionLevel() const
G4String fNtupleDirectoryName
std::ostringstream G4ExceptionDescription
G4String GetNtupleFileName(const G4String &ntupleName) const
G4bool CreateHistoDirectory()
virtual G4bool CloseFile() final
virtual G4bool WriteFile() final
G4String fHistoDirectoryName
const G4AnalysisVerbose * GetVerboseL2() const
std::shared_ptr< tools::wroot::file > GetNtupleFile(G4int index) const
G4RootFileManager(const G4AnalysisManagerState &state)
G4GLOB_DLL std::ostream G4cout
virtual G4bool OpenFile(const G4String &fileName) final
const G4AnalysisVerbose * GetVerboseL4() const
virtual ~G4RootFileManager()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4bool fLockNtupleDirectoryName
tools::wroot::directory * GetMainNtupleDirectory(G4int index) const
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisVerbose * GetVerboseL1() const