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

#include <G4XmlFileManager.hh>

Inheritance diagram for G4XmlFileManager:
Collaboration diagram for G4XmlFileManager:

Public Types

using NtupleType = tools::waxml::ntuple
 
using NtupleDescriptionType = G4TNtupleDescription< NtupleType >
 

Public Member Functions

 G4XmlFileManager (const G4AnalysisManagerState &state)
 
 ~G4XmlFileManager ()
 
virtual G4bool OpenFile (const G4String &fileName) final
 
virtual G4bool WriteFile () final
 
virtual G4bool CloseFile () final
 
G4bool CreateHnFile ()
 
G4bool CloseHnFile ()
 
G4bool CreateNtupleFile (NtupleDescriptionType *ntupleDescription)
 
G4bool CloseNtupleFile (NtupleDescriptionType *ntupleDescription)
 
std::shared_ptr< std::ofstream > GetHnFile () 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 46 of file G4XmlFileManager.hh.

Member Typedef Documentation

using G4XmlFileManager::NtupleType = tools::waxml::ntuple

Definition at line 53 of file G4XmlFileManager.hh.

Constructor & Destructor Documentation

G4XmlFileManager::G4XmlFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 39 of file G4XmlFileManager.cc.

40  : G4VFileManager(state),
41  fHnFile(nullptr)
42 {
43 }
G4VFileManager(const G4AnalysisManagerState &state)
G4XmlFileManager::~G4XmlFileManager ( )

Definition at line 46 of file G4XmlFileManager.cc.

47 {}

Member Function Documentation

G4bool G4XmlFileManager::CloseFile ( )
finalvirtual

Implements G4VFileManager.

Definition at line 72 of file G4XmlFileManager.cc.

73 {
74  // Unlock file name
75 
76  fLockFileName = false;
77  fIsOpenFile = false;
78  return true;
79 }
G4bool G4XmlFileManager::CloseHnFile ( )

Definition at line 111 of file G4XmlFileManager.cc.

112 {
113  // No file may be open if no master manager is instantiated
114  // and no histograms were booked
115  if ( ! fHnFile.get() ) return true;
116 
117 #ifdef G4VERBOSE
118  if ( fState.GetVerboseL4() )
119  fState.GetVerboseL4()->Message("close", "histo file", GetFullFileName());
120 #endif
121 
122  // close file
123  tools::waxml::end(*fHnFile);
124  fHnFile->close();
125 
126 #ifdef G4VERBOSE
127  if ( fState.GetVerboseL1() )
128  fState.GetVerboseL1()->Message("close", "histo file", GetFullFileName());
129 #endif
130 
131 
132  return true;
133 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
const G4AnalysisVerbose * GetVerboseL4() const
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisVerbose * GetVerboseL1() const

Here is the call graph for this function:

G4bool G4XmlFileManager::CloseNtupleFile ( NtupleDescriptionType ntupleDescription)

Definition at line 170 of file G4XmlFileManager.cc.

172 {
173  G4String ntupleName = ntupleDescription->fNtupleBooking.name();
174 
175 #ifdef G4VERBOSE
176  if ( fState.GetVerboseL4() )
178  ->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
179 #endif
180 
181  // close file
182  tools::waxml::end(*(ntupleDescription->fFile));
183  ntupleDescription->fFile->close();
184 
185 #ifdef G4VERBOSE
186  if ( fState.GetVerboseL1() )
188  ->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
189 #endif
190 
191  return true;
192 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
G4String GetNtupleFileName(const G4String &ntupleName) const
const G4AnalysisVerbose * GetVerboseL4() const
const G4AnalysisVerbose * GetVerboseL1() const

Here is the call graph for this function:

G4bool G4XmlFileManager::CreateHnFile ( )

Definition at line 82 of file G4XmlFileManager.cc.

83 {
84 #ifdef G4VERBOSE
85  if ( fState.GetVerboseL4() )
86  fState.GetVerboseL4()->Message("create", "histo file", GetFullFileName());
87 #endif
88 
89  // delete a previous file if it exists
90  //if ( fHnFile ) delete fHnFile;
91 
92  fHnFile = std::make_shared<std::ofstream>(GetFullFileName());
93  if ( fHnFile->fail() ) {
94  G4ExceptionDescription description;
95  description << " " << "Cannot open file " << GetFullFileName();
96  G4Exception("G4XmlFileManager::CreateHnFile()",
97  "Analysis_W001", JustWarning, description);
98  return false;
99  }
100 
101  tools::waxml::begin(*fHnFile);
102 #ifdef G4VERBOSE
103  if ( fState.GetVerboseL1() )
104  fState.GetVerboseL1()->Message("create", "histo file", GetFullFileName());
105 #endif
106 
107  return true;
108 }
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
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisVerbose * GetVerboseL1() const

Here is the call graph for this function:

G4bool G4XmlFileManager::CreateNtupleFile ( NtupleDescriptionType ntupleDescription)

Definition at line 136 of file G4XmlFileManager.cc.

138 {
139  G4String ntupleName = ntupleDescription->fNtupleBooking.name();
140 
141 #ifdef G4VERBOSE
142  if ( fState.GetVerboseL4() )
144  ->Message("create", "ntuple file", GetNtupleFileName(ntupleName));
145 #endif
146 
147  auto ntupleFile = new std::ofstream(GetNtupleFileName(ntupleName));
148  if ( ntupleFile->fail() ) {
149  G4ExceptionDescription description;
150  description << " " << "Cannot open file "
151  << GetNtupleFileName(ntupleName);
152  G4Exception("G4XmlFileManager::CreateNtupleFile()",
153  "Analysis_W001", JustWarning, description);
154  return false;
155  }
156 
157  tools::waxml::begin(*ntupleFile);
158  ntupleDescription->fFile = ntupleFile;
159 
160 #ifdef G4VERBOSE
161  if ( fState.GetVerboseL1() )
163  ->Message("create", "ntuple file", GetNtupleFileName(ntupleName));
164 #endif
165 
166  return true;
167 }
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 GetNtupleFileName(const G4String &ntupleName) const
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4AnalysisVerbose * GetVerboseL1() const

Here is the call graph for this function:

std::shared_ptr< std::ofstream > G4XmlFileManager::GetHnFile ( ) const
inline

Definition at line 77 of file G4XmlFileManager.hh.

78 { return fHnFile; }
G4bool G4XmlFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 54 of file G4XmlFileManager.cc.

55 {
56  // Keep and locks file name
57  fFileName = fileName;
58  fLockFileName = true;
59  fIsOpenFile = true;
60 
61  return true;
62 }
G4bool G4XmlFileManager::WriteFile ( )
finalvirtual

Implements G4VFileManager.

Definition at line 65 of file G4XmlFileManager.cc.

66 {
67  // Nothing to be done here
68  return true;
69 }

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