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

#include <G4RootFileManager.hh>

+ Inheritance diagram for G4RootFileManager:

Public Member Functions

 G4RootFileManager (const G4AnalysisManagerState &state)
 
 G4RootFileManager ()=delete
 
 ~G4RootFileManager () override=default
 
G4bool OpenFile (const G4String &fileName) final
 
G4String GetFileType () const final
 
G4bool HasCycles () const final
 
std::shared_ptr< G4RootFileCreateNtupleFile (RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
 
std::shared_ptr< G4RootFileGetNtupleFile (RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
 
G4bool CloseNtupleFile (RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
 
void SetBasketSize (unsigned int basketSize)
 
void SetBasketEntries (unsigned int basketEntries)
 
unsigned int GetBasketSize () const
 
unsigned int GetBasketEntries () const
 
G4String GetNtupleFileName (const G4String &ntupleName, G4int cycle=0) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber, G4int cycle=0) const
 
- Public Member Functions inherited from G4VTFileManager< G4RootFile >
 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< G4RootFileGetFile () 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< G4RootFileCreateFileImpl (const G4String &fileName) final
 
G4bool WriteFileImpl (std::shared_ptr< G4RootFile > file) final
 
G4bool CloseFileImpl (std::shared_ptr< G4RootFile > 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< G4RootFile >
std::shared_ptr< G4RootFilefFile
 
- 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 53 of file G4RootFileManager.hh.

Constructor & Destructor Documentation

◆ G4RootFileManager() [1/2]

G4RootFileManager::G4RootFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 42 of file G4RootFileManager.cc.

44{
45 // Create helpers defined in the base class
46 fH1FileManager = std::make_shared<G4RootHnFileManager<histo::h1d>>(this);
47 fH2FileManager = std::make_shared<G4RootHnFileManager<histo::h2d>>(this);
48 fH3FileManager = std::make_shared<G4RootHnFileManager<histo::h3d>>(this);
49 fP1FileManager = std::make_shared<G4RootHnFileManager<histo::p1d>>(this);
50 fP2FileManager = std::make_shared<G4RootHnFileManager<histo::p2d>>(this);
51}
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

◆ G4RootFileManager() [2/2]

G4RootFileManager::G4RootFileManager ( )
delete

◆ ~G4RootFileManager()

G4RootFileManager::~G4RootFileManager ( )
overridedefault

Member Function Documentation

◆ CloseFileImpl()

G4bool G4RootFileManager::CloseFileImpl ( std::shared_ptr< G4RootFile file)
finalprotected

Definition at line 158 of file G4RootFileManager.cc.

159{
160// New prototype: called by G4TFileManager base classe
161
162 if (file == nullptr) return false;
163
164 // write file (only once)
165 unsigned int n;
166 std::get<0>(*file)->write(n);
167
168 // close file
169 std::get<0>(*file)->close();
170
171 return true;
172}

◆ CloseNtupleFile()

G4bool G4RootFileManager::CloseNtupleFile ( RootNtupleDescription ntupleDescription,
G4int  mainNumber = -1 
)

Definition at line 237 of file G4RootFileManager.cc.

239{
240 // auto result = true;
241
242 // Notify not empty file
243 auto ntupleFileName = GetNtupleFileName(ntupleDescription, true, mainNumber);
244 auto result = SetIsEmpty(ntupleFileName, ! ntupleDescription->GetHasFill());
245
246 // Ntuple files will be closed with CloseFiles() calls
247 ntupleDescription->GetFile().reset();
248
249 return result;
250}
std::shared_ptr< FT > GetFile() const
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final

◆ CreateFileImpl()

std::shared_ptr< G4RootFile > G4RootFileManager::CreateFileImpl ( const G4String fileName)
finalprotectedvirtual

Implements G4TFileManager< FT >.

Definition at line 116 of file G4RootFileManager.cc.

117{
118 // create file
119 std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(G4cout, fileName);
120 file->add_ziper('Z',toolx::compress_buffer);
121 file->set_compression(fState.GetCompressionLevel());
122
123 if ( ! file->is_open() ) {
124 Warn("Cannot create file " + fileName, fkClass, "CreateFileImpl");
125 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
126 }
127
128 // create histo directory
129 tools::wroot::directory* hdirectory
130 = CreateDirectory(file.get(), fHistoDirectoryName, "histograms");
131 if (hdirectory == nullptr) {
132 // Warning is issued in CreateDirectory
133 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
134 }
135
136 // create ntuple directory
137 tools::wroot::directory* ndirectory
138 = CreateDirectory(file.get(), fNtupleDirectoryName, "ntuples");
139 if (ndirectory == nullptr) {
140 // Warning is issued in CreateDirectory
141 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
142 }
143
144 return std::make_shared<G4RootFile>(file, hdirectory, ndirectory);
145}
G4GLOB_DLL std::ostream G4cout
const G4AnalysisManagerState & fState
G4String fNtupleDirectoryName
G4String fHistoDirectoryName
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ CreateNtupleFile()

std::shared_ptr< G4RootFile > G4RootFileManager::CreateNtupleFile ( RootNtupleDescription ntupleDescription,
G4int  mainNumber = -1 
)

Definition at line 205 of file G4RootFileManager.cc.

207{
208 // get ntuple file name per object
209 auto perThread = true;
210 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
211
212 auto file = GetTFile(ntupleFileName, false);
213 if (! file) {
214 file = CreateTFile(ntupleFileName);
215 }
216
217 // register file in ntuple description only if it is not main ntuple file
218 // (main ntuple files are managed in main ntuple manager)
219 if ( mainNumber == -1 ) {
220 ntupleDescription->SetFile(file);
221 }
222
223 return file;
224}
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)

◆ GetBasketEntries()

unsigned int G4RootFileManager::GetBasketEntries ( ) const
inline

Definition at line 127 of file G4RootFileManager.hh.

128{ return fBasketEntries; }

◆ GetBasketSize()

unsigned int G4RootFileManager::GetBasketSize ( ) const
inline

Definition at line 123 of file G4RootFileManager.hh.

124{ return fBasketSize; }

◆ GetFileType()

G4String G4RootFileManager::GetFileType ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 67 of file G4RootFileManager.hh.

67{ return "root"; }

◆ GetNtupleFile()

std::shared_ptr< G4RootFile > G4RootFileManager::GetNtupleFile ( RootNtupleDescription ntupleDescription,
G4bool  perThread = true,
G4int  mainNumber = -1 
) const

Definition at line 227 of file G4RootFileManager.cc.

229{
230 // get ntuple file name per object
231 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
232
233 return GetTFile(ntupleFileName, false);
234}

◆ 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}
G4bool HasCycles() const final
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}

