Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
G4GenericFileManager Class Reference

#include <G4GenericFileManager.hh>

Inheritance diagram for G4GenericFileManager:
G4VFileManager G4BaseFileManager

Public Member Functions

void AddFileName (const G4String &fileName)
 
virtual void Clear () final
 
virtual G4bool CloseFile (const G4String &fileName) final
 
virtual G4bool CloseFiles () final
 
virtual G4bool CreateFile (const G4String &fileName) final
 
std::shared_ptr< G4VNtupleFileManagerCreateNtupleFileManager (G4AnalysisOutput output)
 
virtual G4bool DeleteEmptyFiles () final
 
 G4GenericFileManager (const G4AnalysisManagerState &state)
 
G4String GetDefaultFileType () const
 
std::shared_ptr< G4VFileManagerGetFileManager (const G4String &fileName)
 
G4String GetFileName () const
 
const std::vector< G4String > & GetFileNames () const
 
virtual G4String GetFileType () const final
 
G4String GetFullFileName (const G4String &baseFileName="", G4bool isPerThread=true) const
 
G4String GetHistoDirectoryName () const
 
template<typename HT >
std::shared_ptr< G4VTHnFileManager< HT > > GetHnFileManager () const
 
G4String GetHnFileName (const G4String &hnType, const G4String &hnName) const
 
G4String GetNtupleDirectoryName () const
 
G4String GetNtupleFileName (const G4String &ntupleName) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber) const
 
G4String GetPlotFileName () const
 
G4bool IsOpenFile () const
 
void LockDirectoryNames ()
 
virtual G4bool OpenFile (const G4String &fileName) final
 
virtual G4bool OpenFiles () final
 
void SetDefaultFileType (const G4String &value)
 
virtual G4bool SetFileName (const G4String &fileName) final
 
virtual G4bool SetHistoDirectoryName (const G4String &dirName)
 
virtual G4bool SetIsEmpty (const G4String &fileName, G4bool isEmpty) final
 
virtual G4bool SetNtupleDirectoryName (const G4String &dirName)
 
void UnlockDirectoryNames ()
 
virtual G4bool WriteFile (const G4String &fileName) final
 
virtual G4bool WriteFiles () final
 
template<typename HT >
G4bool WriteTExtra (const G4String &fileName, HT *ht, const G4String &htName)
 
virtual ~G4GenericFileManager ()=default
 

Protected Member Functions

void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 

Protected Attributes

G4String fFileName
 
std::vector< G4StringfFileNames
 
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 }
 
G4String fHistoDirectoryName
 
G4bool fIsOpenFile { false }
 
G4bool fLockDirectoryNames { false }
 
G4String fNtupleDirectoryName
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager { nullptr }
 
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager { nullptr }
 
const G4AnalysisManagerStatefState
 

Private Member Functions

void CreateFileManager (G4AnalysisOutput output)
 
std::shared_ptr< G4VFileManagerGetFileManager (G4AnalysisOutput output) const
 

Private Attributes

std::shared_ptr< G4CsvFileManagerfCsvFileManager { nullptr }
 
std::shared_ptr< G4VFileManagerfDefaultFileManager { nullptr }
 
G4String fDefaultFileType
 
std::vector< std::shared_ptr< G4VFileManager > > fFileManagers
 
G4bool fHdf5Warn { true }
 
std::shared_ptr< G4RootFileManagerfRootFileManager { nullptr }
 
std::shared_ptr< G4XmlFileManagerfXmlFileManager { nullptr }
 

Static Private Attributes

static constexpr std::string_view fkClass { "G4GenericFileManager" }
 

Detailed Description

Definition at line 52 of file G4GenericFileManager.hh.

Constructor & Destructor Documentation

◆ G4GenericFileManager()

G4GenericFileManager::G4GenericFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 62 of file G4GenericFileManager.cc.

63 : G4VFileManager(state)
64{}
G4VFileManager()=delete

◆ ~G4GenericFileManager()

virtual G4GenericFileManager::~G4GenericFileManager ( )
virtualdefault

Member Function Documentation

