78#ifdef ROOFIT_LEGACY_EVAL_BACKEND
90#include <unordered_map>
91#include <unordered_set>
97bool isCacheSet(std::string
const& setName) {
99 return setName.rfind(
"CACHE_", 0) == 0;
104using std::string, std::list, std::map, std::vector, std::ifstream, std::ofstream, std::fstream, std::make_unique;
195 TNamed(other), _uuid(other._uuid), _classes(other._classes,this)
204 for(
auto * snap : static_range_cast<RooArgSet*>(other._snapshots)) {
207 snapClone->
setName(snap->GetName()) ;
212 for (map<string,RooArgSet>::const_iterator iter3 = other._namedSets.begin() ; iter3 != other._namedSets.end() ; ++iter3) {
218 for(
TObject * gobj : other._genObjects) {
224 handle->ReplaceWS(
this);
234 if(newname && std::string(newname) !=
GetName()) {
275 std::vector<std::string> tokens =
ROOT::Split(fileSpec,
":");
278 if (tokens.size() != 3) {
279 std::ostringstream stream;
280 for (
const auto& token : tokens) {
281 stream <<
"\n\t" << token;
283 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR in file specification, expecting 'filename:wsname:objname', but '" << fileSpec <<
"' given."
284 <<
"\nTokens read are:" << stream.str() << std::endl;
288 const std::string&
filename = tokens[0];
289 const std::string& wsname = tokens[1];
290 const std::string& objname = tokens[2];
295 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR opening file " <<
filename << std::endl ;
302 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR: No object named " << wsname <<
" in file " <<
filename
303 <<
" or object is not a RooWorkspace" << std::endl ;
310 bool ret =
import(*warg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
315 bool ret =
import(*wdata,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
319 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR: No RooAbsArg or RooAbsData object named " << objname
320 <<
" in workspace " << wsname <<
" in file " <<
filename << std::endl ;
337 ret |=
import(*oneArg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
390 pc.
defineString(
"conflictSuffix",
"RenameConflictNodes",0) ;
391 pc.
defineInt(
"renameConflictOrig",
"RenameConflictNodes",0,0) ;
393 pc.
defineString(
"allVarsSuffix",
"RenameAllVariables",0) ;
394 pc.
defineString(
"allVarsExcept",
"RenameAllVariables",1) ;
398 pc.
defineInt(
"useExistingNodes",
"RecycleConflictNodes",0,0) ;
400 pc.
defineInt(
"noRecursion",
"NoRecursion",0,0) ;
401 pc.
defineMutex(
"RenameConflictNodes",
"RenameAllNodes") ;
402 pc.
defineMutex(
"RenameConflictNodes",
"RecycleConflictNodes") ;
403 pc.
defineMutex(
"RenameAllNodes",
"RecycleConflictNodes") ;
404 pc.
defineMutex(
"RenameVariable",
"RenameAllVariables") ;
413 const char* suffixC = pc.
getString(
"conflictSuffix") ;
414 const char* suffixA = pc.
getString(
"allSuffix") ;
415 const char* suffixV = pc.
getString(
"allVarsSuffix") ;
416 const char* exceptVars = pc.
getString(
"allVarsExcept") ;
417 const char* varChangeIn = pc.
getString(
"varChangeIn") ;
418 const char* varChangeOut = pc.
getString(
"varChangeOut") ;
419 bool renameConflictOrig = pc.
getInt(
"renameConflictOrig") ;
420 Int_t useExistingNodes = pc.
getInt(
"useExistingNodes") ;
426 if (suffixC && strlen(suffixC)==0) suffixC = nullptr ;
427 if (suffixA && strlen(suffixA)==0) suffixA = nullptr ;
429 bool conflictOnly = suffixA ? false : true ;
430 const char* suffix = suffixA ? suffixA : suffixC ;
433 std::unordered_map<string,string> varMap ;
434 if (strlen(varChangeIn)>0) {
437 const std::vector<std::string> tokIn =
ROOT::Split(varChangeIn,
", ",
true);
438 const std::vector<std::string> tokOut =
ROOT::Split(varChangeOut,
", ",
true);
439 for (
unsigned int i=0; i < tokIn.size(); ++i) {
440 varMap.insert(std::make_pair(tokIn[i], tokOut[i]));
443 assert(tokIn.size() == tokOut.size());
448 std::set<string> exceptVarNames ;
449 if (exceptVars && strlen(exceptVars)) {
450 const std::vector<std::string> toks =
ROOT::Split(exceptVars,
", ",
true);
451 exceptVarNames.insert(toks.begin(), toks.end());
454 if (suffixV !=
nullptr && strlen(suffixV)>0) {
455 std::unique_ptr<RooArgSet> vars{inArg.getVariables()};
456 for (
const auto v : *vars) {
457 if (exceptVarNames.find(
v->GetName())==exceptVarNames.end()) {
458 varMap[
v->GetName()] =
Form(
"%s_%s",
v->GetName(),suffixV) ;
468 const char* tagWs = wsarg ? wsarg->getStringAttribute(
"factory_tag") : nullptr ;
469 bool factoryMatch = (tagIn && tagWs && !strcmp(tagIn,tagWs)) ;
471 ((
RooAbsArg&)inArg).setAttribute(
"RooWorkspace::Recycle") ;
474 if (!suffix && wsarg && !useExistingNodes && !(inArg.isFundamental() && !varMap[inArg.GetName()].empty())) {
477 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR importing object named " << inArg.GetName()
478 <<
": another instance with same name already in the workspace and no conflict resolution protocol specified" << std::endl ;
482 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") Object " << inArg.GetName() <<
" is already in workspace!" << std::endl ;
488 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") Recycling existing object " << inArg.GetName() <<
" created with identical factory specification" << std::endl ;
499 const bool pruneClones = useExistingNodes && !suffix && varMap.empty() && !noRecursion;
508 branchSet.
add(inArg);
510 inArg.branchNodeServerList(&branchSet);
513 for (
const auto branch : branchSet) {
515 if (wsbranch && wsbranch != branch && !branch->getAttribute(
"RooWorkspace::Recycle") && !useExistingNodes) {
516 conflictNodes.add(*branch);
522 if (!conflictNodes.empty() && !suffix && !useExistingNodes) {
523 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR object named " << inArg.GetName() <<
": component(s) "
524 << conflictNodes <<
" already in the workspace and no conflict resolution protocol specified" << std::endl ;
533 std::vector<RooAbsArg const *> recycledSources;
539 std::vector<RooAbsArg const *> toClone;
540 std::unordered_set<TNamed const *> visited;
541 visited.insert(inArg.namePtr());
542 std::vector<RooAbsArg const *> stack{&inArg};
543 while (!stack.empty()) {
548 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") using existing copy of "
549 << wsnode->ClassName() <<
"::" << wsnode->GetName() <<
" for import of "
550 << inArg.ClassName() <<
"::" << inArg.GetName() << std::endl;
552 recycledSources.push_back(
arg);
554 toClone.push_back(
arg);
558 auto const &servers =
arg->
servers().containedObjects();
559 for (
auto it = servers.rbegin(); it != servers.rend(); ++it) {
560 if (visited.insert((*it)->namePtr()).second) {
561 stack.push_back(*it);
568 cloneSet.addOwned(std::move(clone));
574 redirectSet.add(cloneSet);
579 clone->redirectServers(redirectSet,
true);
593 if (pruneClones && cloneSet.empty()) {
598 RooAbsArg* cloneTop = cloneSet.find(inArg.GetName()) ;
602 conflictNodes.removeAll() ;
603 conflictNodes.add(branchSet) ;
609 bool nodesRenamed = false ;
613 string topName2 = cloneTop ? cloneTop->
GetName() : inArg.GetName();
614 if (!renameConflictOrig) {
616 for (
const auto cnode : conflictNodes) {
617 RooAbsArg* cnode2 = cloneSet.find(cnode->GetName()) ;
618 string origName = cnode2->
GetName() ;
619 cnode2->SetName(
Form(
"%s_%s",cnode2->GetName(),suffix)) ;
620 cnode2->SetTitle(
Form(
"%s (%s)",cnode2->GetTitle(),suffix)) ;
621 nodesRenamed = true ;
622 string tag =
"ORIGNAME:" + origName;
623 cnode2->setAttribute(tag.c_str()) ;
624 if (!cnode2->getStringAttribute(
"origName")) {
625 cnode2->setStringAttribute(
"origName",origName.c_str());
629 if (cnode2==cloneTop) {
630 topName2 = cnode2->GetName() ;
634 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName()
635 <<
") Resolving name conflict in workspace by changing name of imported node "
636 << origName <<
" to " << cnode2->GetName() << std::endl ;
642 for (
const auto cnode : conflictNodes) {
644 string origName = cnode->GetName() ;
648 if (!wsnode->getStringAttribute(
"origName")) {
653 wsnode->SetName(
Form(
"%s_%s",cnode->GetName(),suffix)) ;
654 wsnode->SetTitle(
Form(
"%s (%s)",cnode->GetTitle(),suffix)) ;
657 for (
unsigned int n=1;
true; ++
n) {
658 string newname =
Form(
"%s_%s_%d",cnode->GetName(),suffix,
n) ;
660 wsnode->SetName(newname.c_str()) ;
661 wsnode->SetTitle(
Form(
"%s (%s %d)",cnode->GetTitle(),suffix,
n)) ;
667 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName()
668 <<
") Resolving name conflict in workspace by changing name of original node "
669 << origName <<
" to " << wsnode->GetName() << std::endl ;
672 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") Internal error: expected to find existing node "
673 << origName <<
" to be renamed, but didn't find it..." << std::endl ;
680 if (strlen(varChangeIn)>0 || (suffixV && strlen(suffixV)>0)) {
683 for (
const auto cnode : cloneSet) {
685 if (varMap.find(cnode->GetName())!=varMap.end()) {
686 string origName = cnode->GetName() ;
687 cnode->SetName(varMap[cnode->GetName()].c_str()) ;
688 nodesRenamed = true ;
689 string tag =
"ORIGNAME:" + origName;
690 cnode->setAttribute(tag.c_str()) ;
691 if (!cnode->getStringAttribute(
"origName")) {
692 cnode->setStringAttribute(
"origName",origName.c_str()) ;
696 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") Changing name of variable "
697 << origName <<
" to " << cnode->GetName() <<
" on request" << std::endl ;
700 if (cnode==cloneTop) {
701 topName2 = cnode->GetName() ;
719 RooArgSet &cloneSet2 = nodesRenamed ? renamedCloneSet : cloneSet;
720 RooAbsArg* cloneTop2 = cloneSet2.find(topName2.c_str()) ;
723 for (
const auto node : cloneSet2) {
724 if (node->importWorkspaceHook(*
this)) {
725 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR object named " << node->GetName()
726 <<
" has an error in importing in one or more of its auxiliary objects, aborting" << std::endl ;
733 for (
const auto node : cloneSet2) {
736 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") WARNING: problems import class code of object "
737 << node->ClassName() <<
"::" << node->GetName() <<
", reading of workspace will require external definition of class" << std::endl ;
743 node->setExpensiveObjectCache(
_eocache) ;
751 if (!silence && useExistingNodes) {
752 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") using existing copy of " << node->ClassName()
753 <<
"::" << node->GetName() <<
" for import of " << cloneTop2->ClassName() <<
"::"
754 << cloneTop2->GetName() << std::endl ;
759 nodesToBeDeleted.addOwned(std::unique_ptr<RooAbsArg>{node});
766 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") importing " << node->ClassName() <<
"::"
767 << node->GetName() << std::endl ;
770 node->setWorkspace(*
this);
782 if (!recycledNodes.empty()) {
783 for (
const auto node : cloneSet2) {
784 node->redirectServers(recycledNodes) ;
788 cloneSet2.releaseOwnership() ;
830 pc.
defineInt(
"embedded",
"Embedded",0,0) ;
840 const char* dsetName = pc.
getString(
"dsetName") ;
841 const char* varChangeIn = pc.
getString(
"varChangeIn") ;
842 const char* varChangeOut = pc.
getString(
"varChangeOut") ;
843 bool embedded = pc.
getInt(
"embedded") ;
847 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") importing dataset " << inData.GetName() << std::endl ;
850 if (dsetName && strlen(dsetName)==0) {
855 if (dataList.size() > 50 && dataList.getHashTableSize() == 0) {
861 if (dsetName && dataList.FindObject(dsetName)) {
862 coutE(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") ERROR dataset with name " << dsetName <<
" already exists in workspace, import aborted" << std::endl ;
865 if (!dsetName && dataList.FindObject(inData.GetName())) {
866 coutE(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") ERROR dataset with name " << inData.GetName() <<
" already exists in workspace, import aborted" << std::endl ;
874 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") changing name of dataset from " << inData.GetName() <<
" to " << dsetName << std::endl ;
875 clone =
static_cast<RooAbsData*
>(inData.Clone(dsetName)) ;
877 clone =
static_cast<RooAbsData*
>(inData.Clone(inData.GetName())) ;
882 if (strlen(varChangeIn)>0) {
884 const std::vector<std::string> tokIn =
ROOT::Split(varChangeIn,
",");
885 const std::vector<std::string> tokOut =
ROOT::Split(varChangeOut,
",");
886 for (
unsigned int i=0; i < tokIn.size(); ++i) {
888 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") changing name of dataset observable " << tokIn[i] <<
" to " << tokOut[i] << std::endl ;
896 if (!
arg(carg->GetName())) {
902 dataList.Add(clone) ;
929 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") WARNING redefining previously defined named set " <<
name << std::endl ;
937 if (!
arg(sarg->GetName())) {
941 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR set constituent \"" << sarg->GetName()
942 <<
"\" is not in workspace and importMissing option is disabled" << std::endl ;
946 wsargs.add(*
arg(sarg->GetName())) ;
968 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName()
969 <<
") WARNING redefining previously defined named set " <<
name << std::endl;
988 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") WARNING redefining previously defined named set " <<
name << std::endl ;
994 for (
const std::string& token :
ROOT::Split(contentList,
",")) {
996 if (!
arg(token.c_str())) {
997 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR proposed set constituent \"" << token
998 <<
"\" is not in workspace" << std::endl ;
1001 wsargs.add(*
arg(token.c_str())) ;
1023 for (
const std::string& token :
ROOT::Split(newContents,
",")) {
1025 if (!
arg(token.c_str())) {
1026 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR proposed set constituent \"" << token
1027 <<
"\" is not in workspace" << std::endl ;
1030 wsargs.add(*
arg(token.c_str())) ;
1047 std::map<string,RooArgSet>::iterator i =
_namedSets.find(
name.c_str());
1048 return (i!=
_namedSets.end()) ? &(i->second) :
nullptr;
1061 coutE(InputArguments) <<
"RooWorkspace::renameSet(" <<
GetName() <<
") ERROR a set with name " <<
name
1062 <<
" does not exist" << std::endl ;
1068 coutE(InputArguments) <<
"RooWorkspace::renameSet(" <<
GetName() <<
") ERROR a set with name " << newName
1069 <<
" already exists" << std::endl ;
1092 coutE(InputArguments) <<
"RooWorkspace::removeSet(" <<
GetName() <<
") ERROR a set with name " <<
name
1093 <<
" does not exist" << std::endl ;
1199 TString className = carg->ClassName() ;
1201 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") WARNING: problems import class code of object "
1202 << carg->ClassName() <<
"::" << carg->GetName() <<
", reading of workspace will require external definition of class" << std::endl ;
1244 snapshot->assign(params) ;
1248 coutI(ObjectHandling) <<
"RooWorkspace::saveSnapshot(" <<
GetName() <<
") replacing previous snapshot with name " <<
name << std::endl ;
1268 coutE(ObjectHandling) <<
"RooWorkspace::loadSnapshot(" <<
GetName() <<
") no snapshot with name " <<
name <<
" is available" << std::endl ;
1274 actualParams.
assign(*snap) ;
1356 for (
const std::string& token :
ROOT::Split(nameList,
",")) {
1361 std::stringstream ss;
1362 ss <<
" RooWorkspace::argSet(" <<
GetName() <<
") no RooAbsArg named \"" << token <<
"\" in workspace" ;
1363 const std::string errorMsg = ss.str();
1364 coutE(InputArguments) << errorMsg << std::endl;
1365 throw std::runtime_error(errorMsg);
1383 return tmp->isFundamental() ? tmp :
nullptr;
1528 std::list<RooAbsData*> ret ;
1529 for(
auto * dat : static_range_cast<RooAbsData*>(
_dataList)) {
1530 ret.push_back(dat) ;
1541 std::list<RooAbsData*> ret ;
1543 ret.push_back(dat) ;
1555 std::list<TObject*> ret ;
1559 if (gobj->IsA()==RooTObjWrap::Class()) {
1560 ret.push_back((
static_cast<RooTObjWrap*
>(gobj))->obj()) ;
1562 ret.push_back(gobj) ;
1571std::string findFileInPath(std::string
const &file, std::list<std::string>
const &dirList)
1574 for (std::string
const &diter : dirList) {
1577 std::string path = cpath;
1600 oocxcoutD(
_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" <<
_wspace->
GetName() <<
") request to import code of class " << tc->GetName() << std::endl ;
1606 oocxcoutD(
_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" <<
_wspace->
GetName() <<
") code of class " << tc->GetName() <<
" already imported, skipping" << std::endl ;
1611 const char* mapEntry =
gInterpreter->GetClassSharedLibs(tc->GetName()) ;
1612 if (mapEntry && strlen(mapEntry)>0) {
1613 oocxcoutD(
_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" <<
_wspace->
GetName() <<
") code of class " << tc->GetName() <<
" is in ROOT distribution, skipping " << std::endl ;
1618 string implfile = tc->GetImplFileName() ;
1619 string declfile = tc->GetDeclFileName() ;
1622 if (implfile.empty() || declfile.empty()) {
1623 oocoutE(
_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" <<
_wspace->
GetName() <<
") ERROR: cannot retrieve code file names for class "
1624 << tc->GetName() <<
" through ROOT TClass interface, unable to import code" << std::endl ;
1631 oocxcoutD(
_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" <<
_wspace->
GetName() <<
") code of class " << tc->GetName() <<
" is in ROOT distribution, skipping " << std::endl ;
1638 if (!(tc->Property() &
kIsAbstract) && !tc->HasDefaultConstructor()) {
1640 << tc->GetName() <<
" : it cannot be persisted because it doesn't have a default constructor. Please fix " << std::endl ;
1647 std::string declpath;
1648 std::string implpath;
1657 if (declpath.empty()) {
1659 << tc->GetName() <<
" because header file " << declfile <<
" is not found in current directory nor in $ROOTSYS" ;
1673 ooccoutW(
_wspace,ObjectHandling) <<
". To fix this problem, add the required directory to the search "
1674 <<
"path using RooWorkspace::addClassDeclImportDir(const char* dir)" << std::endl ;
1688 if (implpath.empty()) {
1690 << tc->GetName() <<
" because implementation file " << implfile <<
" is not found in current directory nor in $ROOTSYS" ;
1704 ooccoutW(
_wspace,ObjectHandling) <<
". To fix this problem add the required directory to the search "
1705 <<
"path using RooWorkspace::addClassImplImportDir(const char* dir)" << std::endl;
1723 const std::string declfilename = !declpath.empty() ?
gSystem->
BaseName(declpath.c_str())
1727 int dotpos2 = strrchr(declfilename.c_str(),
'.') - declfilename.c_str() ;
1728 string declfilebase = declfilename.substr(0,dotpos2) ;
1729 string declfileext = declfilename.substr(dotpos2+1) ;
1731 list<string> extraHeaders ;
1734 if (
_fmap.find(declfilebase) ==
_fmap.end()) {
1737 std::fstream fdecl(!declpath.empty() ? declpath.c_str() : declfile.c_str());
1742 <<
") ERROR opening declaration file " << declfile << std::endl ;
1747 <<
") importing code of class " << tc->GetName()
1748 <<
" from " << (!implpath.empty() ? implpath.c_str() : implfile.c_str())
1749 <<
" and " << (!declpath.empty() ? declpath.c_str() : declfile.c_str()) << std::endl ;
1754 while(fdecl.getline(buf,1023)) {
1757 bool processedInclude = false ;
1758 char* extincfile = nullptr ;
1761 if (strstr(buf,
"#include")) {
1764 strlcpy(tmp, buf, 64000);
1765 bool stdinclude = strchr(buf,
'<');
1766 strtok(tmp,
" <\"");
1767 char *incfile = strtok(
nullptr,
" <>\"");
1772 hpath +=
"/include/";
1776 <<
") scheduling include file " << incfile <<
" for import" << std::endl;
1777 extraHeaders.push_back(incfile);
1778 extincfile = incfile;
1779 processedInclude =
true;
1784 if (processedInclude) {
1785 decl +=
"// external include file below retrieved from workspace code storage\n" ;
1786 decl +=
Form(
"#include \"%s\"\n",extincfile) ;
1794 fstream fimpl(!implpath.empty() ? implpath.c_str() : implfile.c_str()) ;
1799 <<
") ERROR opening implementation file " << implfile << std::endl ;
1806 while(fimpl.getline(buf,1023)) {
1810 bool foundSelfInclude=false ;
1811 bool processedInclude = false ;
1812 char* extincfile = nullptr ;
1815 if (strstr(buf,
"#include")) {
1818 strlcpy(tmp, buf, 64000);
1819 bool stdinclude = strchr(buf,
'<');
1820 strtok(tmp,
" <\"");
1821 char *incfile = strtok(
nullptr,
" <>\"");
1823 if (strstr(incfile, declfilename.c_str())) {
1824 foundSelfInclude =
true;
1827 if (!stdinclude && !foundSelfInclude) {
1830 hpath +=
"/include/";
1835 <<
") scheduling include file " << incfile <<
" for import" << std::endl;
1836 extraHeaders.push_back(incfile);
1837 extincfile = incfile;
1838 processedInclude =
true;
1845 if (foundSelfInclude) {
1848 impl +=
"// class declaration include file below retrieved from workspace code storage\n" ;
1849 impl +=
Form(
"#include \"%s.%s\"\n",declfilebase.c_str(),declfileext.c_str()) ;
1850 }
else if (processedInclude) {
1851 impl +=
"// external include file below retrieved from workspace code storage\n" ;
1852 impl +=
Form(
"#include \"%s\"\n",extincfile) ;
1860 _fmap[declfilebase]._hfile = decl ;
1861 _fmap[declfilebase]._cxxfile = impl ;
1862 _fmap[declfilebase]._hext = declfileext ;
1865 for (list<string>::iterator ehiter = extraHeaders.begin() ; ehiter != extraHeaders.end() ; ++ehiter ) {
1869 eh.
_hname = ehiter->c_str() ;
1870 fstream fehdr(ehiter->c_str()) ;
1873 while(fehdr.getline(buf2,1023)) {
1876 if (strstr(buf2,
"#include")) {
1879 strlcpy(tmp, buf2, 64000);
1880 bool stdinclude = strchr(buf,
'<');
1881 strtok(tmp,
" <\"");
1882 char *incfile = strtok(
nullptr,
" <>\"");
1887 hpath +=
"/include/";
1891 <<
") scheduling recursive include file " << incfile <<
" for import"
1893 extraHeaders.push_back(incfile);
1901 eh._hfile = ehimpl.c_str();
1903 _ehmap[ehiter->c_str()] = eh;
1911 <<
") code of class " << tc->GetName()
1912 <<
" was already imported from " << (!implpath.empty() ? implpath : implfile)
1913 <<
" and " << (!declpath.empty() ? declpath.c_str() : declfile.c_str()) << std::endl;
1925 TList* bl = tc->GetListOfBases() ;
1926 std::list<TClass*> bases ;
1927 for(
auto * base : static_range_cast<TBaseClass*>(*bl)) {
1928 if (baseNameList.Length()>0) {
1929 baseNameList +=
"," ;
1931 baseNameList += base->GetClassPointer()->
GetName() ;
1932 bases.push_back(base->GetClassPointer()) ;
1937 _c2fmap[tc->GetName()]._baseName = baseNameList ;
1938 _c2fmap[tc->GetName()]._fileBase = declfilebase ;
1941 for(
TClass* bclass : bases) {
1961 if (
_dir)
return true ;
1963 std::string title=
"TDirectory representation of RooWorkspace " + std::string(
GetName());
1988 if (oldObj && !replaceExisting) {
1989 coutE(InputArguments) <<
"RooWorkspace::import(" <<
GetName() <<
") generic object with name "
1990 <<
object.GetName() <<
" is already in workspace and replaceExisting flag is set to false" << std::endl ;
1996 object.IsA()->SetDirectoryAutoAdd(
nullptr);
2006 object.IsA()->SetDirectoryAutoAdd(func);
2028 if (oldObj && !replaceExisting) {
2029 coutE(InputArguments) <<
"RooWorkspace::import(" <<
GetName() <<
") generic object with name "
2030 << aliasName <<
" is already in workspace and replaceExisting flag is set to false" << std::endl ;
2035 auto wrapper =
new RooTObjWrap(
object.
Clone());
2036 wrapper->setOwning(
true) ;
2037 wrapper->SetName(aliasName) ;
2038 wrapper->SetTitle(aliasName) ;
2082 if (ret)
return ret ;
2086 if (ret)
return ret ;
2103 if (!gobj)
return nullptr;
2106 if (gobj->IsA()==RooTObjWrap::Class())
return (
static_cast<RooTObjWrap*
>(gobj))->obj() ;
2130 std::unique_ptr<TFile>
f{
TFile::Open(fileName, recreate ?
"RECREATE" :
"UPDATE") };
2131 if (!
f ||
f->IsZombie())
2147 cxcoutD(ObjectHandling) <<
"INFO: Creating RooFactoryWSTool associated with this workspace" << std::endl ;
2148 _factory = make_unique<RooFactoryWSTool>(*
this);
2172 bool treeMode(
false) ;
2173 bool verbose(
false);
2174 if (
TString(opts).Contains(
"t")) {
2177 if (
TString(opts).Contains(
"v")) {
2181 std::cout << std::endl <<
"RooWorkspace(" <<
GetName() <<
") " <<
GetTitle() <<
" contents" << std::endl << std::endl ;
2201 if (!parg->hasClients()) {
2210 if (!parg->hasClients()) {
2211 funcSet.add(*parg) ;
2218 if (!parg->hasClients()) {
2219 catfuncSet.add(*parg) ;
2227 convResoSet.add(*parg) ;
2229 resoSet.add(*parg) ;
2242 funcSet.add(*parg) ;
2247 catfuncSet.add(*parg) ;
2265 if (!varSet.
empty()) {
2267 std::cout <<
"variables" << std::endl ;
2268 std::cout <<
"---------" << std::endl ;
2269 std::cout << varSet << std::endl ;
2270 std::cout << std::endl ;
2273 if (!pdfSet.empty()) {
2274 std::cout <<
"p.d.f.s" << std::endl ;
2275 std::cout <<
"-------" << std::endl ;
2279 parg->printComponentTree() ;
2284 std::cout << std::endl ;
2288 if (!resoSet.empty()) {
2289 std::cout <<
"analytical resolution models" << std::endl ;
2290 std::cout <<
"----------------------------" << std::endl ;
2295 std::cout << std::endl ;
2299 if (!funcSet.empty()) {
2300 std::cout <<
"functions" << std::endl ;
2301 std::cout <<
"--------" << std::endl ;
2305 parg->printComponentTree() ;
2310 std::cout << std::endl ;
2313 if (!catfuncSet.empty()) {
2314 std::cout <<
"category functions" << std::endl ;
2315 std::cout <<
"------------------" << std::endl ;
2319 parg->printComponentTree() ;
2324 std::cout << std::endl ;
2328 std::cout <<
"datasets" << std::endl ;
2329 std::cout <<
"--------" << std::endl ;
2330 for(
auto * data2 : static_range_cast<RooAbsData*>(
_dataList)) {
2331 std::cout << data2->ClassName() <<
"::" << data2->GetName() << *data2->get() << std::endl;
2333 std::cout << std::endl ;
2337 std::cout <<
"embedded datasets (in pdfs and functions)" << std::endl ;
2338 std::cout <<
"-----------------------------------------" << std::endl ;
2340 std::cout << data2->ClassName() <<
"::" << data2->GetName() << *data2->get() << std::endl ;
2342 std::cout << std::endl ;
2346 std::cout <<
"parameter snapshots" << std::endl ;
2347 std::cout <<
"-------------------" << std::endl ;
2348 for(
auto * snap : static_range_cast<RooArgSet*>(
_snapshots)) {
2349 std::cout << snap->GetName() <<
" = (" ;
2352 if (first) { first=false ; }
else { std::cout <<
"," ; }
2353 std::cout <<
a->GetName() <<
"=" ;
2354 a->printValue(std::cout) ;
2355 if (
a->isConstant()) {
2356 std::cout <<
"[C]" ;
2359 std::cout <<
")" << std::endl ;
2361 std::cout << std::endl ;
2366 std::cout <<
"named sets" << std::endl ;
2367 std::cout <<
"----------" << std::endl ;
2368 for (map<string,RooArgSet>::const_iterator it =
_namedSets.begin() ; it !=
_namedSets.end() ; ++it) {
2369 if (verbose || !isCacheSet(it->first)) {
2370 std::cout << it->first <<
":" << it->second << std::endl;
2374 std::cout << std::endl ;
2379 std::cout <<
"generic objects" << std::endl ;
2380 std::cout <<
"---------------" << std::endl ;
2382 if (gobj->IsA()==RooTObjWrap::Class()) {
2383 std::cout << (static_cast<RooTObjWrap*>(gobj))->
obj()->
ClassName() <<
"::" << gobj->GetName() << std::endl ;
2385 std::cout << gobj->ClassName() <<
"::" << gobj->GetName() << std::endl ;
2388 std::cout << std::endl ;
2393 std::cout <<
"study modules" << std::endl ;
2394 std::cout <<
"-------------" << std::endl ;
2396 std::cout << smobj->ClassName() <<
"::" << smobj->GetName() << std::endl ;
2398 std::cout << std::endl ;
2403 std::cout <<
"embedded class code" << std::endl ;
2404 std::cout <<
"-------------------" << std::endl ;
2406 std::cout << std::endl ;
2410 std::cout <<
"embedded precalculated expensive components" << std::endl ;
2411 std::cout <<
"-------------------------------------------" << std::endl ;
2432 if (R__b.IsReading()) {
2436 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2443 name.Streamer(R__b);
2444 _fmap[
name]._hext.Streamer(R__b);
2445 _fmap[
name]._hfile.Streamer(R__b);
2446 _fmap[
name]._cxxfile.Streamer(R__b);
2454 name.Streamer(R__b);
2455 _c2fmap[
name]._baseName.Streamer(R__b);
2456 _c2fmap[
name]._fileBase.Streamer(R__b);
2465 name.Streamer(R__b);
2466 _ehmap[
name]._hname.Streamer(R__b);
2467 _ehmap[
name]._hfile.Streamer(R__b);
2471 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
2474 _compiledOK = !compileClasses();
2479 R__c = R__b.WriteVersion(thisClass::IsA(),
true);
2482 UInt_t count = _fmap.size();
2484 map<TString, ClassFiles>::iterator iter = _fmap.begin();
2485 while (iter != _fmap.end()) {
2486 TString key_copy(iter->first);
2487 key_copy.Streamer(R__b);
2488 iter->second._hext.Streamer(R__b);
2489 iter->second._hfile.Streamer(R__b);
2490 iter->second._cxxfile.Streamer(R__b);
2496 count = _c2fmap.size();
2498 map<TString, ClassRelInfo>::iterator iter2 = _c2fmap.begin();
2499 while (iter2 != _c2fmap.end()) {
2500 TString key_copy(iter2->first);
2501 key_copy.Streamer(R__b);
2502 iter2->second._baseName.Streamer(R__b);
2503 iter2->second._fileBase.Streamer(R__b);
2508 count = _ehmap.size();
2510 map<TString, ExtraHeader>::iterator iter3 = _ehmap.begin();
2511 while (iter3 != _ehmap.end()) {
2512 TString key_copy(iter3->first);
2513 key_copy.Streamer(R__b);
2514 iter3->second._hname.Streamer(R__b);
2515 iter3->second._hfile.Streamer(R__b);
2519 R__b.SetByteCount(R__c,
true);
2534 if (R__b.IsReading()) {
2540 node->ioStreamerPass2();
2547 node->setExpensiveObjectCache(
_eocache);
2548 node->setWorkspace(*
this);
2549#ifdef ROOFIT_LEGACY_EVAL_BACKEND
2550 if (
dynamic_cast<RooAbsOptTestStatistic *
>(node)) {
2551 RooAbsOptTestStatistic *tmp =
static_cast<RooAbsOptTestStatistic *
>(node);
2552 if (tmp->isSealed() && tmp->sealNotice() && strlen(tmp->sealNotice()) > 0) {
2553 std::cout <<
"RooWorkspace::Streamer(" <<
GetName() <<
") " << node->ClassName() <<
"::" << node->GetName()
2554 <<
" : " << tmp->sealNotice() << std::endl;
2562 handle->ReplaceWS(
this);
2570 map<RooAbsArg *, vector<RooAbsArg *>> extClients;
2571 map<RooAbsArg *, vector<RooAbsArg *>> extValueClients;
2572 map<RooAbsArg *, vector<RooAbsArg *>> extShapeClients;
2577 std::vector<RooAbsArg *> clientsTmp{tmparg->_clientList.begin(), tmparg->_clientList.end()};
2578 for (
auto client : clientsTmp) {
2581 const auto refCount = tmparg->_clientList.refCount(client);
2582 auto &bufferVec = extClients[tmparg];
2584 bufferVec.insert(bufferVec.end(), refCount, client);
2585 tmparg->_clientList.Remove(client,
true);
2590 clientsTmp.assign(tmparg->_clientListValue.begin(), tmparg->_clientListValue.end());
2591 for (
auto vclient : clientsTmp) {
2593 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" <<
GetName() <<
") element " << tmparg->GetName()
2594 <<
" has external value client link to " << vclient <<
" (" << vclient->GetName()
2595 <<
") with ref count " << tmparg->_clientListValue.refCount(vclient) << std::endl;
2597 const auto refCount = tmparg->_clientListValue.refCount(vclient);
2598 auto &bufferVec = extValueClients[tmparg];
2600 bufferVec.insert(bufferVec.end(), refCount, vclient);
2601 tmparg->_clientListValue.Remove(vclient,
true);
2606 clientsTmp.assign(tmparg->_clientListShape.begin(), tmparg->_clientListShape.end());
2607 for (
auto sclient : clientsTmp) {
2609 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" <<
GetName() <<
") element " << tmparg->GetName()
2610 <<
" has external shape client link to " << sclient <<
" (" << sclient->GetName()
2611 <<
") with ref count " << tmparg->_clientListShape.refCount(sclient) << std::endl;
2613 const auto refCount = tmparg->_clientListShape.refCount(sclient);
2614 auto &bufferVec = extShapeClients[tmparg];
2616 bufferVec.insert(bufferVec.end(), refCount, sclient);
2617 tmparg->_clientListShape.Remove(sclient,
true);
2626 for (
auto &iterx : extClients) {
2627 for (
auto client : iterx.second) {
2628 iterx.first->_clientList.Add(client);
2632 for (
auto &iterx : extValueClients) {
2633 for (
auto client : iterx.second) {
2634 iterx.first->_clientListValue.Add(client);
2638 for (
auto &iterx : extShapeClients) {
2639 for (
auto client : iterx.second) {
2640 iterx.first->_clientListShape.Add(client);
2655 map<TString,ClassRelInfo>::const_iterator iter = _c2fmap.begin() ;
2656 while(iter!=_c2fmap.end()) {
2660 ret += iter->first ;
2673 static const UInt_t crctab[256] = { 0x00000000,
2674 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
2675 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
2676 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
2677 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
2678 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
2679 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
2680 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
2681 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
2682 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
2683 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
2684 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
2685 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
2686 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
2687 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
2688 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
2689 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
2690 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
2691 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
2692 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
2693 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
2694 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
2695 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
2696 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
2697 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
2698 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
2699 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
2700 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
2701 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
2702 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
2703 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
2704 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
2705 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
2706 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
2707 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
2708 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
2709 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
2710 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
2711 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
2712 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
2713 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
2714 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
2715 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
2716 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
2717 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
2718 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
2719 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
2720 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
2721 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
2722 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
2723 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
2724 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
2728 while (sz--) crc = (crc << 8) ^
UInt_t(*
data++) ^ crctab[crc >> 24];
2736 unsigned long sz = strlen(
data);
2737 switch (strlen(
data)) {
2749 return crc32(
data + 4, sz - 4, (
data[0] << 24) | (
data[1] << 16) |
2768 bool haveDir=false ;
2773 bool writeExtraHeaders(
false) ;
2776 map<TString,ClassRelInfo>::iterator iter = _c2fmap.begin() ;
2777 while(iter!=_c2fmap.end()) {
2779 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing class " << iter->first.Data() << std::endl ;
2783 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Embedded class "
2784 << iter->first <<
" already in ROOT class table, skipping" << std::endl ;
2794 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() reusing code export directory " << dirName.c_str()
2795 <<
" to extract coded embedded in workspace" << std::endl ;
2798 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() creating code export directory " << dirName.c_str()
2799 <<
" to extract coded embedded in workspace" << std::endl ;
2801 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR creating code export directory " << dirName.c_str()
2802 <<
" to extract coded embedded in workspace" << std::endl ;
2811 if (!writeExtraHeaders) {
2812 writeExtraHeaders = true ;
2814 map<TString,ExtraHeader>::iterator extraIter = _ehmap.begin() ;
2815 while(extraIter!=_ehmap.end()) {
2818 bool needEHWrite=true ;
2819 string fdname =
Form(
"%s/%s",dirName.c_str(),extraIter->second._hname.Data()) ;
2820 ifstream ifdecl(fdname.c_str()) ;
2824 while (ifdecl.getline(buf, 64000)) {
2829 UInt_t crcWS = crc32(extraIter->second._hfile.Data());
2830 needEHWrite = (crcFile != crcWS);
2835 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting extra header file "
2836 << fdname << std::endl;
2841 ofstream fdecl(fdname.c_str());
2843 oocoutE(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file " << fdname
2844 <<
" for writing" << std::endl;
2847 fdecl << extraIter->second._hfile.Data();
2856 ClassFiles& cfinfo = _fmap[iter->second._fileBase] ;
2858 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing file with base " << iter->second._fileBase << std::endl ;
2861 if (cfinfo._extracted) {
2862 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() file with base name " << iter->second._fileBase
2863 <<
" has already been extracted, skipping to next class" << std::endl ;
2868 bool needDeclWrite=true ;
2869 string fdname =
Form(
"%s/%s.%s",dirName.c_str(),iter->second._fileBase.Data(),cfinfo._hext.Data()) ;
2870 ifstream ifdecl(fdname.c_str()) ;
2874 while (ifdecl.getline(buf, 64000)) {
2879 UInt_t crcWS = crc32(cfinfo._hfile.Data()) ;
2880 needDeclWrite = (crcFile!=crcWS) ;
2884 if (needDeclWrite) {
2885 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting declaration code of class " << iter->first <<
", file " << fdname << std::endl ;
2886 ofstream fdecl(fdname.c_str()) ;
2888 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file "
2889 << fdname <<
" for writing" << std::endl ;
2892 fdecl << cfinfo._hfile ;
2897 bool needImplWrite=true ;
2898 string finame =
Form(
"%s/%s.cxx",dirName.c_str(),iter->second._fileBase.Data()) ;
2899 ifstream ifimpl(finame.c_str()) ;
2903 while (ifimpl.getline(buf, 64000)) {
2908 UInt_t crcWS = crc32(cfinfo._cxxfile.Data()) ;
2909 needImplWrite = (crcFile!=crcWS) ;
2913 if (needImplWrite) {
2914 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting implementation code of class " << iter->first <<
", file " << finame << std::endl ;
2915 ofstream fimpl(finame.c_str()) ;
2917 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file"
2918 << finame <<
" for writing" << std::endl ;
2921 fimpl << cfinfo._cxxfile ;
2926 cfinfo._extracted = true ;
2927 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() marking code unit " << iter->second._fileBase <<
" as extracted" << std::endl ;
2930 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Compiling code unit " << iter->second._fileBase.Data() <<
" to define class " << iter->first << std::endl ;
2934 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR compiling class " << iter->first.Data() <<
", to fix this you can do the following: " << std::endl
2935 <<
" 1) Fix extracted source code files in directory " << dirName.c_str() <<
"/" << std::endl
2936 <<
" 2) In clean ROOT session compiled fixed classes by hand using '.x " << dirName.c_str() <<
"/ClassName.cxx+'" << std::endl
2937 <<
" 3) Reopen file with RooWorkspace with broken source code in UPDATE mode. Access RooWorkspace to force loading of class" << std::endl
2938 <<
" Broken instances in workspace will _not_ be compiled, instead precompiled fixed instances will be used." << std::endl
2939 <<
" 4) Reimport fixed code in workspace using 'RooWorkspace::importClassCode(\"*\",true)' method, Write() updated workspace to file and close file" << std::endl
2940 <<
" 5) Reopen file in clean ROOT session to confirm that problems are fixed" << std::endl ;
2967 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" <<
GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << std::endl ;
2969 InternalAppend(
obj) ;
2980 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" <<
GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << std::endl ;
2982 InternalAppend(
obj) ;
2994 if (removedObj ==
_dir)
_dir =
nullptr;
3005 std::vector<std::string> invalidSets;
3008 auto const& setName =
c.first;
3009 auto&
set =
c.second;
3010 std::size_t oldSize =
set.
size();
3015 if(
set.
size() < oldSize && isCacheSet(setName)) {
3016 invalidSets.emplace_back(setName);
3021 for(std::string
const& setName : invalidSets) {
short Version_t
Class version identifier (short)
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
const char Option_t
Option string (const char)
R__EXTERN TClassTable * gClassTable
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 filename
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 bytes
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
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'.
static void ioStreamerPass2Finalize()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
const RefCountList_t & servers() const
List of all servers of this object.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
A space to attach TBranches.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
void useHashMapForFind(bool flag) const
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual bool changeObservableName(const char *from, const char *to)
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
Abstract base class for RooStudyManager modules.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
bool containsInstance(const RooAbsArg &var) const override
Check if this exact instance is in this collection.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
Object to represent discrete states.
Named container for two doubles, two integers two object points and three string pointers that can be...
Configurable parser for RooCmdArg named arguments.
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
bool ok(bool verbose) const
Return true of parsing was successful.
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false) const
Return string property registered with name 'name'.
bool defineString(const char *name, const char *argName, int stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
bool defineInt(const char *name, const char *argName, int intNum, int defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
int getInt(const char *name, int defaultValue=0) const
Return integer property registered with name 'name'.
Singleton class that serves as repository for objects that are expensive to calculate.
static RooExpensiveObjectCache & instance()
Return reference to singleton instance.
void importCacheObjects(RooExpensiveObjectCache &other, const char *ownerName, bool verbose=false)
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
bool Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
TObject * find(const char *name) const
Return pointer to object with given name in collection.
virtual void Add(TObject *arg)
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
virtual bool Remove(TObject *arg)
Remove object from collection.
static RooMsgService & instance()
Return reference to singleton instance.
static bool setAddDirectoryStatus(bool flag)
Configure whether new instances of RooPlot will add themselves to gDirectory.
Variable that can be changed from the outside.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
An interface to set and retrieve a workspace.
std::map< TString, ExtraHeader > _ehmap
void Streamer(TBuffer &) override
Custom streamer for the workspace.
std::string listOfClassNames() const
Return STL string with last of class names contained in the code repository.
bool autoImportClass(TClass *tc, bool doReplace=false)
Import code of class 'tc' into the repository.
bool compileClasses()
For all classes in the workspace for which no class definition is found in the ROOT class table extra...
std::map< TString, ClassRelInfo > _c2fmap
std::map< TString, ClassFiles > _fmap
void InternalAppend(TObject *obj)
Internal access to TDirectory append method.
void Add(TObject *, bool) override
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
TClass * IsA() const override
void Append(TObject *, bool) override
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
Persistable container for RooFit projects.
RooExpensiveObjectCache _eocache
Cache for expensive objects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooLinkedList _genObjects
List of generic objects.
static std::list< std::string > _classDeclDirList
const RooArgSet * getSnapshot(const char *name) const
Return the RooArgSet containing a snapshot of variables contained in the workspace.
static void addClassDeclImportDir(const char *dir)
Add dir to search path for class declaration (header) files.
void Print(Option_t *opts=nullptr) const override
Print contents of the workspace.
RooLinkedList _dataList
List of owned datasets.
RooAbsCategory * catfunc(RooStringView name) const
Retrieve discrete function (RooAbsCategory) with given name. A null pointer is returned if not found.
WSDir * _dir
! Transient ROOT directory representation of workspace
static void addClassImplImportDir(const char *dir)
Add dir to search path for class implementation (.cxx) files.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
std::map< std::string, RooArgSet > _namedSets
Map of named RooArgSets.
RooAbsData * embeddedData(RooStringView name) const
Retrieve dataset (binned or unbinned) 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.
void clearStudies()
Remove all RooStudyManager modules.
bool renameSet(const char *name, const char *newName)
Rename set to a new name.
std::unique_ptr< RooFactoryWSTool > _factory
! Factory tool associated with workspace
RooArgSet allVars() const
Return set with all variable objects.
RooArgSet argSet(RooStringView nameList) const
Return set of RooAbsArgs matching to given list of names.
bool writeToFile(const char *fileName, bool recreate=true)
Save this current workspace into given file.
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 cd(const char *path=nullptr)
RooArgSet allCats() const
Return set with all category objects.
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
RooLinkedList _views
List of model views.
bool commitTransaction()
Commit an ongoing import transaction.
~RooWorkspace() override
Workspace destructor.
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
TObject * Clone(const char *newname="") const override
TObject::Clone() needs to be overridden.
RooArgSet allResolutionModels() const
Return set with all resolution model objects.
RooLinkedList _snapshots
List of parameter snapshots.
bool saveSnapshot(RooStringView, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
RooArgSet allPdfs() const
Return set with all probability density function objects.
void Streamer(TBuffer &) override
Stream an object of class RooWorkspace.
TObject * genobj(RooStringView name) const
Return generic object with given name.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
RooLinkedList _studyMods
List if StudyManager modules.
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
static void setClassFileExportDir(const char *dir=nullptr)
Specify the name of the directory in which embedded source code is unpacked and compiled.
bool importClassCode(const char *pat="*", bool doReplace=false)
Import code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
bool makeDir()
Create transient TDirectory representation of this workspace.
RooArgSet allCatFunctions() const
Return set with all category function objects.
static std::string _classFileExportDir
static std::list< std::string > _classImplDirList
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.
RooWorkspace()
Default constructor.
bool removeSet(const char *name)
Remove a named set from the workspace.
RooArgSet allFunctions() const
Return set with all function objects.
RooFactoryWSTool & factory()
Return instance to factory tool.
bool extendSet(const char *name, const char *newContents)
Define a named set in the workspace through a comma separated list of names of objects already in the...
RooExpensiveObjectCache & expensiveObjectCache()
RooArgSet _sandboxNodes
! Sandbox for incoming objects in a transaction
bool defineSetInternal(const char *name, const RooArgSet &aset)
bool _openTrans
! Is there a transaction open?
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
bool addStudy(RooAbsStudy &study)
Insert RooStudyManager module.
static void autoImportClassCode(bool flag)
If flag is true, source code of classes not the ROOT distribution is automatically imported if on obj...
RooLinkedList _embeddedDataList
List of owned datasets that are embedded in pdfs.
RooArgSet _allOwnedNodes
List of owned pdfs and components.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
std::list< RooAbsData * > allEmbeddedData() const
Return list of all dataset in the workspace.
bool loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
bool defineSet(const char *name, const RooArgSet &aset, bool importMissing=false)
Define a named RooArgSet with given constituents.
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.
Buffer base class used for serializing objects.
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
TClass instances represent classes, structs and namespaces in the ROOT type system.
const char * GetName() const override
Return name of this collection.
Bool_t cd() override
Change current directory to "this" directory.
TDirectory::TContext keeps track and restore the current directory.
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
Mother of all ROOT objects.
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Regular expression class.
const char * Data() const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual const char * Getenv(const char *env)
Get environment variable.
virtual int MakeDirectory(const char *name)
Make a directory.
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename".
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
void(* DirAutoAdd_t)(void *, TDirectory *)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.