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