Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4XmlFileManager Class Reference

#include <G4XmlFileManager.hh>

+ Inheritance diagram for G4XmlFileManager:

Public Member Functions

 G4XmlFileManager (const G4AnalysisManagerState &state)
 
 G4XmlFileManager ()=delete
 
 ~G4XmlFileManager () override=default
 
G4bool OpenFile (const G4String &fileName) final
 
G4String GetFileType () const final
 
G4bool CreateNtupleFile (XmlNtupleDescription *ntupleDescription)
 
G4bool CloseNtupleFile (XmlNtupleDescription *ntupleDescription)
 
G4String GetNtupleFileName (const G4String &ntupleName, G4int cycle=0) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber, G4int cycle=0) const
 
- Public Member Functions inherited from G4VTFileManager< std::ofstream >
 G4VTFileManager (const G4AnalysisManagerState &state)
 
 ~G4VTFileManager () override=default
 
G4bool CreateFile (const G4String &fileName) final
 
G4bool WriteFile (const G4String &fileName) final
 
virtual G4bool WriteFile (const G4String &fileName)=0
 
G4bool CloseFile (const G4String &fileName) final
 
virtual G4bool CloseFile (const G4String &fileName)=0
 
G4bool SetIsEmpty (const G4String &fileName, G4bool isEmpty) final
 
G4bool OpenFiles () final
 
G4bool WriteFiles () final
 
G4bool CloseFiles () final
 
G4bool DeleteEmptyFiles () final
 
void Clear () final
 
std::shared_ptr< std::ofstream > GetFile () const
 
- Public Member Functions inherited from G4VFileManager
 G4VFileManager (const G4AnalysisManagerState &state)
 
 G4VFileManager ()=delete
 
 ~G4VFileManager () override=default
 
virtual G4bool OpenFile (const G4String &fileName)=0
 
virtual G4bool CreateFile (const G4String &fileName)=0
 
virtual G4bool WriteFile (const G4String &fileName)=0
 
virtual G4bool CloseFile (const G4String &fileName)=0
 
virtual G4bool SetIsEmpty (const G4String &fileName, G4bool isEmpty)=0
 
virtual G4bool OpenFiles ()=0
 
virtual G4bool WriteFiles ()=0
 
virtual G4bool CloseFiles ()=0
 
virtual G4bool DeleteEmptyFiles ()=0
 
virtual void Clear ()=0
 
G4bool SetFileName (const G4String &fileName) final
 
virtual G4bool SetHistoDirectoryName (const G4String &dirName)
 
virtual G4bool SetNtupleDirectoryName (const G4String &dirName)
 
void LockDirectoryNames ()
 
void UnlockDirectoryNames ()
 
G4bool IsOpenFile () const
 
G4String GetHistoDirectoryName () const
 
G4String GetNtupleDirectoryName () const
 
G4int GetCycle () const
 
template<typename HT >
std::shared_ptr< G4VTHnFileManager< HT > > GetHnFileManager () const
 
- Public Member Functions inherited from G4BaseFileManager
 G4BaseFileManager (const G4AnalysisManagerState &state)
 
 G4BaseFileManager ()=delete
 
virtual ~G4BaseFileManager ()=default
 
virtual G4bool SetFileName (const G4String &fileName)
 
virtual G4String GetFileType () const
 
virtual G4bool HasCycles () const
 
void AddFileName (const G4String &fileName)
 
G4String GetFileName () const
 
G4String GetFullFileName (const G4String &baseFileName="", G4bool isPerThread=true) const
 
const std::vector< G4String > & GetFileNames () const
 
G4String GetHnFileName (const G4String &hnType, const G4String &hnName) const
 
G4String GetHnFileName (const G4String &fileName, G4int cycle=0) const
 
G4String GetNtupleFileName (const G4String &ntupleName, G4int cycle=0) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber, G4int cycle=0) const
 
G4String GetPlotFileName () const
 
- Public Member Functions inherited from G4TFileManager< FT >
 G4TFileManager (const G4AnalysisManagerState &state)
 
 G4TFileManager ()=delete
 
