File indexing completed on 2025-01-18 09:58:45
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 G4NtupleBookingManager_h
0032 #define G4NtupleBookingManager_h 1
0033
0034 #include "G4BaseAnalysisManager.hh"
0035 #include "G4AnalysisUtilities.hh"
0036 #include "globals.hh"
0037
0038 #include "tools/ntuple_booking"
0039
0040 #include <set>
0041 #include <string_view>
0042 #include <vector>
0043
0044 struct G4NtupleBooking
0045 {
0046 G4NtupleBooking() = default;
0047 ~G4NtupleBooking() = default;
0048
0049 void SetDeleted(G4bool deleted, G4bool keepSetting) {
0050 fDeleted = std::make_pair(deleted, keepSetting);
0051 }
0052 G4bool GetDeleted() const {
0053 return fDeleted.first;
0054 }
0055 void Reset() {
0056 if (! fDeleted.second) {
0057
0058 fFileName.clear();
0059 fActivation = true;
0060 }
0061 SetDeleted(false, false);
0062 }
0063
0064 tools::ntuple_booking fNtupleBooking;
0065 G4int fNtupleId { G4Analysis::kInvalidId };
0066 G4String fFileName;
0067 G4bool fActivation { true };
0068 std::pair<G4bool, G4bool> fDeleted { false, false };
0069 };
0070
0071 class G4NtupleBookingManager : public G4BaseAnalysisManager
0072 {
0073
0074
0075 friend class G4VAnalysisManager;
0076
0077 public:
0078 explicit G4NtupleBookingManager(const G4AnalysisManagerState& state);
0079 G4NtupleBookingManager() = delete;
0080 ~G4NtupleBookingManager() override;
0081
0082 const std::vector<G4NtupleBooking*>& GetNtupleBookingVector() const;
0083
0084
0085
0086 void SetFileType(const G4String& fileType);
0087 G4String GetFileType() const;
0088 G4bool IsEmpty() const;
0089
0090
0091 tools::ntuple_booking* GetNtuple(G4bool warn,
0092 G4bool onlyIfActive) const;
0093 tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn,
0094 G4bool onlyIfActive) const;
0095
0096 protected:
0097
0098
0099 G4int CreateNtuple(const G4String& name, const G4String& title);
0100
0101
0102
0103 G4int CreateNtupleIColumn(const G4String& name,
0104 std::vector<int>* vector);
0105 G4int CreateNtupleFColumn(const G4String& name,
0106 std::vector<float>* vector) ;
0107 G4int CreateNtupleDColumn(const G4String& name,
0108 std::vector<double>* vector);
0109 G4int CreateNtupleSColumn(const G4String& name,
0110 std::vector<std::string>* vector);
0111 G4NtupleBooking* FinishNtuple() ;
0112
0113
0114 G4int CreateNtupleIColumn(G4int ntupleId,
0115 const G4String& name, std::vector<int>* vector);
0116 G4int CreateNtupleFColumn(G4int ntupleId,
0117 const G4String& name, std::vector<float>* vector);
0118 G4int CreateNtupleDColumn(G4int ntupleId,
0119 const G4String& name, std::vector<double>* vector);
0120 G4int CreateNtupleSColumn(G4int ntupleId,
0121 const G4String& name, std::vector<std::string>* vector);
0122 G4NtupleBooking* FinishNtuple(G4int ntupleId);
0123
0124
0125
0126
0127 G4bool SetFirstNtupleColumnId(G4int firstId);
0128 G4int GetFirstNtupleColumnId() const;
0129
0130
0131
0132 void SetActivation(G4bool activation);
0133 void SetActivation(G4int ntupleId, G4bool activation);
0134 G4bool GetActivation(G4int ntupleId) const;
0135
0136
0137 void SetFileName(const G4String& fileName);
0138 void SetFileName(G4int id, const G4String& fileName);
0139 G4String GetFileName(G4int id) const;
0140
0141
0142 G4int GetNofNtuples(G4bool onlyIfExist = false) const;
0143
0144
0145 void ClearData();
0146
0147
0148 G4bool Delete(G4int id, G4bool keepSetting);
0149
0150
0151 G4bool List(std::ostream& output, G4bool onlyIfActive = true);
0152
0153
0154 std::vector<G4NtupleBooking*> fNtupleBookingVector;
0155 std::set<G4int> fFreeIds;
0156
0157 private:
0158
0159
0160 G4NtupleBooking* GetNtupleBookingInFunction(
0161 G4int id,
0162 std::string_view function,
0163 G4bool warn = true) const;
0164
0165 G4bool CheckName(const G4String& name, const G4String& objectType) const;
0166 template <typename T>
0167 G4int CreateNtupleTColumn(G4int ntupleId,
0168 const G4String& name, std::vector<T>* vector);
0169 G4int GetCurrentNtupleId() const;
0170
0171
0172 static constexpr std::string_view fkClass { "G4NtupleBookingManager" };
0173
0174
0175 G4String fFileType;
0176 G4int fFirstNtupleColumnId { 0 };
0177 G4bool fLockFirstNtupleColumnId { false };
0178 G4int fCurrentNtupleId { G4Analysis::kInvalidId };
0179 };
0180
0181 #include "G4NtupleBookingManager.icc"
0182
0183 #endif