◆ AddFileName()

void G4BaseFileManager::AddFileName ( const G4String fileName)
inherited

Definition at line 44 of file G4BaseFileManager.cc.

45{
46 // G4cout << "registering " << fileName << " in manager of " << GetFileType() << G4endl;
47
48 // Do nothing in file name is already present
49 for ( const auto& name : fFileNames ) {
50 if ( name == fileName ) return;
51 }
52
53 fFileNames.push_back(fileName);
54}
std::vector< G4String > fFileNames
const char * name(G4int ptype)

References G4BaseFileManager::fFileNames, and G4InuclParticleNames::name().

◆ Clear()

void G4GenericFileManager::Clear ( )
finalvirtual

Implements G4VFileManager.

Definition at line 292 of file G4GenericFileManager.cc.

293{
294// Clear files data
295
296 for ( const auto& fileManager : fFileManagers ) {
297 if ( ! fileManager ) continue;
298
299 fileManager->Clear();
300 }
302}
std::vector< std::shared_ptr< G4VFileManager > > fFileManagers
void UnlockDirectoryNames()

References fFileManagers, and G4VFileManager::UnlockDirectoryNames().

◆ CloseFile()

G4bool G4GenericFileManager::CloseFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 333 of file G4GenericFileManager.cc.

334{
335// New prototype, fully implemented in templated base class
336
337 auto fileManager = GetFileManager(fileName);
338 if ( ! fileManager ) {
339 FileManagerWarning(fileName, fkClass, "CloseFile", fHdf5Warn);
340 return false;
341 }
342
343 return fileManager->CloseFile(fileName);
344}
std::shared_ptr< G4VFileManager > GetFileManager(const G4String &fileName)
static constexpr std::string_view fkClass
void FileManagerWarning(const G4String &fileName, std::string_view className, std::string_view functionName, G4bool hdf5Warn=true)

References fHdf5Warn, anonymous_namespace{G4GenericFileManager.cc}::FileManagerWarning(), fkClass, and GetFileManager().

◆ CloseFiles()

G4bool G4GenericFileManager::CloseFiles ( )
finalvirtual

Implements G4VFileManager.

Definition at line 246 of file G4GenericFileManager.cc.

247{
248// Close all files regeistered with objects
249
250 Message(kVL4, "close", "analysis files");
251
252 auto result = true;
253
254 for ( const auto& fileManager : fFileManagers ) {
255 if ( ! fileManager ) continue;
256
257 Message(kVL4, "close", fileManager->GetFileType(), "files");
258
259 result &= fileManager->CloseFiles();
260 }
261
262 fIsOpenFile = false;
263
264 Message(kVL3, "close", "analysis files", "", result);
265
266 return result;
267}
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
constexpr G4int kVL3
constexpr G4int kVL4

References fFileManagers, G4VFileManager::fIsOpenFile, G4Analysis::kVL3, G4Analysis::kVL4, and G4BaseFileManager::Message().

◆ CreateFile()

G4bool G4GenericFileManager::CreateFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 305 of file G4GenericFileManager.cc.

306{
307// New prototype, fully implemented in templated base class
308
309 auto fileManager = GetFileManager(fileName);
310 if ( ! fileManager ) {
311 FileManagerWarning(fileName, fkClass, "CreateFile", fHdf5Warn);
312 return false;
313 }
314
315 return fileManager->CreateFile(fileName);
316}

References fHdf5Warn, anonymous_namespace{G4GenericFileManager.cc}::FileManagerWarning(), fkClass, and GetFileManager().

◆ CreateFileManager()

void G4GenericFileManager::CreateFileManager ( G4AnalysisOutput  output)
private

Definition at line 71 of file G4GenericFileManager.cc.

