Geant4-11
G4RootPNtupleManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// Class for Root pntuple management.
28//
29// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
30
31#ifndef G4RootPNtupleManager_h
32#define G4RootPNtupleManager_h 1
33
38#include "G4AutoLock.hh"
39#include "globals.hh"
40
41#include <vector>
42#include <string_view>
43
45
46namespace tools {
47namespace wroot {
48class file;
49class ntuple;
50class imt_ntuple;
51}
52}
53
54// Mutex implementation as in pwroot.cpp
55// with replacement tools::mutex -> G4Mutex
56
57class mutex : public virtual tools::wroot::imutex {
58 using parent = tools::wroot::imutex;
59public:
60 virtual bool lock() {
61 // G4cout << "!!! Mutex lock" << G4endl;
62 m_mutex.lock();
63 return true;}
64 virtual bool unlock() {
66 // G4cout << "!!! Mutex unlock" << G4endl;
67 return true; }
68 //virtual bool trylock() {return m_mutex.trylock();}
69public:
70 mutex(G4AutoLock& a_mutex):m_mutex(a_mutex){}
71 virtual ~mutex() = default;
72protected:
73 mutex(const mutex& a_from):parent(a_from),m_mutex(a_from.m_mutex){}
74 mutex& operator=(const mutex&){return *this;}
75protected:
77};
78
80{
83
84 public:
86 std::shared_ptr<G4NtupleBookingManager> bookingManger,
87 std::shared_ptr<G4RootMainNtupleManager> main,
88 G4bool rowWise, G4bool rowMode);
90 virtual ~G4RootPNtupleManager();
91
92 private:
93 // Methods to manipulate ntuples
94 void CreateNtupleFromMain(G4RootPNtupleDescription* ntupleDescription,
95 tools::wroot::ntuple* mainNtuple);
96 // void CreateNtupleFromMain(G4NtupleBooking* g4NtupleBooking,
97 // tools::wroot::ntuple* mainNtuple);
99
100 // Methods to create ntuples
101 //
102 virtual G4int CreateNtuple(G4NtupleBooking* booking) final;
103
104 // Methods to fill ntuples
105 // Methods for ntuple with id = FirstNtupleId (from base class)
111 // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
112 virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
113 virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
114 virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
115 virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
116 const G4String& value) final;
117 virtual G4bool AddNtupleRow(G4int ntupleId) final;
118 virtual G4bool Merge() final;
119
120 // Clear all data
121 virtual void Clear() final;
122
123 // Activation option
124 //
125 virtual void SetActivation(G4bool activation) final;
126 virtual void SetActivation(G4int ntupleId, G4bool activation) final;
127 virtual G4bool GetActivation(G4int ntupleId) const final;
128
129 // Access methods
130 virtual G4int GetNofNtuples() const final;
131
132 // Set methods
133 void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
134
135 private:
137 GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn = true) const;
138 tools::wroot::base_pntuple*
139 GetNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
140 tools::wroot::ntuple*
141 GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
142
143 template <typename T>
144 G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
145
146 template <typename T>
147 G4bool FillNtupleTColumn(G4int columnId, const T& value);
148
149 // Static data members
150 static constexpr std::string_view fkClass { "G4RootPNtupleManager" };
151
152 // Data members
153 std::shared_ptr<G4NtupleBookingManager> fBookingManager;
154 std::shared_ptr<G4RootMainNtupleManager> fMainNtupleManager;
155 std::vector<G4RootPNtupleDescription*> fNtupleDescriptionVector;
156 std::vector<tools::wroot::imt_ntuple*> fNtupleVector;
160};
161
163
164#endif
G4double(* function)(G4double)
float G4float
Definition: G4Types.hh:84
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
int main(int argc, char *argv[])
virtual G4bool FillNtupleSColumn(G4int id, const G4String &value) final
virtual G4bool FillNtupleFColumn(G4int id, G4float value) final
virtual G4bool FillNtupleDColumn(G4int id, G4double value) final
virtual G4bool FillNtupleIColumn(G4int id, G4int value) final
virtual G4bool AddNtupleRow() final
virtual void SetActivation(G4bool activation) final
G4RootPNtupleDescription * GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn=true) const
virtual G4int CreateNtuple(G4NtupleBooking *booking) final
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final
std::vector< G4RootPNtupleDescription * > fNtupleDescriptionVector
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T &value)
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String &value) final
tools::wroot::base_pntuple * GetNtupleInFunction(G4int id, std::string_view function, G4bool warn=true) const
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
G4RootPNtupleManager()=delete
std::shared_ptr< G4NtupleBookingManager > fBookingManager
static constexpr std::string_view fkClass
virtual void Clear() final
virtual G4bool Merge() final
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final
std::shared_ptr< G4RootMainNtupleManager > fMainNtupleManager
virtual G4int GetNofNtuples() const final
tools::wroot::ntuple * GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn=true) const
virtual G4bool GetActivation(G4int ntupleId) const final
std::vector< tools::wroot::imt_ntuple * > fNtupleVector
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final
void CreateNtupleFromMain(G4RootPNtupleDescription *ntupleDescription, tools::wroot::ntuple *mainNtuple)
virtual G4bool AddNtupleRow() final
mutex & operator=(const mutex &)
virtual bool lock()
mutex(const mutex &a_from)
tools::wroot::imutex parent
mutex(G4AutoLock &a_mutex)
virtual ~mutex()=default
G4AutoLock & m_mutex
virtual bool unlock()