Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends
G4NtupleBookingManager Class Reference

#include <G4NtupleBookingManager.hh>

Inheritance diagram for G4NtupleBookingManager:
G4BaseAnalysisManager

Public Member Functions

 G4NtupleBookingManager ()=delete
 
 G4NtupleBookingManager (const G4AnalysisManagerState &state)
 
G4String GetFileType () const
 
G4int GetFirstId () const
 
const std::vector< G4NtupleBooking * > & GetNtupleBookingVector () const
 
G4bool IsEmpty () const
 
void SetFileType (const G4String &fileType)
 
G4bool SetFirstId (G4int firstId)
 
void SetLockFirstId (G4bool lockFirstId)
 
 ~G4NtupleBookingManager ()
 

Protected Member Functions

void ClearData ()
 
G4int CreateNtuple (const G4String &name, const G4String &title)
 
G4int CreateNtupleDColumn (const G4String &name, std::vector< double > *vector)
 
G4int CreateNtupleDColumn (G4int ntupleId, const G4String &name, std::vector< double > *vector)
 
G4int CreateNtupleFColumn (const G4String &name, std::vector< float > *vector)
 
G4int CreateNtupleFColumn (G4int ntupleId, const G4String &name, std::vector< float > *vector)
 
G4int CreateNtupleIColumn (const G4String &name, std::vector< int > *vector)
 
G4int CreateNtupleIColumn (G4int ntupleId, const G4String &name, std::vector< int > *vector)
 
G4int CreateNtupleSColumn (const G4String &name, std::vector< std::string > *vector)
 
G4int CreateNtupleSColumn (G4int ntupleId, const G4String &name, std::vector< std::string > *vector)
 
G4NtupleBookingFinishNtuple ()
 
G4NtupleBookingFinishNtuple (G4int ntupleId)
 
G4bool GetActivation (G4int ntupleId) const
 
G4String GetFileName (G4int id) const
 
G4int GetFirstNtupleColumnId () const
 
G4int GetNofNtupleBookings () const
 
G4bool IsVerbose (G4int verboseLevel) const
 
void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 
void SetActivation (G4bool activation)
 
void SetActivation (G4int ntupleId, G4bool activation)
 
void SetFileName (const G4String &fileName)
 
void SetFileName (G4int id, const G4String &fileName)
 
G4bool SetFirstNtupleColumnId (G4int firstId)
 

Protected Attributes

G4int fFirstId { 0 }
 
G4bool fLockFirstId { false }
 
std::vector< G4NtupleBooking * > fNtupleBookingVector
 
const G4AnalysisManagerStatefState
 

Private Member Functions

template<typename T >
G4int CreateNtupleTColumn (G4int ntupleId, const G4String &name, std::vector< T > *vector)
 
G4int GetCurrentNtupleId () const
 
G4NtupleBookingGetNtupleBookingInFunction (G4int id, std::string_view function, G4bool warn=true) const
 

Private Attributes

G4String fFileType
 
G4int fFirstNtupleColumnId { 0 }
 
G4bool fLockFirstNtupleColumnId { false }
 

Static Private Attributes

static constexpr std::string_view fkClass { "G4NtupleBookingManager" }
 

Friends

class G4VAnalysisManager
 

Detailed Description

Definition at line 54 of file G4NtupleBookingManager.hh.

Constructor & Destructor Documentation

◆ G4NtupleBookingManager() [1/2]

G4NtupleBookingManager::G4NtupleBookingManager ( const G4AnalysisManagerState state)
explicit

Definition at line 41 of file G4NtupleBookingManager.cc.

44{}
G4BaseAnalysisManager()=delete

◆ G4NtupleBookingManager() [2/2]

G4NtupleBookingManager::G4NtupleBookingManager ( )
delete

◆ ~G4NtupleBookingManager()

G4NtupleBookingManager::~G4NtupleBookingManager ( )

Definition at line 47 of file G4NtupleBookingManager.cc.

48{
49 for ( auto ntupleBooking : fNtupleBookingVector ) {
50 delete ntupleBooking;
51 }
52}
std::vector< G4NtupleBooking * > fNtupleBookingVector

References fNtupleBookingVector.

Member Function Documentation

◆ ClearData()

void G4NtupleBookingManager::ClearData ( )
protected

Definition at line 276 of file G4NtupleBookingManager.cc.

277{
278 for ( auto ntupleBooking : fNtupleBookingVector ) {
279 delete ntupleBooking;
280 }
281 fNtupleBookingVector.clear();
283
284 Message(G4Analysis::kVL2, "clear", "ntupleBookings");
285}
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
constexpr G4int kVL2

References fLockFirstNtupleColumnId, fNtupleBookingVector, G4Analysis::kVL2, and G4BaseAnalysisManager::Message().

◆ CreateNtuple()

G4int G4NtupleBookingManager::CreateNtuple ( const G4String name,
const G4String title 
)
protected

Definition at line 82 of file G4NtupleBookingManager.cc.

84{
85 Message(kVL4, "create", "ntuple booking", name);
86
87 // Create ntuple description
88 auto index = fNtupleBookingVector.size();
89 auto ntupleBooking = new G4NtupleBooking();
90 fNtupleBookingVector.push_back(ntupleBooking);
91
92 // Save name & title in ntuple booking
93 ntupleBooking->fNtupleBooking.set_name(name);
94 ntupleBooking->fNtupleBooking.set_title(title);
95 ntupleBooking->fNtupleId = G4int(index + fFirstId);
96
97 // Create ntuple
98 fLockFirstId = true;
99
100 Message(kVL2, "create", "ntuple booking",
101 name + " ntupleId " + to_string(ntupleBooking->fNtupleId));
102
103 return ntupleBooking->fNtupleId;
104}
int G4int
Definition: G4Types.hh:85
constexpr G4int kVL4
const char * name(G4int ptype)

References G4BaseAnalysisManager::fFirstId, G4BaseAnalysisManager::fLockFirstId, fNtupleBookingVector, G4Analysis::kVL2, G4Analysis::kVL4, G4BaseAnalysisManager::Message(), and G4InuclParticleNames::name().

◆ CreateNtupleDColumn() [1/2]

G4int G4NtupleBookingManager::CreateNtupleDColumn ( const G4String name,
std::vector< double > *  vector 
)
protected

Definition at line 121 of file G4NtupleBookingManager.cc.

123{
125}
G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
G4int GetCurrentNtupleId() const

References CreateNtupleDColumn(), GetCurrentNtupleId(), and G4InuclParticleNames::name().

Referenced by CreateNtupleDColumn().

◆ CreateNtupleDColumn() [2/2]

G4int G4NtupleBookingManager::CreateNtupleDColumn ( G4int  ntupleId,
const G4String name,
std::vector< double > *  vector 
)
protected

Definition at line 155 of file G4NtupleBookingManager.cc.

157{
158 return CreateNtupleTColumn<double>(ntupleId, name, vector);
159}

References G4InuclParticleNames::name().

◆ CreateNtupleFColumn() [1/2]

G4int G4NtupleBookingManager::CreateNtupleFColumn ( const G4String name,
std::vector< float > *  vector 
)
protected

Definition at line 114 of file G4NtupleBookingManager.cc.

116{
118}
G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)

References CreateNtupleFColumn(), GetCurrentNtupleId(), and G4InuclParticleNames::name().

Referenced by CreateNtupleFColumn().

◆ CreateNtupleFColumn() [2/2]

G4int G4NtupleBookingManager::CreateNtupleFColumn ( G4int  ntupleId,
const G4String name,
std::vector< float > *  vector 
)
protected

Definition at line 148 of file G4NtupleBookingManager.cc.

150{
151 return CreateNtupleTColumn<float>(ntupleId, name, vector);
152}

References G4InuclParticleNames::name().

◆ CreateNtupleIColumn() [1/2]

G4int G4NtupleBookingManager::CreateNtupleIColumn ( const G4String name,
std::vector< int > *  vector 
)
protected

Definition at line 107 of file G4NtupleBookingManager.cc.

109{
111}
G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)

References CreateNtupleIColumn(), GetCurrentNtupleId(), and G4InuclParticleNames::name().

Referenced by CreateNtupleIColumn().

◆ CreateNtupleIColumn() [2/2]

G4int G4NtupleBookingManager::CreateNtupleIColumn ( G4int  ntupleId,
const G4String name,
std::vector< int > *  vector 
)
protected

Definition at line 141 of file G4NtupleBookingManager.cc.

143{
144 return CreateNtupleTColumn<int>(ntupleId, name, vector);
145}

