Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 #include"G4HadronicDeveloperParameters.hh" 27 28 G4HadronicDeveloperParameters& G4HadronicDeveloperParameters::GetInstance(){ 29 static G4HadronicDeveloperParameters instance; 30 return instance; 31 } 32 33 G4HadronicDeveloperParameters::G4HadronicDeveloperParameters(){ 34 } 35 36 G4HadronicDeveloperParameters::G4HadronicDeveloperParameters( const G4HadronicDeveloperParameters& ){ 37 } 38 39 G4bool G4HadronicDeveloperParameters::SetDefault( const G4String& name , const G4bool value ){ 40 G4bool status = false; 41 const std::map< G4String , const G4bool >::const_iterator it = b_defaults.find( name ); 42 if ( it == b_defaults.cend() ) { 43 status = true; 44 b_defaults.insert( std::pair<G4String, const G4bool>( name , value ) ); 45 b_values.insert( std::pair<G4String, G4bool>( name , value ) ); 46 } else { 47 /*error*/ 48 issue_is_already_defined( name ); 49 } 50 return status; 51 } 52 53 G4bool G4HadronicDeveloperParameters::SetDefault( const G4String& name , const G4int value , G4int lower_limit , G4int upper_limit ){ 54 G4bool status = false; 55 const std::map< G4String , const G4int >::const_iterator it = i_defaults.find( name ); 56 if ( it == i_defaults.cend() ) { 57 status = true; 58 i_defaults.insert( std::pair<G4String, const G4int>( name , value ) ); 59 i_values.insert( std::pair<G4String, G4int>( name , value ) ); 60 i_limits.insert( std::pair< G4String,std::pair< const G4int , const G4int> >( name, std::pair< const G4int , const G4int> ( lower_limit , upper_limit ) ) ); 61 } else { 62 /*error*/ 63 issue_is_already_defined( name ); 64 } 65 return status; 66 } 67 68 G4bool G4HadronicDeveloperParameters::SetDefault( const G4String& name , const G4double value , G4double lower_limit , G4double upper_limit ){ 69 G4bool status = false; 70 const std::map< G4String , const G4double >::const_iterator it = defaults.find( name ); 71 if ( it == defaults.cend() ) { 72 status = true; 73 defaults.insert( std::pair<G4String, const G4double>( name , value ) ); 74 values.insert( std::pair<G4String, G4double>( name , value ) ); 75 limits.insert( std::pair< G4String,std::pair< const G4double , const G4double> >( name, std::pair< const G4double , const G4double> ( lower_limit , upper_limit ) ) ); 76 } else { 77 /*error*/ 78 issue_is_already_defined( name ); 79 } 80 return status; 81 } 82 83 G4bool G4HadronicDeveloperParameters::Set( const G4String& name , const G4bool value ){ 84 G4bool status = false; 85 const std::map<G4String,G4bool>::iterator it = b_values.find( name ); 86 if ( it != b_values.cend() ) { 87 if ( it->second == b_defaults.find(name)->second ) { 88 status = true; 89 it->second = value; 90 } else { 91 /*change more than once*/ 92 issue_has_changed( name ); 93 } 94 } else { 95 /*Parameter of "name" does not exist*/ 96 issue_no_param( name ); 97 } 98 return status; 99 } 100 101 G4bool G4HadronicDeveloperParameters::Set( const G4String& name , const G4int value ){ 102 G4bool status = false; 103 const std::map<G4String,G4int>::iterator it = i_values.find( name ); 104 if ( it != i_values.cend() ) { 105 if ( it->second == i_defaults.find(name)->second ) { 106 if ( check_value_within_limits( i_limits.find(name)->second , value ) ) { 107 /*value is OK*/ 108 status = true; 109 it->second = value; 110 } else { 111 /*Value is outside of valid range*/ 112 issue_non_eligible_value( name ); 113 } 114 } else { 115 /*change more than once*/ 116 issue_has_changed( name ); 117 } 118 } else { 119 /*Parameter of "name" does not exist*/ 120 issue_no_param( name ); 121 } 122 return status; 123 } 124 125 G4bool G4HadronicDeveloperParameters::Set( const G4String& name , const G4double value ){ 126 G4bool status = false; 127 const std::map<G4String,G4double>::iterator it = values.find( name ); 128 if ( it != values.cend() ) { 129 if ( it->second == defaults.find(name)->second ) { 130 if ( check_value_within_limits( limits.find(name)->second , value ) ) { 131 /*value is OK*/ 132 status = true; 133 it->second = value; 134 } else { 135 /*Value is outside of valid range*/ 136 issue_non_eligible_value( name ); 137 } 138 } else { 139 /*change more than once*/ 140 issue_has_changed( name ); 141 } 142 } else { 143 /*Parameter of "name" does not exist*/ 144 issue_no_param( name ); 145 } 146 return status; 147 } 148 149 G4bool G4HadronicDeveloperParameters::GetDefault( const G4String& name , G4bool& value ) { 150 G4bool status = false; 151 const std::map<G4String,const G4bool>::const_iterator it = b_defaults.find( name ); 152 if ( it != b_defaults.cend() ) { 153 status = true; 154 value = it->second; 155 } else { 156 /*Parameter of "name" does not exist*/ 157 issue_no_param( name ); 158 } 159 return status; 160 } 161 162 G4bool G4HadronicDeveloperParameters::GetDefault( const G4String& name , G4int& value ) { 163 G4bool status = false; 164 const std::map<G4String,const G4int>::const_iterator it = i_defaults.find( name ); 165 if ( it != i_defaults.cend() ) { 166 status = true; 167 value = it->second; 168 } else { 169 /*Parameter of "name" does not exist*/ 170 issue_no_param( name ); 171 } 172 return status; 173 } 174 175 G4bool G4HadronicDeveloperParameters::GetDefault( const G4String& name , G4double& value ) { 176 G4bool status = false; 177 const std::map<G4String,const G4double>::const_iterator it = defaults.find( name ); 178 if ( it != defaults.cend() ) { 179 status = true; 180 value = it->second; 181 } else { 182 /*Parameter of "name" does not exist*/ 183 issue_no_param( name ); 184 } 185 return status; 186 } 187 188 G4bool G4HadronicDeveloperParameters::Get( const G4String& name , G4double& value ) { 189 return get( name , value ); 190 } 191 192 G4bool G4HadronicDeveloperParameters::DeveloperGet( const G4String& name , G4double& value ) { 193 return get( name , value , true ); 194 } 195 196 G4bool G4HadronicDeveloperParameters::get( const G4String& name , G4bool& value , G4bool check_change ) { 197 G4bool status = false; 198 const std::map<G4String,G4bool>::const_iterator it = b_values.find( name ); 199 if ( it != b_values.cend() ) { 200 status = true; 201 value = it->second; 202 if ( check_change && value != b_defaults.find(name)->second ) { 203 //Parameter "name" has changed from default 204 issue_is_modified( name ); 205 } 206 } else { 207 //Parameter of "name" does not exist 208 issue_no_param( name ); 209 } 210 return status; 211 } 212 213 G4bool G4HadronicDeveloperParameters::Get( const G4String& name , G4int& value ) { 214 return get( name , value ); 215 } 216 217 G4bool G4HadronicDeveloperParameters::DeveloperGet( const G4String& name , G4int& value ) { 218 return get( name , value , true ); 219 } 220 221 G4bool G4HadronicDeveloperParameters::get( const G4String& name , G4int& value , G4bool check_change ) { 222 G4bool status = false; 223 const std::map<G4String,G4int>::const_iterator it = i_values.find( name ); 224 if ( it != i_values.cend() ) { 225 status = true; 226 value = it->second; 227 if ( check_change && value != i_defaults.find(name)->second ) { 228 //Parameter "name" has changed from default 229 issue_is_modified( name ); 230 } 231 } else { 232 //Parameter of "name" does not exist 233 issue_no_param( name ); 234 } 235 return status; 236 } 237 238 G4bool G4HadronicDeveloperParameters::Get( const G4String& name , G4bool& value ) { 239 return get( name , value ); 240 } 241 242 G4bool G4HadronicDeveloperParameters::DeveloperGet( const G4String& name , G4bool& value ) { 243 return get( name , value , true ); 244 } 245 246 G4bool G4HadronicDeveloperParameters::get( const G4String& name , G4double& value , G4bool check_change ) { 247 G4bool status = false; 248 const std::map<G4String,G4double>::const_iterator it = values.find( name ); 249 if ( it != values.cend() ) { 250 status = true; 251 value = it->second; 252 if ( check_change && value != defaults.find(name)->second ) { 253 /*Parameter "name" has changed from default*/ 254 issue_is_modified( name ); 255 } 256 } else { 257 /*Parameter of "name" does not exist*/ 258 issue_no_param( name ); 259 } 260 return status; 261 } 262 263 void G4HadronicDeveloperParameters::Dump( const G4String& name ) { 264 //const std::map<G4String,G4double>::const_iterator it = values.find( name ); 265 if ( b_values.find( name ) != b_values.cend() ) { 266 G4cout << "G4HadronicDeveloperParameters: " 267 << "name = " << name 268 << ", default value = " << b_defaults.find( name )->second 269 << ", current value = " << b_values.find( name )->second 270 << "." << G4endl; 271 } else if ( i_values.find( name ) != i_values.cend() ) { 272 G4cout << "G4HadronicDeveloperParameters: " 273 << "name = " << name 274 << ", default value = " << i_defaults.find( name )->second 275 << ", lower limit = " << i_limits.find( name )->second.first 276 << ", upper limit = " << i_limits.find( name )->second.second 277 << ", current value = " << i_values.find( name )->second 278 << "." << G4endl; 279 } else if ( values.find( name ) != values.cend() ) { 280 G4cout << "G4HadronicDeveloperParameters: " 281 << "name = " << name 282 << ", default value = " << defaults.find( name )->second 283 << ", lower limit = " << limits.find( name )->second.first 284 << ", upper limit = " << limits.find( name )->second.second 285 << ", current value = " << values.find( name )->second 286 << "." << G4endl; 287 } else { 288 /*Parameter of "name" does not exist*/ 289 issue_no_param( name ); 290 } 291 } 292 293 G4bool G4HadronicDeveloperParameters::check_value_within_limits( std::pair<const G4double,const G4double>& alimits , const G4double value ){ 294 if ( alimits.first <= value && value <= alimits.second ) { 295 return true; 296 } else { 297 return false; 298 } 299 } 300 301 G4bool G4HadronicDeveloperParameters::check_value_within_limits( std::pair<const G4int,const G4int>& alimits , const G4int value ){ 302 if ( alimits.first <= value && value <= alimits.second ) { 303 return true; 304 } else { 305 return false; 306 } 307 } 308 309 void G4HadronicDeveloperParameters::issue_no_param( const G4String& name ){ 310 G4String text("Parameter "); 311 text += name; 312 text += " does not exist."; 313 G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_001", FatalException , text ); 314 } 315 316 void G4HadronicDeveloperParameters::issue_has_changed( const G4String& name ) { 317 G4String text("Parameter "); 318 text += name; 319 text += " has already been changed once."; 320 G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_002", FatalException , text ); 321 } 322 void G4HadronicDeveloperParameters::issue_non_eligible_value( const G4String& name ) { 323 G4String text("The value of the parameter "); 324 text += name; 325 text += " is outside the allowable range."; 326 G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_003", FatalException , text ); 327 } 328 void G4HadronicDeveloperParameters::issue_is_already_defined( const G4String& name ) { 329 G4String text("Parameter "); 330 text += name; 331 text += " is already defined."; 332 G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_004", FatalException , text ); 333 } 334 void G4HadronicDeveloperParameters::issue_is_modified( const G4String& name ) { 335 G4String text("Parameter "); 336 text += name; 337 text += " has changed from default value."; 338 G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_005", JustWarning , text ); 339 } 340