Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4UIcommand.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 //
26 //
27 // $Id: G4UIcommand.cc 108081 2017-12-21 07:53:54Z gcosmo $
28 //
29 //
30 
31 #include "G4UIcommand.hh"
32 #include "G4UImessenger.hh"
33 #include "G4UImanager.hh"
34 #include "G4UIcommandStatus.hh"
35 #include "G4StateManager.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4Tokenizer.hh"
38 #include "G4ios.hh"
39 #include <sstream>
40 #include <iomanip>
41 
43  : messenger(0), toBeBroadcasted(false), toBeFlushed(false), workerThreadOnly(false),
44  commandFailureCode(0), failureDescription(""),
45  bp(0), token(IDENTIFIER),paramERR(0)
46 {
47 }
48 
49 G4UIcommand::G4UIcommand(const char * theCommandPath,
50  G4UImessenger * theMessenger, G4bool tBB)
51 :messenger(theMessenger),toBeBroadcasted(tBB),toBeFlushed(false), workerThreadOnly(false),
52  commandFailureCode(0), failureDescription(""),
53  bp(0), token(IDENTIFIER),paramERR(0)
54 {
55  G4String comStr = theCommandPath;
56  if(!theMessenger)
57  { // this must be a directory
58  if(comStr(comStr.length()-1)!='/')
59  {
60  G4cerr << "G4UIcommand Warning : " << G4endl;
61  G4cerr << " <" << theCommandPath << "> must be a directory." << G4endl;
62  G4cerr << " '/' is appended." << G4endl;
63  comStr += "/";
64  }
65  }
67  G4String nullString;
68  availabelStateList.clear();
75 }
76 
77 #ifdef G4MULTITHREADED
78 #include "G4Threading.hh"
79 #endif
80 
82 (const char * theCommandPath)
83 {
84  commandPath = theCommandPath;
85  commandName = theCommandPath;
86  G4int commandNameIndex = commandName.last('/');
87  commandName.remove(0,commandNameIndex+1);
88 #ifdef G4MULTITHREADED
89  if(messenger && messenger->CommandsShouldBeInMaster()
91  {
92  toBeBroadcasted = false;
94  }
95  else
97 #else
99 #endif
100 }
101 
103 {
104  G4UImanager* fUImanager = G4UImanager::GetUIpointer();
105  if(fUImanager) fUImanager->RemoveCommand(this);
106 
107  G4int n_parameterEntry = parameter.size();
108  for( G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
109  { delete parameter[i_thParameter]; }
110  parameter.clear();
111 }
112 
114 {
115  return ( commandPath == right.GetCommandPath() );
116 }
117 
119 {
120  return ( commandPath != right.GetCommandPath() );
121 }
122 
123 #include "G4Threading.hh"
124 
126 {
127  G4String correctParameters;
128  G4int n_parameterEntry = parameter.size();
129  if( n_parameterEntry != 0 )
130  {
131  G4String aToken;
132  G4String correctToken;
133  G4Tokenizer parameterToken( parameterList );
134  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
135  {
136  if(i_thParameter > 0)
137  {
138  correctParameters.append(" ");
139  }
140  aToken = parameterToken();
141  if( aToken.length()>0 && aToken(0)=='"' )
142  {
143  while( aToken(aToken.length()-1) != '"'
144  || ( aToken.length()==1 && aToken(0)=='"' ))
145  {
146  G4String additionalToken = parameterToken();
147  if( additionalToken.isNull() )
148  { return fParameterUnreadable+i_thParameter; }
149  aToken += " ";
150  aToken += additionalToken;
151  }
152  }
153  else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()=='s')
154  {
155  G4String anotherToken;
156  while(!((anotherToken=parameterToken()).isNull()))
157  {
158  G4int idxs = anotherToken.index("#");
159  if(idxs==G4int(std::string::npos))
160  {
161  aToken += " ";
162  aToken += anotherToken;
163  }
164  else if(idxs>0)
165  {
166  aToken += " ";
167  aToken += anotherToken(0,idxs);
168  break;
169  }
170  else
171  { break; }
172  }
173  }
174 
175  if( aToken.isNull() || aToken == "!" )
176  {
177  if(parameter[i_thParameter]->IsOmittable())
178  {
179  if(parameter[i_thParameter]->GetCurrentAsDefault())
180  {
182  G4String parVal;
183  for(G4int ii=0;ii<i_thParameter;ii++)
184  {
185  parVal = cvSt();
186  if (parVal(0)=='"')
187  {
188  while( parVal(parVal.length()-1) != '"' )
189  {
190  G4String additionalToken = cvSt();
191  if( additionalToken.isNull() )
192  { return fParameterUnreadable+i_thParameter; }
193  parVal += " ";
194  parVal += additionalToken;
195  }
196  }
197  }
198  G4String aCVToken = cvSt();
199  if (aCVToken(0)=='"')
200  {
201  while( aCVToken(aCVToken.length()-1) != '"' )
202  {
203  G4String additionalToken = cvSt();
204  if( additionalToken.isNull() )
205  { return fParameterUnreadable+i_thParameter; }
206  aCVToken += " ";
207  aCVToken += additionalToken;
208  }
209  // aCVToken.strip(G4String::both,'"');
210  }
211  correctParameters.append(aCVToken);
212  }
213  else
214  { correctParameters.append(parameter[i_thParameter]->GetDefaultValue()); }
215  }
216  else
217  { return fParameterUnreadable+i_thParameter; }
218  }
219  else
220  {
221  G4int stat = parameter[i_thParameter]->CheckNewValue( aToken );
222  if(stat) return stat+i_thParameter;
223  correctParameters.append(aToken);
224  }
225  }
226  }
227 
228  if(CheckNewValue( correctParameters ))
229  { return fParameterOutOfRange+99; }
230 
232 
233  messenger->SetNewValue( this, correctParameters );
234  return 0;
235 }
236 
238 {
239  return messenger->GetCurrentValue(this);
240 }
241 
243 {
244  availabelStateList.clear();
245  availabelStateList.push_back(s1);
246 }
247 
250 {
251  availabelStateList.clear();
252  availabelStateList.push_back(s1);
253  availabelStateList.push_back(s2);
254 }
255 
259 {
260  availabelStateList.clear();
261  availabelStateList.push_back(s1);
262  availabelStateList.push_back(s2);
263  availabelStateList.push_back(s3);
264 }
265 
270 {
271  availabelStateList.clear();
272  availabelStateList.push_back(s1);
273  availabelStateList.push_back(s2);
274  availabelStateList.push_back(s3);
275  availabelStateList.push_back(s4);
276 }
277 
283 {
284  availabelStateList.clear();
285  availabelStateList.push_back(s1);
286  availabelStateList.push_back(s2);
287  availabelStateList.push_back(s3);
288  availabelStateList.push_back(s4);
289  availabelStateList.push_back(s5);
290 }
291 
293 {
294  G4bool av = false;
295  G4ApplicationState currentState
297 
298  G4int nState = availabelStateList.size();
299  for(G4int i=0;i<nState;i++)
300  {
301  if(availabelStateList[i]==currentState)
302  {
303  av = true;
304  break;
305  }
306  }
307 
308  return av;
309 }
310 
311 G4double G4UIcommand::ValueOf(const char* unitName)
312 {
313  G4double value = 0.;
314  value = G4UnitDefinition::GetValueOf(unitName);
315  return value;
316 }
317 
318 G4String G4UIcommand::CategoryOf(const char* unitName)
319 {
320  return G4UnitDefinition::GetCategory(unitName);
321 }
322 
323 G4String G4UIcommand::UnitsList(const char* unitCategory)
324 {
325  G4String retStr;
327  size_t i;
328  for(i=0;i<UTbl.size();i++)
329  { if(UTbl[i]->GetName()==unitCategory) break; }
330  if(i==UTbl.size())
331  {
332  G4cerr << "Unit category <" << unitCategory << "> is not defined." << G4endl;
333  return retStr;
334  }
335  G4UnitsContainer& UCnt = UTbl[i]->GetUnitsList();
336  retStr = UCnt[0]->GetSymbol();
337  G4int je = UCnt.size();
338  for(G4int j=1;j<je;j++)
339  {
340  retStr += " ";
341  retStr += UCnt[j]->GetSymbol();
342  }
343  for(G4int k=0;k<je;k++)
344  {
345  retStr += " ";
346  retStr += UCnt[k]->GetName();
347  }
348  return retStr;
349 }
350 
352 {
353  G4cout << G4endl;
354  G4cout << G4endl;
355  if(commandPath(commandPath.length()-1)!='/')
356  { G4cout << "Command " << commandPath << G4endl; }
357  if(workerThreadOnly)
358  { G4cout << " ---- available only in worker thread" << G4endl; }
359  G4cout << "Guidance :" << G4endl;
360  G4int n_guidanceEntry = commandGuidance.size();
361  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
362  { G4cout << commandGuidance[i_thGuidance] << G4endl; }
363  if( ! rangeString.isNull() )
364  { G4cout << " Range of parameters : " << rangeString << G4endl; }
365  G4int n_parameterEntry = parameter.size();
366  if( n_parameterEntry > 0 )
367  {
368  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
369  { parameter[i_thParameter]->List(); }
370  }
371  G4cout << G4endl;
372 }
373 
375 {
376  G4String vl = "0";
377  if(boolVal) vl = "1";
378  return vl;
379 }
380 
382 {
383  std::ostringstream os;
384  os << intValue;
385  G4String vl = os.str();
386  return vl;
387 }
388 
390 {
391  std::ostringstream os;
393  { os << std::setprecision(17) << doubleValue; }
394  else
395  { os << doubleValue; }
396  G4String vl = os.str();
397  return vl;
398 }
399 
400 G4String G4UIcommand::ConvertToString(G4double doubleValue,const char* unitName)
401 {
402  G4String unt = unitName;
403  G4double uv = ValueOf(unitName);
404 
405  std::ostringstream os;
407  { os << std::setprecision(17) << doubleValue/uv << " " << unitName; }
408  else
409  { os << doubleValue/uv << " " << unitName; }
410  G4String vl = os.str();
411  return vl;
412 }
413 
415 {
416  std::ostringstream os;
418  { os << std::setprecision(17) << vec.x() << " " << vec.y() << " " << vec.z(); }
419  else
420  { os << vec.x() << " " << vec.y() << " " << vec.z(); }
421  G4String vl = os.str();
422  return vl;
423 }
424 
426 {
427  G4String unt = unitName;
428  G4double uv = ValueOf(unitName);
429 
430  std::ostringstream os;
432  { os << std::setprecision(17) << vec.x()/uv << " " << vec.y()/uv << " " << vec.z()/uv << " " << unitName; }
433  else
434  { os << vec.x()/uv << " " << vec.y()/uv << " " << vec.z()/uv << " " << unitName; }
435  G4String vl = os.str();
436  return vl;
437 }
438 
440 {
441  G4String v = st;
442  v.toUpper();
443  G4bool vl = false;
444  if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
445  { vl = true; }
446  return vl;
447 }
448 
450 {
451  G4int vl;
452  std::istringstream is(st);
453  is >> vl;
454  return vl;
455 }
456 
458 {
459  G4double vl;
460  std::istringstream is(st);
461  is >> vl;
462  return vl;
463 }
464 
466 {
467  G4double vl;
468  char unts[30];
469 
470  std::istringstream is(st);
471  is >> vl >> unts;
472  G4String unt = unts;
473 
474  return (vl*ValueOf(unt));
475 }
476 
478 {
479  G4double vx;
480  G4double vy;
481  G4double vz;
482  std::istringstream is(st);
483  is >> vx >> vy >> vz;
484  return G4ThreeVector(vx,vy,vz);
485 }
486 
488 {
489  G4double vx;
490  G4double vy;
491  G4double vz;
492  char unts[30];
493  std::istringstream is(st);
494  is >> vx >> vy >> vz >> unts;
495  G4String unt = unts;
496  G4double uv = ValueOf(unt);
497  return G4ThreeVector(vx*uv,vy*uv,vz*uv);
498 }
499 
500 
501 // ----- the following is used by CheckNewValue() ------------
502 
503 
504 #include <ctype.h> // isalpha(), toupper()
505 
506 //#include "checkNewValue_debug.icc"
507 //#define DEBUG 1
508 
510 CheckNewValue(const char * newValue)
511 {
512  yystype result;
513  // if( TypeCheck(newValue) == 0 ) return 1;
514  if( ! rangeString.isNull() )
515  { if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
516  return 0; // succeeded
517 }
518 
519 // ------------------ type check routines -------------------
520 
522 TypeCheck(const char * t)
523 {
524  G4String aNewValue;
525  char type;
526  std::istringstream is(t);
527  for (unsigned i=0; i< parameter.size(); i++) {
528  is >> aNewValue;
529  type = toupper(parameter[i]->GetParameterType());
530  switch ( type ) {
531  case 'D':
532  if( IsDouble(aNewValue)==0 ){
533  G4cerr << aNewValue << ": double value expected."
534  << G4endl;
535  return 0;
536  } break;
537  case 'I':
538  if( IsInt(aNewValue,20)==0 ){
539  G4cerr <<aNewValue<<": integer expected."
540  <<G4endl;
541  return 0;
542  } break;
543  case 'S':
544  break;
545  case 'B':
546  aNewValue.toUpper();
547  if (aNewValue == "Y" || aNewValue == "N"
548  ||aNewValue == "YES" || aNewValue == "NO"
549  ||aNewValue == "1" || aNewValue == "0"
550  ||aNewValue == "T" || aNewValue == "F"
551  ||aNewValue == "TRUE" || aNewValue == "FALSE")
552  return 1;
553  else return 0;
554  break;
555  default: ;
556  }
557  }
558  return 1;
559 }
560 
561 
563 IsInt(const char* buf, short maxDigits)
564 {
565  const char* p= buf;
566  G4int length=0;
567  if( *p == '+' || *p == '-') { ++p; }
568  if( isdigit( (G4int)(*p) )) {
569  while( isdigit( (G4int)(*p) )) { ++p; ++length; }
570  if( *p == '\0' ) {
571  if( length > maxDigits) {
572  G4cerr <<"digit length exceeds"<<G4endl;
573  return 0;
574  }
575  return 1;
576  } else {
577  // G4cerr <<"illegal character after int:"<<buf<<G4endl;
578  }
579  } else {
580  // G4cerr <<"illegal int:"<<buf<<G4endl;
581  }
582  return 0;
583 }
584 
585 
587 ExpectExponent(const char* str) // used only by IsDouble()
588 {
589  G4int maxExplength;
590  if( IsInt( str, maxExplength=7 )) return 1;
591  else return 0;
592 }
593 
594 
596 IsDouble(const char* buf)
597 {
598  const char* p= buf;
599  switch( *p) {
600  case '+': case '-': ++p;
601  if( isdigit(*p) ) {
602  while( isdigit( (G4int)(*p) )) { ++p; }
603  switch ( *p ) {
604  case '\0': return 1;
605  // break;
606  case 'E': case 'e':
607  return ExpectExponent(++p );
608  // break;
609  case '.': ++p;
610  if( *p == '\0' ) return 1;
611  if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
612  if( isdigit(*p) ) {
613  while( isdigit( (G4int)(*p) )) { ++p; }
614  if( *p == '\0' ) return 1;
615  if( *p == 'e' || *p =='E') return ExpectExponent(++p);
616  } else return 0; break;
617  default: return 0;
618  }
619  }
620  if( *p == '.' ) { ++p;
621  if( isdigit(*p) ) {
622  while( isdigit( (G4int)(*p) )) { ++p; }
623  if( *p == '\0' ) return 1;
624  if( *p == 'e' || *p =='E') return ExpectExponent(++p);
625  }
626  }
627  break;
628  case '.': ++p;
629  if( isdigit(*p) ) {
630  while( isdigit( (G4int)(*p) )) { ++p; }
631  if( *p == '\0' ) return 1;
632  if( *p == 'e' || *p =='E' ) return ExpectExponent(++p);
633  } break;
634  default: // digit is expected
635  if( isdigit(*p) ) {
636  while( isdigit( (G4int)(*p) )) { ++p; }
637  if( *p == '\0' ) return 1;
638  if( *p == 'e' || *p =='E') return ExpectExponent(++p);
639  if( *p == '.' ) { ++p;
640  if( *p == '\0' ) return 1;
641  if( *p == 'e' || *p =='E') return ExpectExponent(++p);
642  if( isdigit(*p) ) {
643  while( isdigit( (G4int)(*p) )) { ++p; }
644  if( *p == '\0' ) return 1;
645  if( *p == 'e' || *p =='E') return ExpectExponent(++p);
646  }
647  }
648  }
649  }
650  return 0;
651 }
652 
653 
654 // ------------------ range Check routines -------------------
656 RangeCheck(const char* t) {
657  yystype result;
658  char type;
659  bp = 0; // reset buffer pointer for G4UIpGetc()
660  std::istringstream is(t);
661  for (unsigned i=0; i< parameter.size(); i++) {
662  type= toupper(parameter[i]->GetParameterType());
663  switch ( type ) {
664  case 'D': is >> newVal[i].D; break;
665  case 'I': is >> newVal[i].I; break;
666  case 'S':
667  case 'B':
668  default: ;
669  }
670  }
671  // PrintToken(); // Print tokens (consumes all tokens)
672  token= Yylex();
673  result = Expression();
674 
675  if( paramERR == 1 ) return 0;
676  if( result.type != CONSTINT) {
677  G4cerr << "Illegal Expression in parameter range." << G4endl;
678  return 0;
679  }
680  if ( result.I ) return 1;
681  G4cerr << "parameter out of range: "<< rangeString << G4endl;
682  return 0;
683 }
684 
685 // ------------------ syntax node functions ------------------
688 {
689  yystype result;
690  #ifdef DEBUG
691  G4cerr << " Expression()" << G4endl;
692  #endif
693  result = LogicalORExpression();
694  return result;
695 }
696 
699 {
700  yystype result;
701  yystype p;
702  p = LogicalANDExpression();
703  if( token != LOGICALOR) return p;
704  if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
705  G4cerr << "Parameter range: illegal type at '||'" << G4endl;
706  paramERR = 1;
707  }
708  result.I = p.I;
709  while (token == LOGICALOR)
710  {
711  token = Yylex();
712  p = LogicalANDExpression();
713  if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
714  G4cerr << "Parameter range: illegal type at '||'" <<G4endl;
715  paramERR = 1;
716  }
717  switch (p.type) {
718  case CONSTINT:
719  result.I += p.I;
720  result.type = CONSTINT; break;
721  case CONSTDOUBLE:
722  result.I += (p.D != 0.0);
723  result.type = CONSTINT; break;
724  default:
725  G4cerr << "Parameter range: unknown type"<<G4endl;
726  paramERR = 1;
727  }
728  }
729  return result;
730 }
731 
734 {
735  yystype result;
736  yystype p;
737  p = EqualityExpression();
738  if( token != LOGICALAND) return p;
739  if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
740  G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
741  paramERR = 1;
742  }
743  result.I = p.I;
744  while (token == LOGICALAND)
745  {
746  token = Yylex();
747  p = EqualityExpression();
748  if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
749  G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
750  paramERR = 1;
751  }
752  switch (p.type) {
753  case CONSTINT:
754  result.I *= p.I;
755  result.type = CONSTINT; break;
756  case CONSTDOUBLE:
757  result.I *= (p.D != 0.0);
758  result.type = CONSTINT; break;
759  default:
760  G4cerr << "Parameter range: unknown type."<< G4endl;
761  paramERR = 1;
762  }
763  }
764  return result;
765 }
766 
767 
770 {
771  yystype arg1, arg2;
772  G4int operat;
773  yystype result;
774  #ifdef DEBUG
775  G4cerr << " EqualityExpression()" <<G4endl;
776  #endif
777  result = RelationalExpression();
778  if( token==EQ || token==NE ) {
779  operat = token;
780  token = Yylex();
781  arg1 = result;
782  arg2 = RelationalExpression();
783  result.I = Eval2( arg1, operat, arg2 ); // semantic action
784  result.type = CONSTINT;
785  #ifdef DEBUG
786  G4cerr << " return code of Eval2(): " << result.I <<G4endl;
787  #endif
788  } else {
789  if (result.type != CONSTINT && result.type != CONSTDOUBLE) {
790  G4cerr << "Parameter range: error at EqualityExpression"
791  << G4endl;
792  paramERR = 1;
793  }
794  }
795  return result;
796 }
797 
798 
801 {
802  yystype arg1, arg2;
803  G4int operat;
804  yystype result;
805  #ifdef DEBUG
806  G4cerr << " RelationalExpression()" <<G4endl;
807  #endif
808 
809  arg1 = AdditiveExpression();
810  if( token==GT || token==GE || token==LT || token==LE ) {
811  operat = token;
812  token = Yylex();
813  arg2 = AdditiveExpression();
814  result.I = Eval2( arg1, operat, arg2 ); // semantic action
815  result.type = CONSTINT;
816  #ifdef DEBUG
817  G4cerr << " return code of Eval2(): " << result.I << G4endl;
818  #endif
819  } else {
820  result = arg1;
821  }
822  #ifdef DEBUG
823  G4cerr <<" return RelationalExpression()"<< G4endl;
824  #endif
825  return result;
826 }
827 
830 { yystype result;
831  result = MultiplicativeExpression();
832  if( token != '+' && token != '-' ) return result;
833  G4cerr << "Parameter range: operator "
834  << (char)token
835  << " is not supported." << G4endl;
836  paramERR = 1;
837  return result;
838 }
839 
842 { yystype result;
843  result = UnaryExpression();
844  if( token != '*' && token != '/' && token != '%' ) return result;
845  G4cerr << "Parameter range: operator "
846  << (char)token
847  << " is not supported." << G4endl;
848  paramERR = 1;
849  return result;
850 }
851 
854 {
855  yystype result;
856  yystype p;
857  #ifdef DEBUG
858  G4cerr <<" UnaryExpression"<< G4endl;
859  #endif
860  switch(token) {
861  case '-':
862  token = Yylex();
863  p = UnaryExpression();
864  if (p.type == CONSTINT) {
865  result.I = - p.I;
866  result.type = CONSTINT;
867  }
868  if (p.type == CONSTDOUBLE) {
869  result.D = - p.D;
870  result.type = CONSTDOUBLE;
871  } break;
872  case '+':
873  token = Yylex();
874  result = UnaryExpression(); break;
875  case '!':
876  token = Yylex();
877  G4cerr << "Parameter range error: "
878  << "operator '!' is not supported (sorry)."
879  << G4endl;
880  paramERR = 1;
881  result = UnaryExpression(); break;
882  default:
883  result = PrimaryExpression();
884  }
885  return result;
886 }
887 
888 
891 {
892  yystype result;
893  #ifdef DEBUG
894  G4cerr <<" primary_exp"<<G4endl;
895  #endif
896  switch (token) {
897  case IDENTIFIER:
898  result.S = yylval.S;
899  result.type = token;
900  token = Yylex(); break;
901  case CONSTINT:
902  result.I = yylval.I;
903  result.type = token;
904  token= Yylex(); break;
905  case CONSTDOUBLE:
906  result.D = yylval.D;
907  result.type = token;
908  token = Yylex(); break;
909  case '(' :
910  token= Yylex();
911  result = Expression();
912  if( token != ')' ) {
913  G4cerr << " ')' expected" << G4endl;
914  paramERR = 1;
915  }
916  token = Yylex();
917  break;
918  default:
919  return result;
920  }
921  return result; // never executed
922 }
923 
924 //---------------- semantic routines ---------------------------------
925 
927 Eval2(yystype arg1, G4int op, yystype arg2)
928 {
929  char newValtype;
930  if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
932  << ": meaningless comparison"
933  << G4endl;
934  paramERR = 1;
935  }
936 
937  if( arg1.type == IDENTIFIER) {
938  unsigned i = IndexOf( arg1.S );
939  newValtype = toupper(parameter[i]->GetParameterType());
940  switch ( newValtype ) {
941  case 'I':
942  if( arg2.type == CONSTINT ) {
943  return CompareInt( newVal[i].I, op, arg2.I );
944  } else {
945  G4cerr << "integer operand expected for "
946  << rangeString
947  << '.' << G4endl;
948  } break;
949  case 'D':
950  if( arg2.type == CONSTDOUBLE ) {
951  return CompareDouble( newVal[i].D, op, arg2.D );
952  } else
953  if ( arg2.type == CONSTINT ) { // integral promotion
954  return CompareDouble( newVal[i].D, op, arg2.I );
955  } break;
956  default: ;
957  }
958  }
959  if( arg2.type == IDENTIFIER) {
960  unsigned i = IndexOf( arg2.S );
961  newValtype = toupper(parameter[i]->GetParameterType());
962  switch ( newValtype ) {
963  case 'I':
964  if( arg1.type == CONSTINT ) {
965  return CompareInt( arg1.I, op, newVal[i].I );
966  } else {
967  G4cerr << "integer operand expected for "
968  << rangeString
969  << '.' << G4endl;
970  } break;
971  case 'D':
972  if( arg1.type == CONSTDOUBLE ) {
973  return CompareDouble( arg1.D, op, newVal[i].D );
974  } else
975  if ( arg1.type == CONSTINT ) { // integral promotion
976  return CompareDouble( arg1.I, op, newVal[i].D );
977  } break;
978  default: ;
979  }
980  }
981  return 0;
982 }
983 
985 CompareInt(G4int arg1, G4int op, G4int arg2)
986 {
987  G4int result=-1;
988  G4String opr;
989  switch (op) {
990  case GT: result = ( arg1 > arg2); opr= ">" ; break;
991  case GE: result = ( arg1 >= arg2); opr= ">="; break;
992  case LT: result = ( arg1 < arg2); opr= "<" ; break;
993  case LE: result = ( arg1 <= arg2); opr= "<="; break;
994  case EQ: result = ( arg1 == arg2); opr= "=="; break;
995  case NE: result = ( arg1 != arg2); opr= "!="; break;
996  default:
997  G4cerr << "Parameter range: error at CompareInt" << G4endl;
998  paramERR = 1;
999  }
1000  #ifdef DEBUG
1001  G4cerr << "CompareInt "
1002  << arg1 << " " << opr << arg2
1003  << " result: " << result
1004  << G4endl;
1005  #endif
1006  return result;
1007 }
1008 
1011 {
1012  G4int result=-1;
1013  G4String opr;
1014  switch (op) {
1015  case GT: result = ( arg1 > arg2); opr= ">"; break;
1016  case GE: result = ( arg1 >= arg2); opr= ">="; break;
1017  case LT: result = ( arg1 < arg2); opr= "<"; break;
1018  case LE: result = ( arg1 <= arg2); opr= "<="; break;
1019  case EQ: result = ( arg1 == arg2); opr= "=="; break;
1020  case NE: result = ( arg1 != arg2); opr= "!="; break;
1021  default:
1022  G4cerr << "Parameter range: error at CompareDouble"
1023  << G4endl;
1024  paramERR = 1;
1025  }
1026  #ifdef DEBUG
1027  G4cerr << "CompareDouble "
1028  << arg1 <<" " << opr << " "<< arg2
1029  << " result: " << result
1030  << G4endl;
1031  #endif
1032  return result;
1033 }
1034 
1035 unsigned G4UIcommand::
1036 IndexOf(const char* nam)
1037 {
1038  unsigned i;
1039  G4String pname;
1040  for( i=0; i<parameter.size(); i++)
1041  {
1042  pname = parameter[i]-> GetParameterName();
1043  if( pname == nam ) {
1044  return i;
1045  }
1046  }
1047  paramERR = 1;
1048  G4cerr << "parameter name:"<<nam<<" not found."<< G4endl;
1049  return 0;
1050 }
1051 
1052 
1053 unsigned G4UIcommand::
1054 IsParameter(const char* nam)
1055 {
1056  G4String pname;
1057  for(unsigned i=0; i<parameter.size(); i++)
1058  {
1059  pname = parameter[i]-> GetParameterName();
1060  if( pname == nam ) return 1;
1061  }
1062  return 0;
1063 }
1064 
1065 
1066 // --------------------- utility functions --------------------------
1067 
1069 Yylex() // reads input and returns token number, KR486
1070 { // (returns EOF)
1071  G4int c;
1072  G4String buf;
1073 
1074  while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
1075  ;
1076  if (c== EOF)
1077  return (tokenNum)EOF; // KR488
1078  buf= "";
1079  if (isdigit(c) || c== '.') { // I or D
1080  do {
1081  buf += G4String((unsigned char)c);
1082  c=G4UIpGetc();
1083  } while (c=='.' || isdigit(c) ||
1084  c=='e' || c=='E' || c=='+' || c=='-');
1085  G4UIpUngetc(c);
1086  const char* t = buf;
1087  std::istringstream is(t);
1088  if ( IsInt(buf.data(),20) ) {
1089  is >> yylval.I;
1090  return CONSTINT;
1091  } else
1092  if ( IsDouble(buf.data()) ) {
1093  is >> yylval.D;
1094  return CONSTDOUBLE;
1095  } else {
1096  G4cerr << buf<<": numeric format error."<<G4endl;
1097  }
1098  }
1099  buf="";
1100  if (isalpha(c)|| c=='_') { // IDENTIFIER
1101  do {
1102  buf += G4String((unsigned char)c);
1103  } while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
1104  G4UIpUngetc(c);
1105  if( IsParameter(buf) ) {
1106  yylval.S =buf;
1107  return IDENTIFIER;
1108  } else {
1109  G4cerr << buf << " is not a parameter name."<< G4endl;
1110  paramERR = 1;
1111  }
1112  }
1113  switch (c) {
1114  case '>': return (tokenNum) Follow('=', GE, GT);
1115  case '<': return (tokenNum) Follow('=', LE, LT);
1116  case '=': return (tokenNum) Follow('=', EQ, '=');
1117  case '!': return (tokenNum) Follow('=', NE, '!');
1118  case '|': return (tokenNum) Follow('|', LOGICALOR, '|');
1119  case '&': return (tokenNum) Follow('&', LOGICALAND, '&');
1120  default:
1121  return (tokenNum) c;
1122  }
1123 }
1124 
1125 
1127 Follow(G4int expect, G4int ifyes, G4int ifno)
1128 {
1129  G4int c = G4UIpGetc();
1130  if ( c== expect)
1131  return ifyes;
1132  G4UIpUngetc(c);
1133  return ifno;
1134 }
1135 
1136 //------------------ low level routines -----------------------------
1138 G4UIpGetc() { // emulation of getc()
1139  G4int length = rangeString.length();
1140  if( bp < length)
1141  return rangeString(bp++);
1142  else
1143  return EOF;
1144 }
1146 G4UIpUngetc(G4int c) { // emulation of ungetc()
1147  if (c<0) return -1;
1148  if (bp >0 && c == rangeString(bp-1)) {
1149  --bp;
1150  } else {
1151  G4cerr << "G4UIpUngetc() failed." << G4endl;
1152  G4cerr << "bp="<<bp <<" c="<<c
1153  << " pR(bp-1)=" << rangeString(bp-1)
1154  << G4endl;
1155  paramERR = 1;
1156  return -1;
1157  }
1158  return 0;
1159 }
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:311
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:318
G4int Follow(G4int expect, G4int ifyes, G4int ifno)
G4int G4UIpUngetc(G4int c)
static G4bool DoublePrecisionStr()
Definition: G4UImanager.cc:187
G4bool isNull() const
CLHEP::Hep3Vector G4ThreeVector
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:457
Definition: Evaluator.cc:66
void toUpper()
G4int TypeCheck(const char *t)
Definition: G4UIcommand.cc:522
G4String S
Definition: G4UItokenNum.hh:66
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:288
yystype EqualityExpression(void)
Definition: G4UIcommand.cc:769
G4int operator!=(const G4UIcommand &right) const
Definition: G4UIcommand.cc:118
yystype yylval
Definition: G4UIcommand.hh:251
#define G4endl
Definition: G4ios.hh:61
double D(double temp)
const char * p
Definition: xmltok.h:285
unsigned IndexOf(const char *)
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:125
G4int CompareDouble(G4double arg1, G4int op, G4double arg2)
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:439
G4bool IsMasterThread()
Definition: G4Threading.cc:130
double z() const
yystype RelationalExpression(void)
Definition: G4UIcommand.cc:800
virtual ~G4UIcommand()
Definition: G4UIcommand.cc:102
G4String rangeString
Definition: G4UIcommand.hh:119
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:300
yystype LogicalANDExpression(void)
Definition: G4UIcommand.cc:733
str_size index(const char *, G4int pos=0) const
G4int G4UIpGetc(void)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
G4int Eval2(yystype arg1, G4int op, yystype arg2)
Definition: G4UIcommand.cc:927
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:86
G4int IsInt(const char *str, short maxLength)
Definition: G4UIcommand.cc:563
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
tokenNum token
Definition: G4UIcommand.hh:250
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
std::vector< G4String > commandGuidance
Definition: G4UIcommand.hh:121
Definition: Evaluator.cc:66
Definition: Evaluator.cc:66
G4int I
Definition: G4UItokenNum.hh:64
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4bool IsWorkerThread()
Definition: G4Threading.cc:129
yystype PrimaryExpression(void)
Definition: G4UIcommand.cc:890
G4int CompareInt(G4int arg1, G4int op, G4int arg2)
Definition: G4UIcommand.cc:985
const char * data() const
G4int RangeCheck(const char *t)
Definition: G4UIcommand.cc:656
yystype AdditiveExpression(void)
Definition: G4UIcommand.cc:829
yystype Expression(void)
Definition: G4UIcommand.cc:687
static G4double GetValueOf(const G4String &)
yystype MultiplicativeExpression(void)
Definition: G4UIcommand.cc:841
static G4UnitsTable & GetUnitsTable()
tokenNum type
Definition: G4UItokenNum.hh:62
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
static G4ThreeVector ConvertTo3Vector(const char *st)
Definition: G4UIcommand.cc:477
G4GLOB_DLL std::ostream G4cerr
G4double G4ParticleHPJENDLHEData::G4double result
virtual G4String GetCurrentValue(G4UIcommand *command)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
Definition: Evaluator.cc:66
G4int IsDouble(const char *str)
Definition: G4UIcommand.cc:596
tokenNum
Definition: G4UItokenNum.hh:36
virtual void List()
Definition: G4UIcommand.cc:351
static const G4double bp
int G4int
Definition: G4Types.hh:78
void G4UIcommandCommonConstructorCode(const char *theCommandPath)
Definition: G4UIcommand.cc:82
G4ApplicationState GetCurrentState() const
std::vector< G4UnitDefinition * > G4UnitsContainer
Definition: Evaluator.cc:66
unsigned IsParameter(const char *)
std::vector< G4UIparameter * > parameter
Definition: G4UIcommand.hh:120
G4UImessenger * messenger
Definition: G4UIcommand.hh:116
tokenNum Yylex(void)
G4GLOB_DLL std::ostream G4cout
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
double x() const
G4ApplicationState
static G4String GetCategory(const G4String &)
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:487
yystype LogicalORExpression(void)
Definition: G4UIcommand.cc:698
double y() const
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:323
G4double D
Definition: G4UItokenNum.hh:63
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:465
G4String GetCurrentValue()
Definition: G4UIcommand.cc:237
std::vector< G4ApplicationState > availabelStateList
Definition: G4UIcommand.hh:122
G4int paramERR
Definition: G4UIcommand.hh:253
G4bool IsAvailable()
Definition: G4UIcommand.cc:292
G4String & append(const G4String &)
G4bool workerThreadOnly
Definition: G4UIcommand.hh:181
G4int CheckNewValue(const char *newValue)
Definition: G4UIcommand.cc:510
std::vector< yystype > newVal
Definition: G4UIcommand.hh:252
yystype UnaryExpression(void)
Definition: G4UIcommand.cc:853
G4int ExpectExponent(const char *str)
Definition: G4UIcommand.cc:587
Definition: Evaluator.cc:66
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:242
G4String commandName
Definition: G4UIcommand.hh:118
G4int operator==(const G4UIcommand &right) const
Definition: G4UIcommand.cc:113
static G4StateManager * GetStateManager()
G4String commandPath
Definition: G4UIcommand.hh:117