◆ HasCycles()

G4bool G4RootFileManager::HasCycles ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 68 of file G4RootFileManager.hh.

68{ return true; }

◆ OpenFile()

G4bool G4RootFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 178 of file G4RootFileManager.cc.

179{
180// Open default file
181
182 // Keep file name
183 fFileName = fileName;
184 auto name = GetFullFileName();
185
186 if ( fFile ) {
187 Warn("File " + fileName + " already exists.", fkClass, "OpenFile");
188 fFile.reset();
189 }
190
191 // Create file (and save in in the file map)
192 fFile = CreateTFile(name);
193 if ( ! fFile ) {
194 Warn("Failed to create file " + fileName, fkClass, "OpenFile");
195 return false;
196 }
197
199 fIsOpenFile = true;
200
201 return true;
202}
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
void LockDirectoryNames()
std::shared_ptr< G4RootFile > fFile
const char * name(G4int ptype)

◆ SetBasketEntries()

void G4RootFileManager::SetBasketEntries ( unsigned int  basketEntries)
inline

Definition at line 119 of file G4RootFileManager.hh.

120{ fBasketEntries = basketEntries; }

◆ SetBasketSize()

void G4RootFileManager::SetBasketSize ( unsigned int  basketSize)
inline

Definition at line 115 of file G4RootFileManager.hh.

116{ fBasketSize = basketSize; }

◆ WriteFileImpl()

G4bool G4RootFileManager::WriteFileImpl ( std::shared_ptr< G4RootFile file)
finalprotected

Definition at line 148 of file G4RootFileManager.cc.

149{
150// New prototype: called by G4TFileManager base classe
151
152 // nothing to be done, but file should exist
153 return (file == nullptr) ? false : true;
154
155}

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