Geant4 10.7.0
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 "G4VFileManager.hh"
32
33using namespace G4Analysis;
34
35//_____________________________________________________________________________
37 const G4AnalysisManagerState& state)
38 : G4BaseAnalysisManager(state),
39 fHnType(hnType),
40 fNofActiveObjects(0),
41 fNofAsciiObjects(0),
42 fNofPlottingObjects(0),
43 fNofFileNameObjects(0),
44 fHnVector(),
45 fFileManager(nullptr)
46{
47}
48
49//_____________________________________________________________________________
51{
52 for ( auto info : fHnVector ) {
53 delete info;
54 }
55}
56
57//
58// private methods
59//
60
61//_____________________________________________________________________________
63{
64// Set activation to a given object
65
66 // Do nothing if activation does not change
67 if ( info->GetActivation() == activation ) return;
68
69 // Change activation and account it in fNofActiveObjects
70 info->SetActivation(activation);
71 if ( activation )
72 fNofActiveObjects++;
73 else
74 fNofActiveObjects--;
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 else
88 fNofPlottingObjects--;
89}
90
91//_____________________________________________________________________________
92void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
93{
94 // Do nothing if file name does not change
95 if ( info->GetFileName() == fileName ) return;
96
97 // Save the info and account a new file name if file manager
98 info->SetFileName(fileName);
99 if (fFileManager) {
100 fFileManager->AddFileName(fileName);
101 } else {
102 G4ExceptionDescription description;
103 description
104 << "Failed to set fileName " << fileName << " for object " << info->GetName() << G4endl
105 << "File manager is not set.";
106 G4Exception("G4HnManager::SetFileName",
107 "Analysis_W012", JustWarning, description);
108 return;
109 }
110
111 if ( fileName != "" ) {
112 fNofFileNameObjects++;
113 } else {
114 fNofFileNameObjects--;
115 }
116}
117
118//
119// public methods
120//
121
122//_____________________________________________________________________________
124{
125 auto info = new G4HnInformation(name, nofDimensions);
126 fHnVector.push_back(info);
127 ++fNofActiveObjects;
128
129 return info;
130}
131
132//_____________________________________________________________________________
134 G4String functionName, G4bool warn) const
135{
136 G4int index = id - fFirstId;
137 if ( index < 0 || index >= G4int(fHnVector.size()) ) {
138 if ( warn ) {
139 G4String inFunction = "G4HnManager::";
140 if ( functionName.size() )
141 inFunction += functionName;
142 else
143 inFunction += "GetHnInformation";
144 G4ExceptionDescription description;
145 description << " " << fHnType << " histogram " << id
146 << " does not exist.";
147 G4Exception(inFunction, "Analysis_W011", JustWarning, description);
148 }
149 return nullptr;
150 }
151 return fHnVector[index];
152}
153
154//_____________________________________________________________________________
156 G4int dimension,
157 G4String functionName, G4bool warn) const
158{
159 auto info = GetHnInformation(id, functionName, warn);
160 if ( ! info ) return nullptr;
161
162 return info->GetHnDimensionInformation(dimension);
163}
164
165//_____________________________________________________________________________
167{
168 return ( fNofActiveObjects > 0 );
169}
170
171//_____________________________________________________________________________
173{
174 return ( fNofAsciiObjects > 0 );
175}
176
177//_____________________________________________________________________________
179{
180 return ( fNofPlottingObjects > 0 );
181}
182
183//_____________________________________________________________________________
185{
186 return ( fNofFileNameObjects > 0 );
187}
188
189//_____________________________________________________________________________
191{
192// Set activation to a given object
193
194 auto info = GetHnInformation(id, "SetActivation");
195
196 if ( ! info ) return;
197
198 SetActivation(info, activation);
199}
200
201//_____________________________________________________________________________
203{
204// Set activation to all objects of the given type
205
206 //std::vector<G4HnInformation*>::iterator it;
207 //for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) {
208 // G4HnInformation* info = *it;
209
210 for ( auto info : fHnVector ) {
211 SetActivation(info, activation);
212 }
213}
214
215//_____________________________________________________________________________
217{
218 auto info = GetHnInformation(id, "SetAscii");
219
220 if ( ! info ) return;
221
222 // Do nothing if ascii does not change
223 if ( info->GetAscii() == ascii ) return;
224
225 // Change ascii and account it in fNofAsciiObjects
226 info->SetAscii(ascii);
227 if ( ascii )
228 fNofAsciiObjects++;
229 else
230 fNofAsciiObjects--;
231}
232
233//_____________________________________________________________________________
235{
236 auto info = GetHnInformation(id, "SetPlotting");
237
238 if ( ! info ) return;
239
240 SetPlotting(info, plotting);
241}
242
243//_____________________________________________________________________________
245{
246// Set plotting to all objects of the given type
247
248 for ( auto info : fHnVector ) {
249 SetPlotting(info, plotting);
250 }
251}
252
253//_____________________________________________________________________________
254void G4HnManager::SetFileName(G4int id, const G4String& fileName)
255{
256 auto info = GetHnInformation(id, "SetFileName");
257
258 if ( ! info ) return;
259
260 SetFileName(info, fileName);
261}
262
263//_____________________________________________________________________________
265{
266// Set plotting to all objects of the given type
267
268 for ( auto info : fHnVector ) {
269 SetFileName(info, fileName);
270 }
271}
272
273//_____________________________________________________________________________
275{
276 auto info = GetHnInformation(id, "SetXAxisIsLog");
277
278 if ( ! info ) return false;
279
280 info->SetIsLogAxis(kX, isLog);
281 return true;
282}
283
284//_____________________________________________________________________________
286{
287 auto info = GetHnInformation(id, "SetYAxisIsLog");
288
289 if ( ! info ) return false;
290
291 info->SetIsLogAxis(kY, isLog);
292 return true;
293}
294
295//_____________________________________________________________________________
297{
298 auto info = GetHnInformation(id, "SetZAxisIsLog");
299
300 if ( ! info ) return false;
301
302 info->SetIsLogAxis(kZ, isLog);
303 return true;
304}
305
306//_____________________________________________________________________________
308{
309 auto info = GetHnInformation(id, "GetName");
310
311 if ( ! info ) return "";
312
313 return info->GetName();
314}
315
316//_____________________________________________________________________________
318{
319 auto info = GetHnDimensionInformation(id, kX, "GetXUnit");
320
321 if ( ! info ) return 1.0;
322
323 return info->fUnit;
324}
325
326//_____________________________________________________________________________
328{
329 auto info = GetHnDimensionInformation(id, kY, "GetYUnit");
330
331 if ( ! info ) return 1.0;
332
333 return info->fUnit;
334}
335
336//_____________________________________________________________________________
338{
339 auto info = GetHnDimensionInformation(id, kZ, "GetZUnit");
340
341 if ( ! info ) return 1.0;
342
343 return info->fUnit;
344}
345
346//_____________________________________________________________________________
348{
349 auto info = GetHnInformation(id, "GetXAxisIsLog");
350
351 if ( ! info ) return false;
352
353 return info->GetIsLogAxis(kX);
354}
355
356//_____________________________________________________________________________
358{
359 auto info = GetHnInformation(id, "GetYAxisIsLog");
360
361 if ( ! info ) return 1.0;
362
363 return info->GetIsLogAxis(kY);
364}
365
366//_____________________________________________________________________________
368{
369 auto info = GetHnInformation(id, "GetZAxisIsLog");
370
371 if ( ! info ) return 1.0;
372
373 return info->GetIsLogAxis(kZ);
374}
375
376//_____________________________________________________________________________
378{
379 auto info = GetHnInformation(id, "GetActivation");
380
381 if ( ! info ) return true;
382
383 return info->GetActivation();
384}
385
386//_____________________________________________________________________________
388{
389 auto info = GetHnInformation(id, "GetAscii");
390
391 if ( ! info ) return false;
392
393 return info->GetAscii();
394}
395
396//_____________________________________________________________________________
398{
399 auto info = GetHnInformation(id, "GetPlotting");
400
401 if ( ! info ) return false;
402
403 return info->GetPlotting();
404}
405
406//_____________________________________________________________________________
408{
409 auto info = GetHnInformation(id, "GetFileName");
410
411 if ( ! info ) return "";
412
413 return info->GetFileName();
414}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
void SetAscii(G4bool ascii)
void SetPlotting(G4bool plotting)
G4bool GetIsLogAxis(G4int axis) const
G4bool GetPlotting() const
void SetFileName(G4String fileName)
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
virtual ~G4HnManager()
Definition: G4HnManager.cc:50
G4bool GetPlotting(G4int id) const
Definition: G4HnManager.cc:397
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:202
G4String GetFileName(G4int id) const
Definition: G4HnManager.cc:407
G4double GetYUnit(G4int id) const
Definition: G4HnManager.cc:327
G4HnDimensionInformation * GetHnDimensionInformation(G4int id, G4int dimension, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:155
G4bool SetZAxisIsLog(G4int id, G4bool isLogAxis)
Definition: G4HnManager.cc:296
G4HnManager(const G4String &hnType, const G4AnalysisManagerState &state)
Definition: G4HnManager.cc:36
G4bool SetYAxisIsLog(G4int id, G4bool isLogAxis)
Definition: G4HnManager.cc:285
G4String GetName(G4int id) const
Definition: G4HnManager.cc:307
G4HnInformation * GetHnInformation(G4int id, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:133
G4bool SetXAxisIsLog(G4int id, G4bool isLogAxis)
Definition: G4HnManager.cc:274
G4bool IsAscii() const
Definition: G4HnManager.cc:172
G4bool IsPlotting() const
Definition: G4HnManager.cc:178
void SetFileName(G4int id, const G4String &fileName)
Definition: G4HnManager.cc:254
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:377
G4bool GetZAxisIsLog(G4int id) const
Definition: G4HnManager.cc:367
G4bool GetXAxisIsLog(G4int id) const
Definition: G4HnManager.cc:347
G4bool IsActive() const
Definition: G4HnManager.cc:166
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:216
G4double GetZUnit(G4int id) const
Definition: G4HnManager.cc:337
G4bool GetYAxisIsLog(G4int id) const
Definition: G4HnManager.cc:357
void SetPlotting(G4int id, G4bool plotting)
Definition: G4HnManager.cc:234
G4double GetXUnit(G4int id) const
Definition: G4HnManager.cc:317
G4bool GetAscii(G4int id) const
Definition: G4HnManager.cc:387
G4bool IsFileName() const
Definition: G4HnManager.cc:184
G4HnInformation * AddHnInformation(const G4String &name, G4int nofDimensions)
Definition: G4HnManager.cc:123
const G4int kY
const G4int kZ
const G4int kX