72{
73 Message(kVL4, "create", "file manager", GetOutputName(output));
74
75 auto outputId = static_cast<size_t>(output);
76 if ( fFileManagers[outputId] ) {
77 Warn("The file manager of " + G4Analysis::GetOutputName(output) +
78 " type already exists.",
79 fkClass, "CreateFileManager");
80 return;
81 }
82
83 // Create the manager
84 switch ( output ) {
86 fCsvFileManager = std::make_shared<G4CsvFileManager>(fState);
88 break;
90#ifdef TOOLS_USE_HDF5
91 fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(fState);
92 fFileManagers[outputId] = fHdf5FileManager;
93#else
94 if ( fHdf5Warn) {
95 Warn("Hdf5 type is not available.", fkClass, "CreateFileManager");
96 fHdf5Warn = false;
97 }
98#endif
99 break;
101 fRootFileManager = std::make_shared<G4RootFileManager>(fState);
103 break;
105 fXmlFileManager = std::make_shared<G4XmlFileManager>(fState);
106 fFileManagers[outputId] = fXmlFileManager ;
107 break;
109 Warn(G4Analysis::GetOutputName(output) + " type is not supported.",
110 fkClass, "CreateFileManager");
111 return;
112 }
113
114 // Pass directory names (only if set)
115 if ( ! GetHistoDirectoryName().empty() ) {
116 fFileManagers[outputId]->SetHistoDirectoryName(GetHistoDirectoryName());
117 }
118 if ( ! GetNtupleDirectoryName().empty() ) {
119 fFileManagers[outputId]->SetNtupleDirectoryName(GetNtupleDirectoryName());
120 }
121
122 Message(kVL3, "create", "file manager", GetOutputName(output));
123}
const G4AnalysisManagerState & fState
std::shared_ptr< G4CsvFileManager > fCsvFileManager
std::shared_ptr< G4XmlFileManager > fXmlFileManager
std::shared_ptr< G4RootFileManager > fRootFileManager
G4String GetNtupleDirectoryName() const
G4String GetHistoDirectoryName() const
G4String GetOutputName(G4AnalysisOutput outputType)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

References anonymous_namespace{G4MTcoutDestination.cc}::empty, fCsvFileManager, fFileManagers, fHdf5Warn, fkClass, fRootFileManager, G4BaseFileManager::fState, fXmlFileManager, G4VFileManager::GetHistoDirectoryName(), G4VFileManager::GetNtupleDirectoryName(), G4Analysis::GetOutputName(), kCsv, kHdf5, kNone, kRoot, G4Analysis::kVL3, G4Analysis::kVL4, kXml, G4BaseFileManager::Message(), and G4Analysis::Warn().

Referenced by CreateNtupleFileManager(), and GetFileManager().

◆ CreateNtupleFileManager()

std::shared_ptr< G4VNtupleFileManager > G4GenericFileManager::CreateNtupleFileManager ( G4AnalysisOutput  output)

Definition at line 401 of file G4GenericFileManager.cc.

402{
403 if ( ! GetFileManager(output) ) {
404 CreateFileManager(output);
405 }
406
407 std::shared_ptr<G4VNtupleFileManager> vNtupleFileManager = nullptr;
408 G4String failure;
409
410 switch ( output ) {
412 auto ntupleFileManager = std::make_shared<G4CsvNtupleFileManager>(fState);
413 ntupleFileManager->SetFileManager(fCsvFileManager);
414 vNtupleFileManager = ntupleFileManager;
415 break;
416 }
418#ifdef TOOLS_USE_HDF5
419 auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(fState);
420 ntupleFileManager->SetFileManager(fHdf5FileManager);
421 vNtupleFileManager = ntupleFileManager;
422#else
423 failure = " Hdf5 is not available";
424#endif
425 break;
426 }
428 auto ntupleFileManager = std::make_shared<G4RootNtupleFileManager>(fState);
429 ntupleFileManager->SetFileManager(fRootFileManager);
430 vNtupleFileManager = ntupleFileManager;
431 break;
432 }
434 auto ntupleFileManager = std::make_shared<G4XmlNtupleFileManager>(fState);
435 ntupleFileManager->SetFileManager(fXmlFileManager);
436 vNtupleFileManager = ntupleFileManager;
437 break;
438 }
440 break;
441 }
442
443 if ( ! vNtupleFileManager ) {
444 Warn("Failed to create ntuple file manager of " +
445 G4Analysis::GetOutputName(output) + " type.\n" + failure,
446 fkClass, "CreateNtupleFileManager");
447 }
448
449 return vNtupleFileManager;
450}
void CreateFileManager(G4AnalysisOutput output)

