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 G4RootPNtupleManager_h
0032 #define G4RootPNtupleManager_h 1
0033
0034 #include "G4BaseNtupleManager.hh"
0035 #include "G4RootMainNtupleManager.hh"
0036 #include "G4RootPNtupleDescription.hh"
0037 #include "G4AnalysisManagerState.hh"
0038 #include "G4AnalysisUtilities.hh"
0039 #include "G4AutoLock.hh"
0040 #include "globals.hh"
0041
0042 #include <vector>
0043 #include <string_view>
0044
0045 class G4RootMainNtupleManager;
0046
0047 namespace tools {
0048 namespace wroot {
0049 class file;
0050 class ntuple;
0051 class imt_ntuple;
0052 }
0053 }
0054
0055
0056
0057
0058 class mutex : public virtual tools::wroot::imutex {
0059 using parent = tools::wroot::imutex;
0060 public:
0061 bool lock() override
0062 {
0063
0064 m_mutex.lock();
0065 return true;
0066 }
0067 bool unlock() override
0068 {
0069 m_mutex.unlock();
0070
0071 return true;
0072 }
0073
0074 public:
0075 mutex(G4AutoLock& a_mutex):m_mutex(a_mutex){}
0076 ~mutex() override = default;
0077
0078 protected:
0079 mutex(const mutex& a_from) = default;
0080 mutex& operator=(const mutex&){return *this;}
0081 protected:
0082 G4AutoLock& m_mutex;
0083 };
0084
0085 class G4RootPNtupleManager : public G4BaseNtupleManager
0086 {
0087 friend class G4RootAnalysisManager;
0088 friend class G4RootNtupleFileManager;
0089
0090 public:
0091 G4RootPNtupleManager(const G4AnalysisManagerState& state,
0092 std::shared_ptr<G4NtupleBookingManager> bookingManger,
0093 std::shared_ptr<G4RootMainNtupleManager> main,
0094 G4bool rowWise, G4bool rowMode);
0095 G4RootPNtupleManager() = delete;
0096 ~G4RootPNtupleManager() override;
0097
0098 private:
0099
0100 void CreateNtupleFromMain(G4RootPNtupleDescription* ntupleDescription,
0101 tools::wroot::ntuple* mainNtuple);
0102 void CreateNtupleDescriptionsFromBooking();
0103 void CreateNtuplesFromMain();
0104 void CreateNtuplesIfNeeded();
0105
0106
0107
0108 G4int CreateNtuple(G4NtupleBooking* booking) final;
0109
0110
0111
0112 using G4BaseNtupleManager::FillNtupleIColumn;
0113 using G4BaseNtupleManager::FillNtupleFColumn;
0114 using G4BaseNtupleManager::FillNtupleDColumn;
0115 using G4BaseNtupleManager::FillNtupleSColumn;
0116 using G4BaseNtupleManager::AddNtupleRow;
0117
0118 G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
0119 G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
0120 G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
0121 G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String& value) final;
0122 G4bool AddNtupleRow(G4int ntupleId) final;
0123 virtual G4bool Merge() final;
0124
0125 virtual G4bool Reset();
0126 void Clear() final;
0127
0128
0129 G4bool Delete(G4int id) final;
0130
0131
0132
0133 void SetActivation(G4bool activation) final;
0134 void SetActivation(G4int ntupleId, G4bool activation) final;
0135 G4bool GetActivation(G4int ntupleId) const final;
0136
0137
0138 void SetNewCycle(G4bool value) final;
0139 G4bool GetNewCycle() const final;
0140
0141
0142 void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
0143
0144 private:
0145 G4RootPNtupleDescription*
0146 GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0147 tools::wroot::base_pntuple*
0148 GetNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0149 tools::wroot::ntuple*
0150 GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0151
0152 template <typename T>
0153 G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
0154
0155 template <typename T>
0156 G4bool FillNtupleTColumn(G4int columnId, const T& value);
0157
0158
0159 static constexpr std::string_view fkClass { "G4RootPNtupleManager" };
0160
0161
0162 std::shared_ptr<G4NtupleBookingManager> fBookingManager;
0163 std::shared_ptr<G4RootMainNtupleManager> fMainNtupleManager;
0164 std::vector<G4RootPNtupleDescription*> fNtupleDescriptionVector;
0165 std::vector<tools::wroot::imt_ntuple*> fNtupleVector;
0166 G4bool fRowWise;
0167 G4bool fRowMode;
0168 G4bool fCreateNtuples { true };
0169 G4bool fNewCycle { false };
0170 };
0171
0172 #include "G4RootPNtupleManager.icc"
0173
0174 #endif