Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4RootFileManager Class Reference

#include <G4RootFileManager.hh>

Inheritance diagram for G4RootFileManager:
Collaboration diagram for G4RootFileManager:

Public Member Functions

 G4RootFileManager (const G4AnalysisManagerState &state)
 
virtual ~G4RootFileManager ()
 
virtual G4bool OpenFile (const G4String &fileName) final
 
virtual G4bool WriteFile () final
 
virtual G4bool CloseFile () final
 
G4bool CreateHistoDirectory ()
 
G4bool CreateNtupleDirectory ()
 
void SetNofNtupleFiles (G4int nofFiles)
 
void SetBasketSize (unsigned int basketSize)
 
tools::wroot::directory * GetHistoDirectory () const
 
tools::wroot::directory * GetNtupleDirectory () const
 
std::shared_ptr
< tools::wroot::file > 
GetNtupleFile (G4int index) const
 
tools::wroot::directory * GetMainNtupleDirectory (G4int index) const
 
unsigned int GetBasketSize () const
 
- Public Member Functions inherited from G4VFileManager
 G4VFileManager (const G4AnalysisManagerState &state)
 
virtual ~G4VFileManager ()
 
virtual G4bool SetFileName (const G4String &fileName) final
 
void LockHistoDirectoryName ()
 
void LockNtupleDirectoryName ()
 
G4bool SetHistoDirectoryName (const G4String &dirName)
 
G4bool SetNtupleDirectoryName (const G4String &dirName)
 
G4bool IsOpenFile () const
 
G4String GetHistoDirectoryName () const
 
G4String GetNtupleDirectoryName () const
 
- Public Member Functions inherited from G4BaseFileManager
 G4BaseFileManager (const G4AnalysisManagerState &state)
 
virtual ~G4BaseFileManager ()
 
G4String GetFileName () const
 
G4String GetFullFileName (const G4String &baseFileName="", G4bool isPerThread=true) const
 
G4String GetHnFileName (const G4String &hnType, const G4String &hnName) const
 
G4String GetNtupleFileName (const G4String &ntupleName) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber) const
 
G4String GetPlotFileName () const
 
G4String GetFileType () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4BaseFileManager
G4String TakeOffExtension (G4String &name) const
 
- Protected Attributes inherited from G4VFileManager
G4bool fIsOpenFile
 
G4String fHistoDirectoryName
 
G4String fNtupleDirectoryName
 
G4bool fLockFileName
 
G4bool fLockHistoDirectoryName
 
G4bool fLockNtupleDirectoryName
 
- Protected Attributes inherited from G4BaseFileManager
const G4AnalysisManagerStatefState
 
G4String fFileName
 

Detailed Description

Definition at line 48 of file G4RootFileManager.hh.

Constructor & Destructor Documentation

G4RootFileManager::G4RootFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 43 of file G4RootFileManager.cc.

44  : G4VFileManager(state),
45  fFile(nullptr),
46  fHistoDirectory(nullptr),
47  fNtupleDirectory(nullptr),
48  fNofNtupleFiles(0),
49  fNtupleFiles(),
50  fMainNtupleDirectories(),
51  fBasketSize(0)
52 {}
G4VFileManager(const G4AnalysisManagerState &state)
G4RootFileManager::~G4RootFileManager ( )
virtual

Definition at line 55 of file G4RootFileManager.cc.

56 {}

Member Function Documentation

G4bool G4RootFileManager::CloseFile ( )
finalvirtual

Implements G4VFileManager.

Definition at line 226 of file G4RootFileManager.cc.

227 {
228  auto finalResult = true;
229 
230  auto result = CloseFile(fFile, GetFullFileName());
231  finalResult = finalResult && result;
232 
233  auto counter = 0;
234  for ( auto ntupleFile : fNtupleFiles ) {
235  result = CloseFile(ntupleFile, GetNtupleFileName(counter++));
236  finalResult = finalResult && result;
237  }
238 
239  fLockFileName = false;
240  fIsOpenFile = false;
241 
242  return finalResult;
243 }
G4double G4ParticleHPJENDLHEData::G4double result
G4String GetNtupleFileName(const G4String &ntupleName) const
virtual G4bool CloseFile() final
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const

Here is the call graph for this function:

G4bool G4RootFileManager::CreateHistoDirectory ( )

Definition at line 246 of file G4RootFileManager.cc.