References CreateFileManager(), fCsvFileManager, fkClass, fRootFileManager, G4BaseFileManager::fState, fXmlFileManager, GetFileManager(), G4Analysis::GetOutputName(), kCsv, kHdf5, kNone, kRoot, kXml, and G4Analysis::Warn().

◆ DeleteEmptyFiles()

G4bool G4GenericFileManager::DeleteEmptyFiles ( )
finalvirtual

Implements G4VFileManager.

Definition at line 270 of file G4GenericFileManager.cc.

271{
272// Close all files regeistered with objects
273
274 Message(kVL4, "delete", "empty files");
275
276 auto result = true;
277
278 for ( const auto& fileManager : fFileManagers ) {
279 if ( ! fileManager ) continue;
280
281 Message(kVL4, "delete", fileManager->GetFileType(), "empty files");
282
283 result &= fileManager->DeleteEmptyFiles();
284 }
285
286 Message(kVL3, "delete", "empty files", "", result);
287
288 return result;
289}

References fFileManagers, G4Analysis::kVL3, G4Analysis::kVL4, and G4BaseFileManager::Message().

◆ GetDefaultFileType()

G4String G4GenericFileManager::GetDefaultFileType ( ) const

◆ GetFileManager() [1/2]

std::shared_ptr< G4VFileManager > G4GenericFileManager::GetFileManager ( const G4String fileName)

Definition at line 134 of file G4GenericFileManager.cc.

135{
136 // Get file extension
137 G4String extension = GetExtension(fileName);
138 if ( ! extension.size() ) {
139 // use the default
140 extension = fDefaultFileType;
141 }
142
143 auto output = G4Analysis::GetOutput(extension);
144 if ( output == G4AnalysisOutput::kNone ) {
145 Warn("The file extension " + extension + "is not supported.",
146 fkClass, "GetFileManager");
147 return nullptr;
148 }
149
150 std::shared_ptr<G4VFileManager> fileManager = GetFileManager(output);
151 if ( ! GetFileManager(output) ) {
152 CreateFileManager(output);
153 fileManager = GetFileManager(output);
154 }
155
156 return GetFileManager(output);
157}
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)

References CreateFileManager(), fDefaultFileType, fkClass, G4Analysis::GetExtension(), GetFileManager(), G4Analysis::GetOutput(), kNone, and G4Analysis::Warn().

Referenced by CloseFile(), CreateFile(), CreateNtupleFileManager(), GetFileManager(), OpenFile(), OpenFiles(), SetIsEmpty(), and WriteFile().

◆ GetFileManager() [2/2]

std::shared_ptr< G4VFileManager > G4GenericFileManager::GetFileManager ( G4AnalysisOutput  output) const
private

Definition at line 127 of file G4GenericFileManager.cc.

128{
129 return fFileManagers[static_cast<size_t>(output)];
130}

References fFileManagers.

◆ GetFileName()

G4String G4BaseFileManager::GetFileName ( ) const
inlineinherited

Definition at line 105 of file G4BaseFileManager.hh.

105 {
106 return fFileName;
107}

References G4BaseFileManager::fFileName.

◆ GetFileNames()

const std::vector< G4String > & G4BaseFileManager::GetFileNames ( ) const
inlineinherited

Definition at line 109 of file G4BaseFileManager.hh.

109 {
110 return fFileNames;
111}

References G4BaseFileManager::fFileNames.

Referenced by OpenFiles().

◆ GetFileType()

virtual G4String G4GenericFileManager::GetFileType ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 79 of file G4GenericFileManager.hh.

79{ return ""; }

◆ GetFullFileName()

G4String G4BaseFileManager::GetFullFileName ( const G4String baseFileName = "",
G4bool  isPerThread = true 
) const
inherited

Definition at line 63 of file G4BaseFileManager.cc.

