Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 112 of file G4XmlFileManager.cc.

113 {
114  // No file may be open if no master manager is instantiated
115  // and no histograms were booked
116  if ( ! fHnFile.get() ) return true;
117 
118 #ifdef G4VERBOSE
119  if ( fState.GetVerboseL4() )
120  fState.GetVerboseL4()->Message("close", "histo file", GetFullFileName());
121 #endif
122 
123  // close file
124  tools::waxml::end(*fHnFile);
125  fHnFile->close();
126 
127 #ifdef G4VERBOSE
128  if ( fState.GetVerboseL1() )
129  fState.GetVerboseL1()->Message("close", "histo file", GetFullFileName());
130 #endif
131 
132 
133  return true;
134 }
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 172 of file G4XmlFileManager.cc.

174 {
175  // Do nothing if there is no file
176  if ( ! ntupleDescription->fFile ) return true;
177 
178  G4String ntupleName = ntupleDescription->fNtupleBooking.name();
179 
180 #ifdef G4VERBOSE
181  if ( fState.GetVerboseL4() )
183  ->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
184 #endif
185 
186  // close file
187  tools::waxml::end(*(ntupleDescription->fFile));
188  ntupleDescription->fFile->close();
189 
190 #ifdef G4VERBOSE
191  if ( fState.GetVerboseL1() )
193  ->Message("close", "ntuple file", GetNtupleFileName(ntupleName));
194 #endif
195 
196  return true;
197 }
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  fHnFile = nullptr;
95  G4ExceptionDescription description;
96  description << " " << "Cannot open file " << GetFullFileName();
97  G4Exception("G4XmlFileManager::CreateHnFile()",
98  "Analysis_W001", JustWarning, description);
99  return false;
100  }
101 
102  tools::waxml::begin(*fHnFile);
103 #ifdef G4VERBOSE
104  if ( fState.GetVerboseL1() )
105  fState.GetVerboseL1()->Message("create", "histo file", GetFullFileName());
106 #endif
107 
108  return true;
109 }
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 137 of file G4XmlFileManager.cc.

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