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