48void FileManagerWarning(
const G4String& fileName,
49 std::string_view className,
50 std::string_view functionName,
53 if (
GetExtension(fileName) ==
"hdf5" && ( ! hdf5Warn ) )
return;
55 Warn(
"Cannot get file manager for " + fileName,
56 className, functionName);
75 auto outputId =
static_cast<size_t>(output);
76 if ( fFileManagers[outputId] ) {
78 " type already exists.",
79 fkClass,
"CreateFileManager");
86 fCsvFileManager = std::make_shared<G4CsvFileManager>(
fState);
87 fFileManagers[outputId] = fCsvFileManager;
91 fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(
fState);
92 fFileManagers[outputId] = fHdf5FileManager;
95 Warn(
"Hdf5 type is not available.", fkClass,
"CreateFileManager");
101 fRootFileManager = std::make_shared<G4RootFileManager>(
fState);
102 fFileManagers[outputId] = fRootFileManager;
105 fXmlFileManager = std::make_shared<G4XmlFileManager>(
fState);
106 fFileManagers[outputId] = fXmlFileManager ;
110 fkClass,
"CreateFileManager");
126std::shared_ptr<G4VFileManager>
129 return fFileManagers[
static_cast<size_t>(output)];
133std::shared_ptr<G4VFileManager>
138 if (extension.size() == 0u) {
140 extension = fDefaultFileType;
145 Warn(
"The file extension " + extension +
"is not supported.",
146 fkClass,
"GetFileManager");
150 std::shared_ptr<G4VFileManager> fileManager =
GetFileManager(output);
152 CreateFileManager(output);
167 if ( ! fileManager )
return false;
169 if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) {
172 Warn(
"Default file manager changed "
173 "(old: " +fDefaultFileManager->GetFileType() +
174 ", new:" + fileManager->GetFileType() +
")",
175 fkClass,
"OpenFile");
177 fDefaultFileManager = fileManager;
178 fDefaultFileType = fileManager->GetFileType();
187 result &= fDefaultFileManager->SetFileName(fileName);
188 result &= fDefaultFileManager->OpenFile(fileName);
193 Message(
kVL1,
"open",
"analysis file", fileName, result);
210 if ( ! fileManager ) {
211 FileManagerWarning(fileName, fkClass,
"OpenFiles", fHdf5Warn);
216 auto newFileName = fileName;
217 if (fileManager == fCsvFileManager) {
218 newFileName = fileManager->GetHnFileName(fileName,
GetCycle());
221 result &= fileManager->CreateFile(newFileName);
224 Message(
kVL3,
"open",
"analysis files",
"", result);
238 for (
const auto& fileManager : fFileManagers ) {
239 if ( ! fileManager )
continue;
241 Message(
kVL4,
"write", fileManager->GetFileType(),
"files");
243 result &= fileManager->WriteFiles();
246 Message(
kVL3,
"write",
"analysis files",
"", result);
260 for (
const auto& fileManager : fFileManagers ) {
261 if ( ! fileManager )
continue;
263 Message(
kVL4,
"close", fileManager->GetFileType(),
"files");
265 result &= fileManager->CloseFiles();
270 Message(
kVL3,
"close",
"analysis files",
"", result);
284 for (
const auto& fileManager : fFileManagers ) {
285 if ( ! fileManager )
continue;
287 Message(
kVL4,
"delete", fileManager->GetFileType(),
"empty files");
289 result &= fileManager->DeleteEmptyFiles();
295 Message(
kVL3,
"delete",
"empty files",
"", result);
305 for (
const auto& fileManager : fFileManagers ) {
306 if ( ! fileManager )
continue;
308 fileManager->Clear();
319 if ( ! fileManager ) {
320 FileManagerWarning(fileName, fkClass,
"CreateFile", fHdf5Warn);
324 return fileManager->CreateFile(fileName);
333 if ( ! fileManager ) {
334 FileManagerWarning(fileName, fkClass,
"WriteFile", fHdf5Warn);
338 return fileManager->WriteFile(fileName);
347 if ( ! fileManager ) {
348 FileManagerWarning(fileName, fkClass,
"CloseFile", fHdf5Warn);
352 return fileManager->CloseFile(fileName);
359 if ( ! fileManager ) {
360 FileManagerWarning(fileName, fkClass,
"SetIsEmpty", fHdf5Warn);
364 return fileManager->SetIsEmpty(fileName, isEmpty);
372 for (
auto& fileManager : fFileManagers ) {
373 if ( fileManager !=
nullptr ) {
374 result &= fileManager->SetHistoDirectoryName(dirName);
385 for (
auto& fileManager : fFileManagers ) {
386 if ( fileManager !=
nullptr ) {
387 result &= fileManager->SetNtupleDirectoryName(dirName);
399 Warn(
"The file type " + value +
"is not supported.\n" +
400 "The default type " + fDefaultFileType +
" will be used.",
401 fkClass,
"SetDeafultFileType");
405 fDefaultFileType = value;
409std::shared_ptr<G4VNtupleFileManager>
413 CreateFileManager(output);
416 std::shared_ptr<G4VNtupleFileManager> vNtupleFileManager =
nullptr;
421 auto ntupleFileManager = std::make_shared<G4CsvNtupleFileManager>(
fState);
422 ntupleFileManager->SetFileManager(fCsvFileManager);
423 vNtupleFileManager = ntupleFileManager;
428 auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(
fState);
429 ntupleFileManager->SetFileManager(fHdf5FileManager);
430 vNtupleFileManager = ntupleFileManager;
432 failure =
" Hdf5 is not available";
437 auto ntupleFileManager = std::make_shared<G4RootNtupleFileManager>(
fState);
438 ntupleFileManager->SetFileManager(fRootFileManager);
439 vNtupleFileManager = ntupleFileManager;
443 auto ntupleFileManager = std::make_shared<G4XmlNtupleFileManager>(
fState);
444 ntupleFileManager->SetFileManager(fXmlFileManager);
445 vNtupleFileManager = ntupleFileManager;
452 if ( ! vNtupleFileManager ) {
453 Warn(
"Failed to create ntuple file manager of " +
455 fkClass,
"CreateNtupleFileManager");
458 return vNtupleFileManager;
const std::vector< G4String > & GetFileNames() const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
const G4AnalysisManagerState & fState
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
G4bool WriteFiles() final
G4bool CreateFile(const G4String &fileName) final
std::shared_ptr< G4VNtupleFileManager > CreateNtupleFileManager(G4AnalysisOutput output)
virtual G4bool OpenFiles() final
G4bool CloseFile(const G4String &fileName) final
std::shared_ptr< G4VFileManager > GetFileManager(const G4String &fileName)
G4bool OpenFile(const G4String &fileName) final
G4bool SetNtupleDirectoryName(const G4String &dirName) override
void SetDefaultFileType(const G4String &value)
G4bool SetHistoDirectoryName(const G4String &dirName) override
G4bool WriteFile(const G4String &fileName) final
G4GenericFileManager(const G4AnalysisManagerState &state)
G4bool CloseFiles() final
G4bool DeleteEmptyFiles() final
G4String GetNtupleDirectoryName() const
G4String GetHistoDirectoryName() const
virtual G4bool SetHistoDirectoryName(const G4String &dirName)
G4bool SetFileName(const G4String &fileName) final
virtual G4bool SetNtupleDirectoryName(const G4String &dirName)
void LockDirectoryNames()
void UnlockDirectoryNames()
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4String GetOutputName(G4AnalysisOutput outputType)
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)