Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NtupleBookingManager Class Reference

#include <G4NtupleBookingManager.hh>

+ Inheritance diagram for G4NtupleBookingManager:

Public Member Functions

 G4NtupleBookingManager (const G4AnalysisManagerState &state)
 
 ~G4NtupleBookingManager ()
 
const std::vector< G4NtupleBooking * > & GetNtupleBookingVector () const
 
void SetFileType (const G4String &fileType)
 
G4String GetFileType () const
 
G4bool IsEmpty () const
 
- Public Member Functions inherited from G4BaseAnalysisManager
 G4BaseAnalysisManager (const G4AnalysisManagerState &state)
 
virtual ~G4BaseAnalysisManager ()
 
G4bool SetFirstId (G4int firstId)
 
void SetLockFirstId (G4bool lockFirstId)
 
G4int GetFirstId () const
 

Protected Member Functions

G4int CreateNtuple (const G4String &name, const G4String &title)
 
G4int CreateNtupleIColumn (const G4String &name, std::vector< int > *vector)
 
G4int CreateNtupleFColumn (const G4String &name, std::vector< float > *vector)
 
G4int CreateNtupleDColumn (const G4String &name, std::vector< double > *vector)
 
G4int CreateNtupleSColumn (const G4String &name)
 
G4NtupleBookingFinishNtuple ()
 
G4int CreateNtupleIColumn (G4int ntupleId, const G4String &name, std::vector< int > *vector)
 
G4int CreateNtupleFColumn (G4int ntupleId, const G4String &name, std::vector< float > *vector)
 
G4int CreateNtupleDColumn (G4int ntupleId, const G4String &name, std::vector< double > *vector)
 
G4int CreateNtupleSColumn (G4int ntupleId, const G4String &name)
 
G4NtupleBookingFinishNtuple (G4int ntupleId)
 
G4bool SetFirstNtupleColumnId (G4int firstId)
 
G4int GetFirstNtupleColumnId () const
 
void SetActivation (G4bool activation)
 
void SetActivation (G4int ntupleId, G4bool activation)
 
G4bool GetActivation (G4int ntupleId) const
 
void SetFileName (const G4String &fileName)
 
void SetFileName (G4int id, const G4String &fileName)
 
G4String GetFileName (G4int id) const
 
G4int GetNofNtupleBookings () const
 

Protected Attributes

std::vector< G4NtupleBooking * > fNtupleBookingVector
 
- Protected Attributes inherited from G4BaseAnalysisManager
const G4AnalysisManagerStatefState
 
G4int fFirstId
 
G4bool fLockFirstId
 

Friends

class G4VAnalysisManager
 

Detailed Description

Definition at line 55 of file G4NtupleBookingManager.hh.

Constructor & Destructor Documentation

◆ G4NtupleBookingManager()

G4NtupleBookingManager::G4NtupleBookingManager ( const G4AnalysisManagerState state)
explicit

Definition at line 40 of file G4NtupleBookingManager.cc.

42 : G4BaseAnalysisManager(state),
44 fFileType(),
45 fFirstNtupleColumnId(0),
46 fLockFirstNtupleColumnId(false)
47{}
std::vector< G4NtupleBooking * > fNtupleBookingVector

◆ ~G4NtupleBookingManager()

G4NtupleBookingManager::~G4NtupleBookingManager ( )

Definition at line 50 of file G4NtupleBookingManager.cc.

51{
52 for ( auto ntupleBooking : fNtupleBookingVector ) {
53 delete ntupleBooking;
54 }
55}

Member Function Documentation

◆ CreateNtuple()

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

Definition at line 88 of file G4NtupleBookingManager.cc.

90{
91#ifdef G4VERBOSE
92 if ( fState.GetVerboseL4() )
93 fState.GetVerboseL4()->Message("create", "ntuple booking", name);
94#endif
95
96 // Create ntuple description
97 auto index = fNtupleBookingVector.size();
98 auto ntupleBooking = new G4NtupleBooking();
99 fNtupleBookingVector.push_back(ntupleBooking);
100
101 // Save name & title in ntuple booking
102 ntupleBooking->fNtupleBooking.set_name(name);
103 ntupleBooking->fNtupleBooking.set_title(title);
104
105 // Create ntuple
106 fLockFirstId = true;
107
108#ifdef G4VERBOSE
109 if ( fState.GetVerboseL2() ) {
110 G4ExceptionDescription description;
111 description << name << " ntupleId " << index + fFirstId;
112 fState.GetVerboseL2()->Message("create", "ntuple booking", description);
113 }
114#endif
115
116 return G4int(index + fFirstId);
117}
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
int G4int
Definition: G4Types.hh:85
const G4AnalysisVerbose * GetVerboseL2() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
const char * name(G4int ptype)

