49 if(theEvaluator ==
nullptr)
59 theEvaluator =
nullptr;
65 char nonCharacters[7] = {
"()+-*/" };
66 for(std::size_t ii = 0; ii < 6; ++ii)
68 if(ch == nonCharacters[ii])
81 for(std::size_t ii = 0; ii < str.length(); ++ii)
83 if(!isdigit(str[ii]) && (str[ii] !=
'.') && (str[ii] !=
'-') &&
87 if(str[ii] ==
'E' || str[ii] ==
'e')
93 if(numE != 0 || ii == str.length() - 1)
113 if(
G4int(val) / val - 1 > precision)
126 G4cout << msg << std::setprecision(8) << vec << std::setprecision(6)
134 <<
" zx=" << rm.
zx() <<
G4endl <<
" xy=" << rm.
xy()
135 <<
" yy=" << rm.
yy() <<
" zy=" << rm.
zy() <<
G4endl
136 <<
" xz=" << rm.
xz() <<
" yz=" << rm.
yz() <<
" zz=" << rm.
zz()
145 for(
auto ite = wl.cbegin(); ite != wl.cend(); ++ite)
161 if(str.find(
':') != 0)
163 G4String ErrMessage =
"Trying to subtract leading colon from a word\n" +
164 G4String(
"that has no leading colon: ") + str;
168 G4String strt = str.substr(1, str.size() - 1);
176 const char* cstr = str.c_str();
182 G4cout <<
" G4tgrUtils::GetString() - Substitute parameter: "
184 str.substr(1, str.size()))
189 str.substr(1, str.size()));
207 G4cout <<
"G4tgrUtils::GetDouble() - Processing: " << str
208 <<
" default unit " << unitval <<
G4endl;
215 else if(str ==
"DBL_MIN")
219 else if(str ==
"FLT_MAX")
223 else if(str ==
"FLT_MIN")
227 else if(str ==
"INT_MAX")
231 else if(str ==
"INT_MIN")
236 const char* cstr = str.c_str();
237 std::set<G4int> separators;
238 separators.insert(-1);
240 for(
G4int ii = 0; ii < strlen; ++ii)
243 if(cs ==
'*' || cs ==
'/' || cs ==
'(' || cs ==
')')
245 separators.insert(ii);
247 else if(cs ==
'+' || cs ==
'-')
251 if((ii < 2) || ((cstr[ii - 1] !=
'E') && (cstr[ii - 1] !=
'e')) ||
254 separators.insert(ii);
258 separators.insert(strlen);
263 std::set<G4int>::const_iterator site, site2;
264 site = separators.cbegin();
267 for(; site2 != separators.cend(); ++site, ++site2)
272 G4cout <<
" Loop to find word between " << *site <<
" " << *site2
279 strnew += str.substr(*site, 1);
282 G4int wlen = (*site2) - (*site) - 1;
286 word = str.substr((*site) + 1, (*site2) - (*site) - 1);
302 const char* cword = word.c_str();
306 word.substr(1, word.size()));
307 if(parstr.substr(0, 1) ==
"-")
312 if(parstr.substr(0, 1) ==
"-")
319 G4cout <<
" G4tgrutils::GetDouble() - Param found: " << word
320 <<
" in string " << str <<
" , substituted by " << parstr
331 if((*site != -1) && (cstr[*site] ==
')'))
334 "There cannot be a ')' before a number: " + word +
335 " in string: " + str;
340 if((*site2 != strlen) && (cstr[*site2] ==
'('))
343 "There cannot be a '(' after a number: " + word +
344 " in string: " + str;
358 "String words cannot start with a digit: " + word +
359 " in string: " + str;
369 if((*site2 == strlen) || (cstr[*site2] !=
'('))
372 "There must be a '(' after a function: " + word +
373 " in string: " + str;
384 if((*site == -1) || ((cstr[*site] !=
'*') && (cstr[*site] !=
'/')))
387 "There must be a '*' before a unit definition: " + word +
410 G4String ErrMess =
"String word is not a parameter, nor a unit\n" +
411 G4String(
"definition nor a function: ") + word +
424 G4String ErrMessage =
"Evaluator error: " + strnew;
437 G4cout <<
" G4tgrUtils::GetDouble() - RESULT= " << val <<
G4endl
438 <<
" from string: " << str <<
" converted to: " << strnew.c_str()
439 <<
" with unit val: " << unitval <<
G4endl;
456 G4String(
" which is not an integer ") + str;
469 if((str ==
"ON") || (str ==
"TRUE"))
473 else if((str ==
"OFF") || (str ==
"FALSE"))
480 G4String(
" which is not 'ON'/'OFF'/'TRUE'/'FALSE' ") +
494 G4String outStr = methodName +
G4String(
". Line read with number of words ");
495 unsigned int wlsize = wl.size();
502 outStr += chartmp +
G4String(
" words");
503 DumpVS(wl, outStr.c_str());
519 if(nWreal != nWcheck)
522 outStr +=
G4String(
"not equal than ");
526 if(nWreal == nWcheck)
536 outStr +=
G4String(
"greater than ");
540 if(nWreal >= nWcheck)
543 outStr +=
G4String(
"greater or equal than ");
554 if(nWreal <= nWcheck)
557 outStr +=
G4String(
"less or equal than ");
561 G4cerr <<
" ERROR!! - G4tgrUtils::CheckListSize()" <<
G4endl
562 <<
" Type of WLSIZE type not found " << st <<
G4endl;
573 if(word ==
"mm" || word ==
"cm" || word ==
"m" || word ==
"km" ||
574 word ==
"millimeter" || word ==
"centimeter" || word ==
"meter" ||
575 word ==
"kilometer" || word ==
"parsec" || word ==
"micrometer" ||
576 word ==
"nanometer" || word ==
"angstrom" || word ==
"fermi" ||
577 word ==
"nm" || word ==
"um" || word ==
"pc" || word ==
"radian" ||
578 word ==
"milliradian" || word ==
"degree" || word ==
"rad" ||
579 word ==
"mrad" || word ==
"deg" || word ==
"ns" || word ==
"becquerel" ||
593 if(word ==
"sin" || word ==
"cos" || word ==
"tan" || word ==
"asin" ||
594 word ==
"acos" || word ==
"atan" || word ==
"atan2" || word ==
"sinh" ||
595 word ==
"cosh" || word ==
"tanh" || word ==
"asinh" || word ==
"acosh" ||
596 word ==
"atanh" || word ==
"sqrt" || word ==
"exp" || word ==
"log" ||
597 word ==
"log10" || word ==
"pow")
612 if(std::fabs(dir.
mag() - 1.) >
615 G4String WarMessage =
"Direction cosines have been normalized to one.\n" +
616 G4String(
"They were normalized to ") +
618 G4Exception(
"G4tgrUtils::GetRotationFromDirection()",
"WrongArgument",
632 else if(dir.
y() == 0.)
638 angy = std::asin(dir.
x() / std::sqrt(1 - dir.
y() * dir.
y()));
642 if(dir.
z() * std::cos(angx) * std::cos(angy) < 0)
657 std::vector<std::pair<size_t, size_t>> stringPairs;
662 std::size_t cStart = 0;
665 size_t cAster = word1.find(
"*", cStart);
666 if(cAster != std::string::npos)
673 "A word has two asterisks together, please correct it",
679 if(word1.size() == 1)
687 stringPairs.push_back(
688 std::pair<size_t, size_t>(cStart, cAster - cStart));
697 return word1 == word2;
704 if(cStart <= word1.length())
706 if(word1.length() != cStart)
708 stringPairs.push_back(
709 std::pair<size_t, size_t>(cStart, word1.length() - cStart));
714 if(stringPairs.size() == 0)
728 for(std::size_t ii = 0; ii < stringPairs.size(); ++ii)
730 std::pair<size_t, size_t> spair = stringPairs[ii];
731 size_t sFound = word2.find(word1.substr(spair.first, spair.second), cStart);
732 if(sFound == std::string::npos)
741 if(spair.first == 0 && sFound != 0)
748 else if((spair.first + spair.second - 1 == word1.length()) &&
749 (sFound + spair.second - 1 != word2.length()))
754 cStart += spair.second;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
HepRotation & rotateX(double delta)
HepRotation & rotateY(double delta)
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
static G4String ConvertToString(G4bool boolVal)
static G4double GetValueOf(const G4String &)
void print_error(G4int status) const
static G4int GetVerboseLevel()
G4String FindParameter(const G4String &name, G4bool exists=true)
static G4tgrParameterMgr * GetInstance()
static G4bool IsNumber(const G4String &str)
static G4String GetString(const G4String &str)
static G4bool IsSeparator(char)
static void CheckWLsize(const std::vector< G4String > &wl, unsigned int nWCheck, WLSIZEtype st, const G4String &methodName)
static void DumpVS(const std::vector< G4String > &wl, const char *msg)
static G4bool IsInteger(const G4double val, const G4double precision=1.e-6)
static G4bool GetBool(const G4String &str)
static void Dumprm(const G4RotationMatrix &rm, const char *msg)
static G4bool CheckListSize(unsigned int nWreal, unsigned int nWcheck, WLSIZEtype st, G4String &outstr)
static void Dump3v(const G4ThreeVector &vec, const char *msg)
static G4bool IsFunction(const G4String &word)
static G4int GetInt(const G4String &str)
static G4double GetDouble(const G4String &str, G4double unitval=1.)
static G4RotationMatrix GetRotationFromDirection(G4ThreeVector dir)
static G4String SubColon(const G4String &str)
static G4bool WordIsUnit(const G4String &word)
static G4bool AreWordsEquivalent(const G4String &word1, const G4String &word2)