Skip to content

Commit c16c5d4

Browse files
authored
Merge pull request #499 from wrzof/message_optical_g4v11
Add nicer error message for unknown property when xml file is read.
2 parents 98658e0 + d0d3f7f commit c16c5d4

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

source/general/include/GateXMLDocument.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class GateXMLDocument
3333
GateXMLDocument(const G4String& filename);
3434
~GateXMLDocument();
3535

36+
const G4String &GetFilename() const;
37+
3638
G4bool Ok() const;
3739

3840
G4String GetName();
@@ -59,6 +61,8 @@ class GateXMLDocument
5961
xmlDocPtr m_doc;
6062
xmlNodePtr m_cur;
6163
G4bool m_reset;
64+
const G4String m_filename;
65+
6266
};
6367

6468
//! Reads a properties table from the xml-file given by doc

source/general/src/GateXMLDocument.cc

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ See LICENSE.md for further details
3636
* Use the Ok() method to check if the opening went ok.
3737
* */
3838
GateXMLDocument::GateXMLDocument(const G4String& filename) :
39-
m_ok(false), m_reset(true)
39+
m_ok(false), m_reset(true), m_filename(filename)
4040

4141
//
4242
// SJ COMMENTS## : read the file by using a messenger mechanism
@@ -305,7 +305,28 @@ void GateXMLDocument::SetState(GateXMLDocumentState state)
305305
m_cur = state.cur;
306306
m_reset = state.reset;
307307
}
308-
308+
309+
// geant4 v11 replaces some properties name by new one
310+
// We propose suggestion for replacements in error message.
311+
const G4String suggest_values_for_keys(const G4String& key)
312+
{
313+
if(key == "FASTTIMECONSTANT")
314+
return "SCINTILLATIONTIMECONSTANT1";
315+
else if( key == "YIELDRATIO")
316+
return "SCINTILLATIONYIELD1";
317+
else if( key == "FASTCOMPONENT")
318+
return "SCINTILLATIONCOMPONENT1";
319+
return "?";
320+
321+
}
322+
323+
324+
325+
const G4String &GateXMLDocument::GetFilename() const
326+
{
327+
return m_filename;
328+
}
329+
309330
G4MaterialPropertiesTable* ReadMaterialPropertiesTable(GateXMLDocument* doc)
310331
{
311332
G4MaterialPropertiesTable* table = 0;
@@ -328,7 +349,21 @@ G4MaterialPropertiesTable* ReadMaterialPropertiesTable(GateXMLDocument* doc)
328349
G4String unitstr = "1 " + doc->GetProperty("unit");
329350
value *= G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(unitstr.c_str());
330351
}
331-
table->AddConstProperty(property.c_str(), value);
352+
353+
auto list_of_known_properties_key = &table->GetMaterialConstPropertyNames();
354+
if(std::count(list_of_known_properties_key->begin(), list_of_known_properties_key->end(), property))
355+
{
356+
table->AddConstProperty(property.c_str(), value);
357+
}
358+
else
359+
{
360+
G4cout << "Unknown property '" << property << "' in xml file '" << doc->GetFilename() << "'. Abort simulation." << G4endl;
361+
G4cout << "Suggestion: property '"<< property << "' can be replaced by '" << suggest_values_for_keys(property) << "'" << G4endl;
362+
exit(-1);
363+
364+
}
365+
366+
332367
}
333368
else if (doc->GetName() == "propertyvector")
334369
{
@@ -358,7 +393,22 @@ G4MaterialPropertiesTable* ReadMaterialPropertiesTable(GateXMLDocument* doc)
358393
G4double value = G4UIcmdWithADouble::GetNewDoubleValue(valuestr.c_str());
359394
vector->InsertValues(energy*energyunit, value*unit);
360395
}
361-
table->AddProperty(property.c_str(), vector);
396+
397+
398+
auto list_of_known_properties_key = &table->GetMaterialPropertyNames();
399+
if(std::count(list_of_known_properties_key->begin(), list_of_known_properties_key->end(), property))
400+
{
401+
table->AddProperty(property.c_str(), vector);
402+
}
403+
else
404+
{
405+
G4cout << "Unknown propertyvector '" << property << "' in xml file '" << doc->GetFilename() << "'. Abort simulation." << G4endl;
406+
G4cout << "Suggestion: propertyvector '"<< property << "' can be replaced by '" << suggest_values_for_keys(property) << "'" << G4endl;
407+
exit(-1);
408+
}
409+
410+
411+
362412
doc->Leave();
363413
}
364414
}

0 commit comments

Comments
 (0)