◆ CreateNtupleDColumn() [1/2]

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

Definition at line 134 of file G4NtupleBookingManager.cc.

136{
137 return CreateNtupleDColumn(GetCurrentNtupleId(), name, vector);
138}
G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)

Referenced by CreateNtupleDColumn().

◆ CreateNtupleDColumn() [2/2]

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

Definition at line 167 of file G4NtupleBookingManager.cc.

169{
170 return CreateNtupleTColumn<double>(ntupleId, name, vector);
171}

◆ CreateNtupleFColumn() [1/2]

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

Definition at line 127 of file G4NtupleBookingManager.cc.

129{
130 return CreateNtupleFColumn(GetCurrentNtupleId(), name, vector);
131}
G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)

Referenced by CreateNtupleFColumn().

◆ CreateNtupleFColumn() [2/2]

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

Definition at line 160 of file G4NtupleBookingManager.cc.

162{
163 return CreateNtupleTColumn<float>(ntupleId, name, vector);
164}

◆ CreateNtupleIColumn() [1/2]

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

Definition at line 120 of file G4NtupleBookingManager.cc.

122{
123 return CreateNtupleIColumn(GetCurrentNtupleId(), name, vector);
124}
G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)

Referenced by CreateNtupleIColumn().

◆ CreateNtupleIColumn() [2/2]

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

Definition at line 153 of file G4NtupleBookingManager.cc.

155{
156 return CreateNtupleTColumn<int>(ntupleId, name, vector);
157}

◆ CreateNtupleSColumn() [1/2]

G4int G4NtupleBookingManager::CreateNtupleSColumn ( const G4String name)
protected

Definition at line 141 of file G4NtupleBookingManager.cc.

142{
143 return CreateNtupleSColumn(GetCurrentNtupleId(), name);
144}
G4int CreateNtupleSColumn(const G4String &name)

Referenced by CreateNtupleSColumn().

◆ CreateNtupleSColumn() [2/2]

G4int G4NtupleBookingManager::CreateNtupleSColumn ( G4int  ntupleId,
const G4String name 
)
protected

Definition at line 174 of file G4NtupleBookingManager.cc.

176{
177 return CreateNtupleTColumn<std::string>(ntupleId, name, nullptr);
178}

