File indexing completed on 2025-01-18 09:59:21
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
0030
0031 #ifndef G4VFileManager_h
0032 #define G4VFileManager_h 1
0033
0034 #include "G4BaseFileManager.hh"
0035 #include "G4VTHnFileManager.hh"
0036 #include "globals.hh"
0037
0038 #include <memory>
0039 #include <string_view>
0040
0041 namespace tools {
0042 namespace histo {
0043 class h1d;
0044 class h2d;
0045 class h3d;
0046 class p1d;
0047 class p2d;
0048 }
0049 }
0050
0051 class G4VFileManager : public G4BaseFileManager
0052 {
0053 public:
0054 explicit G4VFileManager(const G4AnalysisManagerState& state);
0055 G4VFileManager() = delete;
0056 ~G4VFileManager() override = default;
0057
0058
0059 virtual G4bool OpenFile(const G4String& fileName) = 0;
0060
0061
0062 virtual G4bool CreateFile(const G4String& fileName) = 0;
0063 virtual G4bool WriteFile(const G4String& fileName) = 0;
0064 virtual G4bool CloseFile(const G4String& fileName) = 0;
0065 virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) = 0;
0066
0067
0068 virtual G4bool OpenFiles() = 0;
0069 virtual G4bool WriteFiles() = 0;
0070 virtual G4bool CloseFiles() = 0;
0071 virtual G4bool DeleteEmptyFiles() = 0;
0072
0073
0074 virtual void Clear() = 0;
0075
0076
0077 G4bool SetFileName(const G4String& fileName) final;
0078 virtual G4bool SetHistoDirectoryName(const G4String& dirName);
0079 virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
0080
0081 void LockDirectoryNames();
0082 void UnlockDirectoryNames();
0083
0084 G4bool IsOpenFile() const;
0085 G4String GetHistoDirectoryName() const;
0086 G4String GetNtupleDirectoryName() const;
0087 G4int GetCycle() const;
0088
0089
0090 template <typename HT>
0091 std::shared_ptr<G4VTHnFileManager<HT>> GetHnFileManager() const;
0092
0093 protected:
0094
0095 static constexpr std::string_view fkClass { "G4VFileManager" };
0096
0097
0098 G4String fHistoDirectoryName;
0099 G4String fNtupleDirectoryName;
0100 G4bool fIsOpenFile { false };
0101 G4bool fLockDirectoryNames { false };
0102
0103
0104 std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>> fH1FileManager { nullptr };
0105 std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>> fH2FileManager { nullptr };
0106 std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>> fH3FileManager { nullptr };
0107 std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>> fP1FileManager { nullptr };
0108 std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>> fP2FileManager { nullptr };
0109 };
0110
0111
0112
0113 inline void G4VFileManager::LockDirectoryNames()
0114 { fLockDirectoryNames = true; }
0115
0116 inline void G4VFileManager::UnlockDirectoryNames()
0117 { fLockDirectoryNames = false; }
0118
0119 inline G4bool G4VFileManager::IsOpenFile() const
0120 { return fIsOpenFile; }
0121
0122 inline G4String G4VFileManager::GetHistoDirectoryName() const
0123 { return fHistoDirectoryName; }
0124
0125 inline G4String G4VFileManager::GetNtupleDirectoryName() const
0126 { return fNtupleDirectoryName; }
0127
0128 inline G4int G4VFileManager::GetCycle() const
0129 { return fState.GetCycle(); }
0130
0131 template <>
0132 inline
0133 std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>>
0134 G4VFileManager::GetHnFileManager<tools::histo::h1d>() const
0135 { return fH1FileManager; }
0136
0137 template <>
0138 inline
0139 std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>>
0140 G4VFileManager::GetHnFileManager<tools::histo::h2d>() const
0141 { return fH2FileManager; }
0142
0143 template <>
0144 inline
0145 std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>>
0146 G4VFileManager::GetHnFileManager<tools::histo::h3d>() const
0147 { return fH3FileManager; }
0148
0149 template <>
0150 inline
0151 std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>>
0152 G4VFileManager::GetHnFileManager<tools::histo::p1d>() const
0153 { return fP1FileManager; }
0154
0155 template <>
0156 inline
0157 std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>>
0158 G4VFileManager::GetHnFileManager<tools::histo::p2d>() const
0159 { return fP2FileManager; }
0160
0161 #endif