Geant4 10.7.0
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)
 
virtual ~G4RootFileManager ()
 
virtual G4bool OpenFile (const G4String &fileName) final
 
virtual G4String GetFileType () 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 WriteNtupleFile (RootNtupleDescription *ntupleDescription)
 
G4bool CloseNtupleFile (RootNtupleDescription *ntupleDescription)
 
void SetBasketSize (unsigned int basketSize)
 
void SetBasketEntries (unsigned int basketEntries)
 
unsigned int GetBasketSize () const
 
unsigned int GetBasketEntries () const
 
G4String GetNtupleFileName (const G4String &ntupleName) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber) const
 
- Public Member Functions inherited from G4VTFileManager< G4RootFile >
 G4VTFileManager (const G4AnalysisManagerState &state)
 
 ~G4VTFileManager ()
 
virtual G4bool CreateFile (const G4String &fileName) final
 
virtual G4bool WriteFile (const G4String &fileName) final
 
virtual G4bool WriteFile (const G4String &fileName)=0
 
virtual G4bool CloseFile (const G4String &fileName) final
 
virtual G4bool CloseFile (const G4String &fileName)=0
 
virtual G4bool SetIsEmpty (const G4String &fileName, G4bool isEmpty) final
 
virtual G4bool WriteFiles () final
 
virtual G4bool CloseFiles () final
 
virtual G4bool DeleteEmptyFiles () final
 
std::shared_ptr< G4RootFileGetFile () const
 
- Public Member Functions inherited from G4VFileManager
 G4VFileManager (const G4AnalysisManagerState &state)
 
virtual ~G4VFileManager ()
 
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 WriteFiles ()=0
 
virtual G4bool CloseFiles ()=0
 
virtual G4bool DeleteEmptyFiles ()=0
 
virtual G4bool SetFileName (const G4String &fileName) final
 
G4bool SetHistoDirectoryName (const G4String &dirName)
 
G4bool SetNtupleDirectoryName (const G4String &dirName)
 
void LockDirectoryNames ()
 
G4bool IsOpenFile () const
 
G4String GetHistoDirectoryName () const
 
G4String GetNtupleDirectoryName () const
 
template<typename HT >
std::shared_ptr< G4VTHnFileManager< HT > > GetHnFileManager () const
 
- Public Member Functions inherited from G4BaseFileManager
 G4BaseFileManager (const G4AnalysisManagerState &state)
 
virtual ~G4BaseFileManager ()
 
virtual G4bool SetFileName (const G4String &fileName)
 
virtual G4String GetFileType () 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 GetNtupleFileName (const G4String &ntupleName) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber) const
 
G4String GetPlotFileName () const
 
- Public Member Functions inherited from G4TFileManager< FT >
 G4TFileManager (const G4AnalysisManagerState &state)
 
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 ()
 

Protected Member Functions

virtual std::shared_ptr< G4RootFileCreateFileImpl (const G4String &fileName) final
 
virtual G4bool WriteFileImpl (std::shared_ptr< G4RootFile > file) final
 
virtual G4bool CloseFileImpl (std::shared_ptr< G4RootFile > file) final
 
- 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
 
G4bool fLockDirectoryNames
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h1d > > fH1FileManager
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager
 
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager
 
- Protected Attributes inherited from G4BaseFileManager
const G4AnalysisManagerStatefState
 
G4String fFileName
 
std::vector< G4StringfFileNames
 

Detailed Description

Definition at line 51 of file G4RootFileManager.hh.

Constructor & Destructor Documentation

◆ G4RootFileManager()

G4RootFileManager::G4RootFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 45 of file G4RootFileManager.cc.

47 fBasketSize(0),
48 fBasketEntries(0)
49{
50 // Create helpers defined in the base class
51 fH1FileManager = std::make_shared<G4RootHnFileManager<histo::h1d>>(this);
52 fH2FileManager = std::make_shared<G4RootHnFileManager<histo::h2d>>(this);
53 fH3FileManager = std::make_shared<G4RootHnFileManager<histo::h3d>>(this);
54 fP1FileManager = std::make_shared<G4RootHnFileManager<histo::p1d>>(this);
55 fP2FileManager = std::make_shared<G4RootHnFileManager<histo::p2d>>(this);
56}
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()

G4RootFileManager::~G4RootFileManager ( )
virtual

Definition at line 59 of file G4RootFileManager.cc.

60{}

Member Function Documentation

◆ CloseFileImpl()

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

Definition at line 187 of file G4RootFileManager.cc.

188{
189// New prototype: called by G4TFileManager base classe
190
191 if ( ! file ) return false;
192
193 // close file
194 std::get<0>(*file)->close();
195
196 return true;
197}

◆ CloseNtupleFile()

G4bool G4RootFileManager::CloseNtupleFile ( RootNtupleDescription ntupleDescription)

Definition at line 268 of file G4RootFileManager.cc.

270{
271 auto finalResult = true;
272
273 if ( ntupleDescription->fFile ) {
274 // Ntuple files are registered in file manager map.
275 // they will be closed with CloseFiles() calls
276 ntupleDescription->fFile.reset();
277 // Notify not empty file
278 auto ntupleFileName = GetNtupleFileName(ntupleDescription);
279 auto result = SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
280 finalResult = result && finalResult;
281 }
282
283 return finalResult;
284}
virtual G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
std::shared_ptr< TF > fFile

