32 #ifndef G4RootPNtupleManager_h
33 #define G4RootPNtupleManager_h 1
57 class mutex :
public virtual tools::wroot::imutex {
58 typedef tools::wroot::imutex parent;
89 enum class G4PNtupleCreateMode {
97 tools::wroot::ntuple* mainNtuple);
98 void CreateNtuplesFromMain();
104 virtual G4int CreateNtupleIColumn(
105 const G4String&
name, std::vector<int>* vector)
override;
106 virtual G4int CreateNtupleFColumn(
107 const G4String&
name, std::vector<float>* vector)
override;
108 virtual G4int CreateNtupleDColumn(
109 const G4String&
name, std::vector<double>* vector)
override;
111 virtual void FinishNtuple()
override;
113 virtual G4int CreateNtupleIColumn(
G4int ntupleId,
114 const G4String&
name, std::vector<int>* vector)
override;
115 virtual G4int CreateNtupleFColumn(
G4int ntupleId,
116 const G4String&
name, std::vector<float>* vector)
override;
117 virtual G4int CreateNtupleDColumn(
G4int ntupleId,
118 const G4String&
name, std::vector<double>* vector)
override;
120 virtual void FinishNtuple(
G4int ntupleId)
override;
128 virtual G4bool AddNtupleRow() final;
136 virtual
G4bool Merge() final;
143 virtual
void SetActivation(
G4bool activation) final;
144 virtual
void SetActivation(
G4int ntupleId,
G4bool activation) final;
145 virtual
G4bool GetActivation(
G4int ntupleId) const final;
146 virtual
G4bool IsEmpty() const final;
149 virtual
G4int GetNofNtuples() const final;
154 tools::wroot::pntuple*
156 tools::wroot::ntuple*
159 template <typename T>
163 template <typename T>
164 G4int CreateNtupleTColumn(
165 const
G4String& name, std::vector<T>* vector);
167 template <typename T>
170 template <typename T>
171 G4bool FillNtupleTColumn(
G4int columnId, const T& value);
174 G4PNtupleCreateMode fCreateMode;
177 std::vector<tools::wroot::pntuple*> fNtupleVector;
183 template <typename T>
185 G4int ntupleId, const
G4String& name, std::vector<T>* vector)
190 description << name <<
" ntupleId " << ntupleId;
195 auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId,
"CreateNtupleTColumn");
199 auto& ntupleBooking = ntupleDescription->fNtupleBooking;
200 auto index = ntupleBooking.columns().size();
202 ntupleBooking.template add_column<T>(
name);
204 ntupleBooking.template add_column<T>(
name, *vector);
211 description << name <<
" ntupleId " << ntupleId;
221 template <
typename T>
222 G4int G4RootPNtupleManager::CreateNtupleTColumn(
223 const G4String& name, std::vector<T>* vector)
225 auto ntupleId = fNtupleDescriptionVector.size() +
fFirstId - 1;
226 return CreateNtupleTColumn<T>(ntupleId,
name, vector);
231 inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
232 G4int ntupleId,
G4int columnId,
const std::string& value)
235 G4cout <<
"Skipping FillNtupleIColumn for " << ntupleId <<
G4endl;
242 description <<
" ntupleId " << ntupleId
243 <<
" columnId " << columnId <<
" value " <<
value;
248 auto ntuple = GetNtupleInFunction(ntupleId,
"FillNtupleTColumn");
249 if ( ! ntuple )
return false;
252 if ( index < 0 || index >=
G4int(ntuple->columns().size()) ) {
254 description <<
" " <<
"ntupleId " << ntupleId
255 <<
" columnId " << columnId <<
" does not exist.";
256 G4Exception(
"G4RootNtupleManager::FillNtupleTColumn()",
261 auto icolumn = ntuple->columns()[index];
262 auto column =
dynamic_cast<tools::wroot::pntuple::column_string*
>(icolumn);
265 description <<
" Column type does not match: "
266 <<
" ntupleId " << ntupleId
267 <<
" columnId " << columnId <<
" value " <<
value;
268 G4Exception(
"G4RootNtupleManager:FillNtupleColumn",
278 description <<
" ntupleId " << ntupleId
279 <<
" columnId " << columnId <<
" value " <<
value;
287 template <
typename T>
288 G4bool G4RootPNtupleManager::FillNtupleTColumn(
289 G4int ntupleId,
G4int columnId,
const T& value)
292 G4cout <<
"Skipping FillNtupleIColumn for " << ntupleId <<
G4endl;
299 description <<
" ntupleId " << ntupleId
300 <<
" columnId " << columnId <<
" value " <<
value;
306 auto ntuple = GetNtupleInFunction(ntupleId,
"FillNtupleTColumn");
307 if ( ! ntuple )
return false;
311 if ( index < 0 || index >=
G4int(ntuple->columns().size()) ) {
313 description <<
" " <<
"ntupleId " << ntupleId
314 <<
" columnId " << columnId <<
" does not exist.";
315 G4Exception(
"G4TNtupleManager::FillNtupleTColumn()",
319 auto icolumn = ntuple->columns()[index];
322 auto column =
dynamic_cast<tools::wroot::pntuple::column<T>*
>(icolumn);
325 description <<
" Column type does not match: "
326 <<
" ntupleId " << ntupleId
327 <<
" columnId " << columnId <<
" value " <<
value;
338 description <<
" ntupleId " << ntupleId
339 <<
" columnId " << columnId <<
" value " <<
value;
347 template <
typename T>
348 G4bool G4RootPNtupleManager::FillNtupleTColumn(
G4int columnId,
const T& value) {
349 return FillNtupleTColumn(0, columnId, value);
mutex & operator=(const mutex &)
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
G4double(* function)(G4double)
const G4AnalysisVerbose * GetVerboseL2() const
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4bool fLockFirstNtupleColumnId
G4RootPNtupleManager(G4RootMainNtupleManager *main, const G4AnalysisManagerState &state)
mutex(const mutex &a_from)
mutex(G4AutoLock &a_mutex)
G4int fFirstNtupleColumnId
G4bool GetIsActivation() const
const G4AnalysisManagerState & fState