65{
66 G4String fileName(baseFileName);
67 if ( fileName == "" ) fileName = fFileName;
68
69 // Take out file extension
70 auto name = G4Analysis::GetBaseName(fileName);
71
72 // Add thread Id to a file name if MT processing
73 if ( isPerThread && ! fState.GetIsMaster() ) {
74 std::ostringstream os;
76 name.append("_t");
77 name.append(os.str());
78 }
79
80 // Add (back if it was present or is defined) file extension
81 auto extension = G4Analysis::GetExtension(fileName, GetFileType());
82 if ( extension.size() ) {
83 name.append(".");
84 name.append(extension);
85 }
86
87 return name;
88}
virtual G4String GetFileType() const
G4String GetBaseName(const G4String &fileName)
G4int G4GetThreadId()
Definition: G4Threading.cc:122

References G4BaseFileManager::fFileName, G4Analysis::GetBaseName(), and G4InuclParticleNames::name().

Referenced by G4Hdf5FileManager::GetNtupleFileName(), G4RootFileManager::GetNtupleFileName(), G4XmlRFileManager::GetRFile(), G4Hdf5RFileManager::GetRFile(), G4RootRFileManager::GetRFile(), G4Hdf5FileManager::OpenFile(), G4RootFileManager::OpenFile(), G4XmlFileManager::OpenFile(), G4XmlRFileManager::OpenRFile(), G4Hdf5RFileManager::OpenRFile(), and G4RootRFileManager::OpenRFile().

◆ GetHistoDirectoryName()

G4String G4VFileManager::GetHistoDirectoryName ( ) const
inlineinherited

Definition at line 120 of file G4VFileManager.hh.

121{ return fHistoDirectoryName; }
G4String fHistoDirectoryName

References G4VFileManager::fHistoDirectoryName.

Referenced by CreateFileManager().

◆ GetHnFileManager()

template<typename HT >
std::shared_ptr< G4VTHnFileManager< HT > > G4VFileManager::GetHnFileManager ( ) const
inherited

◆ GetHnFileName()

G4String G4BaseFileManager::GetHnFileName ( const G4String hnType,
const G4String hnName 
) const
inherited

Definition at line 91 of file G4BaseFileManager.cc.

93{
94 return G4Analysis::GetHnFileName(fFileName, GetFileType(), hnType, hnName);
95}
G4String GetHnFileName(const G4String &fileName, const G4String &fileType, const G4String &hnType, const G4String &hnName)

References G4BaseFileManager::fFileName, G4BaseFileManager::GetFileType(), and G4Analysis::GetHnFileName().

◆ GetNtupleDirectoryName()

G4String G4VFileManager::GetNtupleDirectoryName ( ) const
inlineinherited

◆ GetNtupleFileName() [1/2]

G4String G4BaseFileManager::GetNtupleFileName ( const G4String ntupleName) const
inherited

Definition at line 98 of file G4BaseFileManager.cc.

99{
101}
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)

References G4BaseFileManager::fFileName, G4BaseFileManager::GetFileType(), and G4Analysis::GetNtupleFileName().

◆ GetNtupleFileName() [2/2]

G4String G4BaseFileManager::GetNtupleFileName ( G4int  ntupleFileNumber) const
inherited

◆ GetPlotFileName()

G4String G4BaseFileManager::GetPlotFileName ( ) const
inherited

Definition at line 110 of file G4BaseFileManager.cc.

111{
113}
G4String GetPlotFileName(const G4String &fileName)

References G4BaseFileManager::fFileName, and G4Analysis::GetPlotFileName().

◆ IsOpenFile()

G4bool G4VFileManager::IsOpenFile ( ) const
inlineinherited

Definition at line 117 of file G4VFileManager.hh.

118{ return fIsOpenFile; }

References G4VFileManager::fIsOpenFile.

◆ LockDirectoryNames()

void G4VFileManager::LockDirectoryNames ( )
inlineinherited

◆ Message()

void G4BaseFileManager::Message ( G4int  level,
const G4String action,
const G4String objectType,
const G4String objectName = "",
G4bool  success = true 
) const
inlineprotectedinherited

