Geant4-11
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
G4AttCheck Class Reference

#include <G4AttCheck.hh>

Public Member Functions

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

Private Member Functions

void AddValuesAndDefs (std::vector< G4AttValue > *newValues, std::map< G4String, G4AttDef > *newDefinitions, const G4String &oldName, const G4String &name, const G4String &value, const G4String &extra, const G4String &description="") const
 
void Init ()
 

Private Attributes

const std::map< G4String, G4AttDef > * fpDefinitions
 
const std::vector< G4AttValue > * fpValues
 

Static Private Attributes

static G4ThreadLocal std::set< G4String > * fCategories = 0
 
static G4ThreadLocal G4bool fFirst = true
 
static G4ThreadLocal std::map< G4String, G4String > * fStandardUnits = 0
 
static G4ThreadLocal std::set< G4String > * fUnitCategories = 0
 
static G4ThreadLocal std::set< G4String > * fUnits = 0
 
static G4ThreadLocal std::set< G4String > * fValueTypes = 0
 

Friends

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

Detailed Description

Definition at line 56 of file G4AttCheck.hh.

Constructor & Destructor Documentation

◆ G4AttCheck()

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

Definition at line 50 of file G4AttCheck.cc.

52 :
53 fpValues(values),
54 fpDefinitions(definitions)
55{
56 Init();
57
58 if (fFirst) { // Initialise static containers.
59 fFirst = false;
60
61 // Legal Unit Category Types...
62 fUnitCategories->insert("Length");
63 fUnitCategories->insert("Energy");
64 fUnitCategories->insert("Time");
65 fUnitCategories->insert("Electric charge");
66 fUnitCategories->insert("Volumic Mass"); // (Density)
67
68 // Corresponding Standard Units...
69 (*fStandardUnits)["Length"] = "m";
70 (*fStandardUnits)["Energy"] = "MeV";
71 (*fStandardUnits)["Time"] = "ns";
72 (*fStandardUnits)["Electric charge"] = "e+";
73 (*fStandardUnits)["Volumic Mass"] = "kg/m3";
74
75 // Legal Categories...
76 fCategories->insert("Bookkeeping");
77 fCategories->insert("Draw");
78 fCategories->insert("Physics");
79 fCategories->insert("PickAction");
80 fCategories->insert("Association");
81
82 // Legal units...
83 fUnits->insert("");
84 fUnits->insert("G4BestUnit");
85 // ...plus any legal unit symbol ("MeV", "km", etc.)...
87 for (size_t i = 0; i < units.size(); ++i) {
88 if (fUnitCategories->find(units[i]->GetName()) !=
89 fUnitCategories->end()) {
90 //G4cout << units[i]->GetName() << G4endl;
91 G4UnitsContainer& container = units[i]->GetUnitsList();
92 for (size_t j = 0; j < container.size(); ++j) {
93 //G4cout << container[j]->GetName() << ' '
94 // << container[j]->GetSymbol() << G4endl;
95 fUnits->insert(container[j]->GetSymbol());
96 }
97 }
98 }
99
100 // Legal Value Types...
101 fValueTypes->insert("G4String");
102 fValueTypes->insert("G4int");
103 fValueTypes->insert("G4double");
104 fValueTypes->insert("G4ThreeVector");
105 fValueTypes->insert("G4bool");
106 }
107}
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:68
static G4ThreadLocal std::set< G4String > * fUnits
Definition: G4AttCheck.hh:106
const std::map< G4String, G4AttDef > * fpDefinitions
Definition: G4AttCheck.hh:100
void Init()
Definition: G4AttCheck.cc:113
static G4ThreadLocal std::set< G4String > * fCategories
Definition: G4AttCheck.hh:105
static G4ThreadLocal G4bool fFirst
Definition: G4AttCheck.hh:102
static G4ThreadLocal std::set< G4String > * fUnitCategories
Definition: G4AttCheck.hh:103
static G4ThreadLocal std::set< G4String > * fValueTypes
Definition: G4AttCheck.hh:107
const std::vector< G4AttValue > * fpValues
Definition: G4AttCheck.hh:99
static G4UnitsTable & GetUnitsTable()

References fCategories, fFirst, fUnitCategories, fUnits, fValueTypes, G4UnitDefinition::GetUnitsTable(), and Init().

◆ ~G4AttCheck()

G4AttCheck::~G4AttCheck ( )

Definition at line 109 of file G4AttCheck.cc.

110{
111}

Member Function Documentation

◆ AddValuesAndDefs()

void G4AttCheck::AddValuesAndDefs ( std::vector< G4AttValue > *  newValues,
std::map< G4String, G4AttDef > *  newDefinitions,
const G4String oldName,
const G4String name,
const G4String value,
const G4String extra,
const G4String description = "" 
) const
private