◆ FinishNtuple() [1/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( )
protected

Definition at line 147 of file G4NtupleBookingManager.cc.

148{
149 return FinishNtuple(GetCurrentNtupleId());
150}
G4NtupleBooking * FinishNtuple()

Referenced by FinishNtuple().

◆ FinishNtuple() [2/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( G4int  ntupleId)
protected

Definition at line 181 of file G4NtupleBookingManager.cc.

183{
184 // Nothing to be done for booking,
185 return GetNtupleBookingInFunction(ntupleId, "FinishNtuple");
186}

◆ GetActivation()

G4bool G4NtupleBookingManager::GetActivation ( G4int  ntupleId) const
protected

Definition at line 225 of file G4NtupleBookingManager.cc.

227{
228 auto ntupleBooking
229 = GetNtupleBookingInFunction(ntupleId, "GetActivation");
230 if ( ! ntupleBooking ) return false;
231
232 return ntupleBooking->fActivation;
233}

◆ GetFileName()

G4String G4NtupleBookingManager::GetFileName ( G4int  id) const
protected

Definition at line 283 of file G4NtupleBookingManager.cc.

285{
286 auto ntupleBooking
287 = GetNtupleBookingInFunction(ntupleId, "GetFileName");
288 if ( ! ntupleBooking ) return "";
289
290 return ntupleBooking->fFileName;
291}

◆ GetFileType()

G4String G4NtupleBookingManager::GetFileType ( ) const

◆ GetFirstNtupleColumnId()

G4int G4NtupleBookingManager::GetFirstNtupleColumnId ( ) const
protected

◆ GetNofNtupleBookings()

G4int G4NtupleBookingManager::GetNofNtupleBookings ( ) const
protected

◆ GetNtupleBookingVector()

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

◆ IsEmpty()

G4bool G4NtupleBookingManager::IsEmpty ( ) const

Definition at line 82 of file G4NtupleBookingManager.cc.

83{
84 return ! fNtupleBookingVector.size();
85}

◆ SetActivation() [1/2]

void G4NtupleBookingManager::SetActivation ( G4bool  activation)
protected

Definition at line 205 of file G4NtupleBookingManager.cc.

207{
208 for ( auto ntupleBooking : fNtupleBookingVector ) {
209 ntupleBooking->fActivation = activation;
210 }
211}

◆ SetActivation() [2/2]

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

Definition at line 214 of file G4NtupleBookingManager.cc.

216{
217 auto ntupleBooking
218 = GetNtupleBookingInFunction(ntupleId, "SetActivation");
219 if ( ! ntupleBooking ) return;
220
221 ntupleBooking->fActivation = activation;
222}

◆ SetFileName() [1/2]

void G4NtupleBookingManager::SetFileName ( const G4String fileName)
protected

Definition at line 236 of file G4NtupleBookingManager.cc.

238{
239 for ( auto ntupleBooking : fNtupleBookingVector ) {
240 ntupleBooking->fFileName = fileName;
241 }
242}

◆ SetFileName() [2/2]

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

Definition at line 245 of file G4NtupleBookingManager.cc.

247{
248 auto ntupleBooking
249 = GetNtupleBookingInFunction(ntupleId, "SetFileName");
250 if ( ! ntupleBooking ) return;
251
252 // Do nothing if file name does not change
253 if ( ntupleBooking->fFileName == fileName ) return;
254
255 auto ntupleFileName = fileName;
256 auto extension = GetExtension(fileName);
257 if ( extension.size() ) {
258 // Check if valid extension (if present)
259 auto output = G4Analysis::GetOutput(extension);
260 if ( output == G4AnalysisOutput::kNone ) {
261 G4ExceptionDescription description;
262 description
263 << "The file extension " << extension << "is not supported.";
264 G4Exception("G4NtupleBookingManager::SetFileName",
265 "Analysis_W051", JustWarning, description);
266 return;
267 }
268 }
269 else {
270 if ( fFileType.size() ) {
271 //add extension if missing and file type is defined
272 ntupleFileName = fileName + "." + fFileType;
273 }
274 }
275
276 // Save the fileName in booking
277 // If extension is still missing (possible with generic manager),
278 // it will be completed with the default one at OpenFile
279 ntupleBooking->fFileName = ntupleFileName;
280}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)

◆ SetFileType()

void G4NtupleBookingManager::SetFileType ( const G4String fileType)

Definition at line 298 of file G4NtupleBookingManager.cc.

299{
300 // do nothing if file type is defined and is same
301 if ( fFileType == fileType ) return;
302
303 // save the type
304 fFileType = fileType;
305
306 // Give warning and redefine file extension in bookings
307 // with file name of different fileTypes
308 for ( auto ntupleBooking : fNtupleBookingVector ) {
309
310 if ( ! (ntupleBooking->fFileName).size() ) continue;
311
312 auto extension = GetExtension(ntupleBooking->fFileName);
313 if ( fFileType == extension ) continue;
314
315 // multiple file types are not suported
316 auto baseFileName = GetBaseName(ntupleBooking->fFileName);
317 auto ntupleFileName = baseFileName + "." + fFileType;
318 if ( extension.size()) {
319 G4ExceptionDescription description;
320 description
321 << "Writing ntuples in files of different output types "
322 << fFileType << ", " << extension << " is not supported." << G4endl
323 << "Ntuple " << ntupleBooking->fNtupleBooking.name()
324 << " will be written in " << ntupleFileName;
325 G4Exception("G4NtupleBookingManager::SetFileType",
326 "Analysis_W051", JustWarning, description);
327 }
328
329 // Save the info in ntuple description
330 ntupleBooking->fFileName = ntupleFileName;
331 }
332}
#define G4endl
Definition: G4ios.hh:57
G4String GetBaseName(const G4String &fileName)

◆ SetFirstNtupleColumnId()

G4bool G4NtupleBookingManager::SetFirstNtupleColumnId ( G4int  firstId)
protected

Definition at line 189 of file G4NtupleBookingManager.cc.

190{
191 if ( fLockFirstNtupleColumnId ) {
192 G4ExceptionDescription description;
193 description
194 << "Cannot set FirstNtupleColumnId as its value was already used.";
195 G4Exception("G4BaseNtupleManager::SetFirstNtupleColumnId()",
196 "Analysis_W013", JustWarning, description);
197 return false;
198 }
199
200 fFirstNtupleColumnId = firstId;
201 return true;
202}

Friends And Related Function Documentation

◆ G4VAnalysisManager

friend class G4VAnalysisManager
friend

Definition at line 59 of file G4NtupleBookingManager.hh.

Member Data Documentation

◆ fNtupleBookingVector

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

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