Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AttCheck Class Reference

#include <G4AttCheck.hh>

Public Member Functions

 G4AttCheck (const std::vector< G4AttValue > *values, const std::map< G4String, G4AttDef > *definitions)
 
 ~G4AttCheck ()
 
const std::vector< G4AttValue > * GetAttValues () const
 
const std::map< G4String, G4AttDef > * GetAttDefs () const
 
G4bool Check (const G4String &leader="") const
 
G4bool Standard (std::vector< G4AttValue > *standardValues, std::map< G4String, G4AttDef > *standardDefinitions) const
 

Friends

std::ostream & operator<< (std::ostream &, const G4AttCheck &)
 

Detailed Description

Definition at line 57 of file G4AttCheck.hh.

Constructor & Destructor Documentation

◆ G4AttCheck()

G4AttCheck::G4AttCheck ( const std::vector< G4AttValue > *  values,
const std::map< G4String, G4AttDef > *  definitions 
)

Definition at line 39 of file G4AttCheck.cc.

41 :
42 fpValues(values),
43 fpDefinitions(definitions)
44{
45 if (fFirst) { // Initialise static containers.
46 fFirst = false;
47
48 // Legal Unit Category Types...
49 fUnitCategories.insert("Length");
50 fUnitCategories.insert("Energy");
51 fUnitCategories.insert("Time");
52 fUnitCategories.insert("Electric charge");
53 fUnitCategories.insert("Volumic Mass"); // (Density)
54
55 // Corresponding Standard Units...
56 fStandardUnits["Length"] = "m";
57 fStandardUnits["Energy"] = "MeV";
58 fStandardUnits["Time"] = "ns";
59 fStandardUnits["Electric charge"] = "e+";
60 fStandardUnits["Volumic Mass"] = "kg/m3";
61
62 // Legal Categories...
63 fCategories.insert("Bookkeeping");
64 fCategories.insert("Draw");
65 fCategories.insert("Physics");
66 fCategories.insert("PickAction");
67 fCategories.insert("Association");
68
69 // Legal units...
70 fUnits.insert("");
71 fUnits.insert("G4BestUnit");
72 // ...plus any legal unit symbol ("MeV", "km", etc.)...
74 for (size_t i = 0; i < units.size(); ++i) {
75 if (fUnitCategories.find(units[i]->GetName()) !=
76 fUnitCategories.end()) {
77 //G4cout << units[i]->GetName() << G4endl;
78 G4UnitsContainer& container = units[i]->GetUnitsList();
79 for (size_t j = 0; j < container.size(); ++j) {
80 //G4cout << container[j]->GetName() << ' '
81 // << container[j]->GetSymbol() << G4endl;
82 fUnits.insert(container[j]->GetSymbol());
83 }
84 }
85 }
86
87 // Legal Value Types...
88 fValueTypes.insert("G4String");
89 fValueTypes.insert("G4int");
90 fValueTypes.insert("G4double");
91 fValueTypes.insert("G4ThreeVector");
92 fValueTypes.insert("G4bool");
93 }
94}
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
std::vector< G4UnitDefinition * > G4UnitsContainer
static G4UnitsTable & GetUnitsTable()

◆ ~G4AttCheck()

G4AttCheck::~G4AttCheck ( )

Definition at line 96 of file G4AttCheck.cc.

96{}

Member Function Documentation

◆ Check()

G4bool G4AttCheck::Check ( const G4String leader = "") const

Definition at line 110 of file G4AttCheck.cc.

