40(
const std::vector<G4AttValue>* values,
41 const std::map<G4String,G4AttDef>* definitions):
43 fpDefinitions(definitions)
49 fUnitCategories.insert(
"Length");
50 fUnitCategories.insert(
"Energy");
51 fUnitCategories.insert(
"Time");
52 fUnitCategories.insert(
"Electric charge");
53 fUnitCategories.insert(
"Volumic Mass");
56 fStandardUnits[
"Length"] =
"m";
57 fStandardUnits[
"Energy"] =
"MeV";
58 fStandardUnits[
"Time"] =
"ns";
59 fStandardUnits[
"Electric charge"] =
"e+";
60 fStandardUnits[
"Volumic Mass"] =
"kg/m3";
63 fCategories.insert(
"Bookkeeping");
64 fCategories.insert(
"Draw");
65 fCategories.insert(
"Physics");
66 fCategories.insert(
"PickAction");
67 fCategories.insert(
"Association");
71 fUnits.insert(
"G4BestUnit");
74 for (
size_t i = 0; i < units.size(); ++i) {
75 if (fUnitCategories.find(units[i]->GetName()) !=
76 fUnitCategories.end()) {
79 for (
size_t j = 0; j < container.size(); ++j) {
82 fUnits.insert(container[j]->GetSymbol());
88 fValueTypes.insert(
"G4String");
89 fValueTypes.insert(
"G4int");
90 fValueTypes.insert(
"G4double");
91 fValueTypes.insert(
"G4ThreeVector");
92 fValueTypes.insert(
"G4bool");
98G4bool G4AttCheck::fFirst =
true;
100std::set<G4String> G4AttCheck::fUnitCategories;
102std::map<G4String,G4String> G4AttCheck::fStandardUnits;
104std::set<G4String> G4AttCheck::fCategories;
106std::set<G4String> G4AttCheck::fUnits;
108std::set<G4String> G4AttCheck::fValueTypes;
113 static G4int iError = 0;
115 if (iError < 10 || iError%100 == 0) {
119 if (!fpValues)
return error;
120 if (!fpDefinitions) {
125 "\n*******************************************************";
130 "\nG4AttCheck: ERROR " << iError <<
": Null definitions pointer"
131 "\n*******************************************************"
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()) {
147 "\n*******************************************************";
152 "\nG4AttCheck: ERROR " << iError <<
": No G4AttDef for G4AttValue \""
153 << valueName <<
"\": " << value <<
154 "\n*******************************************************"
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()) {
166 "\n*******************************************************";
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) {
180 "\n*******************************************************"
184 if(category ==
"Physics" && fUnits.find(extra) == fUnits.end()) {
189 "\n*******************************************************";
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) {
203 "\n*******************************************************"
207 if (fValueTypes.find(valueType) == fValueTypes.end()) {
212 "\n*******************************************************";
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) {
226 "\n*******************************************************"
238 if (!ac.fpDefinitions) {
239 os <<
"G4AttCheck: ERROR: zero definitions pointer." << endl;
244 os << storeKey <<
':' << endl;
248 os <<
"G4AttCheck: zero values pointer." << endl;
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);
258 if (iDef == ac.fpDefinitions->end()) {
260 os <<
"G4AttCheck: ERROR: No G4AttDef for G4AttValue \""
261 << valueName <<
"\": " << value << endl;
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()) {
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) {
278 if(category ==
"Physics" && ac.fUnits.find(extra) == ac.fUnits.end()) {
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) {
290 if (ac.fValueTypes.find(valueType) == ac.fValueTypes.end()) {
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) {
304 os << iDef->second.GetDesc()
307 if (iDef->second.GetCategory() ==
"Physics" &&
308 !iDef->second.GetExtra().empty()) {
309 os <<
" (" << iDef->second.GetExtra() <<
")";
317void G4AttCheck::AddValuesAndDefs
318(std::vector<G4AttValue>* standardValues,
319 std::map<G4String,G4AttDef>* standardDefinitions,
324 const G4String& description)
const {
326 standardValues->push_back(
G4AttValue(name,value,
""));
328 (*standardDefinitions)[name] = fpDefinitions->find(oldName)->second;
330 (*standardDefinitions)[name].SetName(name);
331 (*standardDefinitions)[name].SetExtra(extra);
332 if (description !=
"") (*standardDefinitions)[name].SetDesc(description);
336(std::vector<G4AttValue>* standardValues,
337 std::map<G4String,G4AttDef>* standardDefinitions)
const {
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()) {
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()) {
359 if (category !=
"Physics") {
360 standardValues->push_back(*iValue);
361 (*standardDefinitions)[valueName] =
362 fpDefinitions->find(valueName)->second;
365 if (valueType ==
"G4ThreeVector") {
369 (standardValues,standardDefinitions,
370 valueName,valueName+
"-X",
372 fpDefinitions->find(valueName)->second.GetDesc()+
"-X");
374 (standardValues,standardDefinitions,
375 valueName,valueName+
"-Y",
377 fpDefinitions->find(valueName)->second.GetDesc()+
"-Y");
379 (standardValues,standardDefinitions,
380 valueName,valueName+
"-Z",
382 fpDefinitions->find(valueName)->second.GetDesc()+
"-Z");
384 standardValues->push_back(*iValue);
385 (*standardDefinitions)[valueName] =
386 fpDefinitions->find(valueName)->second;
391 if (extra ==
"G4BestUnit") {
392 valueAndUnit = value;
393 valueAndUnit = valueAndUnit.
strip();
394 unit = valueAndUnit.substr(valueAndUnit.rfind(
' ')+1);
396 valueAndUnit = value +
' ' + extra;
397 valueAndUnit = valueAndUnit.
strip();
401 if (fUnitCategories.find(unitCategory) != fUnitCategories.end()) {
402 G4String standardUnit = fStandardUnits[unitCategory];
406 if (valueType ==
"G4ThreeVector") {
410 (standardValues,standardDefinitions,
411 valueName,valueName+
"-X",
413 (internalValue.
x()/valueOfStandardUnit),
415 fpDefinitions->find(valueName)->second.GetDesc()+
"-X");
417 (standardValues,standardDefinitions,
418 valueName,valueName+
"-Y",
420 (internalValue.
y()/valueOfStandardUnit),
422 fpDefinitions->find(valueName)->second.GetDesc()+
"-Y");
424 (standardValues,standardDefinitions,
425 valueName,valueName+
"-Z",
427 (internalValue.
z()/valueOfStandardUnit),
429 fpDefinitions->find(valueName)->second.GetDesc()+
"-Z");
434 (standardValues,standardDefinitions,
437 (internalValue/valueOfStandardUnit),
447 G4cerr <<
"G4AttCheck::Standard: Conversion error." <<
G4endl;
std::ostream & operator<<(std::ostream &os, const G4AttCheck &ac)
std::vector< G4UnitsCategory * > G4UnitsTable
std::vector< G4UnitDefinition * > G4UnitsContainer
void print(G4double elem)
G4DLLIMPORT std::ostream G4cerr
G4AttCheck(const std::vector< G4AttValue > *values, const std::map< G4String, G4AttDef > *definitions)
G4bool Check(const G4String &leader="") const
G4bool Standard(std::vector< G4AttValue > *standardValues, std::map< G4String, G4AttDef > *standardDefinitions) const
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4String ConvertToString(G4bool boolVal)
static G4double ConvertToDimensionedDouble(const char *st)
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static G4UnitsTable & GetUnitsTable()
G4bool GetStoreKey(const std::map< G4String, G4AttDef > *definitions, G4String &key)