Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4HnManager.cc
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// Author: Ivana Hrivnacova, 18/06/2013 ([email protected])
28
29#include "G4HnManager.hh"
30#include "G4HnMessenger.hh"
31
33#include "G4VFileManager.hh"
34
35#include <utility>
36
37using namespace G4Analysis;
38using std::to_string;
39
40//_____________________________________________________________________________
42 : G4BaseAnalysisManager(state), fHnType(std::move(hnType))
43{
44 fMessenger = std::make_unique<G4HnMessenger>(*this);
45}
46
47//_____________________________________________________________________________
49{
50 for ( auto info : fHnVector ) {
51 delete info;
52 }
53}
54
55//
56// private methods
57//
58
59//_____________________________________________________________________________
61{
62// Set activation to a given object
63
64 // Do nothing if activation does not change
65 if ( info->GetActivation() == activation ) return;
66
67 // Change activation and account it in fNofActiveObjects
68 info->SetActivation(activation);
69 if (activation) {
70 fNofActiveObjects++;
71 }
72 else {
73 fNofActiveObjects--;
74 }
75}
76
77//_____________________________________________________________________________
79{
80 // Do nothing if ascii does not change
81 if ( info->GetPlotting() == plotting ) return;
82
83 // Change Plotting and account it in fNofPlottingObjects
84 info->SetPlotting(plotting);
85 if (plotting) {
86 fNofPlottingObjects++;
87 }
88 else {
89 fNofPlottingObjects--;
90 }
91}
92
93//_____________________________________________________________________________
94void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
95{
96 // Do nothing if file name does not change
97 if ( info->GetFileName() == fileName ) return;
98
99 // Save the info and account a new file name if file manager
100 info->SetFileName(fileName);
101 if (fFileManager) {
102 fFileManager->AddFileName(fileName);
103 } else {
104 Warn("Failed to set fileName " + fileName +
105 " for object " + info->GetName() + ".\nFile manager is not set.",
106 fkClass, "SetFileName");
107 return;
108 }
109
110 if ( fileName != "" ) {
111 fNofFileNameObjects++;
112 } else {
113 fNofFileNameObjects--;
114 }
115}
116
117//
118// public methods
119//
120
121//_____________________________________________________________________________
123{
124 auto info = new G4HnInformation(name, nofDimensions);
125 fHnVector.push_back(info);
126 ++fNofActiveObjects;
127
128 return info;
129}
130
131//_____________________________________________________________________________
133{
134 for ( auto info : fHnVector ) {
135 delete info;
136 }
137 fHnVector.clear();
138 SetLockFirstId(false);
139}
140
141//_____________________________________________________________________________
143 std::string_view functionName, G4bool warn) const
144{
145 G4int index = id - fFirstId;
146 if ( index < 0 || index >= G4int(fHnVector.size()) ) {
147 if ( warn ) {
148 Warn(fHnType + " histogram " + to_string(id) + " does not exist.",
149 fkClass, functionName);
150 }
151 return nullptr;
152 }
153 return fHnVector[index];
154}
155
156//_____________________________________________________________________________
158 G4int dimension,
159 std::string_view functionName, G4bool warn) const
160{
161 auto info = GetHnInformation(id, functionName, warn);
162 if (info == nullptr) return nullptr;
163
164 return info->GetHnDimensionInformation(dimension);
165}
166
167//_____________________________________________________________________________
169{
170 return ( fNofActiveObjects > 0 );
171}
172
173//_____________________________________________________________________________
175{
176 return ( fNofAsciiObjects > 0 );
177}
178
179//_____________________________________________________________________________
181{
182 return ( fNofPlottingObjects > 0 );
183}
184
185//_____________________________________________________________________________
187{
188 return ( fNofFileNameObjects > 0 );
189}
190
191//_____________________________________________________________________________
193{
194// Set activation to a given object
195
196 auto info = GetHnInformation(id, "SetActivation");
197
198 if (info == nullptr) return;
199
200 SetActivation(info, activation);
201}
202
203//_____________________________________________________________________________
205{
206// Set activation to all objects of the given type
207
208 //std::vector<G4HnInformation*>::iterator it;
209 //for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) {
210 // G4HnInformation* info = *it;
211
212 for ( auto info : fHnVector ) {
213 SetActivation(info, activation);
214 }
215}
216
217//_____________________________________________________________________________
219{
220 auto info = GetHnInformation(id, "SetAscii");
221
222 if (info == nullptr) return;
223
224 // Do nothing if ascii does not change
225 if ( info->GetAscii() == ascii ) return;
226
227 // Change ascii and account it in fNofAsciiObjects
228 info->SetAscii(ascii);
229 if (ascii) {
230 fNofAsciiObjects++;
231 }
232 else {
233 fNofAsciiObjects--;
234 }
235}
236
237//_____________________________________________________________________________
239{
240 auto info = GetHnInformation(id, "SetPlotting");
241
242 if (info == nullptr) return;
243
244 SetPlotting(info, plotting);
245}
246
247//_____________________________________________________________________________
249{
250// Set plotting to all objects of the given type
251
252 for ( auto info : fHnVector ) {
253 SetPlotting(info, plotting);
254 }
255}
256
257//_____________________________________________________________________________
258void G4HnManager::SetFileName(G4int id, const G4String& fileName)
259{
260 auto info = GetHnInformation(id, "SetFileName");
261
262 if (info == nullptr) return;
263
264 SetFileName(info, fileName);
265}
266
267//_____________________________________________________________________________
269{
270// Set plotting to all objects of the given type
271
272 for ( auto info : fHnVector ) {
273 SetFileName(info, fileName);
274 }
275}
276
277//_____________________________________________________________________________
278G4bool G4HnManager::SetAxisIsLog(unsigned int idim, G4int id, G4bool isLog)
279{
280 auto info = GetHnInformation(id, "SetAxisIsLog");
281
282 if (info == nullptr) return false;
283
284 info->SetIsLogAxis(idim, isLog);
285 return true;
286}
287
288//_____________________________________________________________________________
290{
291 auto info = GetHnInformation(id, "GetName");
292
293 if (info == nullptr) return "";
294
295 return info->GetName();
296}
297
298//_____________________________________________________________________________
299G4double G4HnManager::GetUnit(unsigned int idim, G4int id) const
300{
301 auto info = GetHnDimensionInformation(id, idim, "GetXUnit");
302
303 if (info == nullptr) return 1.0;
304
305 return info->fUnit;
306}
307
308//_____________________________________________________________________________
309G4bool G4HnManager::GetAxisIsLog(unsigned int idim, G4int id) const
310{
311 auto info = GetHnInformation(id, "GetXAxisIsLog");
312
313 if (info == nullptr) return false;
314
315 return info->GetIsLogAxis(idim);
316}
317
318//_____________________________________________________________________________
320{
321 auto info = GetHnInformation(id, "GetActivation");
322
323 if (info == nullptr) return true;
324
325 return info->GetActivation();
326}
327
328//_____________________________________________________________________________
330{
331 auto info = GetHnInformation(id, "GetAscii");
332
333 if (info == nullptr) return false;
334
335 return info->GetAscii();
336}
337
338//_____________________________________________________________________________
340{
341 auto info = GetHnInformation(id, "GetPlotting");
342
343 if (info == nullptr) return false;
344
345 return info->GetPlotting();
346}
347
348//_____________________________________________________________________________
350{
351 auto info = GetHnInformation(id, "GetFileName");
352
353 if (info == nullptr) return "";
354
355 return info->GetFileName();
356}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void SetLockFirstId(G4bool lockFirstId)
void SetAscii(G4bool ascii)
void SetPlotting(G4bool plotting)
G4bool GetIsLogAxis(G4int axis) const
G4bool GetPlotting() const
G4bool GetActivation() const
G4bool GetAscii() const
G4String GetName() const
void SetIsLogAxis(G4int axis, G4bool isLog)
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
void SetActivation(G4bool activation)
G4String GetFileName() const
void SetFileName(const G4String &fileName)
G4HnDimensionInformation * GetHnDimensionInformation(G4int id, G4int dimension, std::string_view functionName, G4bool warn=true) const
Definition: G4HnManager.cc:157
void ClearData()
Definition: G4HnManager.cc:132
G4bool GetPlotting(G4int id) const
Definition: G4HnManager.cc:339
G4bool SetAxisIsLog(unsigned int idim, G4int id, G4bool isLogAxis)
Definition: G4HnManager.cc:278
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:204
G4String GetFileName(G4int id) const
Definition: G4HnManager.cc:349
G4String GetName(G4int id) const
Definition: G4HnManager.cc:289
G4bool IsAscii() const
Definition: G4HnManager.cc:174
~G4HnManager() override
Definition: G4HnManager.cc:48
G4bool IsPlotting() const
Definition: G4HnManager.cc:180
void SetFileName(G4int id, const G4String &fileName)
Definition: G4HnManager.cc:258
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:319
G4bool GetAxisIsLog(unsigned int idim, G4int id) const
Definition: G4HnManager.cc:309
G4double GetUnit(unsigned int idim, G4int id) const
Definition: G4HnManager.cc:299
G4bool IsActive() const
Definition: G4HnManager.cc:168
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:218
void SetPlotting(G4int id, G4bool plotting)
Definition: G4HnManager.cc:238
G4HnInformation * GetHnInformation(G4int id, std::string_view functionName, G4bool warn=true) const
Definition: G4HnManager.cc:142
G4HnManager()=delete
G4bool GetAscii(G4int id) const
Definition: G4HnManager.cc:329
G4bool IsFileName() const
Definition: G4HnManager.cc:186
G4HnInformation * AddHnInformation(const G4String &name, G4int nofDimensions)
Definition: G4HnManager.cc:122
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)