42 : messenger(0), toBeBroadcasted(false), toBeFlushed(false), workerThreadOnly(false),
49 :messenger(theMessenger),toBeBroadcasted(tBB),toBeFlushed(false), workerThreadOnly(false),
55 if(comStr(comStr.length()-1)!=
'/')
58 G4cerr <<
" <" << theCommandPath <<
"> must be a directory." <<
G4endl;
63 G4UIcommandCommonConstructorCode (comStr);
65 availabelStateList.clear();
74 void G4UIcommand::G4UIcommandCommonConstructorCode
75 (
const char * theCommandPath)
77 commandPath = theCommandPath;
78 commandName = theCommandPath;
79 G4int commandNameIndex = commandName.
last(
'/');
80 commandName.
remove(0,commandNameIndex+1);
90 G4int n_parameterEntry = parameter.size();
91 for(
G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
92 {
delete parameter[i_thParameter]; }
111 G4int n_parameterEntry = parameter.size();
112 if( n_parameterEntry != 0 )
117 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
119 if(i_thParameter > 0)
121 correctParameters.
append(
" ");
123 aToken = parameterToken();
124 if( aToken.length()>0 && aToken(0)==
'"' )
126 while( aToken(aToken.length()-1) !=
'"'
127 || ( aToken.length()==1 && aToken(0)==
'"' ))
129 G4String additionalToken = parameterToken();
130 if( additionalToken.
isNull() )
133 aToken += additionalToken;
136 else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()==
's')
139 while(!((anotherToken=parameterToken()).isNull()))
142 if(idxs==
G4int(std::string::npos))
145 aToken += anotherToken;
150 aToken += anotherToken(0,idxs);
158 if( aToken.
isNull() || aToken ==
"!" )
160 if(parameter[i_thParameter]->IsOmittable())
162 if(parameter[i_thParameter]->GetCurrentAsDefault())
166 for(
G4int ii=0;ii<i_thParameter;ii++)
171 while( parVal(parVal.length()-1) !=
'"' )
174 if( additionalToken.
isNull() )
177 parVal += additionalToken;
182 if (aCVToken(0)==
'"')
184 while( aCVToken(aCVToken.length()-1) !=
'"' )
187 if( additionalToken.
isNull() )
190 aCVToken += additionalToken;
194 correctParameters.
append(aCVToken);
197 { correctParameters.
append(parameter[i_thParameter]->GetDefaultValue()); }
204 G4int stat = parameter[i_thParameter]->CheckNewValue( aToken );
205 if(stat)
return stat+i_thParameter;
206 correctParameters.
append(aToken);
227 availabelStateList.clear();
228 availabelStateList.push_back(s1);
234 availabelStateList.clear();
235 availabelStateList.push_back(s1);
236 availabelStateList.push_back(s2);
243 availabelStateList.clear();
244 availabelStateList.push_back(s1);
245 availabelStateList.push_back(s2);
246 availabelStateList.push_back(s3);
254 availabelStateList.clear();
255 availabelStateList.push_back(s1);
256 availabelStateList.push_back(s2);
257 availabelStateList.push_back(s3);
258 availabelStateList.push_back(s4);
267 availabelStateList.clear();
268 availabelStateList.push_back(s1);
269 availabelStateList.push_back(s2);
270 availabelStateList.push_back(s3);
271 availabelStateList.push_back(s4);
272 availabelStateList.push_back(s5);
281 G4int nState = availabelStateList.size();
282 for(
G4int i=0;i<nState;i++)
284 if(availabelStateList[i]==currentState)
311 for(i=0;i<UTbl.size();i++)
312 {
if(UTbl[i]->GetName()==unitCategory)
break; }
315 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined." <<
G4endl;
319 retStr = UCnt[0]->GetSymbol();
320 G4int je = UCnt.size();
321 for(
G4int j=1;j<je;j++)
324 retStr += UCnt[j]->GetSymbol();
326 for(
G4int k=0;k<je;k++)
329 retStr += UCnt[k]->GetName();
338 if(commandPath(commandPath.length()-1)!=
'/')
341 {
G4cout <<
" ---- available only in worker thread" <<
G4endl; }
343 G4int n_guidanceEntry = commandGuidance.size();
344 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
346 if( ! rangeString.
isNull() )
347 {
G4cout <<
" Range of parameters : " << rangeString <<
G4endl; }
348 G4int n_parameterEntry = parameter.size();
349 if( n_parameterEntry > 0 )
351 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
352 { parameter[i_thParameter]->List(); }
360 if(boolVal) vl =
"1";
366 std::ostringstream os;
374 std::ostringstream os;
385 std::ostringstream os;
386 os << doubleValue/uv <<
" " << unitName;
393 std::ostringstream os;
394 os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
404 std::ostringstream os;
405 os << vec.
x()/uv <<
" " << vec.
y()/uv <<
" " << vec.
z()/uv
416 if( v==
"Y" || v==
"YES" || v==
"1" || v==
"T" || v==
"TRUE" )
424 std::istringstream is(st);
432 std::istringstream is(st);
442 std::istringstream is(st);
454 std::istringstream is(st);
455 is >> vx >> vy >> vz;
465 std::istringstream is(st);
466 is >> vx >> vy >> vz >> unts;
486 if( ! rangeString.
isNull() )
494 TypeCheck(
const char * t)
498 std::istringstream is(t);
499 for (
unsigned i=0; i< parameter.size(); i++) {
501 type = toupper(parameter[i]->GetParameterType());
504 if( IsDouble(aNewValue)==0 ){
505 G4cerr << aNewValue <<
": double value expected."
510 if( IsInt(aNewValue,20)==0 ){
511 G4cerr <<aNewValue<<
": integer expected."
519 if (aNewValue ==
"Y" || aNewValue ==
"N"
520 ||aNewValue ==
"YES" || aNewValue ==
"NO"
521 ||aNewValue ==
"1" || aNewValue ==
"0"
522 ||aNewValue ==
"T" || aNewValue ==
"F"
523 ||aNewValue ==
"TRUE" || aNewValue ==
"FALSE")
535 IsInt(
const char* buf,
short maxDigits)
539 if( *p ==
'+' || *p ==
'-') { ++
p; }
540 if( isdigit( (
G4int)(*p) )) {
541 while( isdigit( (
G4int)(*p) )) { ++
p; ++length; }
543 if( length > maxDigits) {
559 ExpectExponent(
const char* str)
562 if( IsInt( str, maxExplength=7 ))
return 1;
568 IsDouble(
const char* buf)
572 case '+':
case '-': ++
p;
574 while( isdigit( (
G4int)(*p) )) { ++
p; }
579 return ExpectExponent(++p );
582 if( *p ==
'\0' )
return 1;
583 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p );
585 while( isdigit( (
G4int)(*p) )) { ++
p; }
586 if( *p ==
'\0' )
return 1;
587 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
588 }
else return 0;
break;
592 if( *p ==
'.' ) { ++
p;
594 while( isdigit( (
G4int)(*p) )) { ++
p; }
595 if( *p ==
'\0' )
return 1;
596 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
602 while( isdigit( (
G4int)(*p) )) { ++
p; }
603 if( *p ==
'\0' )
return 1;
604 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p);
608 while( isdigit( (
G4int)(*p) )) { ++
p; }
609 if( *p ==
'\0' )
return 1;
610 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
611 if( *p ==
'.' ) { ++
p;
612 if( *p ==
'\0' )
return 1;
613 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
615 while( isdigit( (
G4int)(*p) )) { ++
p; }
616 if( *p ==
'\0' )
return 1;
617 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
628 RangeCheck(
const char* t) {
632 std::istringstream is(t);
633 for (
unsigned i=0; i< parameter.size(); i++) {
634 type= toupper(parameter[i]->GetParameterType());
636 case 'D': is >> newVal[i].D;
break;
637 case 'I': is >> newVal[i].I;
break;
645 result = Expression();
647 if( paramERR == 1 )
return 0;
649 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
652 if ( result.
I )
return 1;
653 G4cerr <<
"parameter out of range: "<< rangeString <<
G4endl;
665 result = LogicalORExpression();
670 LogicalORExpression(
void)
674 p = LogicalANDExpression();
677 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
684 p = LogicalANDExpression();
686 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
694 result.
I += (p.
D != 0.0);
705 LogicalANDExpression(
void)
709 p = EqualityExpression();
712 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
719 p = EqualityExpression();
721 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
729 result.
I *= (p.
D != 0.0);
741 EqualityExpression(
void)
749 result = RelationalExpression();
750 if( token==
EQ || token==
NE ) {
754 arg2 = RelationalExpression();
755 result.
I = Eval2( arg1, operat, arg2 );
762 G4cerr <<
"Parameter range: error at EqualityExpression"
772 RelationalExpression(
void)
781 arg1 = AdditiveExpression();
782 if( token==
GT || token==
GE || token==
LT || token==
LE ) {
785 arg2 = AdditiveExpression();
786 result.
I = Eval2( arg1, operat, arg2 );
801 AdditiveExpression(
void)
803 result = MultiplicativeExpression();
804 if( token !=
'+' && token !=
'-' )
return result;
805 G4cerr <<
"Parameter range: operator "
807 <<
" is not supported." << G4endl;
813 MultiplicativeExpression(
void)
815 result = UnaryExpression();
816 if( token !=
'*' && token !=
'/' && token !=
'%' )
return result;
817 G4cerr <<
"Parameter range: operator "
819 <<
" is not supported." << G4endl;
825 UnaryExpression(
void)
835 p = UnaryExpression();
846 result = UnaryExpression();
break;
849 G4cerr <<
"Parameter range error: "
850 <<
"operator '!' is not supported (sorry)."
853 result = UnaryExpression();
break;
855 result = PrimaryExpression();
862 PrimaryExpression(
void)
872 token = Yylex();
break;
876 token= Yylex();
break;
880 token = Yylex();
break;
883 result = Expression();
904 <<
": meaningless comparison"
910 unsigned i = IndexOf( arg1.
S );
911 newValtype = toupper(parameter[i]->GetParameterType());
912 switch ( newValtype ) {
915 return CompareInt( newVal[i].I, op, arg2.
I );
917 G4cerr <<
"integer operand expected for "
923 return CompareDouble( newVal[i].D, op, arg2.
D );
926 return CompareDouble( newVal[i].D, op, arg2.
I );
932 unsigned i = IndexOf( arg2.
S );
933 newValtype = toupper(parameter[i]->GetParameterType());
934 switch ( newValtype ) {
937 return CompareInt( arg1.
I, op, newVal[i].I );
939 G4cerr <<
"integer operand expected for "
945 return CompareDouble( arg1.
D, op, newVal[i].D );
948 return CompareDouble( arg1.
I, op, newVal[i].D );
962 case GT: result = ( arg1 > arg2); opr=
">" ;
break;
963 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
964 case LT: result = ( arg1 < arg2); opr=
"<" ;
break;
965 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
966 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
967 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
969 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
974 << arg1 <<
" " << opr << arg2
975 <<
" result: " << result
987 case GT: result = ( arg1 > arg2); opr=
">";
break;
988 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
989 case LT: result = ( arg1 < arg2); opr=
"<";
break;
990 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
991 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
992 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
994 G4cerr <<
"Parameter range: error at CompareDouble"
999 G4cerr <<
"CompareDouble "
1000 << arg1 <<
" " << opr <<
" "<< arg2
1001 <<
" result: " << result
1007 unsigned G4UIcommand::
1008 IndexOf(
const char* nam)
1012 for( i=0; i<parameter.size(); i++)
1014 pname = parameter[i]-> GetParameterName();
1015 if( pname == nam ) {
1020 G4cerr <<
"parameter name:"<<nam<<
" not found."<<
G4endl;
1025 unsigned G4UIcommand::
1026 IsParameter(
const char* nam)
1029 for(
unsigned i=0; i<parameter.size(); i++)
1031 pname = parameter[i]-> GetParameterName();
1032 if( pname == nam )
return 1;
1046 while(( c= G4UIpGetc())==
' '|| c==
'\t' || c==
'\n' )
1051 if (isdigit(c) || c==
'.') {
1055 }
while (c==
'.' || isdigit(c) ||
1056 c==
'e' || c==
'E' || c==
'+' || c==
'-');
1058 const char* t = buf;
1059 std::istringstream is(t);
1060 if ( IsInt(buf.
data(),20) ) {
1064 if ( IsDouble(buf.
data()) ) {
1072 if (isalpha(c)|| c==
'_') {
1075 }
while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c==
'_'));
1077 if( IsParameter(buf) ) {
1088 case '=':
return (
tokenNum) Follow(
'=',
EQ,
'=');
1089 case '!':
return (
tokenNum) Follow(
'=',
NE,
'!');
1101 G4int c = G4UIpGetc();
1111 G4int length = rangeString.length();
1113 return rangeString(bp++);
1118 G4UIpUngetc(
G4int c) {
1120 if (bp >0 && c == rangeString(bp-1)) {
1124 G4cerr <<
"bp="<<bp <<
" c="<<c
1125 <<
" pR(bp-1)=" << rangeString(bp-1)
virtual G4String GetCurrentValue(G4UIcommand *command)
CLHEP::Hep3Vector G4ThreeVector
G4int operator!=(const G4UIcommand &right) const
G4String & remove(str_size)
std::vector< G4UnitsCategory * > G4UnitsTable
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
G4double G4NeutronHPJENDLHEData::G4double result
static G4String ConvertToString(G4bool boolVal)
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
static G4UImanager * GetUIpointer()
static G4StateManager * GetStateManager()
static G4double GetValueOf(const G4String &)
G4GLOB_DLL std::ostream G4cout
G4int CheckNewValue(const char *newValue)
str_size index(const char *, G4int pos=0) const
static G4String UnitsList(const char *unitCategory)
static G4bool ConvertToBool(const char *st)
static G4double ConvertToDouble(const char *st)
void RemoveCommand(G4UIcommand *aCommand)
const G4String & GetCommandPath() const
void AvailableForStates(G4ApplicationState s1)
G4ApplicationState GetCurrentState() const
static G4int ConvertToInt(const char *st)
static G4UnitsTable & GetUnitsTable()
G4int operator==(const G4UIcommand &right) const
static G4String GetCategory(const G4String &)
const char * data() const
void AddNewCommand(G4UIcommand *newCommand)
G4String & append(const G4String &)
static G4double ValueOf(const char *unitName)
const XML_Char int const XML_Char * value
std::vector< G4UnitDefinition * > G4UnitsContainer
static G4String CategoryOf(const char *unitName)
virtual G4int DoIt(G4String parameterList)
G4String GetCurrentValue()
G4GLOB_DLL std::ostream G4cerr
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)