Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NtupleBookingManager.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// Manager class for ntuple booking for all output types.
28//
29// Author: Ivana Hrivnacova, 19/06/2015 ([email protected])
30
31#ifndef G4NtupleBookingManager_h
32#define G4NtupleBookingManager_h 1
33
36#include "globals.hh"
37
38#include "tools/ntuple_booking"
39
40#include <set>
41#include <string_view>
42#include <vector>
43
45{
46 G4NtupleBooking() = default;
47 ~G4NtupleBooking() = default;
48
49 void SetDeleted(G4bool deleted, G4bool keepSetting) {
50 fDeleted = std::make_pair(deleted, keepSetting);
51 }
53 return fDeleted.first;
54 }
55 void Reset() {
56 if (! fDeleted.second) {
57 // Reset information unless "keepSetting" option is true
58 fFileName.clear();
59 fActivation = true;
60 }
61 SetDeleted(false, false);
62 }
63
64 tools::ntuple_booking fNtupleBooking;
68 std::pair<G4bool, G4bool> fDeleted { false, false };
69};
70
72{
73 // Disable using the object managers outside G4VAnalysisManager and
74 // its messenger
75 friend class G4VAnalysisManager;
76
77 public:
80 ~G4NtupleBookingManager() override;
81
82 const std::vector<G4NtupleBooking*>& GetNtupleBookingVector() const;
83
84 // File type
85 // (only one output file type allowed for ntuples)
86 void SetFileType(const G4String& fileType);
88 G4bool IsEmpty() const;
89
90 // Access methods
91 tools::ntuple_booking* GetNtuple(G4bool warn,
92 G4bool onlyIfActive) const;
93 tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn,
94 G4bool onlyIfActive) const;
95
96 protected:
97 // Methods to create ntuples
98 //
99 G4int CreateNtuple(const G4String& name, const G4String& title);
100
101 // Create columns in the last created ntuple (from base class)
102 // Create columns in the last created ntuple
104 std::vector<int>* vector);
106 std::vector<float>* vector) ;
108 std::vector<double>* vector);
110 std::vector<std::string>* vector);
112
113 // Create columns in the ntuple with given id
115 const G4String& name, std::vector<int>* vector);
117 const G4String& name, std::vector<float>* vector);
119 const G4String& name, std::vector<double>* vector);
121 const G4String& name, std::vector<std::string>* vector);
123
124 // The ntuple column ids are generated automatically starting from 0;
125 // with the following function it is possible to change it
126 // to start from another value
129
130 // Activation option
131 //
132 void SetActivation(G4bool activation);
133 void SetActivation(G4int ntupleId, G4bool activation);
134 G4bool GetActivation(G4int ntupleId) const;
135
136 // // File name option
137 void SetFileName(const G4String& fileName);
138 void SetFileName(G4int id, const G4String& fileName);
139 G4String GetFileName(G4int id) const;
140
141 // Access methods
142 G4int GetNofNtuples(G4bool onlyIfExist = false) const;
143
144 // Clear data
145 void ClearData();
146
147 // Method to delete selected ntuples
148 G4bool Delete(G4int id, G4bool keepSetting);
149
150 // List ntuples
151 G4bool List(std::ostream& output, G4bool onlyIfActive = true);
152
153 // Data members
154 std::vector<G4NtupleBooking*> fNtupleBookingVector;
155 std::set<G4int> fFreeIds;
156
157 private:
158 // Methods
159 // Common implementation
160 G4NtupleBooking* GetNtupleBookingInFunction(
161 G4int id,
162 std::string_view function,
163 G4bool warn = true) const;
164
165 G4bool CheckName(const G4String& name, const G4String& objectType) const;
166 template <typename T>
167 G4int CreateNtupleTColumn(G4int ntupleId,
168 const G4String& name, std::vector<T>* vector);
169 G4int GetCurrentNtupleId() const;
170
171 // Static data members
172 static constexpr std::string_view fkClass { "G4NtupleBookingManager" };
173
174 // Data members
175 G4String fFileType;
176 G4int fFirstNtupleColumnId { 0 };
177 G4bool fLockFirstNtupleColumnId { false };
178 G4int fCurrentNtupleId { G4Analysis::kInvalidId };
179};
180
181#include "G4NtupleBookingManager.icc"
182
183#endif
G4double(*)(G4double) function
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4int GetFirstNtupleColumnId() const
G4bool GetActivation(G4int ntupleId) const
G4bool SetFirstNtupleColumnId(G4int firstId)
std::vector< G4NtupleBooking * > fNtupleBookingVector
G4int GetNofNtuples(G4bool onlyIfExist=false) const
G4String GetFileName(G4int id) const
G4int CreateNtupleSColumn(const G4String &name, std::vector< std::string > *vector)
G4bool Delete(G4int id, G4bool keepSetting)
G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
G4int CreateNtuple(const G4String &name, const G4String &title)
G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)
G4String GetFileType() const
const std::vector< G4NtupleBooking * > & GetNtupleBookingVector() const
G4NtupleBookingManager()=delete
void SetFileName(const G4String &fileName)
G4bool List(std::ostream &output, G4bool onlyIfActive=true)
tools::ntuple_booking * GetNtuple(G4bool warn, G4bool onlyIfActive) const
G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)
void SetFileType(const G4String &fileType)
void SetActivation(G4bool activation)
constexpr G4int kInvalidId
void SetDeleted(G4bool deleted, G4bool keepSetting)
~G4NtupleBooking()=default
tools::ntuple_booking fNtupleBooking
std::pair< G4bool, G4bool > fDeleted
G4NtupleBooking()=default