References G4InuclParticleNames::name().

◆ CreateNtupleSColumn() [1/2]

G4int G4NtupleBookingManager::CreateNtupleSColumn ( const G4String name,
std::vector< std::string > *  vector 
)
protected

Definition at line 128 of file G4NtupleBookingManager.cc.

130{
132}
G4int CreateNtupleSColumn(const G4String &name, std::vector< std::string > *vector)

References CreateNtupleSColumn(), GetCurrentNtupleId(), and G4InuclParticleNames::name().

Referenced by CreateNtupleSColumn().

◆ CreateNtupleSColumn() [2/2]

G4int G4NtupleBookingManager::CreateNtupleSColumn ( G4int  ntupleId,
const G4String name,
std::vector< std::string > *  vector 
)
protected

Definition at line 162 of file G4NtupleBookingManager.cc.

164{
165 return CreateNtupleTColumn<std::string>(ntupleId, name, vector);
166}

References G4InuclParticleNames::name().

◆ CreateNtupleTColumn()

template<typename T >
G4int G4NtupleBookingManager::CreateNtupleTColumn ( G4int  ntupleId,
const G4String name,
std::vector< T > *  vector 
)
private

◆ FinishNtuple() [1/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( )
protected

Definition at line 135 of file G4NtupleBookingManager.cc.

136{
138}
G4NtupleBooking * FinishNtuple()

References FinishNtuple(), and GetCurrentNtupleId().

Referenced by FinishNtuple().

◆ FinishNtuple() [2/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( G4int  ntupleId)
protected

Definition at line 169 of file G4NtupleBookingManager.cc.

171{
172 // Nothing to be done for booking,
173 return GetNtupleBookingInFunction(ntupleId, "FinishNtuple");
174}
G4NtupleBooking * GetNtupleBookingInFunction(G4int id, std::string_view function, G4bool warn=true) const

References GetNtupleBookingInFunction().

◆ GetActivation()

G4bool G4NtupleBookingManager::GetActivation ( G4int  ntupleId) const
protected

Definition at line 210 of file G4NtupleBookingManager.cc.

212{
213 auto ntupleBooking
214 = GetNtupleBookingInFunction(ntupleId, "GetActivation");
215 if ( ! ntupleBooking ) return false;
216
217 return ntupleBooking->fActivation;
218}

References GetNtupleBookingInFunction().

◆ GetCurrentNtupleId()

G4int G4NtupleBookingManager::GetCurrentNtupleId ( ) const
private

◆ GetFileName()

G4String G4NtupleBookingManager::GetFileName ( G4int  id) const
protected

Definition at line 265 of file G4NtupleBookingManager.cc.

267{
268 auto ntupleBooking
269 = GetNtupleBookingInFunction(ntupleId, "GetFileName");
270 if ( ! ntupleBooking ) return "";
271
272 return ntupleBooking->fFileName;
273}

References GetNtupleBookingInFunction().

◆ GetFileType()

G4String G4NtupleBookingManager::GetFileType ( ) const

◆ GetFirstId()

G4int G4BaseAnalysisManager::GetFirstId ( ) const
inlineinherited

Definition at line 94 of file G4BaseAnalysisManager.hh.

94 {
95 return fFirstId;
96}

References G4BaseAnalysisManager::fFirstId.

◆ GetFirstNtupleColumnId()

G4int G4NtupleBookingManager::GetFirstNtupleColumnId ( ) const
protected

◆ GetNofNtupleBookings()

G4int G4NtupleBookingManager::GetNofNtupleBookings ( ) const
protected

◆ GetNtupleBookingInFunction()

G4NtupleBooking * G4NtupleBookingManager::GetNtupleBookingInFunction ( G4int  id,
std::string_view  function,
G4bool  warn = true 
) const
private

Definition at line 56 of file G4NtupleBookingManager.cc.

58{
59 auto index = id - fFirstId;
60 if ( index < 0 || index >= G4int(fNtupleBookingVector.size()) ) {
61 if ( warn) {
62 Warn("Ntuple booking " + to_string(id) + " does not exist.",
63 fkClass, functionName);
64 }
65 return nullptr;
66 }
67
68 return fNtupleBookingVector[index];
69}
static constexpr std::string_view fkClass
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

References G4BaseAnalysisManager::fFirstId, fkClass, fNtupleBookingVector, and G4Analysis::Warn().

Referenced by FinishNtuple(), GetActivation(), GetFileName(), SetActivation(), and SetFileName().

◆ GetNtupleBookingVector()

const std::vector< G4NtupleBooking * > & G4NtupleBookingManager::GetNtupleBookingVector ( ) const

◆ IsEmpty()

G4bool G4NtupleBookingManager::IsEmpty ( ) const

Definition at line 76 of file G4NtupleBookingManager.cc.

77{
78 return ! fNtupleBookingVector.size();
79}

References fNtupleBookingVector.

◆ IsVerbose()

G4bool G4BaseAnalysisManager::IsVerbose ( G4int  verboseLevel) const
inlineprotectedinherited

Definition at line 80 of file G4BaseAnalysisManager.hh.

81{ return fState.IsVerbose(verboseLevel); }
G4bool IsVerbose(G4int verboseLevel) const
const G4AnalysisManagerState & fState

References G4BaseAnalysisManager::fState, and G4AnalysisManagerState::IsVerbose().

Referenced by G4RootPNtupleManager::AddNtupleRow(), and G4RootPNtupleManager::Merge().

◆ Message()

void G4BaseAnalysisManager::Message ( G4int  level,
const G4String action,
const G4String objectType,
const G4String objectName = "",
G4bool  success = true 
) const
inlineprotectedinherited

◆ SetActivation() [1/2]

void G4NtupleBookingManager::SetActivation ( G4bool  activation)
protected

Definition at line 190 of file G4NtupleBookingManager.cc.

192{
193 for ( auto ntupleBooking : fNtupleBookingVector ) {
194 ntupleBooking->fActivation = activation;
195 }
196}

References fNtupleBookingVector.

◆ SetActivation() [2/2]

void G4NtupleBookingManager::SetActivation ( G4int  ntupleId,
G4bool  activation 
)
protected

Definition at line 199 of file G4NtupleBookingManager.cc.

201{
202 auto ntupleBooking
203 = GetNtupleBookingInFunction(ntupleId, "SetActivation");
204 if ( ! ntupleBooking ) return;
205
206 ntupleBooking->fActivation = activation;
207}

References GetNtupleBookingInFunction().

◆ SetFileName() [1/2]

void G4NtupleBookingManager::SetFileName ( const G4String fileName)
protected

Definition at line 221 of file G4NtupleBookingManager.cc.

223{
224 for ( auto ntupleBooking : fNtupleBookingVector ) {
225 ntupleBooking->fFileName = fileName;
226 }
227}

References fNtupleBookingVector.

◆ SetFileName() [2/2]

void G4NtupleBookingManager::SetFileName ( G4int  id,
const G4String fileName 
)
protected

Definition at line 230 of file G4NtupleBookingManager.cc.

232{
233 auto ntupleBooking
234 = GetNtupleBookingInFunction(ntupleId, "SetFileName");
235 if ( ! ntupleBooking ) return;
236
237 // Do nothing if file name does not change
238 if ( ntupleBooking->fFileName == fileName ) return;
239
240 auto ntupleFileName = fileName;
241 auto extension = GetExtension(fileName);
242 if ( extension.size() ) {
243 // Check if valid extension (if present)
244 auto output = G4Analysis::GetOutput(extension);
245 if ( output == G4AnalysisOutput::kNone ) {
246 Warn("The file extension " + extension + " is not supported.",
247 fkClass, "SetFileName");
248 return;
249 }
250 }
251 else {
252 if ( fFileType.size() ) {
253 //add extension if missing and file type is defined
254 ntupleFileName = fileName + "." + fFileType;
255 }
256 }
257
258 // Save the fileName in booking
259 // If extension is still missing (possible with generic manager),
260 // it will be completed with the default one at OpenFile
261 ntupleBooking->fFileName = ntupleFileName;
262}
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)

References fFileType, fkClass, G4Analysis::GetExtension(), GetNtupleBookingInFunction(), G4Analysis::GetOutput(), kNone, and G4Analysis::Warn().

◆ SetFileType()

void G4NtupleBookingManager::SetFileType ( const G4String fileType)

Definition at line 292 of file G4NtupleBookingManager.cc.

293{
294 // do nothing if file type is defined and is same
295 if ( fFileType == fileType ) return;
296
297 // save the type
298 fFileType = fileType;
299
300 // Give warning and redefine file extension in bookings
301 // with file name of different fileTypes
302 for ( auto ntupleBooking : fNtupleBookingVector ) {
303
304 if ( ! (ntupleBooking->fFileName).size() ) continue;
305
306 auto extension = GetExtension(ntupleBooking->fFileName);
307 if ( fFileType == extension ) continue;
308
309 // multiple file types are not suported
310 auto baseFileName = GetBaseName(ntupleBooking->fFileName);
311 auto ntupleFileName = baseFileName + "." + fFileType;
312 if ( extension.size() ) {
313 Warn("Writing ntuples in files of different output types " +
314 fFileType + ", " + extension + " is not supported.",
315 fkClass, "SetFileType");
316 }
317
318 // Save the info in ntuple description
319 ntupleBooking->fFileName = ntupleFileName;
320 }
321}
G4String GetBaseName(const G4String &fileName)

References fFileType, fkClass, fNtupleBookingVector, G4Analysis::GetBaseName(), G4Analysis::GetExtension(), and G4Analysis::Warn().

◆ SetFirstId()

G4bool G4BaseAnalysisManager::SetFirstId ( G4int  firstId)
inherited

Definition at line 46 of file G4BaseAnalysisManager.cc.

47{
48 if ( fLockFirstId ) {
49 Warn("Cannot set FirstId as its value was already used.",
50 fkClass, "SetFirstId");
51
52 return false;
53 }
54
55 fFirstId = firstId;
56 return true;
57}
static constexpr std::string_view fkClass

References G4BaseAnalysisManager::fFirstId, G4BaseAnalysisManager::fkClass, G4BaseAnalysisManager::fLockFirstId, and G4Analysis::Warn().

◆ SetFirstNtupleColumnId()

G4bool G4NtupleBookingManager::SetFirstNtupleColumnId ( G4int  firstId)
protected

Definition at line 177 of file G4NtupleBookingManager.cc.

178{
180 Warn("Cannot set FirstNtupleColumnId as its value was already used.",
181 fkClass, "SetFirstNtupleColumnId");
182 return false;
183 }
184
185 fFirstNtupleColumnId = firstId;
186 return true;
187}

