Geant4 11.1.1
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 ()=delete
 
 ~G4NtupleBookingManager () override
 
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)
 
 G4BaseAnalysisManager ()=delete
 
virtual ~G4BaseAnalysisManager ()=default
 
G4bool SetFirstId (G4int firstId)
 
void SetLockFirstId (G4bool lockFirstId)
 
G4int GetFirstId () const
 
G4int GetCycle () 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, std::vector< std::string > *vector)
 
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, std::vector< std::string > *vector)
 
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
 
void ClearData ()
 
- Protected Member Functions inherited from G4BaseAnalysisManager
G4bool IsVerbose (G4int verboseLevel) const
 
void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 

Protected Attributes

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

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 ( )
override

Definition at line 47 of file G4NtupleBookingManager.cc.

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

Member Function Documentation

◆ ClearData()

void G4NtupleBookingManager::ClearData ( )
protected

Definition at line 290 of file G4NtupleBookingManager.cc.

291{
292 for ( auto ntupleBooking : fNtupleBookingVector ) {
293 delete ntupleBooking;
294 }
295 fNtupleBookingVector.clear();
296 fLockFirstNtupleColumnId = false;
297
298 Message(G4Analysis::kVL2, "clear", "ntupleBookings");
299}
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
constexpr G4int kVL2

◆ CreateNtuple()

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

Definition at line 94 of file G4NtupleBookingManager.cc.

96{
97 if ( ! CheckName(name, "Ntuple") ) return kInvalidId;
98
99 Message(kVL4, "create", "ntuple booking", name);
100
101 // Create ntuple description
102 auto index = fNtupleBookingVector.size();
103 auto ntupleBooking = new G4NtupleBooking();
104 fNtupleBookingVector.push_back(ntupleBooking);
105
106 // Save name & title in ntuple booking
107 ntupleBooking->fNtupleBooking.set_name(name);
108 ntupleBooking->fNtupleBooking.set_title(title);
109 ntupleBooking->fNtupleId = G4int(index + fFirstId);
110
111 // Create ntuple
112 fLockFirstId = true;
113
114 Message(kVL2, "create", "ntuple booking",
115 name + " ntupleId " + to_string(ntupleBooking->fNtupleId));
116
117 return ntupleBooking->fNtupleId;
118}
int G4int
Definition: G4Types.hh:85
constexpr G4int kVL4
constexpr G4int kInvalidId

◆ CreateNtupleDColumn() [1/2]

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

Definition at line 135 of file G4NtupleBookingManager.cc.

137{
138 return CreateNtupleDColumn(GetCurrentNtupleId(), name, vector);
139}
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 169 of file G4NtupleBookingManager.cc.

171{
172 return CreateNtupleTColumn<double>(ntupleId, name, vector);
173}

◆ CreateNtupleFColumn() [1/2]

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

Definition at line 128 of file G4NtupleBookingManager.cc.

130{
131 return CreateNtupleFColumn(GetCurrentNtupleId(), name, vector);
132}
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 162 of file G4NtupleBookingManager.cc.

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

◆ CreateNtupleIColumn() [1/2]

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

Definition at line 121 of file G4NtupleBookingManager.cc.

123{
124 return CreateNtupleIColumn(GetCurrentNtupleId(), name, vector);
125}
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 155 of file G4NtupleBookingManager.cc.

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

◆ CreateNtupleSColumn() [1/2]

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

Definition at line 142 of file G4NtupleBookingManager.cc.

144{
145 return CreateNtupleSColumn(GetCurrentNtupleId(), name, vector);
146}
G4int CreateNtupleSColumn(const G4String &name, std::vector< std::string > *vector)

Referenced by CreateNtupleSColumn().

◆ CreateNtupleSColumn() [2/2]

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

Definition at line 176 of file G4NtupleBookingManager.cc.

178{
179 return CreateNtupleTColumn<std::string>(ntupleId, name, vector);
180}

