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 ( ! fIsOpenFile )
return true;
132 if ( fState.GetVerboseL4() )
133 fState.GetVerboseL4()->Message(
"write",
"file", fileName);
137 auto result = rfile->write(n);
140 if ( fState.GetVerboseL1() )
141 fState.GetVerboseL1()->Message(
"write",
"file", fileName,
result);
156 if ( ! fIsOpenFile )
return true;
159 if ( fState.GetVerboseL4() )
160 fState.GetVerboseL4()->Message(
"close",
"file", fileName);
166 if ( fState.GetVerboseL1() )
167 fState.GetVerboseL1()->Message(
"close",
"file", fileName,
true);
187 fFile = std::make_shared<tools::wroot::file>(
G4cout,
name);
188 fFile->add_ziper(
'Z',tools::compress_buffer);
191 if ( ! fFile->is_open() ) {
194 description <<
" " <<
"Cannot open file " << fileName;
219 auto finalResult =
true;
222 finalResult = finalResult &&
result;
225 for (
auto ntupleFile : fNtupleFiles ) {
227 finalResult = finalResult &&
result;
235 auto finalResult =
true;
238 finalResult = finalResult &&
result;
241 for (
auto ntupleFile : fNtupleFiles ) {
243 finalResult = finalResult &&
result;
257 fHistoDirectory = &(fFile->dir());
268 if ( ! fHistoDirectory ) {
272 G4Exception(
"G4RootFileManager::CreateHistoDirectory()",
291 fNtupleDirectory = &(fFile->dir());
302 if ( ! fNtupleDirectory ) {
306 G4Exception(
"G4RootFileManager::CreateNtupleDirectory()",
321 std::shared_ptr<tools::wroot::file>
324 if ( index==0 && ( ! fNtupleFiles.size() ) )
return fFile;
326 if ( index < 0 || index >=
G4int(fNtupleFiles.size()) ) {
327 G4String inFunction =
"G4RootFileManager::GetNtupleFile()";
329 description <<
" " <<
"ntuple file " << index <<
" does not exist.";
334 return fNtupleFiles[index];
338 tools::wroot::directory*
341 if ( index==0 && ( ! fMainNtupleDirectories.size() ) )
return fNtupleDirectory;
343 if ( index < 0 || index >=
G4int(fMainNtupleDirectories.size()) ) {
344 G4String inFunction =
"G4RootFileManager::GetMainNtupleDirectory()";
346 description <<
" " <<
"main ntuple directory " << index <<
" does not exist.";
351 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