78#ifdef ROOFIT_LEGACY_EVAL_BACKEND
95bool isCacheSet(std::string
const& setName) {
97 return setName.rfind(
"CACHE_", 0) == 0;
114list<string> RooWorkspace::_classDeclDirList ;
115list<string> RooWorkspace::_classImplDirList ;
116string RooWorkspace::_classFileExportDir =
".wscode.%s.%s" ;
117bool RooWorkspace::_autoClass = false ;
123void RooWorkspace::addClassDeclImportDir(
const char* dir)
125 _classDeclDirList.push_back(dir) ;
132void RooWorkspace::addClassImplImportDir(
const char* dir)
134 _classImplDirList.push_back(dir) ;
143void RooWorkspace::setClassFileExportDir(
const char* dir)
146 _classFileExportDir = dir ;
148 _classFileExportDir =
".wscode.%s.%s" ;
158void RooWorkspace::autoImportClassCode(
bool flag)
196 TNamed(other), _uuid(other._uuid), _classes(other._classes,this)
199 other._allOwnedNodes.snapshot(_allOwnedNodes,
true) ;
202 for(
TObject *data2 : other._dataList) _dataList.Add(data2->Clone());
205 for(
auto * snap : static_range_cast<RooArgSet*>(other._snapshots)) {
208 snapClone->
setName(snap->GetName()) ;
209 _snapshots.Add(snapClone) ;
213 for (map<string,RooArgSet>::const_iterator iter3 = other._namedSets.begin() ; iter3 != other._namedSets.end() ; ++iter3) {
215 std::unique_ptr<RooArgSet> tmp{
static_cast<RooArgSet*
>(_allOwnedNodes.selectCommon(iter3->second))};
216 _namedSets[iter3->first].
add(*tmp) ;
220 for(
TObject * gobj : other._genObjects) {
228 _genObjects.Add(theClone);
237 if(newname && std::string(newname) !=
GetName()) {
238 out->SetName(newname);
254 _snapshots.Delete() ;
258 _genObjects.Delete() ;
260 _embeddedDataList.Delete();
277 std::vector<std::string> tokens =
ROOT::Split(fileSpec,
":");
280 if (tokens.size() != 3) {
281 std::ostringstream stream;
282 for (
const auto& token : tokens) {
283 stream <<
"\n\t" << token;
285 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR in file specification, expecting 'filename:wsname:objname', but '" << fileSpec <<
"' given."
286 <<
"\nTokens read are:" << stream.str() << endl;
290 const std::string&
filename = tokens[0];
291 const std::string& wsname = tokens[1];
292 const std::string& objname = tokens[2];
297 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR opening file " <<
filename << endl ;
304 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR: No object named " << wsname <<
" in file " <<
filename
305 <<
" or object is not a RooWorkspace" << endl ;
312 bool ret =
import(*warg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
317 bool ret =
import(*wdata,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
321 coutE(InputArguments) <<
"RooWorkspace(" <<
GetName() <<
") ERROR: No RooAbsArg or RooAbsData object named " << objname
322 <<
" in workspace " << wsname <<
" in file " <<
filename << endl ;
338 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::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) {
456 for (
const auto v : *vars) {
457 if (exceptVarNames.find(
v->GetName())==exceptVarNames.end()) {
458 varMap[
v->GetName()] =
Form(
"%s_%s",
v->GetName(),suffixV) ;
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" << endl ;
482 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") Object " << inArg.
GetName() <<
" is already in workspace!" << endl ;
488 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") Recycling existing object " << inArg.
GetName() <<
" created with identical factory specification" << endl ;
497 branchSet.
add(inArg) ;
502 for (
const auto branch : branchSet) {
503 RooAbsArg* wsbranch = _allOwnedNodes.find(branch->GetName()) ;
504 if (wsbranch && wsbranch!=branch && !branch->
getAttribute(
"RooWorkspace::Recycle") && !useExistingNodes) {
505 conflictNodes.
add(*branch) ;
510 if (!conflictNodes.
empty() && !suffix && !useExistingNodes) {
511 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR object named " << inArg.
GetName() <<
": component(s) "
512 << conflictNodes <<
" already in the workspace and no conflict resolution protocol specified" << endl ;
525 conflictNodes.
add(branchSet) ;
529 string topName2 = cloneTop->
GetName() ;
530 if (!renameConflictOrig) {
532 for (
const auto cnode : conflictNodes) {
534 string origName = cnode2->
GetName() ;
537 string tag =
Form(
"ORIGNAME:%s",origName.c_str()) ;
544 if (cnode2==cloneTop) {
549 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName()
550 <<
") Resolving name conflict in workspace by changing name of imported node "
551 << origName <<
" to " << cnode2->
GetName() << endl ;
557 for (
const auto cnode : conflictNodes) {
559 string origName = cnode->GetName() ;
560 RooAbsArg* wsnode = _allOwnedNodes.find(origName.c_str()) ;
567 if (!_allOwnedNodes.find(
Form(
"%s_%s",cnode->GetName(),suffix))) {
568 wsnode->
SetName(
Form(
"%s_%s",cnode->GetName(),suffix)) ;
569 wsnode->
SetTitle(
Form(
"%s (%s)",cnode->GetTitle(),suffix)) ;
572 for (
unsigned int n=1;
true; ++
n) {
573 string newname =
Form(
"%s_%s_%d",cnode->GetName(),suffix,
n) ;
574 if (!_allOwnedNodes.find(newname.c_str())) {
575 wsnode->
SetName(newname.c_str()) ;
576 wsnode->
SetTitle(
Form(
"%s (%s %d)",cnode->GetTitle(),suffix,
n)) ;
582 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName()
583 <<
") Resolving name conflict in workspace by changing name of original node "
584 << origName <<
" to " << wsnode->
GetName() << endl ;
587 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") Internal error: expected to find existing node "
588 << origName <<
" to be renamed, but didn't find it..." << endl ;
595 if (strlen(varChangeIn)>0 || (suffixV && strlen(suffixV)>0)) {
598 for (
const auto cnode : cloneSet) {
600 if (varMap.find(cnode->GetName())!=varMap.end()) {
601 string origName = cnode->GetName() ;
602 cnode->SetName(varMap[cnode->GetName()].c_str()) ;
603 string tag =
Form(
"ORIGNAME:%s",origName.c_str()) ;
604 cnode->setAttribute(tag.c_str()) ;
605 if (!cnode->getStringAttribute(
"origName")) {
606 cnode->setStringAttribute(
"origName",origName.c_str()) ;
610 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") Changing name of variable "
611 << origName <<
" to " << cnode->GetName() <<
" on request" << endl ;
614 if (cnode==cloneTop) {
615 topName2 = cnode->GetName() ;
631 for (
const auto branch2 : branchSet2) {
632 if (_allOwnedNodes.find(branch2->GetName())) {
633 conflictNodes2.
add(*branch2) ;
638 if (!conflictNodes2.
empty()) {
639 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR object named " << inArg.
GetName() <<
": component(s) "
640 << conflictNodes2 <<
" cause naming conflict after conflict resolution protocol was executed" << endl ;
645 for (
const auto node : cloneSet2) {
646 if (node->importWorkspaceHook(*
this)) {
647 coutE(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") ERROR object named " << node->
GetName()
648 <<
" has an error in importing in one or more of its auxiliary objects, aborting" << endl ;
655 for (
const auto node : cloneSet2) {
657 if (!_classes.autoImportClass(node->IsA())) {
658 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") WARNING: problems import class code of object "
659 << node->
ClassName() <<
"::" << node->GetName() <<
", reading of workspace will require external definition of class" << endl ;
665 node->setExpensiveObjectCache(_eocache) ;
669 RooAbsArg* wsnode = _allOwnedNodes.find(node->GetName()) ;
673 if (!silence && useExistingNodes) {
674 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") using existing copy of " << node->
ClassName()
675 <<
"::" << node->GetName() <<
" for import of " << cloneTop2->
ClassName() <<
"::"
676 << cloneTop2->
GetName() << endl ;
678 recycledNodes.
add(*_allOwnedNodes.find(node->GetName())) ;
681 nodesToBeDeleted.
addOwned(std::unique_ptr<RooAbsArg>{node});
688 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") importing " << node->ClassName() <<
"::"
689 << node->GetName() << endl ;
691 _allOwnedNodes.addOwned(std::unique_ptr<RooAbsArg>{node});
693 _sandboxNodes.add(*node) ;
696 _dir->InternalAppend(node) ;
703 if (!recycledNodes.
empty()) {
704 for (
const auto node : cloneSet2) {
705 node->redirectServers(recycledNodes) ;
750 pc.
defineInt(
"embedded",
"Embedded",0,0) ;
760 const char* dsetName = pc.
getString(
"dsetName") ;
761 const char* varChangeIn = pc.
getString(
"varChangeIn") ;
762 const char* varChangeOut = pc.
getString(
"varChangeOut") ;
763 bool embedded = pc.
getInt(
"embedded") ;
767 coutI(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") importing dataset " << inData.
GetName() << endl ;
770 if (dsetName && strlen(dsetName)==0) {
774 RooLinkedList& dataList = embedded ? _embeddedDataList : _dataList ;
781 if (dsetName && dataList.
FindObject(dsetName)) {
782 coutE(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") ERROR dataset with name " << dsetName <<
" already exists in workspace, import aborted" << endl ;
786 coutE(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") ERROR dataset with name " << inData.
GetName() <<
" already exists in workspace, import aborted" << endl ;
794 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") changing name of dataset from " << inData.
GetName() <<
" to " << dsetName << endl ;
802 if (strlen(varChangeIn)>0) {
804 const std::vector<std::string> tokIn =
ROOT::Split(varChangeIn,
",");
805 const std::vector<std::string> tokOut =
ROOT::Split(varChangeOut,
",");
806 for (
unsigned int i=0; i < tokIn.size(); ++i) {
808 coutI(ObjectHandling) <<
"RooWorkSpace::import(" <<
GetName() <<
") changing name of dataset observable " << tokIn[i] <<
" to " << tokOut[i] << endl ;
816 if (!
arg(carg->GetName())) {
822 dataList.
Add(clone) ;
824 _dir->InternalAppend(clone) ;
829 carg->setExpensiveObjectCache(expensiveObjectCache()) ;
847 map<string,RooArgSet>::iterator i = _namedSets.find(
name) ;
848 if (i!=_namedSets.end()) {
849 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") WARNING redefining previously defined named set " <<
name << endl ;
857 if (!
arg(sarg->GetName())) {
861 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR set constituent \"" << sarg->
GetName()
862 <<
"\" is not in workspace and importMissing option is disabled" << endl ;
866 wsargs.
add(*
arg(sarg->GetName())) ;
871 _namedSets[
name].removeAll() ;
872 _namedSets[
name].add(wsargs) ;
878bool RooWorkspace::defineSetInternal(
const char *
name,
const RooArgSet &aset)
885 map<string, RooArgSet>::iterator i = _namedSets.find(
name);
886 if (i != _namedSets.end()) {
887 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName()
888 <<
") WARNING redefining previously defined named set " <<
name << endl;
892 _namedSets[
name].removeAll();
893 _namedSets[
name].add(aset);
905 map<string,RooArgSet>::iterator i = _namedSets.find(
name) ;
906 if (i!=_namedSets.end()) {
907 coutW(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") WARNING redefining previously defined named set " <<
name << endl ;
913 for (
const std::string& token :
ROOT::Split(contentList,
",")) {
915 if (!
arg(token.c_str())) {
916 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR proposed set constituent \"" << token
917 <<
"\" is not in workspace" << endl ;
920 wsargs.
add(*
arg(token.c_str())) ;
924 _namedSets[
name].removeAll() ;
925 _namedSets[
name].add(wsargs) ;
942 for (
const std::string& token :
ROOT::Split(newContents,
",")) {
944 if (!
arg(token.c_str())) {
945 coutE(InputArguments) <<
"RooWorkspace::defineSet(" <<
GetName() <<
") ERROR proposed set constituent \"" << token
946 <<
"\" is not in workspace" << endl ;
949 wsargs.
add(*
arg(token.c_str())) ;
953 _namedSets[
name].add(wsargs,
true) ;
966 std::map<string,RooArgSet>::iterator i = _namedSets.
find(
name.c_str());
967 return (i!=_namedSets.end()) ? &(i->second) :
nullptr;
980 coutE(InputArguments) <<
"RooWorkspace::renameSet(" <<
GetName() <<
") ERROR a set with name " <<
name
981 <<
" does not exist" << endl ;
987 coutE(InputArguments) <<
"RooWorkspace::renameSet(" <<
GetName() <<
") ERROR a set with name " << newName
988 <<
" already exists" << endl ;
993 _namedSets[newName].add(_namedSets[
name]) ;
996 _namedSets.erase(
name) ;
1011 coutE(InputArguments) <<
"RooWorkspace::removeSet(" <<
GetName() <<
") ERROR a set with name " <<
name
1012 <<
" does not exist" << endl ;
1017 _namedSets.erase(
name) ;
1057 for(
RooAbsArg * tmpArg : _sandboxNodes) {
1058 _allOwnedNodes.remove(*tmpArg) ;
1060 _sandboxNodes.removeAll() ;
1063 _openTrans = false ;
1081 _dir->InternalAppend(sarg) ;
1086 _sandboxNodes.removeAll() ;
1089 _openTrans = false ;
1101 return _classes.autoImportClass(theClass,doReplace) ;
1117 for (
RooAbsArg * carg : _allOwnedNodes) {
1118 TString className = carg->ClassName() ;
1119 if (className.
Index(re)>=0 && !_classes.autoImportClass(carg->IsA(),doReplace)) {
1120 coutW(ObjectHandling) <<
"RooWorkspace::import(" <<
GetName() <<
") WARNING: problems import class code of object "
1121 << carg->ClassName() <<
"::" << carg->GetName() <<
", reading of workspace will require external definition of class" << endl ;
1162 snapshot->assign(params) ;
1165 if (std::unique_ptr<RooArgSet> oldSnap{
static_cast<RooArgSet*
>(_snapshots.FindObject(
name.c_str()))}) {
1166 coutI(ObjectHandling) <<
"RooWorkspace::saveSnapshot(" <<
GetName() <<
") replacing previous snapshot with name " <<
name << endl ;
1167 _snapshots.Remove(oldSnap.get()) ;
1170 _snapshots.Add(snapshot) ;
1186 coutE(ObjectHandling) <<
"RooWorkspace::loadSnapshot(" <<
GetName() <<
") no snapshot with name " <<
name <<
" is available" << endl ;
1192 actualParams.
assign(*snap) ;
1216 return dynamic_cast<RooAbsPdf*
>(_allOwnedNodes.find(
name.c_str())) ;
1225 return dynamic_cast<RooAbsReal*
>(_allOwnedNodes.find(
name.c_str())) ;
1234 return dynamic_cast<RooRealVar*
>(_allOwnedNodes.find(
name.c_str())) ;
1243 return dynamic_cast<RooCategory*
>(_allOwnedNodes.find(
name.c_str())) ;
1262 return _allOwnedNodes.find(
name.c_str()) ;
1274 for (
const std::string& token :
ROOT::Split(nameList,
",")) {
1279 std::stringstream ss;
1280 ss <<
" RooWorkspace::argSet(" <<
GetName() <<
") no RooAbsArg named \"" << token <<
"\" in workspace" ;
1281 const std::string errorMsg = ss.str();
1282 coutE(InputArguments) << errorMsg << std::endl;
1283 throw std::runtime_error(errorMsg);
1311 return static_cast<RooAbsData*
>(_dataList.FindObject(
name.c_str())) ;
1320 return static_cast<RooAbsData*
>(_embeddedDataList.FindObject(
name.c_str())) ;
1366RooArgSet RooWorkspace::allFunctions()
const
1387RooArgSet RooWorkspace::allCatFunctions()
const
1406RooArgSet RooWorkspace::allResolutionModels()
const
1444std::list<RooAbsData*> RooWorkspace::allData()
const
1446 std::list<RooAbsData*> ret ;
1448 ret.push_back(dat) ;
1457std::list<RooAbsData*> RooWorkspace::allEmbeddedData()
const
1459 std::list<RooAbsData*> ret ;
1461 ret.push_back(dat) ;
1471std::list<TObject*> RooWorkspace::allGenericObjects()
const
1473 std::list<TObject*> ret ;
1474 for(
TObject * gobj : _genObjects) {
1477 if (gobj->IsA()==RooTObjWrap::Class()) {
1478 ret.push_back((
static_cast<RooTObjWrap*
>(gobj))->obj()) ;
1480 ret.push_back(gobj) ;
1497bool RooWorkspace::CodeRepo::autoImportClass(
TClass* tc,
bool doReplace)
1500 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->
GetName() <<
") request to import code of class " << tc->
GetName() << endl ;
1505 if (!doReplace && _c2fmap.find(tc->
GetName())!=_c2fmap.end()) {
1506 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->
GetName() <<
" already imported, skipping" << endl ;
1512 if (mapEntry && strlen(mapEntry)>0) {
1513 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->
GetName() <<
" is in ROOT distribution, skipping " << endl ;
1522 if (implfile.empty() || declfile.empty()) {
1523 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") ERROR: cannot retrieve code file names for class "
1524 << tc->
GetName() <<
" through ROOT TClass interface, unable to import code" << endl ;
1531 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->
GetName() <<
" is in ROOT distribution, skipping " << endl ;
1539 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING cannot import class "
1540 << tc->
GetName() <<
" : it cannot be persisted because it doesn't have a default constructor. Please fix " << endl ;
1547 std::string declpath;
1548 std::string implpath;
1555 list<string>::iterator diter = RooWorkspace::_classDeclDirList.begin() ;
1557 while(diter!= RooWorkspace::_classDeclDirList.
end()) {
1571 if (declpath.empty()) {
1572 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING Cannot access code of class "
1573 << tc->
GetName() <<
" because header file " << declfile <<
" is not found in current directory nor in $ROOTSYS" ;
1574 if (!_classDeclDirList.empty()) {
1575 ooccoutW(_wspace,ObjectHandling) <<
", nor in the search path " ;
1576 diter = RooWorkspace::_classDeclDirList.begin() ;
1578 while(diter!= RooWorkspace::_classDeclDirList.
end()) {
1580 if (diter!=RooWorkspace::_classDeclDirList.begin()) {
1581 ooccoutW(_wspace,ObjectHandling) <<
"," ;
1583 ooccoutW(_wspace,ObjectHandling) << diter->c_str() ;
1587 ooccoutW(_wspace,ObjectHandling) <<
". To fix this problem, add the required directory to the search "
1588 <<
"path using RooWorkspace::addClassDeclImportDir(const char* dir)" << endl ;
1600 list<string>::iterator iiter = RooWorkspace::_classImplDirList.begin() ;
1602 while(iiter!= RooWorkspace::_classImplDirList.
end()) {
1616 if (implpath.empty()) {
1617 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING Cannot access code of class "
1618 << tc->
GetName() <<
" because implementation file " << implfile <<
" is not found in current directory nor in $ROOTSYS" ;
1619 if (!_classDeclDirList.empty()) {
1620 ooccoutW(_wspace,ObjectHandling) <<
", nor in the search path " ;
1621 iiter = RooWorkspace::_classImplDirList.begin() ;
1623 while(iiter!= RooWorkspace::_classImplDirList.
end()) {
1625 if (iiter!=RooWorkspace::_classImplDirList.begin()) {
1626 ooccoutW(_wspace,ObjectHandling) <<
"," ;
1628 ooccoutW(_wspace,ObjectHandling) << iiter->c_str() ;
1632 ooccoutW(_wspace,ObjectHandling) <<
". To fix this problem add the required directory to the search "
1633 <<
"path using RooWorkspace::addClassImplImportDir(const char* dir)" << endl;
1651 const std::string declfilename = !declpath.empty() ?
gSystem->
BaseName(declpath.c_str())
1655 int dotpos2 = strrchr(declfilename.c_str(),
'.') - declfilename.c_str() ;
1656 string declfilebase = declfilename.substr(0,dotpos2) ;
1657 string declfileext = declfilename.substr(dotpos2+1) ;
1659 list<string> extraHeaders ;
1662 if (_fmap.find(declfilebase) == _fmap.end()) {
1665 std::fstream fdecl(!declpath.empty() ? declpath.c_str() : declfile.c_str());
1669 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1670 <<
") ERROR opening declaration file " << declfile << endl ;
1674 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1675 <<
") importing code of class " << tc->
GetName()
1676 <<
" from " << (!implpath.empty() ? implpath.c_str() : implfile.c_str())
1677 <<
" and " << (!declpath.empty() ? declpath.c_str() : declfile.c_str()) << endl ;
1682 while(fdecl.getline(buf,1023)) {
1685 bool processedInclude = false ;
1686 char* extincfile = nullptr ;
1689 if (strstr(buf,
"#include")) {
1692 strlcpy(tmp, buf, 64000);
1693 bool stdinclude = strchr(buf,
'<');
1694 strtok(tmp,
" <\"");
1695 char *incfile = strtok(
nullptr,
" <>\"");
1700 hpath +=
"/include/";
1703 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1704 <<
") scheduling include file " << incfile <<
" for import" << endl;
1705 extraHeaders.push_back(incfile);
1706 extincfile = incfile;
1707 processedInclude =
true;
1712 if (processedInclude) {
1713 decl +=
"// external include file below retrieved from workspace code storage\n" ;
1714 decl +=
Form(
"#include \"%s\"\n",extincfile) ;
1722 fstream fimpl(!implpath.empty() ? implpath.c_str() : implfile.c_str()) ;
1726 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1727 <<
") ERROR opening implementation file " << implfile << endl ;
1734 while(fimpl.getline(buf,1023)) {
1738 bool foundSelfInclude=false ;
1739 bool processedInclude = false ;
1740 char* extincfile = nullptr ;
1743 if (strstr(buf,
"#include")) {
1746 strlcpy(tmp, buf, 64000);
1747 bool stdinclude = strchr(buf,
'<');
1748 strtok(tmp,
" <\"");
1749 char *incfile = strtok(
nullptr,
" <>\"");
1751 if (strstr(incfile, declfilename.c_str())) {
1752 foundSelfInclude =
true;
1755 if (!stdinclude && !foundSelfInclude) {
1758 hpath +=
"/include/";
1762 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1763 <<
") scheduling include file " << incfile <<
" for import" << endl;
1764 extraHeaders.push_back(incfile);
1765 extincfile = incfile;
1766 processedInclude =
true;
1773 if (foundSelfInclude) {
1776 impl +=
"// class declaration include file below retrieved from workspace code storage\n" ;
1777 impl +=
Form(
"#include \"%s.%s\"\n",declfilebase.c_str(),declfileext.c_str()) ;
1778 }
else if (processedInclude) {
1779 impl +=
"// external include file below retrieved from workspace code storage\n" ;
1780 impl +=
Form(
"#include \"%s\"\n",extincfile) ;
1788 _fmap[declfilebase]._hfile = decl ;
1789 _fmap[declfilebase]._cxxfile = impl ;
1790 _fmap[declfilebase]._hext = declfileext ;
1793 for (list<string>::iterator ehiter = extraHeaders.begin() ; ehiter != extraHeaders.end() ; ++ehiter ) {
1794 if (_ehmap.find(*ehiter) == _ehmap.end()) {
1797 eh._hname = ehiter->c_str() ;
1798 fstream fehdr(ehiter->c_str()) ;
1801 while(fehdr.getline(buf2,1023)) {
1804 if (strstr(buf2,
"#include")) {
1807 strlcpy(tmp, buf2, 64000);
1808 bool stdinclude = strchr(buf,
'<');
1809 strtok(tmp,
" <\"");
1810 char *incfile = strtok(
nullptr,
" <>\"");
1815 hpath +=
"/include/";
1818 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1819 <<
") scheduling recursive include file " << incfile <<
" for import"
1821 extraHeaders.push_back(incfile);
1829 eh._hfile = ehimpl.c_str();
1831 _ehmap[ehiter->c_str()] = eh;
1838 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1839 <<
") code of class " << tc->
GetName()
1840 <<
" was already imported from " << (!implpath.empty() ? implpath : implfile)
1841 <<
" and " << (!declpath.empty() ? declpath.c_str() : declfile.c_str()) << std::endl;
1854 std::list<TClass*> bases ;
1856 if (baseNameList.
Length()>0) {
1857 baseNameList +=
"," ;
1859 baseNameList += base->GetClassPointer()->GetName() ;
1860 bases.push_back(base->GetClassPointer()) ;
1865 _c2fmap[tc->
GetName()]._baseName = baseNameList ;
1866 _c2fmap[tc->
GetName()]._fileBase = declfilebase ;
1869 for(
TClass* bclass : bases) {
1870 autoImportClass(bclass,doReplace) ;
1887bool RooWorkspace::makeDir()
1889 if (_dir)
return true ;
1891 std::string title=
"TDirectory representation of RooWorkspace " + std::string(
GetName());
1892 _dir =
new WSDir(
GetName(),title.c_str(),
this) ;
1894 for (
RooAbsArg * darg : _allOwnedNodes) {
1896 _dir->InternalAppend(darg) ;
1915 std::unique_ptr<TObject> oldObj{_genObjects.FindObject(
object.
GetName())};
1916 if (oldObj && !replaceExisting) {
1917 coutE(InputArguments) <<
"RooWorkspace::import(" <<
GetName() <<
") generic object with name "
1918 <<
object.GetName() <<
" is already in workspace and replaceExisting flag is set to false" << endl ;
1924 object.IsA()->SetDirectoryAutoAdd(
nullptr);
1928 _genObjects.Replace(oldObj.get(),
object.Clone()) ;
1930 _genObjects.Add(
object.
Clone()) ;
1934 object.IsA()->SetDirectoryAutoAdd(func);
1955 std::unique_ptr<TObject> oldObj{_genObjects.FindObject(aliasName)};
1956 if (oldObj && !replaceExisting) {
1957 coutE(InputArguments) <<
"RooWorkspace::import(" <<
GetName() <<
") generic object with name "
1958 << aliasName <<
" is already in workspace and replaceExisting flag is set to false" << endl ;
1963 auto wrapper =
new RooTObjWrap(
object.
Clone()) ;
1965 wrapper->setOwning(
true) ;
1966 wrapper->SetName(aliasName) ;
1967 wrapper->SetTitle(aliasName) ;
1970 _genObjects.Replace(oldObj.get(),wrapper) ;
1972 _genObjects.Add(wrapper) ;
1986 _studyMods.Add(clone) ;
1996void RooWorkspace::clearStudies()
2011 if (ret)
return ret ;
2015 if (ret)
return ret ;
2018 return genobj(
name) ;
2032 if (!gobj)
return nullptr;
2035 if (gobj->
IsA()==RooTObjWrap::Class())
return (
static_cast<RooTObjWrap*
>(gobj))->obj() ;
2044bool RooWorkspace::cd(
const char* path)
2047 return _dir->cd(path) ;
2055bool RooWorkspace::writeToFile(
const char* fileName,
bool recreate)
2057 TFile f(fileName,recreate?
"RECREATE":
"UPDATE") ;
2072 cxcoutD(ObjectHandling) <<
"INFO: Creating RooFactoryWSTool associated with this workspace" << endl ;
2073 _factory = make_unique<RooFactoryWSTool>(*
this);
2086 return factory().process(expr.
c_str()) ;
2097 bool treeMode(
false) ;
2099 if (
TString(opts).Contains(
"t")) {
2102 if (
TString(opts).Contains(
"v")) {
2106 cout << endl <<
"RooWorkspace(" <<
GetName() <<
") " <<
GetTitle() <<
" contents" << endl << endl ;
2126 if (!parg->hasClients()) {
2135 if (!parg->hasClients()) {
2136 funcSet.
add(*parg) ;
2143 if (!parg->hasClients()) {
2144 catfuncSet.
add(*parg) ;
2152 convResoSet.
add(*parg) ;
2154 resoSet.
add(*parg) ;
2167 funcSet.
add(*parg) ;
2172 catfuncSet.
add(*parg) ;
2190 if (!varSet.
empty()) {
2192 cout <<
"variables" << endl ;
2193 cout <<
"---------" << endl ;
2194 cout << varSet << endl ;
2198 if (!pdfSet.
empty()) {
2199 cout <<
"p.d.f.s" << endl ;
2200 cout <<
"-------" << endl ;
2204 parg->printComponentTree() ;
2213 if (!resoSet.
empty()) {
2214 cout <<
"analytical resolution models" << endl ;
2215 cout <<
"----------------------------" << endl ;
2224 if (!funcSet.
empty()) {
2225 cout <<
"functions" << endl ;
2226 cout <<
"--------" << endl ;
2230 parg->printComponentTree() ;
2238 if (!catfuncSet.
empty()) {
2239 cout <<
"category functions" << endl ;
2240 cout <<
"------------------" << endl ;
2244 parg->printComponentTree() ;
2252 if (!_dataList.empty()) {
2253 cout <<
"datasets" << endl ;
2254 cout <<
"--------" << endl ;
2256 std::cout << data2->ClassName() <<
"::" << data2->GetName() << *data2->get() << std::endl;
2258 std::cout << std::endl ;
2261 if (!_embeddedDataList.empty()) {
2262 cout <<
"embedded datasets (in pdfs and functions)" << endl ;
2263 cout <<
"-----------------------------------------" << endl ;
2265 cout << data2->ClassName() <<
"::" << data2->GetName() << *data2->get() << endl ;
2270 if (!_snapshots.empty()) {
2271 cout <<
"parameter snapshots" << endl ;
2272 cout <<
"-------------------" << endl ;
2274 cout << snap->GetName() <<
" = (" ;
2277 if (
first) {
first=false ; }
else { cout <<
"," ; }
2278 cout <<
a->GetName() <<
"=" ;
2279 a->printValue(cout) ;
2280 if (
a->isConstant()) {
2284 cout <<
")" << endl ;
2290 if (!_namedSets.empty()) {
2291 cout <<
"named sets" << endl ;
2292 cout <<
"----------" << endl ;
2293 for (map<string,RooArgSet>::const_iterator it = _namedSets.begin() ; it != _namedSets.end() ; ++it) {
2294 if (verbose || !isCacheSet(it->first)) {
2295 cout << it->first <<
":" << it->second << endl;
2303 if (!_genObjects.empty()) {
2304 cout <<
"generic objects" << endl ;
2305 cout <<
"---------------" << endl ;
2306 for(
TObject* gobj : _genObjects) {
2307 if (gobj->
IsA()==RooTObjWrap::Class()) {
2308 cout << (static_cast<RooTObjWrap*>(gobj))->obj()->ClassName() <<
"::" << gobj->
GetName() << endl ;
2317 if (!_studyMods.empty()) {
2318 cout <<
"study modules" << endl ;
2319 cout <<
"-------------" << endl ;
2320 for(
TObject* smobj : _studyMods) {
2321 cout << smobj->ClassName() <<
"::" << smobj->GetName() << endl ;
2327 if (!_classes.listOfClassNames().empty()) {
2328 cout <<
"embedded class code" << endl ;
2329 cout <<
"-------------------" << endl ;
2330 cout << _classes.listOfClassNames() << endl ;
2334 if (!_eocache.empty()) {
2335 cout <<
"embedded precalculated expensive components" << endl ;
2336 cout <<
"-------------------------------------------" << endl ;
2352void RooWorkspace::CodeRepo::Streamer(
TBuffer &R__b)
2354 typedef ::RooWorkspace::CodeRepo thisClass;
2369 _fmap[
name]._hext.Streamer(R__b);
2370 _fmap[
name]._hfile.Streamer(R__b);
2371 _fmap[
name]._cxxfile.Streamer(R__b);
2380 _c2fmap[
name]._baseName.Streamer(R__b);
2381 _c2fmap[
name]._fileBase.Streamer(R__b);
2391 _ehmap[
name]._hname.Streamer(R__b);
2392 _ehmap[
name]._hfile.Streamer(R__b);
2399 _compiledOK = !compileClasses();
2407 UInt_t count = _fmap.size();
2409 map<TString, ClassFiles>::iterator iter = _fmap.begin();
2410 while (iter != _fmap.end()) {
2411 TString key_copy(iter->first);
2412 key_copy.Streamer(R__b);
2413 iter->second._hext.Streamer(R__b);
2414 iter->second._hfile.Streamer(R__b);
2415 iter->second._cxxfile.Streamer(R__b);
2421 count = _c2fmap.size();
2423 map<TString, ClassRelInfo>::iterator iter2 = _c2fmap.begin();
2424 while (iter2 != _c2fmap.end()) {
2425 TString key_copy(iter2->first);
2426 key_copy.Streamer(R__b);
2427 iter2->second._baseName.Streamer(R__b);
2428 iter2->second._fileBase.Streamer(R__b);
2433 count = _ehmap.size();
2435 map<TString, ExtraHeader>::iterator iter3 = _ehmap.begin();
2436 while (iter3 != _ehmap.end()) {
2437 TString key_copy(iter3->first);
2438 key_copy.Streamer(R__b);
2439 iter3->second._hname.Streamer(R__b);
2440 iter3->second._hfile.Streamer(R__b);
2464 for (
RooAbsArg *node : _allOwnedNodes) {
2465 node->ioStreamerPass2();
2471 for (
RooAbsArg *node : _allOwnedNodes) {
2472 node->setExpensiveObjectCache(_eocache);
2473 node->setWorkspace(*
this);
2474#ifdef ROOFIT_LEGACY_EVAL_BACKEND
2478 cout <<
"RooWorkspace::Streamer(" <<
GetName() <<
") " << node->
ClassName() <<
"::" << node->GetName()
2489 map<RooAbsArg *, vector<RooAbsArg *>> extClients;
2490 map<RooAbsArg *, vector<RooAbsArg *>> extValueClients;
2491 map<RooAbsArg *, vector<RooAbsArg *>> extShapeClients;
2493 for (
RooAbsArg *tmparg : _allOwnedNodes) {
2496 std::vector<RooAbsArg *> clientsTmp{tmparg->_clientList.begin(), tmparg->_clientList.end()};
2497 for (
auto client : clientsTmp) {
2498 if (!_allOwnedNodes.containsInstance(*client)) {
2500 const auto refCount = tmparg->_clientList.refCount(client);
2501 auto &bufferVec = extClients[tmparg];
2503 bufferVec.insert(bufferVec.end(), refCount, client);
2504 tmparg->_clientList.Remove(client,
true);
2509 clientsTmp.assign(tmparg->_clientListValue.begin(), tmparg->_clientListValue.end());
2510 for (
auto vclient : clientsTmp) {
2511 if (!_allOwnedNodes.containsInstance(*vclient)) {
2512 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" <<
GetName() <<
") element " << tmparg->GetName()
2513 <<
" has external value client link to " << vclient <<
" (" << vclient->GetName()
2514 <<
") with ref count " << tmparg->_clientListValue.refCount(vclient) << endl;
2516 const auto refCount = tmparg->_clientListValue.refCount(vclient);
2517 auto &bufferVec = extValueClients[tmparg];
2519 bufferVec.insert(bufferVec.end(), refCount, vclient);
2520 tmparg->_clientListValue.Remove(vclient,
true);
2525 clientsTmp.assign(tmparg->_clientListShape.begin(), tmparg->_clientListShape.end());
2526 for (
auto sclient : clientsTmp) {
2527 if (!_allOwnedNodes.containsInstance(*sclient)) {
2528 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" <<
GetName() <<
") element " << tmparg->GetName()
2529 <<
" has external shape client link to " << sclient <<
" (" << sclient->GetName()
2530 <<
") with ref count " << tmparg->_clientListShape.refCount(sclient) << endl;
2532 const auto refCount = tmparg->_clientListShape.refCount(sclient);
2533 auto &bufferVec = extShapeClients[tmparg];
2535 bufferVec.insert(bufferVec.end(), refCount, sclient);
2536 tmparg->_clientListShape.Remove(sclient,
true);
2545 for (
auto &iterx : extClients) {
2546 for (
auto client : iterx.second) {
2547 iterx.first->_clientList.Add(client);
2551 for (
auto &iterx : extValueClients) {
2552 for (
auto client : iterx.second) {
2553 iterx.first->_clientListValue.Add(client);
2557 for (
auto &iterx : extShapeClients) {
2558 for (
auto client : iterx.second) {
2559 iterx.first->_clientListShape.Add(client);
2571std::string RooWorkspace::CodeRepo::listOfClassNames()
const
2574 map<TString,ClassRelInfo>::const_iterator iter = _c2fmap.begin() ;
2575 while(iter!=_c2fmap.end()) {
2579 ret += iter->first ;
2592 static const UInt_t crctab[256] = { 0x00000000,
2593 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
2594 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
2595 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
2596 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
2597 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
2598 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
2599 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
2600 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
2601 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
2602 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
2603 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
2604 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
2605 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
2606 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
2607 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
2608 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
2609 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
2610 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
2611 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
2612 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
2613 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
2614 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
2615 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
2616 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
2617 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
2618 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
2619 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
2620 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
2621 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
2622 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
2623 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
2624 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
2625 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
2626 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
2627 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
2628 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
2629 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
2630 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
2631 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
2632 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
2633 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
2634 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
2635 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
2636 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
2637 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
2638 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
2639 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
2640 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
2641 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
2642 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
2643 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
2647 while (sz--) crc = (crc << 8) ^
UInt_t(*
data++) ^ crctab[crc >> 24];
2655 unsigned long sz = strlen(
data);
2656 switch (strlen(
data)) {
2668 return crc32(
data + 4, sz - 4, (
data[0] << 24) | (
data[1] << 16) |
2684bool RooWorkspace::CodeRepo::compileClasses()
2686 bool haveDir=false ;
2689 string dirName =
Form(_classFileExportDir.c_str(),_wspace->uuid().AsString(),_wspace->GetName()) ;
2691 bool writeExtraHeaders(
false) ;
2694 map<TString,ClassRelInfo>::iterator iter = _c2fmap.begin() ;
2695 while(iter!=_c2fmap.end()) {
2697 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing class " << iter->first.Data() << endl ;
2701 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Embedded class "
2702 << iter->first <<
" already in ROOT class table, skipping" << endl ;
2712 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() reusing code export directory " << dirName.c_str()
2713 <<
" to extract coded embedded in workspace" << endl ;
2716 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() creating code export directory " << dirName.c_str()
2717 <<
" to extract coded embedded in workspace" << endl ;
2719 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR creating code export directory " << dirName.c_str()
2720 <<
" to extract coded embedded in workspace" << endl ;
2729 if (!writeExtraHeaders) {
2730 writeExtraHeaders = true ;
2732 map<TString,ExtraHeader>::iterator extraIter = _ehmap.begin() ;
2733 while(extraIter!=_ehmap.end()) {
2736 bool needEHWrite=true ;
2737 string fdname =
Form(
"%s/%s",dirName.c_str(),extraIter->second._hname.Data()) ;
2738 ifstream ifdecl(fdname.c_str()) ;
2742 while (ifdecl.getline(buf, 64000)) {
2747 UInt_t crcWS = crc32(extraIter->second._hfile.Data());
2748 needEHWrite = (crcFile != crcWS);
2753 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting extra header file "
2759 ofstream fdecl(fdname.c_str());
2761 oocoutE(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file " << fdname
2762 <<
" for writing" << endl;
2765 fdecl << extraIter->second._hfile.Data();
2774 ClassFiles& cfinfo = _fmap[iter->second._fileBase] ;
2776 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing file with base " << iter->second._fileBase << endl ;
2779 if (cfinfo._extracted) {
2780 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() file with base name " << iter->second._fileBase
2781 <<
" has already been extracted, skipping to next class" << endl ;
2786 bool needDeclWrite=true ;
2787 string fdname =
Form(
"%s/%s.%s",dirName.c_str(),iter->second._fileBase.Data(),cfinfo._hext.Data()) ;
2788 ifstream ifdecl(fdname.c_str()) ;
2792 while (ifdecl.getline(buf, 64000)) {
2797 UInt_t crcWS = crc32(cfinfo._hfile.Data()) ;
2798 needDeclWrite = (crcFile!=crcWS) ;
2802 if (needDeclWrite) {
2803 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting declaration code of class " << iter->first <<
", file " << fdname << endl ;
2804 ofstream fdecl(fdname.c_str()) ;
2806 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file "
2807 << fdname <<
" for writing" << endl ;
2810 fdecl << cfinfo._hfile ;
2815 bool needImplWrite=true ;
2816 string finame =
Form(
"%s/%s.cxx",dirName.c_str(),iter->second._fileBase.Data()) ;
2817 ifstream ifimpl(finame.c_str()) ;
2821 while (ifimpl.getline(buf, 64000)) {
2826 UInt_t crcWS = crc32(cfinfo._cxxfile.Data()) ;
2827 needImplWrite = (crcFile!=crcWS) ;
2831 if (needImplWrite) {
2832 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting implementation code of class " << iter->first <<
", file " << finame << endl ;
2833 ofstream fimpl(finame.c_str()) ;
2835 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file"
2836 << finame <<
" for writing" << endl ;
2839 fimpl << cfinfo._cxxfile ;
2844 cfinfo._extracted = true ;
2845 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() marking code unit " << iter->second._fileBase <<
" as extracted" << endl ;
2848 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Compiling code unit " << iter->second._fileBase.Data() <<
" to define class " << iter->first << endl ;
2852 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR compiling class " << iter->first.Data() <<
", to fix this you can do the following: " << endl
2853 <<
" 1) Fix extracted source code files in directory " << dirName.c_str() <<
"/" << endl
2854 <<
" 2) In clean ROOT session compiled fixed classes by hand using '.x " << dirName.c_str() <<
"/ClassName.cxx+'" << endl
2855 <<
" 3) Reopen file with RooWorkspace with broken source code in UPDATE mode. Access RooWorkspace to force loading of class" << endl
2856 <<
" Broken instances in workspace will _not_ be compiled, instead precompiled fixed instances will be used." << endl
2857 <<
" 4) Reimport fixed code in workspace using 'RooWorkspace::importClassCode(\"*\",true)' method, Write() updated workspace to file and close file" << endl
2858 <<
" 5) Reopen file in clean ROOT session to confirm that problems are fixed" << endl ;
2873void RooWorkspace::WSDir::InternalAppend(
TObject* obj)
2882void RooWorkspace::WSDir::Add(
TObject* obj,
bool)
2885 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" << GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << endl ;
2887 InternalAppend(obj) ;
2895void RooWorkspace::WSDir::Append(
TObject* obj,
bool)
2898 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" << GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << endl ;
2900 InternalAppend(obj) ;
2911 _dataList.RecursiveRemove(removedObj);
2912 if (removedObj == _dir) _dir =
nullptr;
2914 _allOwnedNodes.RecursiveRemove(removedObj);
2916 _dataList.RecursiveRemove(removedObj);
2917 _embeddedDataList.RecursiveRemove(removedObj);
2918 _views.RecursiveRemove(removedObj);
2919 _snapshots.RecursiveRemove(removedObj);
2920 _genObjects.RecursiveRemove(removedObj);
2921 _studyMods.RecursiveRemove(removedObj);
2923 std::vector<std::string> invalidSets;
2925 for(
auto &
c : _namedSets) {
2926 auto const& setName =
c.first;
2927 auto&
set =
c.second;
2928 std::size_t oldSize =
set.
size();
2933 if(
set.
size() < oldSize && isCacheSet(setName)) {
2934 invalidSets.emplace_back(setName);
2939 for(std::string
const& setName : invalidSets) {
2943 _eocache.RecursiveRemove(removedObj);
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
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
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 ...
void SetName(const char *name) override
Set the name of the TNamed.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
A space to attach TBranches.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
const char * GetName() const override
Returns name of object.
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.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
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 base class for test statistics objects that evaluate a function or PDF at each point of a gi...
const char * sealNotice() const
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.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), 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.
void importCacheObjects(RooExpensiveObjectCache &other, const char *ownerName, bool verbose=false)
A wrapper around TIterator derivatives.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
Int_t getHashTableSize() const
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.
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
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...
const char * c_str() const
An interface to set and retrieve a workspace.
virtual void ReplaceWS(RooWorkspace *ws)=0
Set the workspace irrespective of what the previous workspace is.
Persistable container for RooFit projects.
const RooArgSet * getSnapshot(const char *name) const
Return the RooArgSet containing a snapshot of variables contained in the workspace.
RooAbsCategory * catfunc(RooStringView name) const
Retrieve discrete function (RooAbsCategory) with given name. A null pointer is returned if not found.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
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.
bool renameSet(const char *name, const char *newName)
Rename set to a new name.
TIterator * componentIterator() const R__DEPRECATED(6
RooArgSet argSet(RooStringView nameList) const
Return set of RooAbsArgs matching to given list of names.
const RooArgSet * set(RooStringView name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
~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.
bool saveSnapshot(RooStringView, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
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...
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.
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.
RooWorkspace()
Default constructor.
bool removeSet(const char *name)
Remove a named set from the workspace.
bool extendSet(const char *name, const char *newContents)
Define a named set in the work space through a comma separated list of names of objects already in th...
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 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.
Each class (see TClass) has a linked list of its base class(es).
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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 * GetImplFileName() const
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Bool_t HasDefaultConstructor(Bool_t testio=kFALSE) const
Return true if we have access to a constructor usable for I/O.
const char * GetDeclFileName() const
Return name of the file containing the declaration of this class.
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
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.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Iterator abstract base class.
The TNamed class is the base class for all named ROOT classes.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
void Print(Option_t *option="") const override
Print TNamed name and title.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual void Delete(Option_t *option="")
Delete this object.
virtual TClass * IsA() const
Regular expression class.
const char * Data() const
virtual void Streamer(TBuffer &)
Stream a string object.
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 char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
virtual int MakeDirectory(const char *name)
Make a directory.
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.