virtual ~G4TFileManager ()
 
std::shared_ptr< FT > CreateTFile (const G4String &fileName)
 
G4bool WriteTFile (const G4String &fileName)
 
G4bool CloseTFile (const G4String &fileName)
 
G4bool SetIsEmpty (const G4String &fileName, G4bool isEmpty)
 
std::shared_ptr< FT > GetTFile (const G4String &fileName, G4bool warn=true) const
 
G4bool OpenFiles ()
 
G4bool WriteFiles ()
 
G4bool CloseFiles ()
 
G4bool DeleteEmptyFiles ()
 
void ClearData ()
 

Protected Member Functions

std::shared_ptr< std::ofstream > CreateFileImpl (const G4String &fileName) final
 
G4bool WriteFileImpl (std::shared_ptr< std::ofstream > file) final
 
G4bool CloseFileImpl (std::shared_ptr< std::ofstream > file) final
 
- Protected Member Functions inherited from G4BaseFileManager
void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 
- Protected Member Functions inherited from G4TFileManager< FT >
virtual std::shared_ptr< FT > CreateFileImpl (const G4String &fileName)=0
 
virtual G4bool WriteFileImpl (std::shared_ptr< FT > file)=0
 
virtual G4bool CloseFileImpl (std::shared_ptr< FT > file)=0
 

Additional Inherited Members

- Protected Attributes inherited from G4VTFileManager< std::ofstream >
std::shared_ptr< std::ofstream > fFile
 
- Protected Attributes inherited from G4VFileManager
G4String fHistoDirectoryName
 
G4String fNtupleDirectoryName
 
G4bool fIsOpenFile { false }
 
G4bool fLockDirectoryNames { false }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h1d > > fH1FileManager { nullptr }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager { nullptr }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager { nullptr }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager { nullptr }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager { nullptr }
 
- Protected Attributes inherited from G4BaseFileManager
const G4AnalysisManagerStatefState
 
G4String fFileName
 
std::vector< G4StringfFileNames
 
- Static Protected Attributes inherited from G4VFileManager
static constexpr std::string_view fkClass { "G4VFileManager" }
 

Detailed Description

Definition at line 50 of file G4XmlFileManager.hh.

Constructor & Destructor Documentation

◆ G4XmlFileManager() [1/2]

G4XmlFileManager::G4XmlFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 40 of file G4XmlFileManager.cc.

42{
43 // Create helpers defined in the base class
44 fH1FileManager = std::make_shared<G4XmlHnFileManager<histo::h1d>>(this);
45 fH2FileManager = std::make_shared<G4XmlHnFileManager<histo::h2d>>(this);
46 fH3FileManager = std::make_shared<G4XmlHnFileManager<histo::h3d>>(this);
47 fP1FileManager = std::make_shared<G4XmlHnFileManager<histo::p1d>>(this);
48 fP2FileManager = std::make_shared<G4XmlHnFileManager<histo::p2d>>(this);
49}
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::h1d > > fH1FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager

◆ G4XmlFileManager() [2/2]

G4XmlFileManager::G4XmlFileManager ( )
delete

◆ ~G4XmlFileManager()

G4XmlFileManager::~G4XmlFileManager ( )
overridedefault

Member Function Documentation

◆ CloseFileImpl()

G4bool G4XmlFileManager::CloseFileImpl ( std::shared_ptr< std::ofstream >  file)
finalprotected

Definition at line 99 of file G4XmlFileManager.cc.

100{
101 if ( ! file ) return false;
102
103 // close file
104 waxml::end(*file);
105 file->close();
106
107 return true;
108}

◆ CloseNtupleFile()

G4bool G4XmlFileManager::CloseNtupleFile ( XmlNtupleDescription ntupleDescription)

Definition at line 160 of file G4XmlFileManager.cc.

