File indexing completed on 2025-01-18 09:59:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef G4TFileManager_h
0030 #define G4TFileManager_h 1
0031
0032 #include "G4TFileInformation.hh"
0033
0034 #include <vector>
0035 #include <memory>
0036 #include <string_view>
0037
0038 template <typename FT>
0039 class G4TFileManager
0040 {
0041 public:
0042 explicit G4TFileManager(const G4AnalysisManagerState& state);
0043 G4TFileManager() = delete;
0044 virtual ~G4TFileManager();
0045
0046
0047
0048 std::shared_ptr<FT> CreateTFile(const G4String& fileName);
0049 G4bool WriteTFile(const G4String& fileName);
0050 G4bool CloseTFile(const G4String& fileName);
0051 G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty);
0052
0053 std::shared_ptr<FT> GetTFile(const G4String& fileName, G4bool warn = true) const;
0054
0055
0056 G4bool OpenFiles();
0057 G4bool WriteFiles();
0058 G4bool CloseFiles();
0059 G4bool DeleteEmptyFiles();
0060
0061
0062 void ClearData();
0063
0064 protected:
0065
0066 virtual std::shared_ptr<FT> CreateFileImpl(const G4String& fileName) = 0;
0067 virtual G4bool WriteFileImpl(std::shared_ptr<FT> file) = 0;
0068 virtual G4bool CloseFileImpl(std::shared_ptr<FT> file) = 0;
0069
0070 private:
0071
0072 void FileNotFoundWarning(const G4String& fileName,
0073 std::string_view functionName) const;
0074 G4TFileInformation<FT>* GetFileInfoInFunction(const G4String& fileName,
0075 std::string_view functionName, G4bool warn = true) const;
0076 std::shared_ptr<FT> GetFileInFunction(const G4String& fileName,
0077 std::string_view functionName, G4bool warn = true) const;
0078
0079 G4bool WriteTFile(std::shared_ptr<FT> file, const G4String& fileName);
0080 G4bool CloseTFile(std::shared_ptr<FT> file, const G4String& fileName);
0081 G4bool DeleteEmptyFile(const G4String& fileName);
0082
0083
0084 static constexpr std::string_view fkClass { "G4TFileManager<FT>" };
0085
0086
0087 const G4AnalysisManagerState& fAMState;
0088 std::map<G4String, G4TFileInformation<FT>*> fFileMap;
0089 };
0090
0091 #include "G4TFileManager.icc"
0092
0093 #endif