◆ CreateFileImpl()

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

Implements G4TFileManager< FT >.

Definition at line 141 of file G4RootFileManager.cc.

142{
143 // create file
144 std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(G4cout, fileName);
145 file->add_ziper('Z',compress_buffer);
146 file->set_compression(fState.GetCompressionLevel());
147
148 if ( ! file->is_open() ) {
149 G4ExceptionDescription description;
150 description << " " << "Cannot create file " << fileName;
151 G4Exception("G4RootFileManager::CreateFileImpl()",
152 "Analysis_W001", JustWarning, description);
153 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
154 }
155
156 // create histo directory
157 tools::wroot::directory* hdirectory
158 = CreateDirectory(file, fHistoDirectoryName, "histograms");
159 if ( ! hdirectory ) {
160 // Warning is issued in CreateDirectory
161 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
162 }
163
164 // create ntuple directory
165 tools::wroot::directory* ndirectory
166 = CreateDirectory(file, fNtupleDirectoryName, "ntuples");
167 if ( ! ndirectory ) {
168 // Warning is issued in CreateDirectory
169 return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
170 }
171
172 return std::make_shared<G4RootFile>(file, hdirectory, ndirectory);
173}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4GLOB_DLL std::ostream G4cout
const G4AnalysisManagerState & fState
G4String fNtupleDirectoryName
G4String fHistoDirectoryName

◆ CreateNtupleFile()

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

Definition at line 236 of file G4RootFileManager.cc.

238{
239 // get ntuple file name per object
240 auto perThread = true;
241 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
242
243 auto file = GetTFile(ntupleFileName, false);
244 if (! file) {
245 file = CreateTFile(ntupleFileName);
246 }
247
248 // register file in ntuple description only if it is not main ntuple file
249 // (main ntuple files are managed in main ntuple manager)
250 if ( mainNumber == -1 ) {
251 ntupleDescription->fFile = file;
252 }
253
254 return file;
255}
std::shared_ptr< FT > GetTFile(const G4String &fileName, G4bool warn=true) const
std::shared_ptr< FT > CreateTFile(const G4String &fileName)

◆ GetBasketEntries()

unsigned int G4RootFileManager::GetBasketEntries ( ) const
inline

Definition at line 120 of file G4RootFileManager.hh.

121{ return fBasketEntries; }

◆ GetBasketSize()

unsigned int G4RootFileManager::GetBasketSize ( ) const
inline

Definition at line 116 of file G4RootFileManager.hh.

117{ return fBasketSize; }

◆ GetFileType()

virtual G4String G4RootFileManager::GetFileType ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 64 of file G4RootFileManager.hh.

64{ return "root"; }

◆ GetNtupleFile()

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

Definition at line 258 of file G4RootFileManager.cc.

260{
261 // get ntuple file name per object
262 auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
263
264 return GetTFile(ntupleFileName, false);
265}

◆ GetNtupleFileName() [1/2]

G4String G4BaseFileManager::GetNtupleFileName ( const G4String ntupleName) const

Definition at line 70 of file G4BaseFileManager.cc.

109{
111}
virtual G4String GetFileType() const final
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)

◆ GetNtupleFileName() [2/2]

G4String G4BaseFileManager::GetNtupleFileName ( G4int  ntupleFileNumber) const

Definition at line 76 of file G4BaseFileManager.cc.

115{
116 return G4Analysis::GetNtupleFileName(fFileName, GetFileType(), ntupleFileNumber);
117}

◆ OpenFile()

G4bool G4RootFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 203 of file G4RootFileManager.cc.

204{
205// Open default file
206
207 // Keep file name
208 fFileName = fileName;
209 auto name = GetFullFileName();
210
211 if ( fFile ) {
212 G4ExceptionDescription description;
213 description << "File " << fileName << " already exists.";
214 G4Exception("G4RootFileManager::OpenFile()",
215 "Analysis_W001", JustWarning, description);
216 fFile.reset();
217 }
218
219 // Create file (and save in in the file map)
220 fFile = CreateTFile(name);
221 if ( ! fFile ) {
222 G4ExceptionDescription description;
223 description << "Failed to create file " << fileName;
224 G4Exception("G4RootFileManager::OpenFile()",
225 "Analysis_W001", JustWarning, description);
226 return false;
227 }
228
229 fIsOpenFile = true;
230 fLockDirectoryNames = true;
231
232 return true;
233}
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
G4bool fLockDirectoryNames
std::shared_ptr< G4RootFile > fFile
const char * name(G4int ptype)

◆ SetBasketEntries()

void G4RootFileManager::SetBasketEntries ( unsigned int  basketEntries)
inline

Definition at line 112 of file G4RootFileManager.hh.

113{ fBasketEntries = basketEntries; }

◆ SetBasketSize()

void G4RootFileManager::SetBasketSize ( unsigned int  basketSize)
inline

Definition at line 108 of file G4RootFileManager.hh.

109{ fBasketSize = basketSize; }

◆ WriteFileImpl()

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

Definition at line 176 of file G4RootFileManager.cc.

177{
178// New prototype: called by G4TFileManager base classe
179
180 if ( ! file ) return false;
181
182 unsigned int n;
183 return std::get<0>(*file)->write(n);
184}

◆ WriteNtupleFile()

G4bool G4RootFileManager::WriteNtupleFile ( RootNtupleDescription ntupleDescription)

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