◆ OpenFile()

G4bool G4GenericFileManager::OpenFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 164 of file G4GenericFileManager.cc.

165{
166 auto fileManager = GetFileManager(fileName);
167 if ( ! fileManager ) return false;
168
169 if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) {
170 // Print warning if default output changed
171 // (maybe be not needed?)
172 Warn("Default file manager changed "
173 "(old: " +fDefaultFileManager->GetFileType() +
174 ", new:" + fileManager->GetFileType() + ")",
175 fkClass, "OpenFile");
176 }
177 fDefaultFileManager = fileManager;
178 fDefaultFileType = fileManager->GetFileType();
179
180 Message(kVL4, "open", "analysis file", fileName);
181
182 auto result = true;
183
184 // Save the default file name
185 // both in the generic file manager and the output specific one
186 result &= SetFileName(fileName);
187 result &= fDefaultFileManager->SetFileName(fileName);
188 result &= fDefaultFileManager->OpenFile(fileName);
189
191 fIsOpenFile = true;
192
193 Message(kVL1, "open", "analysis file", fileName, result);
194
195 return result;
196}
std::shared_ptr< G4VFileManager > fDefaultFileManager
virtual G4bool SetFileName(const G4String &fileName) final
void LockDirectoryNames()
constexpr G4int kVL1

References fDefaultFileManager, fDefaultFileType, G4VFileManager::fIsOpenFile, fkClass, GetFileManager(), G4Analysis::kVL1, G4Analysis::kVL4, G4VFileManager::LockDirectoryNames(), G4BaseFileManager::Message(), G4VFileManager::SetFileName(), and G4Analysis::Warn().

◆ OpenFiles()

G4bool G4GenericFileManager::OpenFiles ( )
finalvirtual

Definition at line 199 of file G4GenericFileManager.cc.

200{
201// Open all files regeistered with objects
202
203 Message(kVL4, "open", "analysis files");
204
205 auto result = true;
206
207 // process names registered in base file manager
208 for ( const auto& fileName : GetFileNames() ) {
209 auto fileManager = GetFileManager(fileName);
210 if ( ! fileManager ) {
211 FileManagerWarning(fileName, fkClass, "OpenFiles", fHdf5Warn);
212 continue;
213 }
214
215 result &= fileManager->CreateFile(fileName);
216 }
217
218 Message(kVL3, "open", "analysis files", "", result);
219
220 return result;
221}
const std::vector< G4String > & GetFileNames() const

References fHdf5Warn, anonymous_namespace{G4GenericFileManager.cc}::FileManagerWarning(), fkClass, GetFileManager(), G4BaseFileManager::GetFileNames(), G4Analysis::kVL3, G4Analysis::kVL4, and G4BaseFileManager::Message().

◆ SetDefaultFileType()

void G4GenericFileManager::SetDefaultFileType ( const G4String value)

Definition at line 385 of file G4GenericFileManager.cc.

386{
387 // Check if value correspond to a valid file type
388 auto output = G4Analysis::GetOutput(value);
389 if ( output == G4AnalysisOutput::kNone ) {
390 Warn("The file type " + value + "is not supported.\n" +
391 "The default type " + fDefaultFileType + " will be used.",
392 fkClass, "SetDeafultFileType");
393 return;
394 }
395
396 fDefaultFileType = value;
397}

References fDefaultFileType, fkClass, G4Analysis::GetOutput(), kNone, and G4Analysis::Warn().

◆ SetFileName()

G4bool G4VFileManager::SetFileName ( const G4String fileName)
finalvirtualinherited

Reimplemented from G4BaseFileManager.

Definition at line 45 of file G4VFileManager.cc.

46{
47 // Check extension
48 auto name = fileName;
49 auto extension = G4Analysis::GetExtension(fileName);
50 if ( extension.size() && GetFileType().size() && extension != GetFileType() ) {
51 // replace extension
52 name = G4Analysis::GetBaseName(fileName) + "." + GetFileType();
53 Warn(fileName + " file extension is not valid for " + GetFileType() + " output.\n" +
54 name + " will be used.", fkClass, "SetFileName");
55 }
56
58}
virtual G4bool SetFileName(const G4String &fileName)
static constexpr std::string_view fkClass