162{
163 // Notify not empty file
164 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
165 auto result = SetIsEmpty(ntupleFileName, ! ntupleDescription->GetHasFill());
166
167 // Ntuple files are registered in file manager map.
168 // they will be closed with CloseFiles() calls
169 ntupleDescription->GetFile().reset();
170
171 return result;
172}
std::shared_ptr< FT > GetFile() const
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final

◆ CreateFileImpl()

std::shared_ptr< std::ofstream > G4XmlFileManager::CreateFileImpl ( const G4String fileName)
finalprotectedvirtual

Implements G4TFileManager< FT >.

Definition at line 79 of file G4XmlFileManager.cc.

80{
81 std::shared_ptr<std::ofstream> file = std::make_shared<std::ofstream>(fileName);
82 if ( file->fail() ) {
83 Warn(G4String("Cannot create file ") + fileName, fkClass, "CreateFileImpl");
84 return nullptr;
85 }
86
87 waxml::begin(*file);
88 return file;
89}
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ CreateNtupleFile()

G4bool G4XmlFileManager::CreateNtupleFile ( XmlNtupleDescription ntupleDescription)

Definition at line 142 of file G4XmlFileManager.cc.

144{
145 // Get ntuple file name per object (if defined)
146 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
147
148 // Create ntuple file name if it does not yet exist
149 auto ntupleFile = GetTFile(ntupleFileName, false);
150 if ( ntupleFile == nullptr) {
151 ntupleFile = CreateTFile(ntupleFileName);
152 }
153
154 ntupleDescription->SetFile(ntupleFile);
155
156 return (ntupleDescription->GetFile() != nullptr);
157}
std::shared_ptr< FT > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< FT > CreateTFile(const G4String &fileName)
void SetFile(std::shared_ptr< FT > file)

◆ GetFileType()

G4String G4XmlFileManager::GetFileType ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 64 of file G4XmlFileManager.hh.

64{ return "xml"; }

◆ GetNtupleFileName() [1/2]

G4String G4BaseFileManager::GetNtupleFileName ( const G4String ntupleName,
G4int  cycle = 0 
) const

Definition at line 80 of file G4BaseFileManager.cc.

110{
111 // Do not pass cycle if supported by the output type
112 auto cycleToPass = (HasCycles()) ? 0 : cycle;
113
114 return G4Analysis::GetNtupleFileName(fFileName, GetFileType(), ntupleName, cycleToPass);
115}
virtual G4bool HasCycles() const
G4String GetFileType() const final
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName, G4int cycle=0)

◆ GetNtupleFileName() [2/2]

G4String G4BaseFileManager::GetNtupleFileName ( G4int  ntupleFileNumber,
G4int  cycle = 0 
) const

Definition at line 88 of file G4BaseFileManager.cc.

120{
121 // Do not pass cycle if supported by the output type
122 auto cycleToPass = (HasCycles()) ? 0 : cycle;
123
124 return G4Analysis::GetNtupleFileName(fFileName, GetFileType(), ntupleFileNumber, cycleToPass);
125}

◆ OpenFile()

G4bool G4XmlFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 115 of file G4XmlFileManager.cc.

116{
117 // Keep and locks file name
118 fFileName = fileName;
120
121 if ( fFile ) {
122 Warn(G4String("File ") + fileName + " already exists.", fkClass, "OpenFile");
123 fFile.reset();
124 }
125
126 // Create histograms file (on master)
127 if ( fState.GetIsMaster() ) {
128 // Create file (and save in in the file map (on master only)
129 fFile = CreateTFile(name);
130 if ( ! fFile) {
131 Warn(G4String("Failed to create file") + fileName, fkClass, "OpenFile");
132 return false;
133 }
134 }
135
136 fIsOpenFile = true;
137
138 return true;
139}
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisManagerState & fState
std::shared_ptr< std::ofstream > fFile
const char * name(G4int ptype)

◆ WriteFileImpl()

G4bool G4XmlFileManager::WriteFileImpl ( std::shared_ptr< std::ofstream >  file)
finalprotected

Definition at line 92 of file G4XmlFileManager.cc.

93{
94 // Nothing to be done here
95 return true;
96}

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