11 evaluator_.setSystemOfUnits(1.
e+3, 1./1.60217733
e-25, 1.
e+9, 1./1.60217733
e-10,
27 const std::string & var,
const std::string & val)
29 std::vector<std::string>::iterator it(vars.begin()), ed(vars.end());
31 for (; it != ed; ++it) {
48 prepare(ns,name,exprValue,newVar,newVal);
50 <<
" in: " << ns <<
" " << name <<
" " << exprValue
51 <<
" pr: " << newVar <<
" " << newVal);
53 evaluator_.setVariable(newVar.c_str(), newVal.c_str());
55 case HepTool::Evaluator::WARNING_EXISTING_VARIABLE:
58 case HepTool::Evaluator::OK:
59 case HepTool::Evaluator::WARNING_EXISTING_FUNCTION:
60 case HepTool::Evaluator::WARNING_BLANK_STRING:
65 std::cout <<
"set-var: ns=" << ns <<
" nm=" << name <<
" val=" << exprValue << std::endl;
67 throwex(ns,name,exprValue,
"can't set parameter !");
75 case HepTool::Evaluator::WARNING_EXISTING_VARIABLE:
78 case HepTool::Evaluator::OK:
79 case HepTool::Evaluator::WARNING_EXISTING_FUNCTION:
80 case HepTool::Evaluator::WARNING_BLANK_STRING:
85 std::cout <<
"set-varname=" << n <<
" val=" << v << std::endl;
87 throwex(
"",n,v,
"can't set parameter !");
97 std::string pseudo(
"(evaluating)");
100 prepare(ns,pseudo,expr, pseudo,prepared);
103 if(
evaluator_.status()!=HepTool::Evaluator::OK) {
104 std::cout <<
"expr: " << prepared << std::endl;
109 throwex(ns,prepared,expr,
"can't evaluate: " + expr + std::string(
"!"));
118 if (
evaluator_.status()!=HepTool::Evaluator::OK) {
119 std::cout <<
"expr: " << expression << std::endl;
124 throwex(
"",expression,
"",
"can't evaluate: " + std::string(expression) + std::string(
"!"));
130 const std::string &
name
135 prepare(ns,name,
"0", newVar,newVal);
136 return evaluator_.findVariable(newVar.c_str());
152 const std::string &
name,
153 const std::string & exprValue,
154 std::string & nameResult,
155 std::string & valResult)
const
157 static const std::string sep(
"___");
162 nameResult = ns + sep +
name;
173 bool insideBracket =
false;
174 bool nsFound =
false;
176 std::vector<int> hasNs(1);
180 switch(exprValue[idx])
183 if (nsFound || insideBracket)
186 "found a ':' outside '[..]' , or too many '[' !",idx);
194 throwex(ns,name,exprValue,
"too many ']' !",idx);
208 if ( (!insideBracket) || nsFound )
211 "found a ':' outside '[..]' , or multiple ':' inside '[..]'",idx);
222 if ( insideBracket || nsFound ) {
224 "'[..]' not closed , or ':' outside of '[..]'",idx);
234 switch(exprValue[idx])
238 if ( !hasNs[varCount] )
240 valResult = valResult + ns + sep;
246 valResult = valResult + sep;
249 valResult = valResult + exprValue[idx];
256 const std::string &
name,
257 const std::string & expr,
258 const std::string &
reason,
261 std::string er = std::string(
"ClhepEvaluator ERROR: ") + reason + std::string(
"\n")
262 + std::string(
" nmspace=") + ns
263 + std::string(
"\n varname=") + name
264 + std::string(
"\n exp=") + expr
265 + std::string(
"\n at=") + expr.substr(0,idx);
292 std::string
e = std::string(
"ClhepEvaluator ERROR: forbidden character '")
293 + s[sz] + std::string(
"' found in '") + s + std::string(
"' !");
bool isDefined(const std::string &ns, const std::string &name)
check whether a variable is already defined or not
std::vector< std::string > variables_
std::vector< std::string > values_
HepTool::Evaluator evaluator_
#define DCOUT_V(M_v_Y, M_v_S)
void clear()
access to the dictionary (namespace,name)->value
void checkname(const std::string &name) const
void throwex(const std::string &ns, const std::string &name, const std::string &expr, const std::string &reason, int idx=0) const
void set(const std::string &ns, const std::string &name, const std::string &exprValue)
put a new variable named 'namespace:name' into the dictionary of the evaluator
double eval(const std::string &ns, const std::string &expr)
evaluate an expression expr inside the local namespace
void prepare(const std::string &ns, const std::string &name, const std::string &exprValue, std::string &nameResult, std::string &valResult) const
void dd_exchange_value(std::vector< std::string > &vars, std::vector< std::string > &vals, const std::string &var, const std::string &val)