References G4VFileManager::fkClass, G4Analysis::GetBaseName(), G4Analysis::GetExtension(), G4BaseFileManager::GetFileType(), G4InuclParticleNames::name(), G4BaseFileManager::SetFileName(), and G4Analysis::Warn().

Referenced by OpenFile().

◆ SetHistoDirectoryName()

G4bool G4GenericFileManager::SetHistoDirectoryName ( const G4String dirName)
virtual

Reimplemented from G4VFileManager.

Definition at line 359 of file G4GenericFileManager.cc.

360{
361 auto result = G4VFileManager::SetHistoDirectoryName(dirName);
362
363 for (auto fileManager : fFileManagers ) {
364 if ( fileManager != nullptr ) {
365 result &= fileManager->SetHistoDirectoryName(dirName);
366 }
367 }
368 return result;
369}
virtual G4bool SetHistoDirectoryName(const G4String &dirName)

References fFileManagers, and G4VFileManager::SetHistoDirectoryName().

◆ SetIsEmpty()

G4bool G4GenericFileManager::SetIsEmpty ( const G4String fileName,
G4bool  isEmpty 
)
finalvirtual

Implements G4VFileManager.

Definition at line 347 of file G4GenericFileManager.cc.

348{
349 auto fileManager = GetFileManager(fileName);
350 if ( ! fileManager ) {
351 FileManagerWarning(fileName, fkClass, "SetIsEmpty", fHdf5Warn);
352 return false;
353 }
354
355 return fileManager->SetIsEmpty(fileName, isEmpty);
356}

References fHdf5Warn, anonymous_namespace{G4GenericFileManager.cc}::FileManagerWarning(), fkClass, and GetFileManager().

◆ SetNtupleDirectoryName()

G4bool G4GenericFileManager::SetNtupleDirectoryName ( const G4String dirName)
virtual

Reimplemented from G4VFileManager.

Definition at line 372 of file G4GenericFileManager.cc.

373{
374 auto result = G4VFileManager::SetNtupleDirectoryName(dirName);
375
376 for (auto fileManager : fFileManagers ) {
377 if ( fileManager != nullptr ) {
378 result &= fileManager->SetNtupleDirectoryName(dirName);
379 }
380 }
381 return result;
382}
virtual G4bool SetNtupleDirectoryName(const G4String &dirName)

References fFileManagers, and G4VFileManager::SetNtupleDirectoryName().

◆ UnlockDirectoryNames()

void G4VFileManager::UnlockDirectoryNames ( )
inlineinherited

Definition at line 114 of file G4VFileManager.hh.

115{ fLockDirectoryNames = false; }

References G4VFileManager::fLockDirectoryNames.

Referenced by Clear().

◆ WriteFile()

G4bool G4GenericFileManager::WriteFile ( const G4String fileName)
finalvirtual

Implements G4VFileManager.

Definition at line 319 of file G4GenericFileManager.cc.

320{
321// New prototype, fully implemented in templated base class
322
323 auto fileManager = GetFileManager(fileName);
324 if ( ! fileManager ) {
325 FileManagerWarning(fileName, fkClass, "WriteFile", fHdf5Warn);
326 return false;
327 }
328
329 return fileManager->WriteFile(fileName);
330}

References fHdf5Warn, anonymous_namespace{G4GenericFileManager.cc}::FileManagerWarning(), fkClass, and GetFileManager().

◆ WriteFiles()

G4bool G4GenericFileManager::WriteFiles ( )
finalvirtual

Implements G4VFileManager.

Definition at line 224 of file G4GenericFileManager.cc.

225{
226// Finish write for all files registered with objects
227
228 Message(kVL4, "write", "analysis files");
229
230 auto result = true;
231
232 for ( const auto& fileManager : fFileManagers ) {
233 if ( ! fileManager ) continue;
234
235 Message(kVL4, "write", fileManager->GetFileType(), "files");
236
237 result &= fileManager->WriteFiles();
238 }
239
240 Message(kVL3, "write", "analysis files", "", result);
241
242 return result;
243}

References fFileManagers, G4Analysis::kVL3, G4Analysis::kVL4, and G4BaseFileManager::Message().

◆ WriteTExtra()

template<typename HT >
G4bool G4GenericFileManager::WriteTExtra ( const G4String fileName,
HT *  ht,
const G4String htName 
)

Field Documentation

◆ fCsvFileManager

std::shared_ptr<G4CsvFileManager> G4GenericFileManager::fCsvFileManager { nullptr }
private

Definition at line 112 of file G4GenericFileManager.hh.

Referenced by CreateFileManager(), and CreateNtupleFileManager().

◆ fDefaultFileManager

std::shared_ptr<G4VFileManager> G4GenericFileManager::fDefaultFileManager { nullptr }
private

Definition at line 107 of file G4GenericFileManager.hh.

Referenced by OpenFile().

◆ fDefaultFileType

G4String G4GenericFileManager::fDefaultFileType
private

Definition at line 106 of file G4GenericFileManager.hh.

Referenced by GetFileManager(), OpenFile(), and SetDefaultFileType().

◆ fFileManagers

std::vector<std::shared_ptr<G4VFileManager> > G4GenericFileManager::fFileManagers
private
Initial value:
{
nullptr, nullptr, nullptr, nullptr
}

Definition at line 108 of file G4GenericFileManager.hh.

Referenced by Clear(), CloseFiles(), CreateFileManager(), DeleteEmptyFiles(), GetFileManager(), SetHistoDirectoryName(), SetNtupleDirectoryName(), and WriteFiles().

◆ fFileName

G4String G4BaseFileManager::fFileName
protectedinherited

◆ fFileNames

std::vector<G4String> G4BaseFileManager::fFileNames
protectedinherited

◆ fH1FileManager

std::shared_ptr<G4VTHnFileManager<tools::histo::h1d> > G4VFileManager::fH1FileManager { nullptr }
protectedinherited

◆ fH2FileManager

std::shared_ptr<G4VTHnFileManager<tools::histo::h2d> > G4VFileManager::fH2FileManager { nullptr }
protectedinherited

◆ fH3FileManager

std::shared_ptr<G4VTHnFileManager<tools::histo::h3d> > G4VFileManager::fH3FileManager { nullptr }
protectedinherited

◆ fHdf5Warn

G4bool G4GenericFileManager::fHdf5Warn { true }
private

◆ fHistoDirectoryName

G4String G4VFileManager::fHistoDirectoryName
protectedinherited

◆ fIsOpenFile

G4bool G4VFileManager::fIsOpenFile { false }
protectedinherited

◆ fkClass

constexpr std::string_view G4GenericFileManager::fkClass { "G4GenericFileManager" }
staticconstexprprivate

◆ fLockDirectoryNames

G4bool G4VFileManager::fLockDirectoryNames { false }
protectedinherited

◆ fNtupleDirectoryName

G4String G4VFileManager::fNtupleDirectoryName
protectedinherited

◆ fP1FileManager

std::shared_ptr<G4VTHnFileManager<tools::histo::p1d> > G4VFileManager::fP1FileManager { nullptr }
protectedinherited

◆ fP2FileManager

std::shared_ptr<G4VTHnFileManager<tools::histo::p2d> > G4VFileManager::fP2FileManager { nullptr }
protectedinherited

◆ fRootFileManager

std::shared_ptr<G4RootFileManager> G4GenericFileManager::fRootFileManager { nullptr }
private

Definition at line 116 of file G4GenericFileManager.hh.

Referenced by CreateFileManager(), and CreateNtupleFileManager().

◆ fState

const G4AnalysisManagerState& G4BaseFileManager::fState
protectedinherited

◆ fXmlFileManager

std::shared_ptr<G4XmlFileManager> G4GenericFileManager::fXmlFileManager { nullptr }
private

Definition at line 117 of file G4GenericFileManager.hh.

Referenced by CreateFileManager(), and CreateNtupleFileManager().


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