110 {
111 // Check only. Silent unless error - then G4cerr. Returns error.
112 G4bool error = false;
113 static G4int iError = 0;
114 G4bool print = false;
115 if (iError < 10 || iError%100 == 0) {
116 print = true;
117 }
118 using namespace std;
119 if (!fpValues) return error; // A null values vector is a valid situation.
120 if (!fpDefinitions) {
121 ++iError;
122 error = true;
123 if (print) {
124 G4cerr <<
125 "\n*******************************************************";
126 if (leader != "") {
127 G4cerr << '\n' << leader;
128 }
129 G4cerr <<
130 "\nG4AttCheck: ERROR " << iError << ": Null definitions pointer"
131 "\n*******************************************************"
132 << G4endl;
133 }
134 return error;
135 }
136 vector<G4AttValue>::const_iterator iValue;
137 for (iValue = fpValues->begin(); iValue != fpValues->end(); ++iValue) {
138 const G4String& valueName = iValue->GetName();
139 const G4String& value = iValue->GetValue();
140 map<G4String,G4AttDef>::const_iterator iDef =
141 fpDefinitions->find(valueName);
142 if (iDef == fpDefinitions->end()) {
143 ++iError;
144 error = true;
145 if (print) {
146 G4cerr <<
147 "\n*******************************************************";
148 if (leader != "") {
149 G4cerr << '\n' << leader;
150 }
151 G4cerr <<
152 "\nG4AttCheck: ERROR " << iError << ": No G4AttDef for G4AttValue \""
153 << valueName << "\": " << value <<
154 "\n*******************************************************"
155 << G4endl;
156 }
157 } else {
158 const G4String& category = iDef->second.GetCategory();
159 const G4String& extra = iDef->second.GetExtra();
160 const G4String& valueType = iDef->second.GetValueType();
161 if (fCategories.find(category) == fCategories.end()) {
162 ++iError;
163 error = true;
164 if (print) {
165 G4cerr <<
166 "\n*******************************************************";
167 if (leader != "") {
168 G4cerr << '\n' << leader;
169 }
170 G4cerr <<
171 "\nG4AttCheck: ERROR " << iError << ": Illegal Category Field \""
172 << category << "\" for G4AttValue \""
173 << valueName << "\": " << value <<
174 "\n Possible Categories:";
175 set<G4String>::iterator i;
176 for (i = fCategories.begin(); i != fCategories.end(); ++i) {
177 G4cerr << ' ' << *i;
178 }
179 G4cerr <<
180 "\n*******************************************************"
181 << G4endl;
182 }
183 }
184 if(category == "Physics" && fUnits.find(extra) == fUnits.end()) {
185 ++iError;
186 error = true;
187 if (print) {
188 G4cerr <<
189 "\n*******************************************************";
190 if (leader != "") {
191 G4cerr << '\n' << leader;
192 }
193 G4cerr <<
194 "\nG4AttCheck: ERROR " << iError << ": Illegal Extra field \""
195 << extra << "\" for G4AttValue \""
196 << valueName << "\": " << value <<
197 "\n Possible Extra fields if Category==\"Physics\":\n ";
198 set<G4String>::iterator i;
199 for (i = fUnits.begin(); i != fUnits.end(); ++i) {
200 G4cerr << ' ' << *i;
201 }
202 G4cerr <<
203 "\n*******************************************************"
204 << G4endl;
205 }
206 }
207 if (fValueTypes.find(valueType) == fValueTypes.end()) {
208 ++iError;
209 error = true;
210 if (print) {
211 G4cerr <<
212 "\n*******************************************************";
213 if (leader != "") {
214 G4cerr << '\n' << leader;
215 }
216 G4cerr <<
217 "\nG4AttCheck: ERROR " << iError << ": Illegal Value Type field \""
218 << valueType << "\" for G4AttValue \""
219 << valueName << "\": " << value <<
220 "\n Possible Value Types:";
221 set<G4String>::iterator i;
222 for (i = fValueTypes.begin(); i != fValueTypes.end(); ++i) {
223 G4cerr << ' ' << *i;
224 }
225 G4cerr <<
226 "\n*******************************************************"
227 << G4endl;
228 }
229 }
230 }
231 }
232 return error;
233}
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
void print(G4double elem)
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr

Referenced by G4TrajectoriesModelDebugG4AttValues(), and G4XXXStoredSceneHandler::PreAddSolid().

◆ GetAttDefs()

const std::map< G4String, G4AttDef > * G4AttCheck::GetAttDefs ( ) const
inline

Definition at line 71 of file G4AttCheck.hh.

71 {
72 return fpDefinitions;
73 }

◆ GetAttValues()

const std::vector< G4AttValue > * G4AttCheck::GetAttValues ( ) const
inline

Definition at line 67 of file G4AttCheck.hh.

67 {
68 return fpValues;
69 }

◆ Standard()

G4bool G4AttCheck::Standard ( std::vector< G4AttValue > *  standardValues,
std::map< G4String, G4AttDef > *  standardDefinitions 
) const

Definition at line 335 of file G4AttCheck.cc.

337 {
338 // Places standard versions in provided vector and map and returns error.
339 // Assumes valid input. Use Check to check.
340 using namespace std;
341 G4bool error = false;
342 vector<G4AttValue>::const_iterator iValue;
343 for (iValue = fpValues->begin(); iValue != fpValues->end(); ++iValue) {
344 const G4String& valueName = iValue->GetName();
345 const G4String& value = iValue->GetValue();
346 map<G4String,G4AttDef>::const_iterator iDef =
347 fpDefinitions->find(valueName);
348 if (iDef == fpDefinitions->end()) {
349 error = true;
350 } else {
351 const G4String& category = iDef->second.GetCategory();
352 const G4String& extra = iDef->second.GetExtra();
353 const G4String& valueType = iDef->second.GetValueType();
354 if (fCategories.find(category) == fCategories.end() ||
355 (category == "Physics" && fUnits.find(extra) == fUnits.end()) ||
356 fValueTypes.find(valueType) == fValueTypes.end()) {
357 error = true;
358 } else {
359 if (category != "Physics") { // Simply copy...
360 standardValues->push_back(*iValue);
361 (*standardDefinitions)[valueName] =
362 fpDefinitions->find(valueName)->second;
363 } else { // "Physics"...
364 if (extra.empty()) { // Dimensionless...
365 if (valueType == "G4ThreeVector") { // Split vector into 3...
366 G4ThreeVector internalValue =
368 AddValuesAndDefs
369 (standardValues,standardDefinitions,
370 valueName,valueName+"-X",
371 G4UIcommand::ConvertToString(internalValue.x()),"",
372 fpDefinitions->find(valueName)->second.GetDesc()+"-X");
373 AddValuesAndDefs
374 (standardValues,standardDefinitions,
375 valueName,valueName+"-Y",
376 G4UIcommand::ConvertToString(internalValue.y()),"",
377 fpDefinitions->find(valueName)->second.GetDesc()+"-Y");
378 AddValuesAndDefs
379 (standardValues,standardDefinitions,
380 valueName,valueName+"-Z",
381 G4UIcommand::ConvertToString(internalValue.z()),"",
382 fpDefinitions->find(valueName)->second.GetDesc()+"-Z");
383 } else { // Simply copy...
384 standardValues->push_back(*iValue);
385 (*standardDefinitions)[valueName] =
386 fpDefinitions->find(valueName)->second;
387 }
388 } else { // Dimensioned...
389 G4String valueAndUnit;
390 G4String unit;
391 if (extra == "G4BestUnit") {
392 valueAndUnit = value;
393 valueAndUnit = valueAndUnit.strip();
394 unit = valueAndUnit.substr(valueAndUnit.rfind(' ')+1);
395 } else {
396 valueAndUnit = value + ' ' + extra;
397 valueAndUnit = valueAndUnit.strip();
398 unit = extra;
399 }
400 G4String unitCategory = G4UnitDefinition::GetCategory(unit);
401 if (fUnitCategories.find(unitCategory) != fUnitCategories.end()) {
402 G4String standardUnit = fStandardUnits[unitCategory];
403 G4double valueOfStandardUnit =
404 G4UnitDefinition::GetValueOf(standardUnit);
405// G4String exstr = iDef->second.GetExtra();
406 if (valueType == "G4ThreeVector") { // Split vector into 3...
407 G4ThreeVector internalValue =
409 AddValuesAndDefs
410 (standardValues,standardDefinitions,
411 valueName,valueName+"-X",
413 (internalValue.x()/valueOfStandardUnit),
414 standardUnit,
415 fpDefinitions->find(valueName)->second.GetDesc()+"-X");
416 AddValuesAndDefs
417 (standardValues,standardDefinitions,
418 valueName,valueName+"-Y",
420 (internalValue.y()/valueOfStandardUnit),
421 standardUnit,
422 fpDefinitions->find(valueName)->second.GetDesc()+"-Y");
423 AddValuesAndDefs
424 (standardValues,standardDefinitions,
425 valueName,valueName+"-Z",
427 (internalValue.z()/valueOfStandardUnit),
428 standardUnit,
429 fpDefinitions->find(valueName)->second.GetDesc()+"-Z");
430 } else {
431 G4double internalValue =
433 AddValuesAndDefs
434 (standardValues,standardDefinitions,
435 valueName,valueName,
437 (internalValue/valueOfStandardUnit),
438 standardUnit);
439 }
440 }
441 }
442 }
443 }
444 }
445 }
446 if (error) {
447 G4cerr << "G4AttCheck::Standard: Conversion error." << G4endl;
448 }
449 return error;
450}
double G4double
Definition: G4Types.hh:64
double z() const
double x() const
double y() const
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:441
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:349
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:429
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:451
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4TrajectoriesModelDebugG4AttValues(), and G4XXXStoredSceneHandler::PreAddSolid().

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const G4AttCheck ac 
)
friend