References fFirstNtupleColumnId, fkClass, fLockFirstNtupleColumnId, and G4Analysis::Warn().

◆ SetLockFirstId()

void G4BaseAnalysisManager::SetLockFirstId ( G4bool  lockFirstId)
inlineinherited

Definition at line 90 of file G4BaseAnalysisManager.hh.

90 {
91 fLockFirstId = lockFirstId;
92}

References G4BaseAnalysisManager::fLockFirstId.

Referenced by G4HnManager::ClearData().

Friends And Related Function Documentation

◆ G4VAnalysisManager

friend class G4VAnalysisManager
friend

Definition at line 58 of file G4NtupleBookingManager.hh.

Field Documentation

◆ fFileType

G4String G4NtupleBookingManager::fFileType
private

Definition at line 144 of file G4NtupleBookingManager.hh.

Referenced by SetFileName(), and SetFileType().

◆ fFirstId

G4int G4BaseAnalysisManager::fFirstId { 0 }
protectedinherited

◆ fFirstNtupleColumnId

G4int G4NtupleBookingManager::fFirstNtupleColumnId { 0 }
private

Definition at line 145 of file G4NtupleBookingManager.hh.

Referenced by SetFirstNtupleColumnId().

◆ fkClass

constexpr std::string_view G4NtupleBookingManager::fkClass { "G4NtupleBookingManager" }
staticconstexprprivate

◆ fLockFirstId

G4bool G4BaseAnalysisManager::fLockFirstId { false }
protectedinherited

◆ fLockFirstNtupleColumnId

G4bool G4NtupleBookingManager::fLockFirstNtupleColumnId { false }
private

Definition at line 146 of file G4NtupleBookingManager.hh.

Referenced by ClearData(), and SetFirstNtupleColumnId().

◆ fNtupleBookingVector

std::vector<G4NtupleBooking*> G4NtupleBookingManager::fNtupleBookingVector
protected

◆ fState

const G4AnalysisManagerState& G4BaseAnalysisManager::fState
protectedinherited

The documentation for this class was generated from the following files: