66 char nonCharacters[7] = {
"()+-*/"};
67 for(
size_t ii = 0; ii < 6; ii++ )
69 if( ch == nonCharacters[ii] )
83 for(
size_t ii=0; ii<str.length(); ii++)
85 if(!isdigit(str[ii]) && (str[ii]!=
'.') && (str[ii]!=
'-') && (str[ii]!=
'+'))
88 if(str[ii] ==
'E' || str[ii] ==
'e' )
90 if( ii == 0 ) {
return 0; }
91 if(numE != 0 || ii == str.length()-1)
112 if(
G4int(val) / val - 1 > precision )
126 G4cout << msg << std::setprecision(8)
127 << vec << std::setprecision(6) <<
G4endl;
135 <<
" xx=" << rm.
xx() <<
" yx=" << rm.
yx() <<
" zx=" << rm.
zx() <<
G4endl
136 <<
" xy=" << rm.
xy() <<
" yy=" << rm.
yy() <<
" zy=" << rm.
zy() <<
G4endl
137 <<
" xz=" << rm.
xz() <<
" yz=" << rm.
yz() <<
" zz=" << rm.
zz() <<
G4endl;
143 const char* msg, std::ostream& outs )
146 std::vector<G4String>::const_iterator ite;
147 for( ite = wl.begin(); ite != wl.end(); ite++ )
165 if( str.find(
':') != 0 )
167 G4String ErrMessage =
"Trying to subtract leading colon from a word\n"
168 +
G4String(
"that has no leading colon: ") + str;
169 G4Exception(
"G4tgrUtils::SubColon()",
"ParseError",
172 G4String strt = str.substr(1,str.size()-1);
181 const char* cstr = str.c_str();
187 G4cout <<
" G4tgrUtils::GetString() - Substitute parameter: "
208 G4cout <<
"G4tgrUtils::GetDouble() - Processing: "
209 << str <<
" default unit " << unitval <<
G4endl;
212 if( str ==
"DBL_MAX" ) {
214 }
else if( str ==
"DBL_MIN" ) {
216 }
else if( str ==
"FLT_MAX" ) {
218 }
else if( str ==
"FLT_MIN" ) {
220 }
else if( str ==
"INT_MAX" ) {
222 }
else if( str ==
"INT_MIN" ) {
226 const char* cstr = str.c_str();
227 std::set<G4int> separators;
228 separators.insert(-1);
230 for(
G4int ii=0; ii<strlen; ii++)
233 if( cs ==
'*' || cs ==
'/' || cs ==
'(' || cs ==
')' )
235 separators.insert(ii);
237 else if( cs ==
'+' || cs ==
'-' )
242 || ( (cstr[ii-1] !=
'E') && (cstr[ii-1] !=
'e') )
245 separators.insert(ii);
249 separators.insert(strlen);
254 std::set<G4int>::const_iterator site, site2;
255 site = separators.begin();
256 site2 = site; site2++;
257 for( ; site2 != separators.end(); site++,site2++)
262 G4cout <<
" Loop to find word between " << *site
263 <<
" " << *site2 <<
G4endl;
267 if( *site != -1 ) { strnew += str.substr(*site,1); }
269 G4int wlen = (*site2)-(*site)-1;
273 word = str.substr((*site)+1,(*site2)-(*site)-1);
289 const char* cword = word.c_str();
290 if( cword[0] ==
'$' )
294 if( parstr.substr(0,1) ==
"-" )
299 if( parstr.substr(0,1) ==
"-" )
306 G4cout <<
" G4tgrutils::GetDouble() - Param found: "
307 << word <<
" in string " << str
308 <<
" , substituted by " << parstr <<
G4endl;
318 if( (*site != -1) && (cstr[*site] ==
')') )
320 G4String ErrMessage =
"There cannot be a ')' before a number: "
321 + word +
" in string: " + str;
322 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
326 if( (*site2 != strlen) && (cstr[*site2] ==
'(') )
328 G4String ErrMessage =
"There cannot be a '(' after a number: "
329 + word +
" in string: " + str;
330 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
340 if( isdigit(word[0]) )
342 G4String ErrMessage =
"String words cannot start with a digit: "
343 + word +
" in string: " + str;
344 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
353 if( (*site2 == strlen) || (cstr[*site2] !=
'(') )
355 G4String ErrMessage =
"There must be a '(' after a function: "
356 + word +
" in string: " + str;
357 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
368 || ( (cstr[*site] !=
'*') && (cstr[*site] !=
'/') ) )
370 G4String ErrMess =
"There must be a '*' before a unit definition: "
371 + word +
" in string " + str;
372 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
392 G4String ErrMess =
"String word is not a parameter, nor a unit\n";
393 +
G4String(
"definition nor a function: ") + word
395 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
406 G4String ErrMessage =
"Evaluator error: " + strnew;
407 G4Exception(
"G4tgrUtils::GetDouble()",
"ParseError",
411 if( nUnits == 0 ) { val *= unitval; }
416 G4cout <<
" G4tgrUtils::GetDouble() - RESULT= " << val <<
G4endl
417 <<
" from string: " << str <<
" converted to: " << strnew.c_str()
418 <<
" with unit val: " << unitval <<
G4endl;
436 +
G4String(
" which is not an integer ") + str;
450 if( (str ==
"ON") || (str ==
"TRUE") )
454 else if( (str ==
"OFF") || (str ==
"FALSE") )
461 +
G4String(
" which is not 'ON'/'OFF'/'TRUE'/'FALSE' ")
477 G4String outStr = methodName +
G4String(
". Line read with number of words ");
478 unsigned int wlsize = wl.size();
485 outStr += chartmp + G4String(
" words");
486 DumpVS( wl, outStr.c_str() );
487 G4String ErrMessage =
" NUMBER OF WORDS: "
489 G4Exception(
"G4tgrUtils::CheckWLsize()",
"ParseError",
502 if( nWreal != nWcheck )
505 outStr +=
G4String(
"not equal than ");
509 if( nWreal == nWcheck )
516 if( nWreal > nWcheck )
519 outStr +=
G4String(
"greater than ");
523 if( nWreal >= nWcheck )
526 outStr +=
G4String(
"greater or equal than ");
530 if( nWreal < nWcheck )
537 if( nWreal <= nWcheck )
540 outStr +=
G4String(
"less or equal than ");
544 G4cerr <<
" ERROR!! - G4tgrUtils::CheckListSize()" <<
G4endl
545 <<
" Type of WLSIZE type not found " << st <<
G4endl;
561 || word ==
"millimeter"
562 || word ==
"centimeter"
564 || word ==
"kilometer"
566 || word ==
"micrometer"
567 || word ==
"nanometer"
568 || word ==
"angstrom"
574 || word ==
"milliradian"
631 G4String WarMessage =
"Direction cosines have been normalized to one.\n"
632 +
G4String(
"They were normalized to ")
634 G4Exception(
"G4tgrUtils::GetRotationFromDirection()",
"WrongArgument",
648 else if( dir.
y() == 0. )
654 angy = std::asin( dir.
x()/std::sqrt(1-dir.
y()*dir.
y()) );
658 if( dir.
z() * std::cos(angx)*std::cos(angy) < 0 )
674 std::vector< std::pair<size_t,size_t> > stringPairs;
682 size_t cAster = word1.find(
"*",cStart);
683 if( cAster != std::string::npos )
685 if( cAster == cStart )
690 "A word has two asterisks together, please correct it",
696 if(word1.size() == 1 ) {
return true; }
699 if( cAster!= cStart )
701 stringPairs.push_back( std::pair<size_t,size_t>(cStart, cAster-cStart) );
710 return word1 == word2;
717 if( cStart <= word1.length() )
719 if( word1.length() != cStart )
721 stringPairs.push_back( std::pair<size_t,size_t>(cStart,
722 word1.length()-cStart) );
727 if( stringPairs.size() == 0 )
741 for(
size_t ii = 0; ii < stringPairs.size(); ii++ )
743 std::pair<size_t,size_t> spair = stringPairs[ii];
744 size_t sFound = word2.find(word1.substr(spair.first, spair.second),cStart);
745 if( sFound == std::string::npos )
754 if( spair.first == 0 && sFound != 0 )
761 else if( (spair.first+spair.second-1 == word1.length())
762 && (sFound+spair.second-1 != word2.length()) )
767 cStart += spair.second;