63using std::string, std::map, std::list, std::pair, std::endl, std::vector;
65#define BUFFER_SIZE 64000
124 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createFactory() ERROR: variable with name '" <<
name <<
"' already exists" << std::endl ;
151 const size_t tmpSize = strlen(stateNameList)+1;
152 std::vector<char> tmp(tmpSize);
153 strlcpy(tmp.data(),stateNameList,tmpSize) ;
155 char* tok = R__STRTOK_R(tmp.data(),
",",&save) ;
157 char* sep = strchr(tok,
'=') ;
160 Int_t id = atoi(sep+1) ;
166 tok = R__STRTOK_R(
nullptr,
",",&save) ;
179 bool isEnum(
const char* classname) {
181 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
188 bool isValidEnumValue(
const char* enumName,
const char* enumConstantName) {
191 if (!enumName)
return false;
194 if (!enumName)
return false;
197 if (theEnum->GetConstant(enumConstantName))
return true;
199 auto tmp = strstr(enumConstantName,
"::");
201 auto enumConstantNameNoScope = tmp+2;
202 if (theEnum->GetConstant(enumConstantNameNoScope))
return true;
208 pair<list<string>,
unsigned int> ctorArgsImpl(
const char* classname, std::size_t nPassedArgs) {
216 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
217 MethodInfo_t* func =
gInterpreter->MethodInfo_Factory(cls);
230 if (
string(classname) !=
gInterpreter->MethodInfo_TypeName(func)) {
236 int nDefaultArgs =
gInterpreter->MethodInfo_NDefaultArg(func);
237 if (nargs == nDefaultArgs) {
241 MethodArgInfo_t* arg =
gInterpreter->MethodArgInfo_Factory(func);
244 const char* argTypeName =
gInterpreter->MethodArgInfo_TypeName(arg);
245 if (nreq<2 && ((
string(
"char*") != argTypeName
247 &&
string(
"const char*") != argTypeName)) {
250 ret.push_back(argTypeName) ;
251 if(!
gInterpreter->MethodArgInfo_DefaultValue(arg)) nreq++;
258 if(
static_cast<int>(nPassedArgs) >= nargs - nDefaultArgs &&
static_cast<int>(nPassedArgs) <= nargs) {
264 return pair<list<string>,
unsigned int>(ret,nreq);
267 pair<list<string>,
unsigned int>
const & ctorArgs(
const char* classname, std::size_t nPassedArgs) {
274 static std::map<pair<string, std::size_t>, pair<list<string>,
unsigned int>> cache;
275 auto key = std::make_pair(
string(classname), nPassedArgs);
276 auto it = cache.find(key);
277 if (it == cache.end()) {
278 it = cache.emplace(std::move(key), ctorArgsImpl(classname, nPassedArgs)).first;
295 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" not found in factory alias table, nor in ROOT class table" << std::endl;
300 className = tc->GetName();
304 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" does not inherit from RooAbsArg" << std::endl;
313 size_t start_tok = 0;
314 bool litmode =
false;
315 for (end_tok = 0; end_tok < tmp.length(); end_tok++) {
317 if (tmp[end_tok]==
'{' || tmp[end_tok]==
'(' || tmp[end_tok]==
'[') blevel++;
318 if (tmp[end_tok]==
'}' || tmp[end_tok]==
')' || tmp[end_tok]==
']') blevel--;
321 if (tmp[end_tok]==
'"' || tmp[end_tok]==
'\'') litmode = !litmode;
326 if (litmode ==
false && blevel == 0 && tmp[end_tok] ==
',') {
327 _args.push_back(tmp.substr(start_tok, end_tok - start_tok));
328 start_tok = end_tok+1;
331 _args.push_back(tmp.substr(start_tok, end_tok));
334 pair<list<string>,
unsigned int>
const & ca = ctorArgs(className,
_args.size()+2) ;
335 if (ca.first.empty()) {
336 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR no suitable constructor found for class " << className << std::endl ;
343 if (
_args.size()+2<ca.second ||
_args.size()+2>ca.first.size()) {
344 if (ca.second==ca.first.size()) {
345 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR number of arguments provided (" <<
_args.size() <<
") for class is invalid, " << className
346 <<
" expects " << ca.first.size()-2 << std::endl ;
349 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR number of arguments provided (" <<
_args.size() <<
") for class is invalid " << className
350 <<
" expect number between " << ca.second-2 <<
" and " << ca.first.size()-2 << std::endl ;
357 string cintExpr(
Form(
"new %s(\"%s\",\"%s\"",className,objName,objName)) ;
365 list<string>::const_iterator ti = ca.first.begin() ; ++ti ; ++ti ;
366 for (vector<string>::iterator ai =
_args.begin() ; ai !=
_args.end() ; ++ai,++ti,++i) {
367 if ((*ti)==
"RooAbsReal&" || (*ti)==
"const RooAbsReal&" || (*ti)==
"RooAbsReal::Ref") {
369 cintExpr +=
Form(
",RooFactoryWSTool::as_FUNC(%d)",i) ;
370 }
else if ((*ti)==
"RooAbsArg&" || (*ti)==
"const RooAbsArg&") {
372 cintExpr +=
Form(
",RooFactoryWSTool::as_ARG(%d)",i) ;
373 }
else if ((*ti)==
"RooRealVar&" || (*ti)==
"const RooRealVar&") {
375 cintExpr +=
Form(
",RooFactoryWSTool::as_VAR(%d)",i) ;
376 }
else if ((*ti)==
"RooAbsRealLValue&" || (*ti)==
"const RooAbsRealLValue&") {
378 cintExpr +=
Form(
",RooFactoryWSTool::as_VARLV(%d)",i) ;
379 }
else if ((*ti)==
"RooCategory&" || (*ti)==
"const RooCategory&") {
381 cintExpr +=
Form(
",RooFactoryWSTool::as_CAT(%d)",i) ;
382 }
else if ((*ti)==
"RooAbsCategory&" || (*ti)==
"const RooAbsCategory&") {
384 cintExpr +=
Form(
",RooFactoryWSTool::as_CATFUNC(%d)",i) ;
385 }
else if ((*ti)==
"RooAbsCategoryLValue&" || (*ti)==
"const RooAbsCategoryLValue&") {
387 cintExpr +=
Form(
",RooFactoryWSTool::as_CATLV(%d)",i) ;
388 }
else if ((*ti)==
"RooAbsPdf&" || (*ti)==
"const RooAbsPdf&") {
390 cintExpr +=
Form(
",RooFactoryWSTool::as_PDF(%d)",i) ;
391 }
else if ((*ti)==
"RooResolutionModel&" || (*ti)==
"const RooResolutionModel&") {
393 cintExpr +=
Form(
",RooFactoryWSTool::as_RMODEL(%d)",i) ;
394 }
else if ((*ti)==
"RooAbsData&" || (*ti)==
"const RooAbsData&") {
396 cintExpr +=
Form(
",RooFactoryWSTool::as_DATA(%d)",i) ;
397 }
else if ((*ti)==
"RooDataSet&" || (*ti)==
"const RooDataSet&") {
399 cintExpr +=
Form(
",RooFactoryWSTool::as_DSET(%d)",i) ;
400 }
else if ((*ti)==
"RooDataHist&" || (*ti)==
"const RooDataHist&") {
402 cintExpr +=
Form(
",RooFactoryWSTool::as_DHIST(%d)",i) ;
403 }
else if ((*ti)==
"const RooArgSet&") {
405 cintExpr +=
Form(
",RooFactoryWSTool::as_SET(%d)",i) ;
406 }
else if ((*ti)==
"const RooArgList&") {
408 cintExpr +=
Form(
",RooFactoryWSTool::as_LIST(%d)",i) ;
409 }
else if ((*ti)==
"const char*") {
411 cintExpr +=
Form(
",RooFactoryWSTool::as_STRING(%d)",i) ;
412 }
else if ((*ti)==
"Int_t" || (*ti)==
"int" || (*ti)==
"bool" || (*ti)==
"bool") {
414 cintExpr +=
Form(
",RooFactoryWSTool::as_INT(%d)",i) ;
415 }
else if ((*ti)==
"double") {
417 cintExpr +=
Form(
",RooFactoryWSTool::as_DOUBLE(%d)",i) ;
418 }
else if (isEnum(ti->c_str())) {
421 if (
_args[i].find(
Form(
"%s::",className)) != string::npos) {
422 qualvalue =
_args[i] ;
424 qualvalue =
Form(
"%s::%s",className,
_args[i].c_str()) ;
426 if (isValidEnumValue(ti->c_str(),qualvalue.c_str())) {
427 cintExpr +=
Form(
",(%s)%s",ti->c_str(),qualvalue.c_str()) ;
429 throw string(
Form(
"Supplied argument %s does not represent a valid state of enum %s",
_args[i].c_str(),ti->c_str())) ;
437 if (ti->find(
"const ")==0) {
438 btype = ti->c_str()+6 ;
442 if (btype.find(
'&')) {
443 btype.erase(btype.size()-1,btype.size()) ;
450 cintExpr +=
Form(
",(%s&)RooFactoryWSTool::as_OBJ(%d)",ti->c_str(),i) ;
452 throw string(
Form(
"Required argument with name %s of type '%s' is not in the workspace",
_args[i].c_str(),ti->c_str())) ;
457 }
catch (
const string &err) {
458 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR constructing " << className <<
"::" << objName <<
": " << err << std::endl ;
463 cxcoutD(
ObjectHandling) <<
"RooFactoryWSTool::createArg() Construct expression is " << cintExpr << std::endl ;
466 if (std::unique_ptr<RooAbsArg> arg{
reinterpret_cast<RooAbsArg*
>(
gROOT->ProcessLineFast(cintExpr.c_str()))}) {
467 if (
string(className)==
"RooGenericPdf") {
468 arg->setStringAttribute(
"factory_tag",
Form(
"EXPR::%s(%s)",objName,varList)) ;
469 }
else if (
string(className)==
"RooFormulaVar") {
470 arg->setStringAttribute(
"factory_tag",
Form(
"expr::%s(%s)",objName,varList)) ;
472 arg->setStringAttribute(
"factory_tag",
Form(
"%s::%s(%s)",className,objName,varList)) ;
478 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR in Cling constructor call to create object" << std::endl ;
499 char* tok = R__STRTOK_R(buf,
",",&save) ;
501 char* star=strchr(tok,
'*') ;
507 pdfList2.add(
asPDF(tok)) ;
509 tok = R__STRTOK_R(
nullptr,
",",&save) ;
511 pdfList.
add(pdfList2) ;
513 }
catch (
const string &err) {
514 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooAddPdf: " << err << std::endl ;
519 RooAddPdf pdf{objName,objName,pdfList,coefList,recursiveCoefs};
520 pdf.setStringAttribute(
"factory_tag",
Form(
"SUM::%s(%s)",objName,specList)) ;
541 char* tok = R__STRTOK_R(buf,
",",&save) ;
543 char* star=strchr(tok,
'*') ;
546 amplList.add(
asFUNC(star+1)) ;
549 amplList2.add(
asFUNC(tok)) ;
551 tok = R__STRTOK_R(
nullptr,
",",&save) ;
553 amplList.add(amplList2) ;
555 }
catch (
const string &err) {
556 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooRealSumPdf: " << err << std::endl ;
561 RooRealSumPdf pdf(objName,objName,amplList,coefList,(amplList.size()==coefList.
size())) ;
576 string regPdfList=
"{" ;
580 char* tok = R__STRTOK_R(buf,
",",&save) ;
582 char *sep = strchr(tok,
'|') ;
589 bool invCond(
false) ;
597 }
catch (
const string &err) {
598 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf Conditional argument: " << err << std::endl ;
605 if (regPdfList.size()>1) {
610 tok = R__STRTOK_R(
nullptr,
",",&save) ;
614 std::unique_ptr<RooProdPdf> pdf;
616 pdf = std::make_unique<RooProdPdf>(objName,objName,
asSET(regPdfList.c_str()),cmdList);
617 }
catch (
const string &err) {
618 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf input set of regular pdfs: " << err << std::endl ;
624 pdf->setStringAttribute(
"factory_tag",
Form(
"PROD::%s(%s)",objName,pdfList)) ;
638 map<string,RooAbsPdf*> theMap ;
643 char* tok = R__STRTOK_R(buf,
",",&save) ;
645 char* eq = strchr(tok,
'=') ;
647 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName
648 <<
" expect mapping token of form 'state=pdfName', but found '" << tok <<
"'" << std::endl ;
655 theMap[tok] = &
asPDF(eq+1) ;
656 }
catch (
const string &err ) {
657 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous: " << err << std::endl ;
661 tok = R__STRTOK_R(
nullptr,
",",&save) ;
666 std::unique_ptr<RooSimultaneous> pdf;
668 pdf = std::make_unique<RooSimultaneous>(objName,objName,theMap,
asCATLV(indexCat)) ;
669 }
catch (
const string &err) {
670 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName <<
" " << err << std::endl ;
676 pdf->setStringAttribute(
"factory_tag",
Form(
"SIMUL::%s(%s,%s)",objName,indexCat,pdfMap)) ;
696 char* tok = R__STRTOK_R(buf,
",",&save) ;
698 char* star=strchr(tok,
'*') ;
701 sumlist2.add(
asFUNC(star+1)) ;
702 sumlist1.add(
asFUNC(tok)) ;
704 sumlist1.add(
asFUNC(tok)) ;
706 tok = R__STRTOK_R(
nullptr,
",",&save) ;
709 }
catch (
const string &err) {
710 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: " << err << std::endl ;
715 if (!sumlist2.empty() && (sumlist1.size()!=sumlist2.size())) {
716 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: syntax error: either all sum terms must be products or none" << std::endl ;
722 auto sum = sumlist2.empty() ? std::make_unique<RooAddition>(objName,objName,sumlist1)
723 : std::make_unique<RooAddition>(objName,objName,sumlist1,sumlist2);
725 sum->setStringAttribute(
"factory_tag",
Form(
"sum::%s(%s)",objName,specList)) ;
842 std::vector<char> buf(strlen(expr)+1);
845 char* buftmp = buf.data();
847 if (!isspace(*expr)) {
864 }
catch (
const string &error) {
865 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERROR in parsing: " << error << std::endl ;
871 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed" << std::endl ;
877 return !out.empty() ?
ws().
arg(out) : nullptr ;
896 if (
string(token).find(
"$Alias(")==0) {
922 const size_t bufBaseSize = strlen(token)+1;
923 std::vector<char> buf_base(bufBaseSize);
924 char* buf = buf_base.data();
925 strlcpy(buf,token,bufBaseSize) ;
928 list<string> singleExpr ;
929 list<char> separator ;
931 bool litmode(
false) ;
935 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
936 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
939 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
943 if (!litmode && blevel==0 && ( (*
p)==
'=' || (*
p) ==
'|' || (*
p) ==
'*')) {
944 separator.push_back(*
p) ;
946 singleExpr.push_back(buf) ;
952 singleExpr.push_back(buf) ;
954 if (singleExpr.size()==1) {
960 list<char>::iterator ic = separator.begin() ;
961 for (list<string>::iterator ii = singleExpr.begin() ; ii!=singleExpr.end() ; ++ii) {
963 if (ic != separator.end()) {
985 if (strlen(arg)==0) {
990 if (arg[0]==
'\'' || arg[0]==
'"') {
995 const size_t bufSize = strlen(arg)+1;
996 std::vector<char> buf(bufSize);
997 strlcpy(buf.data(),arg,bufSize) ;
998 char* bufptr = buf.data();
1002 vector<string> args ;
1006 char* tmpx = R__STRTOK_R(buf.data(),
"([",&save) ;
1007 func = tmpx ? tmpx :
"" ;
1008 char*
p = R__STRTOK_R(
nullptr,
"",&save) ;
1018 bool litmode(
false) ;
1022 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
1023 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
1026 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
1032 if (!litmode && blevel==0 && ((*
p)==
',')) {
1034 args.push_back(tok) ;
1043 if (
p>bufptr && (*(
p-1)==
')'||*(
p-1)==
']')) {
1052 p = R__STRTOK_R(
nullptr,
"",&save) ;
1054 args.push_back(tmp) ;
1062 for(
const char* pp=arg ; *pp!=0 ; pp++) {
1063 if (*pp==
'(' || *pp==
'[' || *pp==
'{') {
1069 if (strstr(func.c_str(),
"::")) {
1074 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: Class::Instance must be followed by (...)" << std::endl ;
1077 }
else if (func[0]!=
'$'){
1081 }
else if (lb==
'(') {
1091 static Int_t globCounter = 0 ;
1093 autoname =
Form(
"gobj%d",globCounter) ;
1095 if (!
ws().arg(autoname)) {
1099 autoname =
Form(
"%s::%s",func.c_str(),autoname.c_str()) ;
1103 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: expect either Class(...) or Instance[...]" << std::endl ;
1111 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: $MetaClass must be followed by (...)" << std::endl ;
1131 const size_t bufSize = strlen(arg)+1;
1132 std::vector<char> buf(bufSize);
1133 strlcpy(buf.data(),arg,bufSize) ;
1135 std::vector<string> args ;
1138 char* tok = buf.data()+1 ;
1139 char*
p = buf.data()+1 ;
1146 if (*
p==
'{' || *
p==
'(' || *
p==
'[') level++ ;
1147 if (*
p==
'}' || *
p==
')' || *
p==
']') level-- ;
1153 if (level==0 && ((*
p)==
',')) {
1155 args.push_back(tok) ;
1163 if (
p>buf.data() && *(
p-1)==
'}') {
1166 args.push_back(tok) ;
1171 vector<string>::iterator iter = args.begin() ;
1173 while(iter!= args.end()) {
1174 if (strlen(ret.c_str())>1) ret +=
"," ;
1198 if (args.size()!=2) {
1199 coutE(
ObjectHandling) <<
"RooFactorWSTool::processAliasExpression() ERROR $Alias() takes exactly two arguments, " << args.size() <<
" args found" << std::endl ;
1219 map<string,string>::iterator item =
_typeAliases.find(className) ;
1223 className = item->second.c_str() ;
1236 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" not defined in ROOT class table" << std::endl ;
1253 for (vector<string>::iterator iter = args.begin() ; iter!=args.end() ; ++iter) {
1254 if (iter!=args.begin()) {
1280 string first = *(args.begin());
1281 bool isNumeric = isdigit(first[0]) || first[0] ==
'.' || first[0] ==
'+' || first[0] ==
'-';
1286 for (
auto const &ai : args) {
1287 if (!allStates.empty()) {
1296 std::unique_ptr<RooRealVar> tmp;
1298 if (args.size() == 1) {
1300 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit);
1302 }
else if (args.size() == 2) {
1305 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xlo, xhi);
1307 }
else if (args.size() == 3) {
1311 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit, xlo, xhi);
1315 tmp->setStringAttribute(
"factory_tag",
varTag(func, args).c_str());
1340 const char *className = R__STRTOK_R(buf,
":",&save) ;
1341 const char *instName = R__STRTOK_R(
nullptr,
":",&save) ;
1342 if (!className) className =
"";
1343 if (!instName) instName =
"" ;
1348 vector<string>::iterator iter = args.begin() ;
1349 vector<string> pargv ;
1351 while(iter!=args.end()) {
1352 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1357 pargv.push_back(tmp) ;
1363 for (map<string,IFace*>::iterator ii=
hooks().begin() ; ii!=
hooks().end() ; ++ii) {
1365 if (
hooks().find(className) !=
hooks().end()) {
1367 return iface->create(*
this, className,instName,pargv) ;
1372 return string(instName) ;
1384 vector<string>::iterator iter = args.begin() ;
1385 vector<string> pargv ;
1386 while(iter!=args.end()) {
1387 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1390 pargv.push_back(tmp) ;
1394 string ret = func+
"("+pargs+
")" ;
1406 const size_t bufSize = strlen(funcExpr)+1;
1407 std::vector<char> buf(bufSize);
1408 strlcpy(buf.data(),funcExpr,bufSize) ;
1409 char* bufptr = buf.data();
1412 vector<string> args ;
1416 char* tmpx = R__STRTOK_R(buf.data(),
"(",&save) ;
1417 func = tmpx ? tmpx :
"" ;
1418 char*
p = R__STRTOK_R(
nullptr,
"",&save) ;
1427 bool litmode(
false) ;
1431 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
1432 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
1435 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
1441 if (!litmode && blevel==0 && ((*
p)==
',')) {
1443 args.push_back(tok) ;
1452 if (
p>bufptr && *(
p-1)==
')') {
1461 p = R__STRTOK_R(
nullptr,
"",&save) ;
1463 args.push_back(tmp) ;
1479 Int_t nParentheses(0);
1482 const char* ptr = arg ;
1484 if (*ptr==
'(') nParentheses++ ;
1485 if (*ptr==
')') nParentheses-- ;
1486 if (*ptr==
'[') nBracket++ ;
1487 if (*ptr==
']') nBracket-- ;
1488 if (*ptr==
'{') nAccolade++ ;
1489 if (*ptr==
'}') nAccolade-- ;
1492 if (nParentheses!=0) {
1493 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nParentheses>0?
"(":
")") <<
"' in expression" << std::endl ;
1497 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nBracket>0?
"[":
"]") <<
"' in expression" << std::endl ;
1501 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nAccolade>0?
"{":
"}") <<
"' in expression" << std::endl ;
1513 if (idx>
_of->_args.size()-1) {
1514 throw string(
Form(
"Need argument number %d, but only %d args are provided",idx,(
Int_t)
_of->_args.size())) ;
1526 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1533 throw string(
Form(
"RooAbsArg named %s not found",arg)) ;
1546 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1552 throw string(
Form(
"RooAbsReal named %s not found",arg)) ;
1556 throw string(
Form(
"Object named %s is not of type RooAbsReal",arg)) ;
1569 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1570 throw string(
Form(
"Numeric literal provided for argument (%s), but lvalue is required",arg)) ;
1575 throw string(
Form(
"RooAbsRealLValue named %s not found",arg)) ;
1579 throw string(
Form(
"Object named %s is not of type RooAbsRealLValue",arg)) ;
1593 throw string(
Form(
"RooRealVar named %s not found",arg)) ;
1608 throw string(
Form(
"RooAbsPdf named %s not found",arg)) ;
1623 throw string(
Form(
"RooResolutionModel named %s not found",arg)) ;
1627 throw string(
Form(
"Object named %s is not of type RooResolutionModel",arg)) ;
1642 throw string(
Form(
"RooAbsCategory named %s not found",arg)) ;
1646 throw string(
Form(
"Object named %s is not of type RooAbsCategory",arg)) ;
1660 throw string(
Form(
"RooAbsCategoryLValue named %s not found",arg)) ;
1665 throw string(
Form(
"Object named %s is not of type RooAbsCategoryLValue",arg)) ;
1679 throw string(
Form(
"RooCategory named %s not found",arg)) ;
1710 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1715 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1717 }
else if (tok[0] ==
'\'') {
1718 tok[strlen(tok) - 1] = 0;
1726 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1729 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1747 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1751 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1753 }
else if (tok[0] ==
'\'') {
1754 tok[strlen(tok) - 1] = 0;
1762 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1765 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1780 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1794 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1798 throw string(
Form(
"Dataset named %s is not of type RooDataHist",arg)) ;
1811 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1815 throw string(
Form(
"Dataset named %s is not of type RooDataSet",arg)) ;
1828 throw string(
Form(
"Object named %s not found",arg)) ;
1840 static vector<string> cbuf(10) ;
1841 static unsigned int cbuf_idx = 0 ;
1844 if (arg==
nullptr || strlen(arg)==0) {
1850 cbuf[cbuf_idx].clear() ;
1851 const char*
p = arg+1 ;
1852 while(*
p && (*
p) !=
'"' && (*
p) !=
'\'' ) {
1853 cbuf[cbuf_idx] += *(
p++) ;
1855 const char* ret = cbuf[cbuf_idx].c_str() ;
1859 if (cbuf_idx==cbuf.size()) cbuf_idx=0 ;
1872 const std::string s{arg};
1895 hooks()[typeName] = iface ;
1905 _hooks =
new map<string,IFace*> ;
1918 vector<string>::iterator iter = args.begin() ;
1919 vector<string> pargv ;
1920 while(iter!=args.end()) {
1921 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1922 string tmp = ft.processExpression(iter->c_str()) ;
1924 pargv.push_back(tmp) ;
1929 string cl(typeName) ;
1933 ft.add(instName,pargs,
false) ;
1935 }
else if (cl==
"RSUM") {
1938 ft.add(instName,pargs,
true) ;
1940 }
else if (cl==
"ASUM") {
1943 ft.amplAdd(instName,pargs) ;
1945 }
else if (cl==
"PROD") {
1948 ft.prod(instName,pargs) ;
1950 }
else if (cl==
"SIMUL") {
1953 if (pargv.size()>1) {
1954 ft.simul(instName,pargv[0].c_str(),strchr(pargs,
',')+1) ;
1956 throw string(
Form(
"Need at least two arguments in call to SIMUL::%s, have %d: %s",instName,(
Int_t)pargv.size(),pargs)) ;
1959 }
else if (cl==
"EXPR") {
1962 if (args.size()<=2) {
1963 ft.createArg(
"RooGenericPdf",instName,pargs) ;
1968 for (
UInt_t i=1 ; i<args.size() ; i++) {
1973 ft.createArg(
"RooGenericPdf",instName,genargs) ;
1976 }
else if (cl==
"FCONV") {
1979 ft.createArg(
"RooFFTConvPdf",instName,pargs) ;
1981 }
else if (cl==
"NCONV") {
1984 ft.createArg(
"RooNumConvPdf",instName,pargs) ;
1986 }
else if (cl==
"sum") {
1989 ft.addfunc(instName,pargs) ;
1991 }
else if (cl==
"prod") {
1994 ft.prodfunc(instName,pargs) ;
1996 }
else if (cl==
"expr") {
1999 if (args.size()<=2) {
2000 ft.createArg(
"RooFormulaVar",instName,pargs) ;
2005 for (
UInt_t i=1 ; i<args.size() ; i++) {
2010 ft.createArg(
"RooFormulaVar",instName,genargs) ;
2013 }
else if (cl ==
"taylorexpand") {
2019 double observablesValue(0.0);
2021 if (pargv.size() < 2)
2022 throw string(
Form(
"taylorexpand::%s, requires atleast 2 arguments (function, observables) atleast, has %d arguments", instName, (
Int_t)pargv.size()));
2024 RooAbsReal &func = ft.asFUNC(pargv[0].c_str());
2025 RooArgList observables = ft.asLIST(pargv[1].c_str());
2027 if (pargv.size() > 3)
2028 order = atoi(pargv[3].c_str());
2029 if (pargv.size() > 2) {
2030 if (pargv[2].find(
',') != string::npos) {
2032 Form(
"taylorexpand::%s, factory syntax supports expansion only around same value for all observables", instName));
2034 observablesValue =
toDouble(pargv[2]);
2038 if (pargv.size() > 3)
2039 order = atoi(pargv[3].c_str());
2040 if (pargv.size() > 4)
2042 if (pargv.size() > 5)
2045 if (pargv.size() > 6) {
2047 Form(
"taylorexpand::%s, requires max. 6 arguments, has %d arguments", instName, (
Int_t)pargv.size()));
2051 if (ft.ws().import(*taylor,
Silence())) ft.logError();
2053 }
else if (cl==
"nconv") {
2056 ft.createArg(
"RooNumConvolution",instName,pargs) ;
2058 }
else if (cl==
"profile") {
2061 ft.createArg(
"RooProfileLL",instName,pargs) ;
2063 }
else if (cl==
"dataobs") {
2066 std::unique_ptr<RooAbsArg> funcClone{
static_cast<RooAbsArg*
>(ft.asARG(pargv[1].c_str()).clone(instName))};
2067 RooAbsArg* arg = ft.asDSET(pargv[0].c_str()).addColumn(*funcClone) ;
2068 if (!ft.ws().fundArg(arg->
GetName())) {
2069 if (ft.ws().import(*arg,
Silence())) ft.logError() ;
2072 }
else if (cl==
"int") {
2079 if (pargv.size()<2 || pargv.size()>3) {
2080 throw string(
Form(
"int::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2083 RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2086 strlcpy(buf,pargv[1].c_str(),256) ;
2088 const char* intobs = R__STRTOK_R(buf,
"|",&save) ;
2089 if (!intobs) intobs=
"" ;
2091 const char* range = R__STRTOK_R(
nullptr,
"",&save) ;
2092 if (!range) range=
"" ;
2094 std::unique_ptr<RooAbsReal> integral;
2095 if (pargv.size()==2) {
2096 if (range && strlen(range)) {
2097 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
Range(range))};
2099 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs))};
2102 if (range && strlen(range)) {
2103 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
Range(range),
NormSet(ft.asSET(pargv[2].c_str())))};
2105 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
NormSet(ft.asSET(pargv[2].c_str())))};
2109 integral->SetName(instName) ;
2110 if (ft.ws().import(*integral,
Silence())) ft.logError() ;
2112 }
else if (cl==
"deriv") {
2116 if (pargv.size()<2 || pargv.size()>3) {
2117 throw string(
Form(
"deriv::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2120 RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2122 std::unique_ptr<RooAbsReal> derivative;
2123 if (pargv.size()==2) {
2124 derivative.reset(func.
derivative(ft.asVAR(pargv[1].c_str()),1));
2126 derivative.reset(func.
derivative(ft.asVAR(pargv[1].c_str()),ft.asINT(pargv[2].c_str())));
2129 derivative->SetName(instName) ;
2130 if (ft.ws().import(*derivative,
Silence())) ft.logError() ;
2132 }
else if (cl==
"cdf") {
2136 if (pargv.size()<2 || pargv.size()>3) {
2137 throw string(
Form(
"cdf::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2140 RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2142 std::unique_ptr<RooAbsReal> cdf;
2143 if (pargv.size()==2) {
2144 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.asSET(pargv[1].c_str()))};
2146 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.asSET(pargv[1].c_str()),ft.asSET(pargv[2].c_str()))};
2149 cdf->SetName(instName) ;
2150 if (ft.ws().import(*cdf,
Silence())) ft.logError() ;
2153 }
else if (cl==
"PROJ") {
2156 if (pargv.size()!=2) {
2157 throw string(
Form(
"PROJ::%s, requires 2 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2160 RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2161 std::unique_ptr<RooAbsPdf> projection{pdf.
createProjection(ft.asSET(pargv[1].c_str()))};
2162 projection->SetName(instName) ;
2164 if (ft.ws().import(*projection,
Silence())) ft.logError() ;
2166 }
else if (cl==
"set") {
2169 if (ft.ws().defineSet(instName,pargs)) {
2171 return string(instName) ;
2176 throw string(
Form(
"RooFactoryWSTool::SpecialsIFace::create() ERROR: Unknown meta-type %s",typeName)) ;
2179 return string(instName) ;
double toDouble(const char *s)
int Int_t
Signed integer 4 bytes (int)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
RooFit::OwningPtr< RooAbsReal > createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset.
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
RooDerivative * derivative(RooRealVar &obs, Int_t order=1, double eps=0.001)
Return function representing first, second or third order derivative of this function.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
Efficient implementation of a sum of PDFs of the form.
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
static std::unique_ptr< RooPolyFunc > taylorExpand(const char *name, const char *title, RooAbsReal &func, const RooArgList &observables, int order=1, std::vector< double > const &observableValues={}, double eps1=1e-6, double eps2=1e-3)
Taylor expanding given function in terms of observables around observableValues.
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
A RooAbsArg implementing string values.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
const RooArgSet * set(RooStringView name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
bool commitTransaction()
Commit an ongoing import transaction.
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
RooAbsReal * function(RooStringView name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
RooConstVar & RooConst(double val)
RooCmdArg Silence(bool flag=true)
RooCmdArg NormSet(Args_t &&... argsOrArgSet)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static uint64_t sum(uint64_t i)