34 #include <boost/algorithm/string/trim.hpp> 123 Bool_t success =
true;
127 i = i->children.begin();
130 std::string str(i->value.begin(), i->value.end());
131 boost::algorithm::trim(str);
134 status = sscanf(str.c_str(),
"FUN%d", &funNo);
179 str = std::string(i->value.begin(), i->value.end());
180 boost::algorithm::trim(str);
181 status = sscanf(str.c_str(),
"%lf", &dvalue);
186 node.
fDvalue = 3.14159265358979323846;
195 str = std::string(i->value.begin(), i->value.end());
196 boost::algorithm::trim(str);
197 status = sscanf(str.c_str(),
"T%d", &ivalue);
201 str = std::string(i->value.begin(), i->value.end());
202 boost::algorithm::trim(str);
203 if (strstr(str.c_str(),
"-")) {
205 status = sscanf(str.c_str(),
"-PAR%d", &ivalue);
207 status = sscanf(str.c_str(),
"PAR%d", &ivalue);
212 str = std::string(i->value.begin(), i->value.end());
213 boost::algorithm::trim(str);
214 status = sscanf(str.c_str(),
"MAP%d", &ivalue);
221 str = std::string(i->value.begin(), i->value.end());
222 if (!strcmp(str.c_str(),
"COS"))
224 else if (!strcmp(str.c_str(),
"SIN"))
226 else if (!strcmp(str.c_str(),
"TAN"))
228 else if (!strcmp(str.c_str(),
"COSH"))
230 else if (!strcmp(str.c_str(),
"SINH"))
232 else if (!strcmp(str.c_str(),
"TANH"))
234 else if (!strcmp(str.c_str(),
"ACOS"))
236 else if (!strcmp(str.c_str(),
"ASIN"))
238 else if (!strcmp(str.c_str(),
"ATAN"))
240 else if (!strcmp(str.c_str(),
"ACOSH"))
242 else if (!strcmp(str.c_str(),
"ASINH"))
244 else if (!strcmp(str.c_str(),
"ATANH"))
246 else if (!strcmp(str.c_str(),
"LOG"))
248 else if (!strcmp(str.c_str(),
"LN"))
250 else if (!strcmp(str.c_str(),
"EXP"))
252 else if (!strcmp(str.c_str(),
"SQRT"))
255 std::cerr << std::endl <<
"**PANIC ERROR**: function " << str <<
" doesn't exist, but you never should have reached this point!";
256 std::cerr << std::endl;
267 str = std::string(i->value.begin(), i->value.end());
269 if (!strcmp(str.c_str(),
"POW"))
272 std::cerr << std::endl <<
"**PANIC ERROR**: function " << str <<
" doesn't exist, but you never should have reached this point!";
273 std::cerr << std::endl;
293 if (*i->value.begin() ==
'*')
307 if (*i->value.begin() ==
'+')
363 if (node.
fIvalue <= static_cast<Int_t>(paramSize))
368 if (node.
fIvalue <= static_cast<Int_t>(mapSize))
392 std::cerr << std::endl <<
">> **PANIC ERROR**: PFunction::FindAndCheckMapAndParamRange: you never should have reached this point!";
393 std::cerr << std::endl <<
">> node.fID = " << node.
fID;
394 std::cerr << std::endl;
438 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: energy meta data not available." << std::endl;
439 std::cerr << std::endl;
445 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: Temp idx=" << node.
fIvalue <<
" requested which is >= #Temp(s)=" <<
fMetaData.
fTemp.size() <<
" available." << std::endl;
446 std::cerr << std::endl;
496 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: node.fID == PFunctionGrammar::functionID: you never should have reached this point!";
497 std::cerr << std::endl;
506 if (expo-floor(expo) != 0.0)
509 return pow(base, expo);
511 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: node.fID == PFunctionGrammar::powerID: you never should have reached this point!";
512 std::cerr << std::endl;
522 if (denominator == 0.0) {
523 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: division by 0.0";
525 std::cerr << std::endl <<
">> " <<
fFuncString.Data() << std::endl;
526 std::cerr << std::endl;
538 std::cerr << std::endl <<
"**PANIC ERROR**: PFunction::EvalNode: you never should have reached this point!";
539 std::cerr << std::endl;
568 for (UInt_t i=0; i<node.
children.size(); i++) {
599 static Int_t termOp = 0;
602 assert(i->children.size() == 0);
603 if (*i->value.begin() ==
'-')
605 fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
606 if (*i->value.begin() ==
'-')
617 assert(i->children.size() == 0);
618 fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
620 assert(i->children.size() == 0);
622 fFuncString += std::string(i->value.begin(), i->value.end()).c_str();
624 assert(i->children.size() == 0);
625 fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
627 assert(i->children.size() == 0);
628 fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
630 assert(i->children.size() == 3);
631 fFuncString += std::string(i->value.begin(), i->value.end()).c_str();
637 assert(i->children.size() == 5);
638 fFuncString += std::string(i->value.begin(), i->value.end()).c_str();
649 if (*i->value.begin() ==
'*') {
650 assert(i->children.size() == 2);
654 }
else if (*i->value.begin() ==
'/') {
655 assert(i->children.size() == 2);
666 if (*i->value.begin() ==
'+') {
667 assert(i->children.size() == 2);
671 }
else if (*i->value.begin() ==
'-') {
672 assert(i->children.size() == 2);
682 assert(i->children.size() == 3);
686 }
else if (*i->value.begin() ==
'=') {
static const int constFieldID
Bool_t fValid
flag showing if the function is valid
static const int funLabelID
virtual void CleanupNode(PFuncTreeNode &node)
virtual void FillFuncEvalTree(iter_t const &i, PFuncTreeNode &node)
static const int assignmentID
virtual Double_t Eval(std::vector< Double_t > param, PMetaData metaData)
static const int constPiID
Int_t fOperatorTag
tag for '+', '-', '*', '/'
static const int constTempID
static const int expressionID
virtual Bool_t FindAndCheckMapAndParamRange(PFuncTreeNode &node, UInt_t mapSize, UInt_t paramSize)
virtual Bool_t GenerateFuncEvalTree()
Double_t fDvalue
for numbers
parse_tree_match_t::tree_iterator iter_t
virtual void InitNode(PFuncTreeNode &node)
virtual void EvalTreeForString(tree_parse_info<> info)
std::vector< Double_t > fParam
parameter vector (from the msr-file Fit Parameter block)
Int_t fFuncNo
function number, i.e. FUNx with x the function number
virtual Double_t EvalNode(PFuncTreeNode &node)
std::vector< Int_t > fMap
map vector
virtual void CleanupFuncEvalTree()
Bool_t fSign
for sign, true means '-', false '+'
Int_t fFunctionTag
tag got "cos", "sin", ...
PMetaData fMetaData
keeps meta data from data files (field, energy, temperature, ...)
static const int functionID
static const int factorID
virtual Bool_t CheckMapAndParamRange(UInt_t mapSize, UInt_t paramSize)
Int_t fID
tag showing what tree element this is
virtual Bool_t SetFuncNo()
Int_t fIvalue
for parameter numbers and maps
std::vector< func_tree_node > children
holding sub-tree
PFunction(tree_parse_info<> info)
virtual void EvalTreeForStringExpression(iter_t const &i)
static const int constGammaMuID
TString fFuncString
clear text representation of the function
static const int constEnergyID
tree_parse_info fInfo
AST parse tree holding a single parsed msr-function in an ascii representation.
static const int parameterID