Definition at line 235 of file G4AttCheck.cc.

236{
237 using namespace std;
238 if (!ac.fpDefinitions) {
239 os << "G4AttCheck: ERROR: zero definitions pointer." << endl;
240 return os;
241 }
242 G4String storeKey;
243 if (G4AttDefStore::GetStoreKey(ac.fpDefinitions, storeKey)) {
244 os << storeKey << ':' << endl;
245 }
246 if (!ac.fpValues) {
247 // A null values vector is a valid situation.
248 os << "G4AttCheck: zero values pointer." << endl;
249 return os;
250 }
251 vector<G4AttValue>::const_iterator iValue;
252 for (iValue = ac.fpValues->begin(); iValue != ac.fpValues->end(); ++iValue) {
253 const G4String& valueName = iValue->GetName();
254 const G4String& value = iValue->GetValue();
255 map<G4String,G4AttDef>::const_iterator iDef =
256 ac.fpDefinitions->find(valueName);
257 G4bool error = false;
258 if (iDef == ac.fpDefinitions->end()) {
259 error = true;
260 os << "G4AttCheck: ERROR: No G4AttDef for G4AttValue \""
261 << valueName << "\": " << value << endl;
262 } else {
263 const G4String& category = iDef->second.GetCategory();
264 const G4String& extra = iDef->second.GetExtra();
265 const G4String& valueType = iDef->second.GetValueType();
266 if (ac.fCategories.find(category) == ac.fCategories.end()) {
267 error = true;
268 os <<
269 "G4AttCheck: ERROR: Illegal Category Field \"" << category
270 << "\" for G4AttValue \"" << valueName << "\": " << value <<
271 "\n Possible Categories:";
272 set<G4String>::iterator i;
273 for (i = ac.fCategories.begin(); i != ac.fCategories.end(); ++i) {
274 os << ' ' << *i;
275 }
276 os << endl;
277 }
278 if(category == "Physics" && ac.fUnits.find(extra) == ac.fUnits.end()) {
279 error = true;
280 os <<
281 "G4AttCheck: ERROR: Illegal Extra field \""<< extra
282 << "\" for G4AttValue \"" << valueName << "\": " << value <<
283 "\n Possible Extra fields if Category==\"Physics\":\n ";
284 set<G4String>::iterator i;
285 for (i = ac.fUnits.begin(); i != ac.fUnits.end(); ++i) {
286 os << ' ' << *i;
287 }
288 os << endl;
289 }
290 if (ac.fValueTypes.find(valueType) == ac.fValueTypes.end()) {
291 error = true;
292 os <<
293 "G4AttCheck: ERROR: Illegal Value Type field \"" << valueType
294 << "\" for G4AttValue \"" << valueName << "\": " << value <<
295 "\n Possible Value Types:";
296 set<G4String>::iterator i;
297 for (i = ac.fValueTypes.begin(); i != ac.fValueTypes.end(); ++i) {
298 os << ' ' << *i;
299 }
300 os << endl;
301 }
302 }
303 if (!error) {
304 os << iDef->second.GetDesc()
305 << " (" << valueName
306 << "): " << value;
307 if (iDef->second.GetCategory() == "Physics" &&
308 !iDef->second.GetExtra().empty()) {
309 os << " (" << iDef->second.GetExtra() << ")";
310 }
311 os << endl;
312 }
313 }
314 return os;
315}
G4bool GetStoreKey(const std::map< G4String, G4AttDef > *definitions, G4String &key)

The documentation for this class was generated from the following files: