41 G4ThreadLocal std::set<G4String> *G4AttCheck::fUnitCategories = 0;
43 G4ThreadLocal std::map<G4String,G4String> *G4AttCheck::fStandardUnits = 0;
45 G4ThreadLocal std::set<G4String> *G4AttCheck::fCategories = 0;
49 G4ThreadLocal std::set<G4String> *G4AttCheck::fValueTypes = 0;
52 (
const std::vector<G4AttValue>* values,
53 const std::map<G4String,G4AttDef>* definitions):
55 fpDefinitions(definitions)
63 fUnitCategories->insert(
"Length");
64 fUnitCategories->insert(
"Energy");
65 fUnitCategories->insert(
"Time");
66 fUnitCategories->insert(
"Electric charge");
67 fUnitCategories->insert(
"Volumic Mass");
70 (*fStandardUnits)[
"Length"] =
"m";
71 (*fStandardUnits)[
"Energy"] =
"MeV";
72 (*fStandardUnits)[
"Time"] =
"ns";
73 (*fStandardUnits)[
"Electric charge"] =
"e+";
74 (*fStandardUnits)[
"Volumic Mass"] =
"kg/m3";
77 fCategories->insert(
"Bookkeeping");
78 fCategories->insert(
"Draw");
79 fCategories->insert(
"Physics");
80 fCategories->insert(
"PickAction");
81 fCategories->insert(
"Association");
85 fUnits->insert(
"G4BestUnit");
88 for (
size_t i = 0; i < units.size(); ++i) {
89 if (fUnitCategories->find(units[i]->GetName()) !=
90 fUnitCategories->end()) {
93 for (
size_t j = 0; j < container.size(); ++j) {
96 fUnits->insert(container[j]->GetSymbol());
102 fValueTypes->insert(
"G4String");
103 fValueTypes->insert(
"G4int");
104 fValueTypes->insert(
"G4double");
105 fValueTypes->insert(
"G4ThreeVector");
106 fValueTypes->insert(
"G4bool");
114 void G4AttCheck::Init()
116 if (!fValueTypes) fValueTypes =
new std::set<G4String>;
117 if (!fUnits) fUnits =
new std::set<G4String>;
118 if (!fCategories) fCategories =
new std::set<G4String>;
119 if (!fStandardUnits) fStandardUnits =
new std::map<G4String,G4String>;
120 if (!fUnitCategories) fUnitCategories =
new std::set<G4String>;
129 if (iError < 10 || iError%100 == 0) {
133 if (!fpValues)
return error;
134 if (!fpDefinitions) {
139 "\n*******************************************************";
144 "\nG4AttCheck: ERROR " << iError <<
": Null definitions pointer"
145 "\n*******************************************************"
150 vector<G4AttValue>::const_iterator iValue;
151 for (iValue = fpValues->begin(); iValue != fpValues->end(); ++iValue) {
152 const G4String& valueName = iValue->GetName();
154 map<G4String,G4AttDef>::const_iterator iDef =
155 fpDefinitions->find(valueName);
156 if (iDef == fpDefinitions->end()) {
161 "\n*******************************************************";
166 "\nG4AttCheck: ERROR " << iError <<
": No G4AttDef for G4AttValue \""
167 << valueName <<
"\": " << value <<
168 "\n*******************************************************"
172 const G4String& category = iDef->second.GetCategory();
173 const G4String& extra = iDef->second.GetExtra();
174 const G4String& valueType = iDef->second.GetValueType();
175 if (fCategories->find(category) == fCategories->end()) {
180 "\n*******************************************************";
185 "\nG4AttCheck: ERROR " << iError <<
": Illegal Category Field \""
186 << category <<
"\" for G4AttValue \""
187 << valueName <<
"\": " << value <<
188 "\n Possible Categories:";
189 set<G4String>::iterator i;
190 for (i = fCategories->begin(); i != fCategories->end(); ++i) {
194 "\n*******************************************************"
198 if(category ==
"Physics" && fUnits->find(extra) == fUnits->end()) {
203 "\n*******************************************************";
208 "\nG4AttCheck: ERROR " << iError <<
": Illegal Extra field \""
209 << extra <<
"\" for G4AttValue \""
210 << valueName <<
"\": " << value <<
211 "\n Possible Extra fields if Category==\"Physics\":\n ";
212 set<G4String>::iterator i;
213 for (i = fUnits->begin(); i != fUnits->end(); ++i) {
217 "\n*******************************************************"
221 if (fValueTypes->find(valueType) == fValueTypes->end()) {
226 "\n*******************************************************";
231 "\nG4AttCheck: ERROR " << iError <<
": Illegal Value Type field \""
232 << valueType <<
"\" for G4AttValue \""
233 << valueName <<
"\": " << value <<
234 "\n Possible Value Types:";
235 set<G4String>::iterator i;
236 for (i = fValueTypes->begin(); i != fValueTypes->end(); ++i) {
240 "\n*******************************************************"
252 if (!ac.fpDefinitions) {
253 os <<
"G4AttCheck: ERROR: zero definitions pointer." << endl;
258 os << storeKey <<
':' << endl;
262 os <<
"G4AttCheck: zero values pointer." << endl;
265 vector<G4AttValue>::const_iterator iValue;
266 for (iValue = ac.fpValues->begin(); iValue != ac.fpValues->end(); ++iValue) {
267 const G4String& valueName = iValue->GetName();
269 map<G4String,G4AttDef>::const_iterator iDef =
270 ac.fpDefinitions->find(valueName);
272 if (iDef == ac.fpDefinitions->end()) {
274 os <<
"G4AttCheck: ERROR: No G4AttDef for G4AttValue \""
275 << valueName <<
"\": " << value << endl;
277 const G4String& category = iDef->second.GetCategory();
278 const G4String& extra = iDef->second.GetExtra();
279 const G4String& valueType = iDef->second.GetValueType();
280 if (ac.fCategories->find(category) == ac.fCategories->end()) {
283 "G4AttCheck: ERROR: Illegal Category Field \"" << category
284 <<
"\" for G4AttValue \"" << valueName <<
"\": " << value <<
285 "\n Possible Categories:";
286 set<G4String>::iterator i;
287 for (i = ac.fCategories->begin(); i != ac.fCategories->end(); ++i) {
292 if(category ==
"Physics" && ac.fUnits->find(extra) == ac.fUnits->end()) {
295 "G4AttCheck: ERROR: Illegal Extra field \""<< extra
296 <<
"\" for G4AttValue \"" << valueName <<
"\": " << value <<
297 "\n Possible Extra fields if Category==\"Physics\":\n ";
298 set<G4String>::iterator i;
299 for (i = ac.fUnits->begin(); i != ac.fUnits->end(); ++i) {
304 if (ac.fValueTypes->find(valueType) == ac.fValueTypes->end()) {
307 "G4AttCheck: ERROR: Illegal Value Type field \"" << valueType
308 <<
"\" for G4AttValue \"" << valueName <<
"\": " << value <<
309 "\n Possible Value Types:";
310 set<G4String>::iterator i;
311 for (i = ac.fValueTypes->begin(); i != ac.fValueTypes->end(); ++i) {
318 os << iDef->second.GetDesc()
321 if (iDef->second.GetCategory() ==
"Physics" &&
322 !iDef->second.GetExtra().empty()) {
323 os <<
" (" << iDef->second.GetExtra() <<
")";
331 void G4AttCheck::AddValuesAndDefs
332 (std::vector<G4AttValue>* standardValues,
333 std::map<G4String,G4AttDef>* standardDefinitions,
341 standardValues->push_back(
G4AttValue(name,value,
""));
343 (*standardDefinitions)[
name] = fpDefinitions->find(oldName)->second;
345 (*standardDefinitions)[
name].SetName(name);
346 (*standardDefinitions)[
name].SetExtra(extra);
347 if (description !=
"") (*standardDefinitions)[
name].SetDesc(description);
351 (std::vector<G4AttValue>* standardValues,
352 std::map<G4String,G4AttDef>* standardDefinitions)
const
358 vector<G4AttValue>::const_iterator iValue;
359 for (iValue = fpValues->begin(); iValue != fpValues->end(); ++iValue) {
360 const G4String& valueName = iValue->GetName();
361 const G4String& value = iValue->GetValue();
362 map<G4String,G4AttDef>::const_iterator iDef =
363 fpDefinitions->find(valueName);
364 if (iDef == fpDefinitions->end()) {
367 const G4String& category = iDef->second.GetCategory();
368 const G4String& extra = iDef->second.GetExtra();
369 const G4String& valueType = iDef->second.GetValueType();
370 if (fCategories->find(category) == fCategories->end() ||
371 (category ==
"Physics" && fUnits->find(extra) == fUnits->end()) ||
372 fValueTypes->find(valueType) == fValueTypes->end()) {
375 if (category !=
"Physics") {
376 standardValues->push_back(*iValue);
377 (*standardDefinitions)[valueName] =
378 fpDefinitions->find(valueName)->second;
381 if (valueType ==
"G4ThreeVector") {
385 (standardValues,standardDefinitions,
386 valueName,valueName+
"-X",
388 fpDefinitions->find(valueName)->second.GetDesc()+
"-X");
390 (standardValues,standardDefinitions,
391 valueName,valueName+
"-Y",
393 fpDefinitions->find(valueName)->second.GetDesc()+
"-Y");
395 (standardValues,standardDefinitions,
396 valueName,valueName+
"-Z",
398 fpDefinitions->find(valueName)->second.GetDesc()+
"-Z");
400 standardValues->push_back(*iValue);
401 (*standardDefinitions)[valueName] =
402 fpDefinitions->find(valueName)->second;
407 if (extra ==
"G4BestUnit") {
408 valueAndUnit =
value;
409 valueAndUnit = valueAndUnit.
strip();
410 unit = valueAndUnit.substr(valueAndUnit.rfind(
' ')+1);
412 valueAndUnit = value +
' ' + extra;
413 valueAndUnit = valueAndUnit.
strip();
417 if (fUnitCategories->find(unitCategory) != fUnitCategories->end()) {
418 G4String standardUnit = (*fStandardUnits)[unitCategory];
422 if (valueType ==
"G4ThreeVector") {
426 (standardValues,standardDefinitions,
427 valueName,valueName+
"-X",
429 (internalValue.
x()/valueOfStandardUnit),
431 fpDefinitions->find(valueName)->second.GetDesc()+
"-X");
433 (standardValues,standardDefinitions,
434 valueName,valueName+
"-Y",
436 (internalValue.
y()/valueOfStandardUnit),
438 fpDefinitions->find(valueName)->second.GetDesc()+
"-Y");
440 (standardValues,standardDefinitions,
441 valueName,valueName+
"-Z",
443 (internalValue.
z()/valueOfStandardUnit),
445 fpDefinitions->find(valueName)->second.GetDesc()+
"-Z");
450 (standardValues,standardDefinitions,
453 (internalValue/valueOfStandardUnit),
463 G4cerr <<
"G4AttCheck::Standard: Conversion error." <<
G4endl;
G4AttCheck(const std::vector< G4AttValue > *values, const std::map< G4String, G4AttDef > *definitions)
G4bool GetStoreKey(const std::map< G4String, G4AttDef > *definitions, G4String &key)
G4String strip(G4int strip_Type=trailing, char c=' ')
std::vector< G4UnitsCategory * > G4UnitsTable
friend std::ostream & operator<<(std::ostream &, const G4AttCheck &)
static G4String ConvertToString(G4bool boolVal)
G4bool Standard(std::vector< G4AttValue > *standardValues, std::map< G4String, G4AttDef > *standardDefinitions) const
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
static G4double GetValueOf(const G4String &)
const XML_Char int const XML_Char * value
void print(G4double elem)
static G4UnitsTable & GetUnitsTable()
static G4String GetCategory(const G4String &)
G4bool Check(const G4String &leader="") const
static PROLOG_HANDLER error
std::vector< G4UnitDefinition * > G4UnitsContainer
G4GLOB_DLL std::ostream G4cerr
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)