247 {
248  if ( fHistoDirectoryName == "" ) {
249  // Do not create a new directory if its name is not set
250  fHistoDirectory = &(fFile->dir());
251  return true;
252  }
253 
254 #ifdef G4VERBOSE
255  if ( fState.GetVerboseL4() )
257  ->Message("create", "directory for histograms", fHistoDirectoryName);
258 #endif
259 
260  fHistoDirectory = fFile->dir().mkdir(fHistoDirectoryName);
261  if ( ! fHistoDirectory ) {
262  G4ExceptionDescription description;
263  description << " "
264  << "cannot create directory " << fHistoDirectoryName;
265  G4Exception("G4RootFileManager::CreateHistoDirectory()",
266  "Analysis_W001", JustWarning, description);
267  return false;
268  }
269 #ifdef G4VERBOSE
270  else {
271  if ( fState.GetVerboseL2() )
273  ->Message("create", "directory for histograms", fHistoDirectoryName);
274  }
275 #endif
276  return true;
277 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String fHistoDirectoryName
const G4AnalysisVerbose * GetVerboseL2() const
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4RootFileManager::CreateNtupleDirectory ( )

Definition at line 280 of file G4RootFileManager.cc.

281 {
282  if ( fNtupleDirectoryName == "" ) {
283  // Do not create a new directory if its name is not set
284  fNtupleDirectory = &(fFile->dir());
285  return true;
286  }
287 
288 #ifdef G4VERBOSE
289  if ( fState.GetVerboseL4() )
291  ->Message("create", "directory for ntuples", fNtupleDirectoryName);
292 #endif
293 
294  fNtupleDirectory = fFile->dir().mkdir(fNtupleDirectoryName);
295  if ( ! fNtupleDirectory ) {
296  G4ExceptionDescription description;
297  description << " "
298  << "cannot create directory " << fNtupleDirectoryName;
299  G4Exception("G4RootFileManager::CreateNtupleDirectory()",
300  "Analysis_W001", JustWarning, description);
301  return false;
302  }
303 #ifdef G4VERBOSE
304  else {
305  if ( fState.GetVerboseL2() )
307  ->Message("create", "directory for ntuples", fNtupleDirectoryName);
308  }
309 #endif
310  return true;
311 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
G4String fNtupleDirectoryName
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const G4AnalysisVerbose * GetVerboseL2() const
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int G4RootFileManager::GetBasketSize ( ) const
inline

Definition at line 105 of file G4RootFileManager.hh.

106 { return fBasketSize; }
tools::wroot::directory * G4RootFileManager::GetHistoDirectory ( ) const
inline

Definition at line 99 of file G4RootFileManager.hh.

100 { return fHistoDirectory; }
tools::wroot::directory * G4RootFileManager::GetMainNtupleDirectory ( G4int  index) const

Definition at line 332 of file G4RootFileManager.cc.

333 {
334  if ( index==0 && ( ! fMainNtupleDirectories.size() ) ) return fNtupleDirectory;
335 
336  if ( index < 0 || index >= G4int(fMainNtupleDirectories.size()) ) {
337  G4String inFunction = "G4RootFileManager::GetMainNtupleDirectory()";
338  G4ExceptionDescription description;
339  description << " " << "main ntuple directory " << index << " does not exist.";
340  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
341  return nullptr;
342  }
343 
344  return fMainNtupleDirectories[index];
345 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

tools::wroot::directory * G4RootFileManager::GetNtupleDirectory ( ) const
inline

Definition at line 102 of file G4RootFileManager.hh.

103 { return fNtupleDirectory; }
std::shared_ptr< tools::wroot::file > G4RootFileManager::GetNtupleFile ( G4int  index) const

Definition at line 315 of file G4RootFileManager.cc.

316 {
317  if ( index==0 && ( ! fNtupleFiles.size() ) ) return fFile;
318 
319  if ( index < 0 || index >= G4int(fNtupleFiles.size()) ) {
320  G4String inFunction = "G4RootFileManager::GetNtupleFile()";
321  G4ExceptionDescription description;
322  description << " " << "ntuple file " << index << " does not exist.";
323  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
324  return nullptr;
325  }
326 
327  return fNtupleFiles[index];
328 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

G4bool G4RootFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 171 of file G4RootFileManager.cc.

172 {
173  // Keep file name
174  fFileName = fileName;
175  auto name = GetFullFileName();
176 
177  // delete previous file if exists
178  //if ( fFile ) delete fFile;
179 
180  // create new file
181  fFile = std::make_shared<tools::wroot::file>(G4cout, name);
182  fFile->add_ziper('Z',tools::compress_buffer);
183  fFile->set_compression(fState.GetCompressionLevel());
184 
185  if ( ! fFile->is_open() ) {
186  G4ExceptionDescription description;
187  description << " " << "Cannot open file " << fileName;
188  G4Exception("G4RootAnalysisManager::OpenFile()",
189  "Analysis_W001", JustWarning, description);
190  return false;
191  }
192 
193  // Create directories
194  if ( ! CreateHistoDirectory() ) return false;
195  if ( ! CreateNtupleDirectory() ) return false;
196 
197  // Open ntuple files
198  OpenNtupleFiles();
199 
200  fLockFileName = true;
203 
204  fIsOpenFile = true;
205 
206  return true;
207 }
const XML_Char * name
Definition: expat.h:151
const G4AnalysisManagerState & fState
G4bool fLockHistoDirectoryName
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool fLockNtupleDirectoryName
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const

Here is the call graph for this function:

void G4RootFileManager::SetBasketSize ( unsigned int  basketSize)
inline

Definition at line 96 of file G4RootFileManager.hh.

97 { fBasketSize = basketSize; }
void G4RootFileManager::SetNofNtupleFiles ( G4int  nofFiles)
inline

Definition at line 93 of file G4RootFileManager.hh.

94 { fNofNtupleFiles = nofFiles; }
G4bool G4RootFileManager::WriteFile ( )
finalvirtual

Implements G4VFileManager.

Definition at line 210 of file G4RootFileManager.cc.

211 {
212  auto finalResult = true;
213 
214  auto result = WriteFile(fFile, GetFullFileName());
215  finalResult = finalResult && result;
216 
217  auto counter = 0;
218  for ( auto ntupleFile : fNtupleFiles ) {
219  result = WriteFile(ntupleFile, GetNtupleFileName(counter++));
220  finalResult = finalResult && result;
221  }
222  return finalResult;
223 }
G4double G4ParticleHPJENDLHEData::G4double result
G4String GetNtupleFileName(const G4String &ntupleName) const
virtual G4bool WriteFile() final
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const

Here is the call graph for this function:


The documentation for this class was generated from the following files: