Problem 2036

Summary: Bug in G4MaterialPropertiesTable::AddConstProperty
Product: Geant4 Reporter: Shawn Tornga <tornga>
Component: materialsAssignee: Marc.Verderi
Status: RESOLVED DUPLICATE    
Severity: normal CC: asai, daren.sawkey
Priority: P4    
Version: 10.4   
Hardware: All   
OS: All   

Description Shawn Tornga 2018-02-22 00:13:33 CET
In the G4MaterialPropertiesTable::AddConstProperty method of G4MaterialPropertiesTable (located in G4MaterialsPropertiesTable.icc), it is impossible to add a new constant property key because the first call is to GetConstPropertyIndex on the provided (NEW) key, which doesn't exist and throws and exception. 

I believe that it should do something like below: (unless of course it's not intended to add new keys ... ). This would make the mapping of constant parameter names non-constant. Another option would be to change the method name to SetConstProperty since really, as it stands, the method can set only existing constant property key values. 

The reason I think it should allow for additional constant property keys is because the user may want to register newly named properties for different materials.

inline void G4MaterialPropertiesTable::AddConstProperty(const char *key, 
  G4double PropertyValue)
{
  // Provides a way of adding a constant property to the Material Properties
  // Table given a key
  auto it = G4MaterialConstPropertyName.find(G4String(key));
  if (it == G4MeterialConstPropertyName.end()) {
    G4MaterialConstPropertyName.insert(G4String(key));
  }
  G4MCPindex index = GetConstPropertyIndex(G4String(key));
  MCP[index] = PropertyValue;
}
Comment 1 Daren Sawkey 2018-02-23 17:48:47 CET
Thanks for your report. This is fixed in the upcoming 10.4.patch1 release. Please let me know if you'd like the fix earlier.

Marc, this can be marked as duplicate of 2030.
Comment 2 asai 2018-03-03 01:00:06 CET

*** This problem has been marked as a duplicate of problem 2030 ***