Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4HadronicDeveloperParameters.cc
이 파일의 문서화 페이지로 가기
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 //
27 
30  return instance;
31 }
32 
34 }
35 
37 }
38 
40  G4bool status = false;
41  const std::map< std::string , const G4bool >::iterator it = b_defaults.find( name );
42  if ( it == b_defaults.end() ) {
43  status = true;
44  b_defaults.insert( std::pair<std::string, const G4bool>( name , value ) );
45  b_values.insert( std::pair<std::string, G4bool>( name , value ) );
46  } else {
47  /*error*/
49  }
50  return status;
51 }
52 
53 G4bool G4HadronicDeveloperParameters::SetDefault( const std::string name , const G4int value , G4int lower_limit , G4int upper_limit ){
54  G4bool status = false;
55  const std::map< std::string , const G4int >::iterator it = i_defaults.find( name );
56  if ( it == i_defaults.end() ) {
57  status = true;
58  i_defaults.insert( std::pair<std::string, const G4int>( name , value ) );
59  i_values.insert( std::pair<std::string, G4int>( name , value ) );
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 {
62  /*error*/
64  }
65  return status;
66 }
67 
68 G4bool G4HadronicDeveloperParameters::SetDefault( const std::string name , const G4double value , G4double lower_limit , G4double upper_limit ){
69  G4bool status = false;
70  const std::map< std::string , const G4double >::iterator it = defaults.find( name );
71  if ( it == defaults.end() ) {
72  status = true;
73  defaults.insert( std::pair<std::string, const G4double>( name , value ) );
74  values.insert( std::pair<std::string, G4double>( name , value ) );
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 {
77  /*error*/
79  }
80  return status;
81 }
82 
84  G4bool status = false;
85  const std::map<std::string,G4bool>::iterator it = b_values.find( name );
86  if ( it != b_values.end() ) {
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 
102  G4bool status = false;
103  const std::map<std::string,G4int>::iterator it = i_values.find( name );
104  if ( it != i_values.end() ) {
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 
126  G4bool status = false;
127  const std::map<std::string,G4double>::iterator it = values.find( name );
128  if ( it != values.end() ) {
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 
150  G4bool status = false;
151  const std::map<std::string,const G4bool>::iterator it = b_defaults.find( name );
152  if ( it != b_defaults.end() ) {
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 
163  G4bool status = false;
164  const std::map<std::string,const G4int>::iterator it = i_defaults.find( name );
165  if ( it != i_defaults.end() ) {
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 
176  G4bool status = false;
177  const std::map<std::string,const G4double>::iterator it = defaults.find( name );
178  if ( it != defaults.end() ) {
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 
189  return get( name , value );
190 }
191 
193  return get( name , value , true );
194 }
195 
196 G4bool G4HadronicDeveloperParameters::get( const std::string name , G4bool& value , G4bool check_change ) {
197  G4bool status = false;
198  const std::map<std::string,G4bool>::iterator it = b_values.find( name );
199  if ( it != b_values.end() ) {
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 
214  return get( name , value );
215 }
216 
218  return get( name , value , true );
219 }
220 
221 G4bool G4HadronicDeveloperParameters::get( const std::string name , G4int& value , G4bool check_change ) {
222  G4bool status = false;
223  const std::map<std::string,G4int>::iterator it = i_values.find( name );
224  if ( it != i_values.end() ) {
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 
239  return get( name , value );
240 }
241 
243  return get( name , value , true );
244 }
245 
246 G4bool G4HadronicDeveloperParameters::get( const std::string name , G4double& value , G4bool check_change ) {
247  G4bool status = false;
248  const std::map<std::string,G4double>::iterator it = values.find( name );
249  if ( it != values.end() ) {
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 std::string name ) {
264  //const std::map<std::string,G4double>::iterator it = values.find( name );
265  if ( b_values.find( name ) != b_values.end() ) {
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.end() ) {
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.end() ) {
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 
310  std::string text("Parameter ");
311  text += name;
312  text += " does not exist.";
313  G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_001", FatalException , text.c_str() );
314 }
315 
317  std::string text("Parameter ");
318  text += name;
319  text += " has already been changed once.";
320  G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_002", FatalException , text.c_str() );
321 }
323  std::string text("The value of the parameter ");
324  text += name;
325  text += " is outside the allowable range.";
326  G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_003", FatalException , text.c_str() );
327 }
329  std::string text("Parameter ");
330  text += name;
331  text += " is already defined.";
332  G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_004", FatalException , text.c_str() );
333 }
335  std::string text("Parameter ");
336  text += name;
337  text += " has changed from default value.";
338  G4Exception( "G4HadronicDeveloperParameters" , "HadDevPara_005", JustWarning , text.c_str() );
339 }
void issue_is_already_defined(const std::string &name)
const XML_Char * name
Definition: expat.h:151
#define G4endl
Definition: G4ios.hh:61
G4bool SetDefault(const std::string name, const G4bool value)
G4bool GetDefault(const std::string name, G4bool &value)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4bool Set(const std::string name, const G4bool)
void issue_no_param(const std::string &name)
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::map< std::string, std::pair< const G4int, const G4int > > i_limits
void issue_is_modified(const std::string &name)
void issue_has_changed(const std::string &name)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
std::map< std::string, const G4int > i_defaults
static MCTruthManager * instance
static G4HadronicDeveloperParameters & GetInstance()
G4GLOB_DLL std::ostream G4cout
G4bool get(const std::string name, G4bool &value, G4bool check_change=false)
std::map< std::string, std::pair< const G4double, const G4double > > limits
std::map< std::string, const G4double > defaults
void issue_non_eligible_value(const std::string &name)
std::map< std::string, const G4bool > b_defaults
G4bool DeveloperGet(const std::string name, G4bool &value)
std::map< std::string, G4int > i_values
G4bool Get(const std::string name, G4bool &value)
std::map< std::string, G4bool > b_values
G4bool check_value_within_limits(std::pair< const G4double, const G4double > &, G4double)
std::map< std::string, G4double > values