Definition at line 330 of file G4AttCheck.cc.

338{
339 // Add new G4AttDeff...
340 standardValues->push_back(G4AttValue(name,value,""));
341 // Copy original G4AttDef...
342 (*standardDefinitions)[name] = fpDefinitions->find(oldName)->second;
343 // ...and make appropriate changes...
344 (*standardDefinitions)[name].SetName(name);
345 (*standardDefinitions)[name].SetExtra(extra);
346 if (description != "") (*standardDefinitions)[name].SetDesc(description);
347}
const char * name(G4int ptype)

References fpDefinitions, and G4InuclParticleNames::name().

Referenced by Standard().

◆ Check()

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

Definition at line 122 of file G4AttCheck.cc.

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

References error, fCategories, fpDefinitions, fpValues, fUnits, fValueTypes, G4cerr, G4endl, G4ThreadLocal, and print().

Referenced by G4TrajectoriesModelDebugG4AttValues().

◆ GetAttDefs()

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

Definition at line 70 of file G4AttCheck.hh.

70 {
71 return fpDefinitions;
72 }

References fpDefinitions.

◆ GetAttValues()

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

Definition at line 66 of file G4AttCheck.hh.

66 {
67 return fpValues;
68 }

References fpValues.

◆ Init()

void G4AttCheck::Init ( )
private

Definition at line 113 of file G4AttCheck.cc.

114{
115 if (!fValueTypes) fValueTypes = new std::set<G4String>;
116 if (!fUnits) fUnits = new std::set<G4String>;
117 if (!fCategories) fCategories = new std::set<G4String>;
118 if (!fStandardUnits) fStandardUnits = new std::map<G4String,G4String>;
119 if (!fUnitCategories) fUnitCategories = new std::set<G4String>;
120}
static G4ThreadLocal std::map< G4String, G4String > * fStandardUnits
Definition: G4AttCheck.hh:104

References fCategories, fStandardUnits, fUnitCategories, fUnits, and fValueTypes.

Referenced by G4AttCheck().

◆ Standard()

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

Definition at line 349 of file G4AttCheck.cc.

352{
353 // Places standard versions in provided vector and map and returns error.
354 // Assumes valid input. Use Check to check.
355 using namespace std;
356 G4bool error = false;
357 vector<G4AttValue>::const_iterator iValue;
358 for (iValue = fpValues->begin(); iValue != fpValues->end(); ++iValue) {
359 const G4String& valueName = iValue->GetName();
360 const G4String& value = iValue->GetValue();
361 map<G4String,G4AttDef>::const_iterator iDef =
362 fpDefinitions->find(valueName);
363 if (iDef == fpDefinitions->end()) {
364 error = true;
365 } else {
366 const G4String& category = iDef->second.GetCategory();
367 const G4String& extra = iDef->second.GetExtra();
368 const G4String& valueType = iDef->second.GetValueType();
369 if (fCategories->find(category) == fCategories->end() ||
370 (category == "Physics" && fUnits->find(extra) == fUnits->end()) ||
371 fValueTypes->find(valueType) == fValueTypes->end()) {
372 error = true;
373 } else {
374 if (category != "Physics") { // Simply copy...
375 standardValues->push_back(*iValue);
376 (*standardDefinitions)[valueName] =
377 fpDefinitions->find(valueName)->second;
378 } else { // "Physics"...
379 if (extra.empty()) { // Dimensionless...
380 if (valueType == "G4ThreeVector") { // Split vector into 3...
381 G4ThreeVector internalValue =
384 (standardValues,standardDefinitions,
385 valueName,valueName+"-X",
386 G4UIcommand::ConvertToString(internalValue.x()),"",
387 fpDefinitions->find(valueName)->second.GetDesc()+"-X");
389 (standardValues,standardDefinitions,
390 valueName,valueName+"-Y",
391 G4UIcommand::ConvertToString(internalValue.y()),"",
392 fpDefinitions->find(valueName)->second.GetDesc()+"-Y");
394 (standardValues,standardDefinitions,
395 valueName,valueName+"-Z",
396 G4UIcommand::ConvertToString(internalValue.z()),"",
397 fpDefinitions->find(valueName)->second.GetDesc()+"-Z");
398 } else { // Simply copy...
399 standardValues->push_back(*iValue);
400 (*standardDefinitions)[valueName] =
401 fpDefinitions->find(valueName)->second;
402 }
403 } else { // Dimensioned...
404 G4String valueAndUnit;
405 G4String unit;
406 if (extra == "G4BestUnit") {
407 valueAndUnit = G4StrUtil::strip_copy(value);
408 unit = valueAndUnit.substr(valueAndUnit.rfind(' ')+1);
409 } else {
410 valueAndUnit = G4StrUtil::strip_copy(value + ' ' + extra);
411 unit = extra;
412 }
413 G4String unitCategory = G4UnitDefinition::GetCategory(unit);
414 if (fUnitCategories->find(unitCategory) != fUnitCategories->end()) {
415 G4String standardUnit = (*fStandardUnits)[unitCategory];
416 G4double valueOfStandardUnit =
417 G4UnitDefinition::GetValueOf(standardUnit);
418// G4String exstr = iDef->second.GetExtra();
419 if (valueType == "G4ThreeVector") { // Split vector into 3...
420 G4ThreeVector internalValue =
423 (standardValues,standardDefinitions,
424 valueName,valueName+"-X",
426 (internalValue.x()/valueOfStandardUnit),
427 standardUnit,
428 fpDefinitions->find(valueName)->second.GetDesc()+"-X");
430 (standardValues,standardDefinitions,
431 valueName,valueName+"-Y",
433 (internalValue.y()/valueOfStandardUnit),
434 standardUnit,
435 fpDefinitions->find(valueName)->second.GetDesc()+"-Y");
437 (standardValues,standardDefinitions,
438 valueName,valueName+"-Z",
440 (internalValue.z()/valueOfStandardUnit),
441 standardUnit,
442 fpDefinitions->find(valueName)->second.GetDesc()+"-Z");
443 } else {
444 G4double internalValue =
447 (standardValues,standardDefinitions,
448 valueName,valueName,
450 (internalValue/valueOfStandardUnit),
451 standardUnit);
452 }
453 }
454 }
455 }
456 }
457 }
458 }
459 if (error) {
460 G4cerr << "G4AttCheck::Standard: Conversion error." << G4endl;
461 }
462 return error;
463}
double G4double
Definition: G4Types.hh:83
double z() const
double x() const
double y() const
void AddValuesAndDefs(std::vector< G4AttValue > *newValues, std::map< G4String, G4AttDef > *newDefinitions, const G4String &oldName, const G4String &name, const G4String &value, const G4String &extra, const G4String &description="") const
Definition: G4AttCheck.cc:331
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:597
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:584
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:608
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.

