File indexing completed on 2025-01-18 09:59:03
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 G4RootFileManager_h
0032 #define G4RootFileManager_h 1
0033
0034 #include "G4VTFileManager.hh"
0035 #include "G4RootFileDef.hh"
0036 #include "G4AnalysisUtilities.hh"
0037 #include "globals.hh"
0038
0039 #include <vector>
0040 #include <memory>
0041 #include <tuple>
0042 #include <string_view>
0043
0044 namespace tools {
0045 namespace wroot{
0046 class ntuple;
0047 }
0048 }
0049
0050
0051 using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
0052
0053 class G4RootFileManager : public G4VTFileManager<G4RootFile>
0054 {
0055 public:
0056 explicit G4RootFileManager(const G4AnalysisManagerState& state);
0057 G4RootFileManager() = delete;
0058 ~G4RootFileManager() override = default;
0059
0060 using G4BaseFileManager::GetNtupleFileName;
0061 using G4VTFileManager<G4RootFile>::WriteFile;
0062 using G4VTFileManager<G4RootFile>::CloseFile;
0063
0064
0065 G4bool OpenFile(const G4String& fileName) final;
0066
0067 G4String GetFileType() const final { return "root"; }
0068 G4bool HasCycles() const final { return true; }
0069
0070
0071 std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
0072 G4int mainNumber = -1);
0073 std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
0074 G4bool perThread = true,
0075 G4int mainNumber = -1) const;
0076 G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription,
0077 G4int mainNumber = -1);
0078
0079
0080 void SetBasketSize(unsigned int basketSize);
0081 void SetBasketEntries(unsigned int basketEntries);
0082
0083
0084 unsigned int GetBasketSize() const;
0085 unsigned int GetBasketEntries() const;
0086
0087 protected:
0088
0089 std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
0090 G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
0091 G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
0092
0093 private:
0094
0095 tools::wroot::directory* CreateDirectory(
0096 tools::wroot::file* rfile,
0097 const G4String& directoryName,
0098 const G4String& objectType) const;
0099 G4String GetNtupleFileName(
0100 RootNtupleDescription* ntupleDescription,
0101 G4bool perThread = true,
0102 G4int mainNumber = -1) const;
0103
0104
0105 static constexpr std::string_view fkClass { "G4RootFileManager" };
0106
0107
0108 unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
0109 unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
0110 };
0111
0112
0113
0114
0115 inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
0116 { fBasketSize = basketSize; }
0117
0118
0119 inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
0120 { fBasketEntries = basketEntries; }
0121
0122
0123 inline unsigned int G4RootFileManager::GetBasketSize() const
0124 { return fBasketSize; }
0125
0126
0127 inline unsigned int G4RootFileManager::GetBasketEntries() const
0128 { return fBasketEntries; }
0129
0130 #endif
0131