50void FileManagerException(
const G4String& fileName,
const G4String& functionName,
53 if (
GetExtension(fileName) ==
"hdf5" && ( ! hdf5Warn ) )
return;
55 G4String where =
"G4GenericFileManager::" + functionName;
56 G4String what =
"Analysis_" + exceptionClassification;
58 description <<
"Cannot get file manager for " << fileName;
65const G4String G4GenericFileManager::fgkDefaultFileType =
"root";
70 fDefaultFileType(fgkDefaultFileType),
71 fDefaultFileManager(nullptr),
78 fCsvFileManager(
nullptr),
80 fHdf5FileManager(
nullptr),
82 fRootFileManager(
nullptr),
83 fXmlFileManager(
nullptr),
104 auto outputId =
static_cast<size_t>(output);
105 if ( fFileManagers[outputId] ) {
110 G4Exception(
"G4GenericFileManager::CreateFileManager",
117 case G4AnalysisOutput::kCsv:
118 fCsvFileManager = std::make_shared<G4CsvFileManager>(
fState);
119 fFileManagers[outputId] = fCsvFileManager;
121 case G4AnalysisOutput::kHdf5:
123 fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(
fState);
124 fFileManagers[outputId] = fHdf5FileManager;
128 description <<
"Hdf5 type is not available.";
129 G4Exception(
"G4GenericFileManager::CreateFileManager",
135 case G4AnalysisOutput::kRoot:
136 fRootFileManager = std::make_shared<G4RootFileManager>(
fState);
137 fFileManagers[outputId] = fRootFileManager;
139 case G4AnalysisOutput::kXml:
140 fXmlFileManager = std::make_shared<G4XmlFileManager>(
fState);
141 fFileManagers[outputId] = fXmlFileManager ;
143 case G4AnalysisOutput::kNone:
147 G4Exception(
"G4GenericFileManager::CreateFileManager",
160std::shared_ptr<G4VFileManager>
163 return fFileManagers[
static_cast<size_t>(output)];
167std::shared_ptr<G4VFileManager>
168G4GenericFileManager::GetFileManager(
const G4String& fileName)
172 if ( ! extension.size() ) {
174 extension = fDefaultFileType;
178 if ( output == G4AnalysisOutput::kNone ) {
182 <<
"The file extension " << extension <<
"is not supported.";
183 G4Exception(
"G4GenericFileManager::GetFileManager",
188 std::shared_ptr<G4VFileManager> fileManager = GetFileManager(output);
189 if ( ! GetFileManager(output) ) {
190 CreateFileManager(output);
191 fileManager = GetFileManager(output);
194 return GetFileManager(output);
204 auto fileManager = GetFileManager(fileName);
205 if ( ! fileManager )
return false;
207 if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) {
212 <<
"Default file manager changed (old: "
213 << fDefaultFileManager->GetFileType()
214 <<
", new:" << fileManager->GetFileType() <<
")";
218 fDefaultFileManager = fileManager;
226 auto finalResult =
true;
232 finalResult = finalResult && result;
233 result = fDefaultFileManager->SetFileName(fileName);
234 finalResult = finalResult && result;
236 result = fDefaultFileManager->OpenFile(fileName);
237 finalResult = finalResult && result;
262 auto finalResult =
true;
267 auto fileManager = GetFileManager(fileName);
268 if ( ! fileManager ) {
269 FileManagerException(fileName,
"OpenFiles",
"W001", fHdf5Warn);
273 result = fileManager->CreateFile(fileName);
274 finalResult = result && finalResult;
297 auto finalResult =
true;
300 for (
auto fileManager : fFileManagers ) {
301 if ( ! fileManager )
continue;
309 result = fileManager->WriteFiles();
310 finalResult = result && finalResult;
333 auto finalResult =
true;
336 for (
auto fileManager : fFileManagers ) {
337 if ( ! fileManager )
continue;
345 result = fileManager->CloseFiles();
346 finalResult = result && finalResult;
369 auto finalResult =
true;
372 for (
auto fileManager : fFileManagers ) {
373 if ( ! fileManager )
continue;
381 result = fileManager->DeleteEmptyFiles();
382 finalResult = result && finalResult;
399 auto fileManager = GetFileManager(fileName);
400 if ( ! fileManager ) {
401 FileManagerException(fileName,
"CreateFile",
"W001", fHdf5Warn);
405 return fileManager->CreateFile(fileName);
413 auto fileManager = GetFileManager(fileName);
414 if ( ! fileManager ) {
415 FileManagerException(fileName,
"WriteFile",
"W021", fHdf5Warn);
419 return fileManager->WriteFile(fileName);
427 auto fileManager = GetFileManager(fileName);
428 if ( ! fileManager ) {
429 FileManagerException(fileName,
"CloseFile",
"W021", fHdf5Warn);
433 return fileManager->CloseFile(fileName);
439 auto fileManager = GetFileManager(fileName);
440 if ( ! fileManager ) {
441 FileManagerException(fileName,
"SetIsEmpty",
"W021", fHdf5Warn);
445 return fileManager->SetIsEmpty(fileName, isEmpty);
453 if ( output == G4AnalysisOutput::kNone ) {
456 <<
"The file type " << value <<
"is not supported." <<
G4endl
457 <<
"The default type " << fDefaultFileType <<
" will be used.";
458 G4Exception(
"G4GenericFileManager::SetDeafultFileType",
463 fDefaultFileType = value;
467std::shared_ptr<G4VNtupleFileManager>
470 if ( ! GetFileManager(output) ) {
471 CreateFileManager(output);
474 std::shared_ptr<G4VNtupleFileManager> vNtupleFileManager =
nullptr;
478 case G4AnalysisOutput::kCsv: {
479 auto ntupleFileManager = std::make_shared<G4CsvNtupleFileManager>(
fState);
480 ntupleFileManager->SetFileManager(fCsvFileManager);
481 vNtupleFileManager = ntupleFileManager;
484 case G4AnalysisOutput::kHdf5: {
486 auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(
fState);
487 ntupleFileManager->SetFileManager(fHdf5FileManager);
488 vNtupleFileManager = ntupleFileManager;
490 failure =
" Hdf5 is not available";
494 case G4AnalysisOutput::kRoot: {
495 auto ntupleFileManager = std::make_shared<G4RootNtupleFileManager>(
fState);
496 ntupleFileManager->SetFileManager(fRootFileManager);
497 vNtupleFileManager = ntupleFileManager;
500 case G4AnalysisOutput::kXml: {
501 auto ntupleFileManager = std::make_shared<G4XmlNtupleFileManager>(
fState);
502 ntupleFileManager->SetFileManager(fXmlFileManager);
503 vNtupleFileManager = ntupleFileManager;
506 case G4AnalysisOutput::kNone:
510 if ( ! vNtupleFileManager ) {
516 G4Exception(
"G4GenericFileManager::CreateNtupleFileManager",
520 return vNtupleFileManager;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL1() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const std::vector< G4String > & GetFileNames() const
const G4AnalysisManagerState & fState
virtual G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
virtual ~G4GenericFileManager()
virtual G4bool WriteFiles() final
virtual G4bool CreateFile(const G4String &fileName) final
std::shared_ptr< G4VNtupleFileManager > CreateNtupleFileManager(G4AnalysisOutput output)
virtual G4bool OpenFiles() final
virtual G4bool CloseFile(const G4String &fileName) final
virtual G4bool OpenFile(const G4String &fileName) final
void SetDefaultFileType(const G4String &value)
virtual G4bool WriteFile(const G4String &fileName) final
G4GenericFileManager(const G4AnalysisManagerState &state)
virtual G4bool CloseFiles() final
virtual G4bool DeleteEmptyFiles() final
G4bool fLockDirectoryNames
virtual G4bool SetFileName(const G4String &fileName) final
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4String GetOutputName(G4AnalysisOutput outputType)
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)