References AddValuesAndDefs(), G4UIcommand::ConvertTo3Vector(), G4UIcommand::ConvertToDimensioned3Vector(), G4UIcommand::ConvertToDimensionedDouble(), G4UIcommand::ConvertToString(), error, fCategories, fpDefinitions, fpValues, fUnitCategories, fUnits, fValueTypes, G4cerr, G4endl, G4UnitDefinition::GetCategory(), G4UnitDefinition::GetValueOf(), G4StrUtil::strip_copy(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

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

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 248 of file G4AttCheck.cc.

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

Field Documentation

◆ fCategories

G4ThreadLocal std::set< G4String > * G4AttCheck::fCategories = 0
staticprivate

Definition at line 105 of file G4AttCheck.hh.

Referenced by Check(), G4AttCheck(), Init(), and Standard().

◆ fFirst

G4ThreadLocal G4bool G4AttCheck::fFirst = true
staticprivate

Definition at line 102 of file G4AttCheck.hh.

Referenced by G4AttCheck().

◆ fpDefinitions

const std::map<G4String,G4AttDef>* G4AttCheck::fpDefinitions
private

Definition at line 100 of file G4AttCheck.hh.

Referenced by AddValuesAndDefs(), Check(), GetAttDefs(), and Standard().

◆ fpValues

const std::vector<G4AttValue>* G4AttCheck::fpValues
private

Definition at line 99 of file G4AttCheck.hh.

Referenced by Check(), GetAttValues(), and Standard().

◆ fStandardUnits

G4ThreadLocal std::map< G4String, G4String > * G4AttCheck::fStandardUnits = 0
staticprivate

Definition at line 104 of file G4AttCheck.hh.

Referenced by Init().

◆ fUnitCategories

G4ThreadLocal std::set< G4String > * G4AttCheck::fUnitCategories = 0
staticprivate

Definition at line 103 of file G4AttCheck.hh.

Referenced by G4AttCheck(), Init(), and Standard().

◆ fUnits

G4ThreadLocal std::set< G4String > * G4AttCheck::fUnits = 0
staticprivate

Definition at line 106 of file G4AttCheck.hh.

Referenced by Check(), G4AttCheck(), Init(), and Standard().

◆ fValueTypes

G4ThreadLocal std::set< G4String > * G4AttCheck::fValueTypes = 0
staticprivate

Definition at line 107 of file G4AttCheck.hh.

Referenced by Check(), G4AttCheck(), Init(), and Standard().


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