◆ FinishNtuple() [1/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( )
protected

Definition at line 149 of file G4NtupleBookingManager.cc.

150{
151 return FinishNtuple(GetCurrentNtupleId());
152}
G4NtupleBooking * FinishNtuple()

Referenced by FinishNtuple().

◆ FinishNtuple() [2/2]

G4NtupleBooking * G4NtupleBookingManager::FinishNtuple ( G4int  ntupleId)
protected

Definition at line 183 of file G4NtupleBookingManager.cc.

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

◆ GetActivation()

G4bool G4NtupleBookingManager::GetActivation ( G4int  ntupleId) const
protected

Definition at line 224 of file G4NtupleBookingManager.cc.

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

◆ GetFileName()

G4String G4NtupleBookingManager::GetFileName ( G4int  id) const
protected

Definition at line 279 of file G4NtupleBookingManager.cc.

281{
282 auto ntupleBooking
283 = GetNtupleBookingInFunction(ntupleId, "GetFileName");
284 if (ntupleBooking == nullptr) return "";
285
286 return ntupleBooking->fFileName;
287}

◆ 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 88 of file G4NtupleBookingManager.cc.

89{
90 return fNtupleBookingVector.size() == 0u;
91}

◆ SetActivation() [1/2]

void G4NtupleBookingManager::SetActivation ( G4bool  activation)
protected

Definition at line 204 of file G4NtupleBookingManager.cc.

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

◆ SetActivation() [2/2]

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

Definition at line 213 of file G4NtupleBookingManager.cc.

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

◆ SetFileName() [1/2]

void G4NtupleBookingManager::SetFileName ( const G4String fileName)
protected

Definition at line 235 of file G4NtupleBookingManager.cc.

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

◆ SetFileName() [2/2]

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

Definition at line 244 of file G4NtupleBookingManager.cc.

246{
247 auto ntupleBooking
248 = GetNtupleBookingInFunction(ntupleId, "SetFileName");
249 if (ntupleBooking == nullptr) return;
250
251 // Do nothing if file name does not change
252 if ( ntupleBooking->fFileName == fileName ) return;
253
254 auto ntupleFileName = fileName;
255 auto extension = GetExtension(fileName);
256 if (extension.size() != 0u) {
257 // Check if valid extension (if present)
258 auto output = G4Analysis::GetOutput(extension);
259 if ( output == G4AnalysisOutput::kNone ) {
260 Warn("The file extension " + extension + " is not supported.",
261 fkClass, "SetFileName");
262 return;
263 }
264 }
265 else {
266 if (fFileType.size() != 0u) {
267 //add extension if missing and file type is defined
268 ntupleFileName = fileName + "." + fFileType;
269 }
270 }
271
272 // Save the fileName in booking
273 // If extension is still missing (possible with generic manager),
274 // it will be completed with the default one at OpenFile
275 ntupleBooking->fFileName = ntupleFileName;
276}
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ SetFileType()

void G4NtupleBookingManager::SetFileType ( const G4String fileType)

Definition at line 306 of file G4NtupleBookingManager.cc.

307{
308 // do nothing if file type is defined and is same
309 if ( fFileType == fileType ) return;
310
311 // save the type
312 fFileType = fileType;
313
314 // Give warning and redefine file extension in bookings
315 // with file name of different fileTypes
316 for ( auto ntupleBooking : fNtupleBookingVector ) {
317 if ((ntupleBooking->fFileName).size() == 0u) continue;
318
319 auto extension = GetExtension(ntupleBooking->fFileName);
320 if ( fFileType == extension ) continue;
321
322 // multiple file types are not suported
323 auto baseFileName = GetBaseName(ntupleBooking->fFileName);
324 auto ntupleFileName = baseFileName + "." + fFileType;
325 if (extension.size() != 0u) {
326 Warn("Writing ntuples in files of different output types " +
327 fFileType + ", " + extension + " is not supported.",
328 fkClass, "SetFileType");
329 }
330
331 // Save the info in ntuple description
332 ntupleBooking->fFileName = ntupleFileName;
333 }
334}
G4String GetBaseName(const G4String &fileName)

◆ SetFirstNtupleColumnId()

G4bool G4NtupleBookingManager::SetFirstNtupleColumnId ( G4int  firstId)
protected

Definition at line 191 of file G4NtupleBookingManager.cc.

192{
193 if ( fLockFirstNtupleColumnId ) {
194 Warn("Cannot set FirstNtupleColumnId as its value was already used.",
195 fkClass, "SetFirstNtupleColumnId");
196 return false;
197 }
198
199 fFirstNtupleColumnId = firstId;
200 return true;
201}

Friends And Related Function Documentation

◆ G4VAnalysisManager

friend class G4VAnalysisManager
friend

Definition at line 58 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: