43 : messenger(0), toBeBroadcasted(false), toBeFlushed(false), workerThreadOnly(false),
50 :messenger(theMessenger),toBeBroadcasted(tBB),toBeFlushed(false), workerThreadOnly(false),
56 if(comStr(comStr.length()-1)!=
'/')
59 G4cerr <<
" <" << theCommandPath <<
"> must be a directory." <<
G4endl;
64 G4UIcommandCommonConstructorCode (comStr);
66 availabelStateList.clear();
75 #ifdef G4MULTITHREADED
79 void G4UIcommand::G4UIcommandCommonConstructorCode
80 (
const char * theCommandPath)
82 commandPath = theCommandPath;
83 commandName = theCommandPath;
84 G4int commandNameIndex = commandName.
last(
'/');
85 commandName.
remove(0,commandNameIndex+1);
86 #ifdef G4MULTITHREADED
105 G4int n_parameterEntry = parameter.size();
106 for(
G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
107 {
delete parameter[i_thParameter]; }
126 G4int n_parameterEntry = parameter.size();
127 if( n_parameterEntry != 0 )
132 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
134 if(i_thParameter > 0)
136 correctParameters.
append(
" ");
138 aToken = parameterToken();
139 if( aToken.length()>0 && aToken(0)==
'"' )
141 while( aToken(aToken.length()-1) !=
'"'
142 || ( aToken.length()==1 && aToken(0)==
'"' ))
144 G4String additionalToken = parameterToken();
145 if( additionalToken.
isNull() )
148 aToken += additionalToken;
151 else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()==
's')
154 while(!((anotherToken=parameterToken()).isNull()))
157 if(idxs==
G4int(std::string::npos))
160 aToken += anotherToken;
165 aToken += anotherToken(0,idxs);
173 if( aToken.
isNull() || aToken ==
"!" )
175 if(parameter[i_thParameter]->IsOmittable())
177 if(parameter[i_thParameter]->GetCurrentAsDefault())
181 for(
G4int ii=0;ii<i_thParameter;ii++)
186 while( parVal(parVal.length()-1) !=
'"' )
189 if( additionalToken.
isNull() )
192 parVal += additionalToken;
197 if (aCVToken(0)==
'"')
199 while( aCVToken(aCVToken.length()-1) !=
'"' )
202 if( additionalToken.
isNull() )
205 aCVToken += additionalToken;
209 correctParameters.
append(aCVToken);
212 { correctParameters.
append(parameter[i_thParameter]->GetDefaultValue()); }
219 G4int stat = parameter[i_thParameter]->CheckNewValue( aToken );
220 if(stat)
return stat+i_thParameter;
221 correctParameters.
append(aToken);
242 availabelStateList.clear();
243 availabelStateList.push_back(s1);
249 availabelStateList.clear();
250 availabelStateList.push_back(s1);
251 availabelStateList.push_back(s2);
258 availabelStateList.clear();
259 availabelStateList.push_back(s1);
260 availabelStateList.push_back(s2);
261 availabelStateList.push_back(s3);
269 availabelStateList.clear();
270 availabelStateList.push_back(s1);
271 availabelStateList.push_back(s2);
272 availabelStateList.push_back(s3);
273 availabelStateList.push_back(s4);
282 availabelStateList.clear();
283 availabelStateList.push_back(s1);
284 availabelStateList.push_back(s2);
285 availabelStateList.push_back(s3);
286 availabelStateList.push_back(s4);
287 availabelStateList.push_back(s5);
296 G4int nState = availabelStateList.size();
297 for(
G4int i=0;i<nState;i++)
299 if(availabelStateList[i]==currentState)
326 for(i=0;i<UTbl.size();i++)
327 {
if(UTbl[i]->GetName()==unitCategory)
break; }
330 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined." <<
G4endl;
334 retStr = UCnt[0]->GetSymbol();
335 G4int je = UCnt.size();
336 for(
G4int j=1;j<je;j++)
339 retStr += UCnt[j]->GetSymbol();
341 for(
G4int k=0;k<je;k++)
344 retStr += UCnt[k]->GetName();
353 if(commandPath(commandPath.length()-1)!=
'/')
356 {
G4cout <<
" ---- available only in worker thread" <<
G4endl; }
358 G4int n_guidanceEntry = commandGuidance.size();
359 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
361 if( ! rangeString.
isNull() )
362 {
G4cout <<
" Range of parameters : " << rangeString <<
G4endl; }
363 G4int n_parameterEntry = parameter.size();
364 if( n_parameterEntry > 0 )
366 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
367 { parameter[i_thParameter]->List(); }
375 if(boolVal) vl =
"1";
381 std::ostringstream os;
389 std::ostringstream os;
391 { os << std::setprecision(17) << doubleValue; }
393 { os << doubleValue; }
403 std::ostringstream os;
405 { os << std::setprecision(17) << doubleValue/uv <<
" " << unitName; }
407 { os << doubleValue/uv <<
" " << unitName; }
414 std::ostringstream os;
416 { os << std::setprecision(17) << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z(); }
418 { os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z(); }
428 std::ostringstream os;
430 { os << std::setprecision(17) << vec.
x()/uv <<
" " << vec.
y()/uv <<
" " << vec.
z()/uv <<
" " << unitName; }
432 { os << vec.
x()/uv <<
" " << vec.
y()/uv <<
" " << vec.
z()/uv <<
" " << unitName; }
442 if( v==
"Y" || v==
"YES" || v==
"1" || v==
"T" || v==
"TRUE" )
450 std::istringstream is(st);
458 std::istringstream is(st);
468 std::istringstream is(st);
480 std::istringstream is(st);
481 is >> vx >> vy >> vz;
491 std::istringstream is(st);
492 is >> vx >> vy >> vz >> unts;
512 if( ! rangeString.
isNull() )
520 TypeCheck(
const char * t)
524 std::istringstream is(t);
525 for (
unsigned i=0; i< parameter.size(); i++) {
527 type = toupper(parameter[i]->GetParameterType());
530 if( IsDouble(aNewValue)==0 ){
531 G4cerr << aNewValue <<
": double value expected."
536 if( IsInt(aNewValue,20)==0 ){
537 G4cerr <<aNewValue<<
": integer expected."
545 if (aNewValue ==
"Y" || aNewValue ==
"N"
546 ||aNewValue ==
"YES" || aNewValue ==
"NO"
547 ||aNewValue ==
"1" || aNewValue ==
"0"
548 ||aNewValue ==
"T" || aNewValue ==
"F"
549 ||aNewValue ==
"TRUE" || aNewValue ==
"FALSE")
561 IsInt(
const char* buf,
short maxDigits)
565 if( *p ==
'+' || *p ==
'-') { ++
p; }
566 if( isdigit( (
G4int)(*p) )) {
567 while( isdigit( (
G4int)(*p) )) { ++
p; ++length; }
569 if( length > maxDigits) {
585 ExpectExponent(
const char* str)
588 if( IsInt( str, maxExplength=7 ))
return 1;
594 IsDouble(
const char* buf)
598 case '+':
case '-': ++
p;
600 while( isdigit( (
G4int)(*p) )) { ++
p; }
605 return ExpectExponent(++p );
608 if( *p ==
'\0' )
return 1;
609 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p );
611 while( isdigit( (
G4int)(*p) )) { ++
p; }
612 if( *p ==
'\0' )
return 1;
613 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
614 }
else return 0;
break;
618 if( *p ==
'.' ) { ++
p;
620 while( isdigit( (
G4int)(*p) )) { ++
p; }
621 if( *p ==
'\0' )
return 1;
622 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
628 while( isdigit( (
G4int)(*p) )) { ++
p; }
629 if( *p ==
'\0' )
return 1;
630 if( *p ==
'e' || *p ==
'E' )
return ExpectExponent(++p);
634 while( isdigit( (
G4int)(*p) )) { ++
p; }
635 if( *p ==
'\0' )
return 1;
636 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
637 if( *p ==
'.' ) { ++
p;
638 if( *p ==
'\0' )
return 1;
639 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
641 while( isdigit( (
G4int)(*p) )) { ++
p; }
642 if( *p ==
'\0' )
return 1;
643 if( *p ==
'e' || *p ==
'E')
return ExpectExponent(++p);
654 RangeCheck(
const char* t) {
658 std::istringstream is(t);
659 for (
unsigned i=0; i< parameter.size(); i++) {
660 type= toupper(parameter[i]->GetParameterType());
662 case 'D': is >> newVal[i].D;
break;
663 case 'I': is >> newVal[i].I;
break;
671 result = Expression();
673 if( paramERR == 1 )
return 0;
675 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
678 if ( result.
I )
return 1;
679 G4cerr <<
"parameter out of range: "<< rangeString <<
G4endl;
691 result = LogicalORExpression();
696 LogicalORExpression(
void)
700 p = LogicalANDExpression();
703 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
710 p = LogicalANDExpression();
712 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
720 result.
I += (p.
D != 0.0);
731 LogicalANDExpression(
void)
735 p = EqualityExpression();
738 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
745 p = EqualityExpression();
747 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
755 result.
I *= (p.
D != 0.0);
767 EqualityExpression(
void)
775 result = RelationalExpression();
776 if( token==
EQ || token==
NE ) {
780 arg2 = RelationalExpression();
781 result.
I = Eval2( arg1, operat, arg2 );
788 G4cerr <<
"Parameter range: error at EqualityExpression"
798 RelationalExpression(
void)
807 arg1 = AdditiveExpression();
808 if( token==
GT || token==
GE || token==
LT || token==
LE ) {
811 arg2 = AdditiveExpression();
812 result.
I = Eval2( arg1, operat, arg2 );
827 AdditiveExpression(
void)
829 result = MultiplicativeExpression();
830 if( token !=
'+' && token !=
'-' )
return result;
831 G4cerr <<
"Parameter range: operator "
833 <<
" is not supported." << G4endl;
839 MultiplicativeExpression(
void)
841 result = UnaryExpression();
842 if( token !=
'*' && token !=
'/' && token !=
'%' )
return result;
843 G4cerr <<
"Parameter range: operator "
845 <<
" is not supported." << G4endl;
851 UnaryExpression(
void)
861 p = UnaryExpression();
872 result = UnaryExpression();
break;
875 G4cerr <<
"Parameter range error: "
876 <<
"operator '!' is not supported (sorry)."
879 result = UnaryExpression();
break;
881 result = PrimaryExpression();
888 PrimaryExpression(
void)
898 token = Yylex();
break;
902 token= Yylex();
break;
906 token = Yylex();
break;
909 result = Expression();
930 <<
": meaningless comparison"
936 unsigned i = IndexOf( arg1.
S );
937 newValtype = toupper(parameter[i]->GetParameterType());
938 switch ( newValtype ) {
941 return CompareInt( newVal[i].I, op, arg2.
I );
943 G4cerr <<
"integer operand expected for "
949 return CompareDouble( newVal[i].
D, op, arg2.
D );
952 return CompareDouble( newVal[i].
D, op, arg2.
I );
958 unsigned i = IndexOf( arg2.
S );
959 newValtype = toupper(parameter[i]->GetParameterType());
960 switch ( newValtype ) {
963 return CompareInt( arg1.
I, op, newVal[i].I );
965 G4cerr <<
"integer operand expected for "
971 return CompareDouble( arg1.
D, op, newVal[i].D );
974 return CompareDouble( arg1.
I, op, newVal[i].D );
988 case GT: result = ( arg1 > arg2); opr=
">" ;
break;
989 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
990 case LT: result = ( arg1 < arg2); opr=
"<" ;
break;
991 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
992 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
993 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
995 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
1000 << arg1 <<
" " << opr << arg2
1001 <<
" result: " << result
1013 case GT: result = ( arg1 > arg2); opr=
">";
break;
1014 case GE: result = ( arg1 >= arg2); opr=
">=";
break;
1015 case LT: result = ( arg1 < arg2); opr=
"<";
break;
1016 case LE: result = ( arg1 <= arg2); opr=
"<=";
break;
1017 case EQ: result = ( arg1 == arg2); opr=
"==";
break;
1018 case NE: result = ( arg1 != arg2); opr=
"!=";
break;
1020 G4cerr <<
"Parameter range: error at CompareDouble"
1025 G4cerr <<
"CompareDouble "
1026 << arg1 <<
" " << opr <<
" "<< arg2
1027 <<
" result: " << result
1033 unsigned G4UIcommand::
1034 IndexOf(
const char* nam)
1038 for( i=0; i<parameter.size(); i++)
1040 pname = parameter[i]-> GetParameterName();
1041 if( pname == nam ) {
1046 G4cerr <<
"parameter name:"<<nam<<
" not found."<<
G4endl;
1051 unsigned G4UIcommand::
1052 IsParameter(
const char* nam)
1055 for(
unsigned i=0; i<parameter.size(); i++)
1057 pname = parameter[i]-> GetParameterName();
1058 if( pname == nam )
return 1;
1072 while(( c= G4UIpGetc())==
' '|| c==
'\t' || c==
'\n' )
1077 if (isdigit(c) || c==
'.') {
1081 }
while (c==
'.' || isdigit(c) ||
1082 c==
'e' || c==
'E' || c==
'+' || c==
'-');
1084 const char* t = buf;
1085 std::istringstream is(t);
1086 if ( IsInt(buf.
data(),20) ) {
1090 if ( IsDouble(buf.
data()) ) {
1098 if (isalpha(c)|| c==
'_') {
1101 }
while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c==
'_'));
1103 if( IsParameter(buf) ) {
1114 case '=':
return (
tokenNum) Follow(
'=',
EQ,
'=');
1115 case '!':
return (
tokenNum) Follow(
'=',
NE,
'!');
1127 G4int c = G4UIpGetc();
1137 G4int length = rangeString.length();
1139 return rangeString(bp++);
1144 G4UIpUngetc(
G4int c) {
1146 if (bp >0 && c == rangeString(bp-1)) {
1150 G4cerr <<
"bp="<<bp <<
" c="<<c
1151 <<
" pR(bp-1)=" << rangeString(bp-1)
G4double G4ParticleHPJENDLHEData::G4double result
virtual G4String GetCurrentValue(G4UIcommand *command)
CLHEP::Hep3Vector G4ThreeVector
G4int operator!=(const G4UIcommand &right) const
static G4UImanager * GetMasterUIpointer()
G4String & remove(str_size)
std::vector< G4UnitsCategory * > G4UnitsTable
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
static G4String ConvertToString(G4bool boolVal)
G4bool CommandsShouldBeInMaster() const
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
const XML_Char int const XML_Char * value
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 &)
static G4bool DoublePrecisionStr()
const char * data() const
void AddNewCommand(G4UIcommand *newCommand)
G4String & append(const G4String &)
static G4double ValueOf(const char *unitName)
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)