75 ClassImp(RooWorkspace);
79 ClassImp(RooWorkspace::CodeRepo);
83 ClassImp(RooWorkspace::WSDir);
85 list<string> RooWorkspace::_classDeclDirList ;
86 list<string> RooWorkspace::_classImplDirList ;
87 string RooWorkspace::_classFileExportDir =
".wscode.%s.%s" ;
88 Bool_t RooWorkspace::_autoClass = kFALSE ;
94 void RooWorkspace::addClassDeclImportDir(
const char* dir)
96 _classDeclDirList.push_back(dir) ;
103 void RooWorkspace::addClassImplImportDir(
const char* dir)
105 _classImplDirList.push_back(dir) ;
114 void RooWorkspace::setClassFileExportDir(
const char* dir)
117 _classFileExportDir = dir ;
119 _classFileExportDir =
".wscode.%s.%s" ;
129 void RooWorkspace::autoImportClassCode(Bool_t flag)
139 RooWorkspace::RooWorkspace() : _classes(this), _dir(nullptr), _factory(nullptr), _doExport(kFALSE), _openTrans(kFALSE)
148 RooWorkspace::RooWorkspace(
const char* name,
const char* title) :
149 TNamed(name,title?title:name), _classes(this), _dir(nullptr), _factory(nullptr), _doExport(kFALSE), _openTrans(kFALSE)
154 RooWorkspace::RooWorkspace(
const char* name, Bool_t doCINTExport) :
155 TNamed(name,name), _classes(this), _dir(nullptr), _factory(nullptr), _doExport(kFALSE), _openTrans(kFALSE)
167 RooWorkspace::RooWorkspace(
const RooWorkspace& other) :
168 TNamed(other), _uuid(other._uuid), _classes(other._classes,this), _dir(nullptr), _factory(nullptr), _doExport(kFALSE), _openTrans(kFALSE)
171 other._allOwnedNodes.snapshot(_allOwnedNodes,kTRUE) ;
174 TIterator* iter = other._dataList.MakeIterator() ;
176 while((data2=iter->Next())) {
177 _dataList.Add(data2->Clone()) ;
182 TIterator* iter2 = other._snapshots.MakeIterator() ;
184 while((snap=(RooArgSet*)iter2->Next())) {
185 RooArgSet* snapClone = (RooArgSet*) snap->snapshot() ;
186 snapClone->setName(snap->GetName()) ;
187 _snapshots.Add(snapClone) ;
192 for (map<string,RooArgSet>::const_iterator iter3 = other._namedSets.begin() ; iter3 != other._namedSets.end() ; ++iter3) {
194 RooArgSet* tmp = (RooArgSet*) _allOwnedNodes.selectCommon(iter3->second) ;
195 _namedSets[iter3->first].add(*tmp) ;
200 TIterator* iter4 = other._genObjects.MakeIterator() ;
202 while((gobj=iter4->Next())) {
203 TObject *theClone = gobj->Clone();
205 auto handle =
dynamic_cast<RooWorkspaceHandle*
>(theClone);
207 handle->ReplaceWS(
this);
210 _genObjects.Add(theClone);
221 RooWorkspace::~RooWorkspace()
233 _snapshots.Delete() ;
237 _genObjects.Delete() ;
245 Bool_t RooWorkspace::import(
const char* fileSpec,
246 const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
247 const RooCmdArg& arg4,
const RooCmdArg& arg5,
const RooCmdArg& arg6,
248 const RooCmdArg& arg7,
const RooCmdArg& arg8,
const RooCmdArg& arg9)
251 std::vector<std::string> tokens = RooHelpers::tokenise(fileSpec,
":");
254 if (tokens.size() != 3) {
255 std::ostringstream stream;
256 for (
const auto& token : tokens) {
257 stream <<
"\n\t" << token;
259 coutE(InputArguments) <<
"RooWorkspace(" << GetName() <<
") ERROR in file specification, expecting 'filename:wsname:objname', but '" << fileSpec <<
"' given."
260 <<
"\nTokens read are:" << stream.str() << endl;
264 const std::string& filename = tokens[0];
265 const std::string& wsname = tokens[1];
266 const std::string& objname = tokens[2];
269 TFile* f = TFile::Open(filename.c_str()) ;
271 coutE(InputArguments) <<
"RooWorkspace(" << GetName() <<
") ERROR opening file " << filename << endl ;
276 RooWorkspace* w =
dynamic_cast<RooWorkspace*
>(f->Get(wsname.c_str())) ;
278 coutE(InputArguments) <<
"RooWorkspace(" << GetName() <<
") ERROR: No object named " << wsname <<
" in file " << filename
279 <<
" or object is not a RooWorkspace" << endl ;
284 RooAbsArg* warg = w->arg(objname.c_str()) ;
286 Bool_t ret =
import(*warg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
290 RooAbsData* wdata = w->data(objname.c_str()) ;
292 Bool_t ret =
import(*wdata,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
297 coutE(InputArguments) <<
"RooWorkspace(" << GetName() <<
") ERROR: No RooAbsArg or RooAbsData object named " << objname
298 <<
" in workspace " << wsname <<
" in file " << filename << endl ;
307 Bool_t RooWorkspace::import(
const RooArgSet& args,
308 const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
309 const RooCmdArg& arg4,
const RooCmdArg& arg5,
const RooCmdArg& arg6,
310 const RooCmdArg& arg7,
const RooCmdArg& arg8,
const RooCmdArg& arg9)
312 unique_ptr<TIterator> iter(args.createIterator()) ;
315 while((oneArg=(RooAbsArg*)iter->Next())) {
316 ret |=
import(*oneArg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) ;
349 Bool_t RooWorkspace::import(
const RooAbsArg& inArg,
350 const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
351 const RooCmdArg& arg4,
const RooCmdArg& arg5,
const RooCmdArg& arg6,
352 const RooCmdArg& arg7,
const RooCmdArg& arg8,
const RooCmdArg& arg9)
355 args.Add((TObject*)&arg1) ;
356 args.Add((TObject*)&arg2) ;
357 args.Add((TObject*)&arg3) ;
358 args.Add((TObject*)&arg4) ;
359 args.Add((TObject*)&arg5) ;
360 args.Add((TObject*)&arg6) ;
361 args.Add((TObject*)&arg7) ;
362 args.Add((TObject*)&arg8) ;
363 args.Add((TObject*)&arg9) ;
366 RooCmdConfig pc(Form(
"RooWorkspace::import(%s)",GetName())) ;
368 pc.defineString(
"conflictSuffix",
"RenameConflictNodes",0) ;
369 pc.defineInt(
"renameConflictOrig",
"RenameConflictNodes",0,0) ;
370 pc.defineString(
"allSuffix",
"RenameAllNodes",0) ;
371 pc.defineString(
"allVarsSuffix",
"RenameAllVariables",0) ;
372 pc.defineString(
"allVarsExcept",
"RenameAllVariables",1) ;
373 pc.defineString(
"varChangeIn",
"RenameVar",0,
"",kTRUE) ;
374 pc.defineString(
"varChangeOut",
"RenameVar",1,
"",kTRUE) ;
375 pc.defineString(
"factoryTag",
"FactoryTag",0) ;
376 pc.defineInt(
"useExistingNodes",
"RecycleConflictNodes",0,0) ;
377 pc.defineInt(
"silence",
"Silence",0,0) ;
378 pc.defineInt(
"noRecursion",
"NoRecursion",0,0) ;
379 pc.defineMutex(
"RenameConflictNodes",
"RenameAllNodes") ;
380 pc.defineMutex(
"RenameConflictNodes",
"RecycleConflictNodes") ;
381 pc.defineMutex(
"RenameAllNodes",
"RecycleConflictNodes") ;
382 pc.defineMutex(
"RenameVariable",
"RenameAllVariables") ;
391 const char* suffixC = pc.getString(
"conflictSuffix") ;
392 const char* suffixA = pc.getString(
"allSuffix") ;
393 const char* suffixV = pc.getString(
"allVarsSuffix") ;
394 const char* exceptVars = pc.getString(
"allVarsExcept") ;
395 const char* varChangeIn = pc.getString(
"varChangeIn") ;
396 const char* varChangeOut = pc.getString(
"varChangeOut") ;
397 Bool_t renameConflictOrig = pc.getInt(
"renameConflictOrig") ;
398 Int_t useExistingNodes = pc.getInt(
"useExistingNodes") ;
399 Int_t silence = pc.getInt(
"silence") ;
400 Int_t noRecursion = pc.getInt(
"noRecursion") ;
404 if (suffixC && strlen(suffixC)==0) suffixC = 0 ;
405 if (suffixA && strlen(suffixA)==0) suffixA = 0 ;
407 Bool_t conflictOnly = suffixA ? kFALSE : kTRUE ;
408 const char* suffix = suffixA ? suffixA : suffixC ;
411 map<string,string> varMap ;
412 if (strlen(varChangeIn)>0) {
415 const std::vector<std::string> tokIn = RooHelpers::tokenise(varChangeIn,
", ");
416 const std::vector<std::string> tokOut = RooHelpers::tokenise(varChangeOut,
", ");
417 for (
unsigned int i=0; i < tokIn.size(); ++i) {
418 varMap.insert(std::make_pair(tokIn[i], tokOut[i]));
421 assert(tokIn.size() == tokOut.size());
426 std::set<string> exceptVarNames ;
427 if (exceptVars && strlen(exceptVars)) {
428 const std::vector<std::string> toks = RooHelpers::tokenise(exceptVars,
", ");
429 exceptVarNames.insert(toks.begin(), toks.end());
432 if (suffixV != 0 && strlen(suffixV)>0) {
433 RooArgSet* vars = inArg.getVariables() ;
434 TIterator* iter = vars->createIterator() ;
436 while((v=(RooAbsArg*)iter->Next())) {
437 if (exceptVarNames.find(v->GetName())==exceptVarNames.end()) {
438 varMap[v->GetName()] = Form(
"%s_%s",v->GetName(),suffixV) ;
446 RooAbsArg* wsarg = _allOwnedNodes.find(inArg.GetName()) ;
449 const char* tagIn = inArg.getStringAttribute(
"factory_tag") ;
450 const char* tagWs = wsarg ? wsarg->getStringAttribute(
"factory_tag") : 0 ;
451 Bool_t factoryMatch = (tagIn && tagWs && !strcmp(tagIn,tagWs)) ;
453 ((RooAbsArg&)inArg).setAttribute(
"RooWorkspace::Recycle") ;
456 if (!suffix && wsarg && !useExistingNodes && !(inArg.isFundamental() && varMap[inArg.GetName()]!=
"")) {
459 coutE(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") ERROR importing object named " << inArg.GetName()
460 <<
": another instance with same name already in the workspace and no conflict resolution protocol specified" << endl ;
464 coutI(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") Object " << inArg.GetName() <<
" is already in workspace!" << endl ;
469 coutI(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") Recycling existing object " << inArg.GetName() <<
" created with identical factory specification" << endl ;
474 RooArgSet conflictNodes ;
475 RooArgSet branchSet ;
477 branchSet.add(inArg) ;
479 inArg.branchNodeServerList(&branchSet) ;
481 TIterator* iter = branchSet.createIterator() ;
483 while ((branch=(RooAbsArg*)iter->Next())) {
484 RooAbsArg* wsbranch = _allOwnedNodes.find(branch->GetName()) ;
485 if (wsbranch && wsbranch!=branch && !branch->getAttribute(
"RooWorkspace::Recycle") && !useExistingNodes) {
486 conflictNodes.add(*branch) ;
492 if (conflictNodes.getSize()>0 && !suffix && !useExistingNodes) {
493 coutE(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") ERROR object named " << inArg.GetName() <<
": component(s) "
494 << conflictNodes <<
" already in the workspace and no conflict resolution protocol specified" << endl ;
499 RooArgSet* cloneSet = (RooArgSet*) RooArgSet(inArg).snapshot(noRecursion==kFALSE) ;
500 RooAbsArg* cloneTop = cloneSet->find(inArg.GetName()) ;
504 conflictNodes.removeAll() ;
505 conflictNodes.add(branchSet) ;
509 string topName2 = cloneTop->GetName() ;
510 if (!renameConflictOrig) {
512 TIterator* citer = conflictNodes.createIterator() ;
514 while ((cnode=(RooAbsArg*)citer->Next())) {
515 RooAbsArg* cnode2 = cloneSet->find(cnode->GetName()) ;
516 string origName = cnode2->GetName() ;
517 cnode2->SetName(Form(
"%s_%s",cnode2->GetName(),suffix)) ;
518 cnode2->SetTitle(Form(
"%s (%s)",cnode2->GetTitle(),suffix)) ;
519 string tag = Form(
"ORIGNAME:%s",origName.c_str()) ;
520 cnode2->setAttribute(tag.c_str()) ;
521 if (!cnode2->getStringAttribute(
"origName")) {
522 string tag2 = Form(
"%s",origName.c_str()) ;
523 cnode2->setStringAttribute(
"origName",tag2.c_str()) ;
527 if (cnode2==cloneTop) {
528 topName2 = cnode2->GetName() ;
532 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName()
533 <<
") Resolving name conflict in workspace by changing name of imported node "
534 << origName <<
" to " << cnode2->GetName() << endl ;
541 TIterator* citer = conflictNodes.createIterator() ;
543 while ((cnode=(RooAbsArg*)citer->Next())) {
545 string origName = cnode->GetName() ;
546 RooAbsArg* wsnode = _allOwnedNodes.find(origName.c_str()) ;
549 if (!wsnode->getStringAttribute(
"origName")) {
550 wsnode->setStringAttribute(
"origName",wsnode->GetName()) ;
553 if (!_allOwnedNodes.find(Form(
"%s_%s",cnode->GetName(),suffix))) {
554 wsnode->SetName(Form(
"%s_%s",cnode->GetName(),suffix)) ;
555 wsnode->SetTitle(Form(
"%s (%s)",cnode->GetTitle(),suffix)) ;
560 string newname = Form(
"%s_%s_%d",cnode->GetName(),suffix,n) ;
561 if (!_allOwnedNodes.find(newname.c_str())) {
562 wsnode->SetName(newname.c_str()) ;
563 wsnode->SetTitle(Form(
"%s (%s %d)",cnode->GetTitle(),suffix,n)) ;
570 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName()
571 <<
") Resolving name conflict in workspace by changing name of original node "
572 << origName <<
" to " << wsnode->GetName() << endl ;
575 coutW(ObjectHandling) <<
"RooWorkspce::import(" << GetName() <<
") Internal error: expected to find existing node "
576 << origName <<
" to be renamed, but didn't find it..." << endl ;
585 if (strlen(varChangeIn)>0 || (suffixV && strlen(suffixV)>0)) {
588 TIterator* cliter = cloneSet->createIterator() ;
590 while ((cnode=(RooAbsArg*)cliter->Next())) {
592 if (varMap.find(cnode->GetName())!=varMap.end()) {
593 string origName = cnode->GetName() ;
594 cnode->SetName(varMap[cnode->GetName()].c_str()) ;
595 string tag = Form(
"ORIGNAME:%s",origName.c_str()) ;
596 cnode->setAttribute(tag.c_str()) ;
597 if (!cnode->getStringAttribute(
"origName")) {
598 string tag2 = Form(
"%s",origName.c_str()) ;
599 cnode->setStringAttribute(
"origName",tag2.c_str()) ;
603 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") Changing name of variable "
604 << origName <<
" to " << cnode->GetName() <<
" on request" << endl ;
607 if (cnode==cloneTop) {
608 topName2 = cnode->GetName() ;
617 RooArgSet* cloneSet2 = (RooArgSet*) RooArgSet(*cloneTop).snapshot(noRecursion==kFALSE) ;
618 RooAbsArg* cloneTop2 = cloneSet2->find(topName2.c_str()) ;
621 RooArgSet conflictNodes2 ;
622 RooArgSet branchSet2 ;
624 TIterator* iter2 = branchSet2.createIterator() ;
626 while ((branch2=(RooAbsArg*)iter2->Next())) {
627 if (_allOwnedNodes.find(branch2->GetName())) {
628 conflictNodes2.add(*branch2) ;
634 if (conflictNodes2.getSize()) {
635 coutE(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") ERROR object named " << inArg.GetName() <<
": component(s) "
636 << conflictNodes2 <<
" cause naming conflict after conflict resolution protocol was executed" << endl ;
641 iter = cloneSet2->createIterator() ;
645 while((node=(RooAbsArg*)iter->Next())) {
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 ;
654 if (cloneSet2->getSize()+_allOwnedNodes.getSize() > 999) _allOwnedNodes.setHashTableSize(1000);
656 RooArgSet recycledNodes ;
657 RooArgSet nodesToBeDeleted ;
658 while((node=(RooAbsArg*)iter->Next())) {
661 if (!_classes.autoImportClass(node->IsA())) {
662 coutW(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") WARNING: problems import class code of object "
663 << node->IsA()->GetName() <<
"::" << node->GetName() <<
", reading of workspace will require external definition of class" << endl ;
668 RooExpensiveObjectCache& oldCache = node->expensiveObjectCache() ;
669 node->setExpensiveObjectCache(_eocache) ;
670 _eocache.importCacheObjects(oldCache,node->GetName(),kTRUE) ;
673 RooAbsArg* wsnode = _allOwnedNodes.find(node->GetName()) ;
677 if (!silence && useExistingNodes) {
678 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") using existing copy of " << node->IsA()->GetName()
679 <<
"::" << node->GetName() <<
" for import of " << cloneTop2->IsA()->GetName() <<
"::"
680 << cloneTop2->GetName() << endl ;
682 recycledNodes.add(*_allOwnedNodes.find(node->GetName())) ;
685 nodesToBeDeleted.addOwned(*node) ;
692 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") importing " << node->IsA()->GetName() <<
"::"
693 << node->GetName() << endl ;
695 _allOwnedNodes.addOwned(*node) ;
697 _sandboxNodes.add(*node) ;
699 if (_dir && node->IsA() != RooConstVar::Class()) {
700 _dir->InternalAppend(node) ;
702 if (_doExport && node->IsA() != RooConstVar::Class()) {
712 cloneSet->releaseOwnership() ;
713 RooFIter cloneSet_iter = cloneSet->fwdIterator() ;
714 RooAbsArg* cloneNode ;
715 while ((cloneNode=(RooAbsArg*)cloneSet_iter.next())) {
721 if (recycledNodes.getSize()>0) {
723 while((node=(RooAbsArg*)iter->Next())) {
724 node->redirectServers(recycledNodes) ;
729 cloneSet2->releaseOwnership() ;
747 Bool_t RooWorkspace::import(RooAbsData& inData,
748 const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
749 const RooCmdArg& arg4,
const RooCmdArg& arg5,
const RooCmdArg& arg6,
750 const RooCmdArg& arg7,
const RooCmdArg& arg8,
const RooCmdArg& arg9)
755 args.Add((TObject*)&arg1) ;
756 args.Add((TObject*)&arg2) ;
757 args.Add((TObject*)&arg3) ;
758 args.Add((TObject*)&arg4) ;
759 args.Add((TObject*)&arg5) ;
760 args.Add((TObject*)&arg6) ;
761 args.Add((TObject*)&arg7) ;
762 args.Add((TObject*)&arg8) ;
763 args.Add((TObject*)&arg9) ;
766 RooCmdConfig pc(Form(
"RooWorkspace::import(%s)",GetName())) ;
768 pc.defineString(
"dsetName",
"Rename",0,
"") ;
769 pc.defineString(
"varChangeIn",
"RenameVar",0,
"",kTRUE) ;
770 pc.defineString(
"varChangeOut",
"RenameVar",1,
"",kTRUE) ;
771 pc.defineInt(
"embedded",
"Embedded",0,0) ;
772 pc.defineInt(
"silence",
"Silence",0,0) ;
781 const char* dsetName = pc.getString(
"dsetName") ;
782 const char* varChangeIn = pc.getString(
"varChangeIn") ;
783 const char* varChangeOut = pc.getString(
"varChangeOut") ;
784 Bool_t embedded = pc.getInt(
"embedded") ;
785 Int_t silence = pc.getInt(
"silence") ;
788 coutI(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") importing dataset " << inData.GetName() << endl ;
791 if (dsetName && strlen(dsetName)==0) {
795 RooLinkedList& dataList = embedded ? _embeddedDataList : _dataList ;
798 if (dsetName && dataList.FindObject(dsetName)) {
799 coutE(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") ERROR dataset with name " << dsetName <<
" already exists in workspace, import aborted" << endl ;
802 if (!dsetName && dataList.FindObject(inData.GetName())) {
803 coutE(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") ERROR dataset with name " << inData.GetName() <<
" already exists in workspace, import aborted" << endl ;
811 coutI(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") changing name of dataset from " << inData.GetName() <<
" to " << dsetName << endl ;
812 clone = (RooAbsData*) inData.Clone(dsetName) ;
814 clone = (RooAbsData*) inData.Clone(inData.GetName()) ;
819 if (strlen(varChangeIn)>0) {
821 const std::vector<std::string> tokIn = RooHelpers::tokenise(varChangeIn,
",");
822 const std::vector<std::string> tokOut = RooHelpers::tokenise(varChangeOut,
",");
823 for (
unsigned int i=0; i < tokIn.size(); ++i) {
825 coutI(ObjectHandling) <<
"RooWorkSpace::import(" << GetName() <<
") changing name of dataset observable " << tokIn[i] <<
" to " << tokOut[i] << endl ;
826 clone->changeObservableName(tokIn[i].c_str(), tokOut[i].c_str());
833 TIterator* iter = clone->get()->createIterator() ;
834 while((carg=(RooAbsArg*)iter->Next())) {
835 if (!arg(carg->GetName())) {
842 dataList.Add(clone) ;
844 _dir->InternalAppend(clone) ;
851 RooFIter iter2 = clone->get()->fwdIterator() ;
852 while ((carg=iter2.next())) {
853 carg->setExpensiveObjectCache(expensiveObjectCache()) ;
868 Bool_t RooWorkspace::defineSet(
const char* name,
const RooArgSet& aset, Bool_t importMissing)
871 map<string,RooArgSet>::iterator i = _namedSets.find(name) ;
872 if (i!=_namedSets.end()) {
873 coutW(InputArguments) <<
"RooWorkspace::defineSet(" << GetName() <<
") WARNING redefining previously defined named set " << name << endl ;
879 TIterator* iter = aset.createIterator() ;
881 while((sarg=(RooAbsArg*)iter->Next())) {
883 if (!arg(sarg->GetName())) {
887 coutE(InputArguments) <<
"RooWorkspace::defineSet(" << GetName() <<
") ERROR set constituent \"" << sarg->GetName()
888 <<
"\" is not in workspace and importMissing option is disabled" << endl ;
892 wsargs.add(*arg(sarg->GetName())) ;
897 _namedSets[name].removeAll() ;
898 _namedSets[name].add(wsargs) ;
904 Bool_t RooWorkspace::defineSetInternal(
const char *name,
const RooArgSet &aset)
911 map<string, RooArgSet>::iterator i = _namedSets.find(name);
912 if (i != _namedSets.end()) {
913 coutW(InputArguments) <<
"RooWorkspace::defineSet(" << GetName()
914 <<
") WARNING redefining previously defined named set " << name << endl;
918 _namedSets[name].removeAll();
919 _namedSets[name].add(aset);
928 Bool_t RooWorkspace::defineSet(
const char* name,
const char* contentList)
931 map<string,RooArgSet>::iterator i = _namedSets.find(name) ;
932 if (i!=_namedSets.end()) {
933 coutW(InputArguments) <<
"RooWorkspace::defineSet(" << GetName() <<
") WARNING redefining previously defined named set " << name << endl ;
939 for (
const std::string& token : RooHelpers::tokenise(contentList,
",")) {
941 if (!arg(token.c_str())) {
942 coutE(InputArguments) <<
"RooWorkspace::defineSet(" << GetName() <<
") ERROR proposed set constituent \"" << token
943 <<
"\" is not in workspace" << endl ;
946 wsargs.add(*arg(token.c_str())) ;
950 _namedSets[name].removeAll() ;
951 _namedSets[name].add(wsargs) ;
963 Bool_t RooWorkspace::extendSet(
const char* name,
const char* newContents)
968 for (
const std::string& token : RooHelpers::tokenise(newContents,
",")) {
970 if (!arg(token.c_str())) {
971 coutE(InputArguments) <<
"RooWorkspace::defineSet(" << GetName() <<
") ERROR proposed set constituent \"" << token
972 <<
"\" is not in workspace" << endl ;
975 wsargs.add(*arg(token.c_str())) ;
979 _namedSets[name].add(wsargs,kTRUE) ;
990 const RooArgSet* RooWorkspace::set(
const char* name)
992 map<string,RooArgSet>::iterator i = _namedSets.find(name) ;
993 return (i!=_namedSets.end()) ? &(i->second) : 0 ;
1002 Bool_t RooWorkspace::renameSet(
const char* name,
const char* newName)
1006 coutE(InputArguments) <<
"RooWorkspace::renameSet(" << GetName() <<
") ERROR a set with name " << name
1007 <<
" does not exist" << endl ;
1013 coutE(InputArguments) <<
"RooWorkspace::renameSet(" << GetName() <<
") ERROR a set with name " << newName
1014 <<
" already exists" << endl ;
1019 _namedSets[newName].add(_namedSets[name]) ;
1022 _namedSets.erase(name) ;
1033 Bool_t RooWorkspace::removeSet(
const char* name)
1037 coutE(InputArguments) <<
"RooWorkspace::removeSet(" << GetName() <<
") ERROR a set with name " << name
1038 <<
" does not exist" << endl ;
1043 _namedSets.erase(name) ;
1055 Bool_t RooWorkspace::startTransaction()
1063 _openTrans = kTRUE ;
1075 Bool_t RooWorkspace::cancelTransaction()
1083 TIterator* iter = _sandboxNodes.createIterator() ;
1085 while((tmpArg=(RooAbsArg*)iter->Next())) {
1086 _allOwnedNodes.remove(*tmpArg) ;
1089 _sandboxNodes.removeAll() ;
1092 _openTrans = kFALSE ;
1097 Bool_t RooWorkspace::commitTransaction()
1108 TIterator* iter = _sandboxNodes.createIterator() ;
1110 while((sarg=(RooAbsArg*)iter->Next())) {
1111 if (_dir && sarg->IsA() != RooConstVar::Class()) {
1112 _dir->InternalAppend(sarg) ;
1114 if (_doExport && sarg->IsA() != RooConstVar::Class()) {
1121 _sandboxNodes.removeAll() ;
1124 _openTrans = kFALSE ;
1134 Bool_t RooWorkspace::importClassCode(TClass* theClass, Bool_t doReplace)
1136 return _classes.autoImportClass(theClass,doReplace) ;
1147 Bool_t RooWorkspace::importClassCode(
const char* pat, Bool_t doReplace)
1151 TRegexp re(pat,kTRUE) ;
1152 TIterator* iter = componentIterator() ;
1154 while((carg=(RooAbsArg*)iter->Next())) {
1155 TString className = carg->IsA()->GetName() ;
1156 if (className.Index(re)>=0 && !_classes.autoImportClass(carg->IsA(),doReplace)) {
1157 coutW(ObjectHandling) <<
"RooWorkspace::import(" << GetName() <<
") WARNING: problems import class code of object "
1158 << carg->IsA()->GetName() <<
"::" << carg->GetName() <<
", reading of workspace will require external definition of class" << endl ;
1175 Bool_t RooWorkspace::saveSnapshot(
const char* name,
const char* paramNames)
1177 return saveSnapshot(name,argSet(paramNames),kFALSE) ;
1190 Bool_t RooWorkspace::saveSnapshot(
const char* name,
const RooArgSet& params, Bool_t importValues)
1192 RooArgSet* actualParams = (RooArgSet*) _allOwnedNodes.selectCommon(params) ;
1193 RooArgSet* snapshot = (RooArgSet*) actualParams->snapshot() ;
1194 delete actualParams ;
1196 snapshot->setName(name) ;
1199 *snapshot = params ;
1202 RooArgSet* oldSnap = (RooArgSet*) _snapshots.FindObject(name) ;
1204 coutI(ObjectHandling) <<
"RooWorkspace::saveSnaphot(" << GetName() <<
") replacing previous snapshot with name " << name << endl ;
1205 _snapshots.Remove(oldSnap) ;
1209 _snapshots.Add(snapshot) ;
1221 Bool_t RooWorkspace::loadSnapshot(
const char* name)
1223 RooArgSet* snap = (RooArgSet*) _snapshots.find(name) ;
1225 coutE(ObjectHandling) <<
"RooWorkspace::loadSnapshot(" << GetName() <<
") no snapshot with name " << name <<
" is available" << endl ;
1229 RooArgSet* actualParams = (RooArgSet*) _allOwnedNodes.selectCommon(*snap) ;
1230 *actualParams = *snap ;
1231 delete actualParams ;
1244 const RooArgSet* RooWorkspace::getSnapshot(
const char* name)
const
1246 RooArgSet* snap = (RooArgSet*) _snapshots.find(name) ;
1248 coutE(ObjectHandling) <<
"RooWorkspace::loadSnapshot(" << GetName() <<
") no snapshot with name " << name <<
" is available" << endl ;
1290 RooAbsPdf* RooWorkspace::pdf(
const char* name)
const
1292 return dynamic_cast<RooAbsPdf*
>(_allOwnedNodes.find(name)) ;
1299 RooAbsReal* RooWorkspace::function(
const char* name)
const
1301 return dynamic_cast<RooAbsReal*
>(_allOwnedNodes.find(name)) ;
1308 RooRealVar* RooWorkspace::var(
const char* name)
const
1310 return dynamic_cast<RooRealVar*
>(_allOwnedNodes.find(name)) ;
1317 RooCategory* RooWorkspace::cat(
const char* name)
const
1319 return dynamic_cast<RooCategory*
>(_allOwnedNodes.find(name)) ;
1326 RooAbsCategory* RooWorkspace::catfunc(
const char* name)
const
1328 return dynamic_cast<RooAbsCategory*
>(_allOwnedNodes.find(name)) ;
1336 RooAbsArg* RooWorkspace::arg(
const char* name)
const
1338 return _allOwnedNodes.find(name) ;
1346 RooArgSet RooWorkspace::argSet(
const char* nameList)
const
1350 for (
const std::string& token : RooHelpers::tokenise(nameList,
",")) {
1351 RooAbsArg* oneArg = arg(token.c_str()) ;
1355 coutE(InputArguments) <<
" RooWorkspace::argSet(" << GetName() <<
") no RooAbsArg named \"" << token <<
"\" in workspace" << endl ;
1367 RooAbsArg* RooWorkspace::fundArg(
const char* name)
const
1369 RooAbsArg* tmp = arg(name) ;
1373 return tmp->isFundamental() ? tmp : 0 ;
1381 RooAbsData* RooWorkspace::data(
const char* name)
const
1383 return (RooAbsData*)_dataList.FindObject(name) ;
1390 RooAbsData* RooWorkspace::embeddedData(
const char* name)
const
1392 return (RooAbsData*)_embeddedDataList.FindObject(name) ;
1401 RooArgSet RooWorkspace::allVars()
const
1406 TIterator* iter = _allOwnedNodes.createIterator() ;
1408 while((parg=(RooAbsArg*)iter->Next())) {
1409 if (parg->IsA()->InheritsFrom(RooRealVar::Class())) {
1422 RooArgSet RooWorkspace::allCats()
const
1427 TIterator* iter = _allOwnedNodes.createIterator() ;
1429 while((parg=(RooAbsArg*)iter->Next())) {
1430 if (parg->IsA()->InheritsFrom(RooCategory::Class())) {
1444 RooArgSet RooWorkspace::allFunctions()
const
1449 TIterator* iter = _allOwnedNodes.createIterator() ;
1451 while((parg=(RooAbsArg*)iter->Next())) {
1452 if (parg->IsA()->InheritsFrom(RooAbsReal::Class()) &&
1453 !parg->IsA()->InheritsFrom(RooAbsPdf::Class()) &&
1454 !parg->IsA()->InheritsFrom(RooConstVar::Class()) &&
1455 !parg->IsA()->InheritsFrom(RooRealVar::Class())) {
1467 RooArgSet RooWorkspace::allCatFunctions()
const
1472 TIterator* iter = _allOwnedNodes.createIterator() ;
1474 while((parg=(RooAbsArg*)iter->Next())) {
1475 if (parg->IsA()->InheritsFrom(RooAbsCategory::Class()) &&
1476 !parg->IsA()->InheritsFrom(RooCategory::Class())) {
1488 RooArgSet RooWorkspace::allResolutionModels()
const
1493 TIterator* iter = _allOwnedNodes.createIterator() ;
1495 while((parg=(RooAbsArg*)iter->Next())) {
1496 if (parg->IsA()->InheritsFrom(RooResolutionModel::Class())) {
1497 if (!((RooResolutionModel*)parg)->isConvolved()) {
1509 RooArgSet RooWorkspace::allPdfs()
const
1514 TIterator* iter = _allOwnedNodes.createIterator() ;
1516 while((parg=(RooAbsArg*)iter->Next())) {
1517 if (parg->IsA()->InheritsFrom(RooAbsPdf::Class()) &&
1518 !parg->IsA()->InheritsFrom(RooResolutionModel::Class())) {
1530 list<RooAbsData*> RooWorkspace::allData()
const
1532 list<RooAbsData*> ret ;
1533 TIterator* iter = _dataList.MakeIterator() ;
1535 while((dat=(RooAbsData*)iter->Next())) {
1536 ret.push_back(dat) ;
1546 list<RooAbsData*> RooWorkspace::allEmbeddedData()
const
1548 list<RooAbsData*> ret ;
1549 TIterator* iter = _embeddedDataList.MakeIterator() ;
1551 while((dat=(RooAbsData*)iter->Next())) {
1552 ret.push_back(dat) ;
1563 list<TObject*> RooWorkspace::allGenericObjects()
const
1565 list<TObject*> ret ;
1566 TIterator* iter = _genObjects.MakeIterator() ;
1568 while((gobj=(RooAbsData*)iter->Next())) {
1571 if (gobj->IsA()==RooTObjWrap::Class()) {
1572 ret.push_back(((RooTObjWrap*)gobj)->obj()) ;
1574 ret.push_back(gobj) ;
1592 Bool_t RooWorkspace::CodeRepo::autoImportClass(TClass* tc, Bool_t doReplace)
1595 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") request to import code of class " << tc->GetName() << endl ;
1600 if (!doReplace && _c2fmap.find(tc->GetName())!=_c2fmap.end()) {
1601 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->GetName() <<
" already imported, skipping" << endl ;
1606 const char* mapEntry = gInterpreter->GetClassSharedLibs(tc->GetName()) ;
1607 if (mapEntry && strlen(mapEntry)>0) {
1608 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->GetName() <<
" is in ROOT distribution, skipping " << endl ;
1613 string implfile = tc->GetImplFileName() ;
1614 string declfile = tc->GetDeclFileName() ;
1617 if (implfile.empty() || declfile.empty()) {
1618 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") ERROR: cannot retrieve code file names for class "
1619 << tc->GetName() <<
" through ROOT TClass interface, unable to import code" << endl ;
1624 TString rootsys = gSystem->Getenv(
"ROOTSYS") ;
1625 if (TString(implfile.c_str()).Index(rootsys)>=0) {
1626 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo(" << _wspace->GetName() <<
") code of class " << tc->GetName() <<
" is in ROOT distribution, skipping " << endl ;
1629 const char* implpath=0 ;
1634 if (!(tc->Property() & kIsAbstract) && !tc->HasDefaultConstructor()) {
1635 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING cannot import class "
1636 << tc->GetName() <<
" : it cannot be persisted because it doesn't have a default constructor. Please fix " << endl ;
1643 char* declpath = 0 ;
1647 if (gSystem->AccessPathName(declfile.c_str())) {
1650 list<string>::iterator diter = RooWorkspace::_classDeclDirList.begin() ;
1652 while(diter!= RooWorkspace::_classDeclDirList.end()) {
1654 declpath = gSystem->ConcatFileName(diter->c_str(),declfile.c_str()) ;
1655 if (!gSystem->AccessPathName(declpath)) {
1668 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING Cannot access code of class "
1669 << tc->GetName() <<
" because header file " << declfile <<
" is not found in current directory nor in $ROOTSYS" ;
1670 if (_classDeclDirList.size()>0) {
1671 ooccoutW(_wspace,ObjectHandling) <<
", nor in the search path " ;
1672 diter = RooWorkspace::_classDeclDirList.begin() ;
1674 while(diter!= RooWorkspace::_classDeclDirList.end()) {
1676 if (diter!=RooWorkspace::_classDeclDirList.begin()) {
1677 ooccoutW(_wspace,ObjectHandling) <<
"," ;
1679 ooccoutW(_wspace,ObjectHandling) << diter->c_str() ;
1683 ooccoutW(_wspace,ObjectHandling) <<
". To fix this problem, add the required directory to the search "
1684 <<
"path using RooWorkspace::addClassDeclImportDir(const char* dir)" << endl ;
1693 if (gSystem->AccessPathName(implfile.c_str())) {
1696 list<string>::iterator iiter = RooWorkspace::_classImplDirList.begin() ;
1698 while(iiter!= RooWorkspace::_classImplDirList.end()) {
1700 implpath = gSystem->ConcatFileName(iiter->c_str(),implfile.c_str()) ;
1701 if (!gSystem->AccessPathName(implpath)) {
1714 oocoutW(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName() <<
") WARNING Cannot access code of class "
1715 << tc->GetName() <<
" because implementation file " << implfile <<
" is not found in current directory nor in $ROOTSYS" ;
1716 if (_classDeclDirList.size()>0) {
1717 ooccoutW(_wspace,ObjectHandling) <<
", nor in the search path " ;
1718 iiter = RooWorkspace::_classImplDirList.begin() ;
1720 while(iiter!= RooWorkspace::_classImplDirList.end()) {
1722 if (iiter!=RooWorkspace::_classImplDirList.begin()) {
1723 ooccoutW(_wspace,ObjectHandling) <<
"," ;
1725 ooccoutW(_wspace,ObjectHandling) << iiter->c_str() ;
1729 ooccoutW(_wspace,ObjectHandling) <<
". To fix this problem add the required directory to the search "
1730 <<
"path using RooWorkspace::addClassImplImportDir(const char* dir)" << endl ;
1748 string declfilename = declpath?gSystem->BaseName(declpath):gSystem->BaseName(declfile.c_str()) ;
1751 int dotpos2 = strrchr(declfilename.c_str(),
'.') - declfilename.c_str() ;
1752 string declfilebase = declfilename.substr(0,dotpos2) ;
1753 string declfileext = declfilename.substr(dotpos2+1) ;
1755 list<string> extraHeaders ;
1758 if (_fmap.find(declfilebase) == _fmap.end()) {
1761 fstream fdecl(declpath?declpath:declfile.c_str()) ;
1765 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1766 <<
") ERROR opening declaration file " << declfile << endl ;
1770 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1771 <<
") importing code of class " << tc->GetName()
1772 <<
" from " << (implpath?implpath:implfile.c_str())
1773 <<
" and " << (declpath?declpath:declfile.c_str()) << endl ;
1778 while(fdecl.getline(buf,1023)) {
1781 Bool_t processedInclude = kFALSE ;
1782 char* extincfile = 0 ;
1785 if (strstr(buf,
"#include")) {
1788 strlcpy(tmp, buf, 64000);
1789 Bool_t stdinclude = strchr(buf,
'<');
1790 strtok(tmp,
" <\"");
1791 char *incfile = strtok(0,
" <>\"");
1795 TString hpath = gSystem->Getenv(
"ROOTSYS");
1796 hpath +=
"/include/";
1798 if (gSystem->AccessPathName(hpath.Data())) {
1799 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1800 <<
") scheduling include file " << incfile <<
" for import" << endl;
1801 extraHeaders.push_back(incfile);
1802 extincfile = incfile;
1803 processedInclude = kTRUE;
1808 if (processedInclude) {
1809 decl +=
"// external include file below retrieved from workspace code storage\n" ;
1810 decl += Form(
"#include \"%s\"\n",extincfile) ;
1818 fstream fimpl(implpath?implpath:implfile.c_str()) ;
1822 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1823 <<
") ERROR opening implementation file " << implfile << endl ;
1830 while(fimpl.getline(buf,1023)) {
1834 Bool_t foundSelfInclude=kFALSE ;
1835 Bool_t processedInclude = kFALSE ;
1836 char* extincfile = 0 ;
1839 if (strstr(buf,
"#include")) {
1842 strlcpy(tmp, buf, 64000);
1843 Bool_t stdinclude = strchr(buf,
'<');
1844 strtok(tmp,
" <\"");
1845 char *incfile = strtok(0,
" <>\"");
1847 if (strstr(incfile, declfilename.c_str())) {
1848 foundSelfInclude = kTRUE;
1851 if (!stdinclude && !foundSelfInclude) {
1853 TString hpath = gSystem->Getenv(
"ROOTSYS");
1854 hpath +=
"/include/";
1857 if (gSystem->AccessPathName(hpath.Data())) {
1858 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1859 <<
") scheduling include file " << incfile <<
" for import" << endl;
1860 extraHeaders.push_back(incfile);
1861 extincfile = incfile;
1862 processedInclude = kTRUE;
1869 if (foundSelfInclude) {
1872 impl +=
"// class declaration include file below retrieved from workspace code storage\n" ;
1873 impl += Form(
"#include \"%s.%s\"\n",declfilebase.c_str(),declfileext.c_str()) ;
1874 }
else if (processedInclude) {
1875 impl +=
"// external include file below retrieved from workspace code storage\n" ;
1876 impl += Form(
"#include \"%s\"\n",extincfile) ;
1884 _fmap[declfilebase]._hfile = decl ;
1885 _fmap[declfilebase]._cxxfile = impl ;
1886 _fmap[declfilebase]._hext = declfileext ;
1889 for (list<string>::iterator ehiter = extraHeaders.begin() ; ehiter != extraHeaders.end() ; ++ehiter ) {
1890 if (_ehmap.find(*ehiter) == _ehmap.end()) {
1893 eh._hname = ehiter->c_str() ;
1894 fstream fehdr(ehiter->c_str()) ;
1897 while(fehdr.getline(buf2,1023)) {
1900 if (strstr(buf2,
"#include")) {
1903 strlcpy(tmp, buf2, 64000);
1904 Bool_t stdinclude = strchr(buf,
'<');
1905 strtok(tmp,
" <\"");
1906 char *incfile = strtok(0,
" <>\"");
1910 TString hpath = gSystem->Getenv(
"ROOTSYS");
1911 hpath +=
"/include/";
1913 if (gSystem->AccessPathName(hpath.Data())) {
1914 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1915 <<
") scheduling recursive include file " << incfile <<
" for import"
1917 extraHeaders.push_back(incfile);
1925 eh._hfile = ehimpl.c_str();
1927 _ehmap[ehiter->c_str()] = eh;
1934 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::autoImportClass(" << _wspace->GetName()
1935 <<
") code of class " << tc->GetName()
1936 <<
" was already imported from " << (implpath?implpath:implfile.c_str())
1937 <<
" and " << (declpath?declpath:declfile.c_str()) << endl ;
1948 TString baseNameList ;
1949 TList* bl = tc->GetListOfBases() ;
1950 TIterator* iter = bl->MakeIterator() ;
1952 list<TClass*> bases ;
1953 while((base=(TBaseClass*)iter->Next())) {
1954 if (baseNameList.Length()>0) {
1955 baseNameList +=
"," ;
1957 baseNameList += base->GetClassPointer()->GetName() ;
1958 bases.push_back(base->GetClassPointer()) ;
1963 _c2fmap[tc->GetName()]._baseName = baseNameList ;
1964 _c2fmap[tc->GetName()]._fileBase = declfilebase ;
1967 list<TClass*>::iterator biter = bases.begin() ;
1968 while(biter!=bases.end()) {
1969 autoImportClass(*biter,doReplace) ;
1996 Bool_t RooWorkspace::makeDir()
1998 if (_dir)
return kTRUE ;
2000 TString title= Form(
"TDirectory representation of RooWorkspace %s",GetName()) ;
2001 _dir =
new WSDir(GetName(),title.Data(),
this) ;
2003 TIterator* iter = componentIterator() ;
2005 while((darg=(RooAbsArg*)iter->Next())) {
2006 if (darg->IsA() != RooConstVar::Class()) {
2007 _dir->InternalAppend(darg) ;
2023 Bool_t RooWorkspace::import(TObject&
object, Bool_t replaceExisting)
2026 TObject* oldObj = _genObjects.FindObject(
object.GetName()) ;
2027 if (oldObj && !replaceExisting) {
2028 coutE(InputArguments) <<
"RooWorkspace::import(" << GetName() <<
") generic object with name "
2029 <<
object.GetName() <<
" is already in workspace and replaceExisting flag is set to false" << endl ;
2034 ROOT::DirAutoAdd_t func =
object.IsA()->GetDirectoryAutoAdd();
2035 object.IsA()->SetDirectoryAutoAdd(0);
2036 Bool_t tmp = RooPlot::setAddDirectoryStatus(kFALSE) ;
2039 _genObjects.Replace(oldObj,
object.Clone()) ;
2042 _genObjects.Add(
object.Clone()) ;
2046 object.IsA()->SetDirectoryAutoAdd(func);
2047 RooPlot::setAddDirectoryStatus(tmp) ;
2064 Bool_t RooWorkspace::import(TObject&
object,
const char* aliasName, Bool_t replaceExisting)
2067 TObject* oldObj = _genObjects.FindObject(
object.GetName()) ;
2068 if (oldObj && !replaceExisting) {
2069 coutE(InputArguments) <<
"RooWorkspace::import(" << GetName() <<
") generic object with name "
2070 <<
object.GetName() <<
" is already in workspace and replaceExisting flag is set to false" << endl ;
2074 TH1::AddDirectory(kFALSE) ;
2075 RooTObjWrap* wrapper =
new RooTObjWrap(
object.Clone()) ;
2076 TH1::AddDirectory(kTRUE) ;
2077 wrapper->setOwning(kTRUE) ;
2078 wrapper->SetName(aliasName) ;
2079 wrapper->SetTitle(aliasName) ;
2082 _genObjects.Replace(oldObj,wrapper) ;
2085 _genObjects.Add(wrapper) ;
2096 Bool_t RooWorkspace::addStudy(RooAbsStudy& study)
2098 RooAbsStudy* clone = (RooAbsStudy*) study.Clone() ;
2099 _studyMods.Add(clone) ;
2109 void RooWorkspace::clearStudies()
2111 _studyMods.Delete() ;
2120 TObject* RooWorkspace::obj(
const char* name)
const
2123 TObject* ret = arg(name) ;
2124 if (ret)
return ret ;
2128 if (ret)
return ret ;
2131 return genobj(name) ;
2139 TObject* RooWorkspace::genobj(
const char* name)
const
2142 TObject* gobj = _genObjects.FindObject(name) ;
2145 if (!gobj)
return 0 ;
2148 if (gobj->IsA()==RooTObjWrap::Class())
return ((RooTObjWrap*)gobj)->obj() ;
2157 Bool_t RooWorkspace::cd(
const char* path)
2160 return _dir->cd(path) ;
2168 Bool_t RooWorkspace::writeToFile(
const char* fileName, Bool_t recreate)
2170 TFile f(fileName,recreate?
"RECREATE":
"UPDATE") ;
2180 RooFactoryWSTool& RooWorkspace::factory()
2185 cxcoutD(ObjectHandling) <<
"INFO: Creating RooFactoryWSTool associated with this workspace" << endl ;
2186 _factory = make_unique<RooFactoryWSTool>(*this);
2196 RooAbsArg* RooWorkspace::factory(
const char* expr)
2198 return factory().process(expr) ;
2207 void RooWorkspace::Print(Option_t* opts)
const
2209 Bool_t treeMode(kFALSE) ;
2210 Bool_t verbose(kFALSE);
2211 if (TString(opts).Contains(
"t")) {
2214 if (TString(opts).Contains(
"v")) {
2218 cout << endl <<
"RooWorkspace(" << GetName() <<
") " << GetTitle() <<
" contents" << endl << endl ;
2225 RooArgSet catfuncSet ;
2226 RooArgSet convResoSet ;
2231 TIterator* iter = _allOwnedNodes.createIterator() ;
2232 while((parg=(RooAbsArg*)iter->Next())) {
2240 if (parg->IsA()->InheritsFrom(RooAbsPdf::Class())) {
2241 if (!parg->hasClients()) {
2246 if (parg->IsA()->InheritsFrom(RooAbsReal::Class()) &&
2247 !parg->IsA()->InheritsFrom(RooAbsPdf::Class()) &&
2248 !parg->IsA()->InheritsFrom(RooConstVar::Class()) &&
2249 !parg->IsA()->InheritsFrom(RooRealVar::Class())) {
2250 if (!parg->hasClients()) {
2251 funcSet.add(*parg) ;
2256 if (parg->IsA()->InheritsFrom(RooAbsCategory::Class()) &&
2257 !parg->IsA()->InheritsFrom(RooCategory::Class())) {
2258 if (!parg->hasClients()) {
2259 catfuncSet.add(*parg) ;
2265 if (parg->IsA()->InheritsFrom(RooResolutionModel::Class())) {
2266 if (((RooResolutionModel*)parg)->isConvolved()) {
2267 convResoSet.add(*parg) ;
2269 resoSet.add(*parg) ;
2273 if (parg->IsA()->InheritsFrom(RooAbsPdf::Class()) &&
2274 !parg->IsA()->InheritsFrom(RooResolutionModel::Class())) {
2278 if (parg->IsA()->InheritsFrom(RooAbsReal::Class()) &&
2279 !parg->IsA()->InheritsFrom(RooAbsPdf::Class()) &&
2280 !parg->IsA()->InheritsFrom(RooConstVar::Class()) &&
2281 !parg->IsA()->InheritsFrom(RooRealVar::Class())) {
2282 funcSet.add(*parg) ;
2285 if (parg->IsA()->InheritsFrom(RooAbsCategory::Class()) &&
2286 !parg->IsA()->InheritsFrom(RooCategory::Class())) {
2287 catfuncSet.add(*parg) ;
2291 if (parg->IsA()->InheritsFrom(RooRealVar::Class())) {
2295 if (parg->IsA()->InheritsFrom(RooCategory::Class())) {
2303 RooFit::MsgLevel oldLevel = RooMsgService::instance().globalKillBelow() ;
2304 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ;
2306 if (varSet.getSize()>0) {
2308 cout <<
"variables" << endl ;
2309 cout <<
"---------" << endl ;
2310 cout << varSet << endl ;
2314 if (pdfSet.getSize()>0) {
2315 cout <<
"p.d.f.s" << endl ;
2316 cout <<
"-------" << endl ;
2318 iter = pdfSet.createIterator() ;
2319 while((parg=(RooAbsArg*)iter->Next())) {
2321 parg->printComponentTree() ;
2331 if (resoSet.getSize()>0) {
2332 cout <<
"analytical resolution models" << endl ;
2333 cout <<
"----------------------------" << endl ;
2335 iter = resoSet.createIterator() ;
2336 while((parg=(RooAbsArg*)iter->Next())) {
2349 if (funcSet.getSize()>0) {
2350 cout <<
"functions" << endl ;
2351 cout <<
"--------" << endl ;
2353 iter = funcSet.createIterator() ;
2354 while((parg=(RooAbsArg*)iter->Next())) {
2356 parg->printComponentTree() ;
2365 if (catfuncSet.getSize()>0) {
2366 cout <<
"category functions" << endl ;
2367 cout <<
"------------------" << endl ;
2369 iter = catfuncSet.createIterator() ;
2370 while((parg=(RooAbsArg*)iter->Next())) {
2372 parg->printComponentTree() ;
2381 if (_dataList.GetSize()>0) {
2382 cout <<
"datasets" << endl ;
2383 cout <<
"--------" << endl ;
2384 iter = _dataList.MakeIterator() ;
2386 while((data2=(RooAbsData*)iter->Next())) {
2387 cout << data2->IsA()->GetName() <<
"::" << data2->GetName() << *data2->get() << endl ;
2393 if (_embeddedDataList.GetSize()>0) {
2394 cout <<
"embedded datasets (in pdfs and functions)" << endl ;
2395 cout <<
"-----------------------------------------" << endl ;
2396 iter = _embeddedDataList.MakeIterator() ;
2398 while((data2=(RooAbsData*)iter->Next())) {
2399 cout << data2->IsA()->GetName() <<
"::" << data2->GetName() << *data2->get() << endl ;
2405 if (_snapshots.GetSize()>0) {
2406 cout <<
"parameter snapshots" << endl ;
2407 cout <<
"-------------------" << endl ;
2408 iter = _snapshots.MakeIterator() ;
2410 while((snap=(RooArgSet*)iter->Next())) {
2411 cout << snap->GetName() <<
" = (" ;
2412 TIterator* aiter = snap->createIterator() ;
2414 Bool_t first(kTRUE) ;
2415 while((a=(RooAbsArg*)aiter->Next())) {
2416 if (first) { first=kFALSE ; }
else { cout <<
"," ; }
2417 cout << a->GetName() <<
"=" ;
2418 a->printValue(cout) ;
2419 if (a->isConstant()) {
2423 cout <<
")" << endl ;
2431 if (_namedSets.size()>0) {
2432 cout <<
"named sets" << endl ;
2433 cout <<
"----------" << endl ;
2434 for (map<string,RooArgSet>::const_iterator it = _namedSets.begin() ; it != _namedSets.end() ; ++it) {
2435 if (verbose || !TString(it->first.c_str()).BeginsWith(
"CACHE_")) {
2436 cout << it->first <<
":" << it->second << endl;
2444 if (_genObjects.GetSize()>0) {
2445 cout <<
"generic objects" << endl ;
2446 cout <<
"---------------" << endl ;
2447 iter = _genObjects.MakeIterator() ;
2449 while((gobj=(TObject*)iter->Next())) {
2450 if (gobj->IsA()==RooTObjWrap::Class()) {
2451 cout << ((RooTObjWrap*)gobj)->obj()->IsA()->GetName() <<
"::" << gobj->GetName() << endl ;
2453 cout << gobj->IsA()->GetName() <<
"::" << gobj->GetName() << endl ;
2461 if (_studyMods.GetSize()>0) {
2462 cout <<
"study modules" << endl ;
2463 cout <<
"-------------" << endl ;
2464 iter = _studyMods.MakeIterator() ;
2466 while((smobj=(TObject*)iter->Next())) {
2467 cout << smobj->IsA()->GetName() <<
"::" << smobj->GetName() << endl ;
2474 if (_classes.listOfClassNames().size()>0) {
2475 cout <<
"embedded class code" << endl ;
2476 cout <<
"-------------------" << endl ;
2477 cout << _classes.listOfClassNames() << endl ;
2481 if (_eocache.size()>0) {
2482 cout <<
"embedded precalculated expensive components" << endl ;
2483 cout <<
"-------------------------------------------" << endl ;
2487 RooMsgService::instance().setGlobalKillBelow(oldLevel) ;
2499 void RooWorkspace::CodeRepo::Streamer(TBuffer &R__b)
2501 typedef ::RooWorkspace::CodeRepo thisClass;
2504 if (R__b.IsReading()) {
2507 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2514 name.Streamer(R__b) ;
2515 _fmap[name]._hext.Streamer(R__b) ;
2516 _fmap[name]._hfile.Streamer(R__b) ;
2517 _fmap[name]._cxxfile.Streamer(R__b) ;
2525 name.Streamer(R__b) ;
2526 _c2fmap[name]._baseName.Streamer(R__b) ;
2527 _c2fmap[name]._fileBase.Streamer(R__b) ;
2536 name.Streamer(R__b) ;
2537 _ehmap[name]._hname.Streamer(R__b) ;
2538 _ehmap[name]._hfile.Streamer(R__b) ;
2542 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
2545 _compiledOK = !compileClasses() ;
2550 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
2553 UInt_t count = _fmap.size() ;
2555 map<TString,ClassFiles>::iterator iter = _fmap.begin() ;
2556 while(iter!=_fmap.end()) {
2557 TString key_copy(iter->first) ;
2558 key_copy.Streamer(R__b) ;
2559 iter->second._hext.Streamer(R__b) ;
2560 iter->second._hfile.Streamer(R__b);
2561 iter->second._cxxfile.Streamer(R__b);
2567 count = _c2fmap.size() ;
2569 map<TString,ClassRelInfo>::iterator iter2 = _c2fmap.begin() ;
2570 while(iter2!=_c2fmap.end()) {
2571 TString key_copy(iter2->first) ;
2572 key_copy.Streamer(R__b) ;
2573 iter2->second._baseName.Streamer(R__b) ;
2574 iter2->second._fileBase.Streamer(R__b);
2579 count = _ehmap.size() ;
2581 map<TString,ExtraHeader>::iterator iter3 = _ehmap.begin() ;
2582 while(iter3!=_ehmap.end()) {
2583 TString key_copy(iter3->first) ;
2584 key_copy.Streamer(R__b) ;
2585 iter3->second._hname.Streamer(R__b) ;
2586 iter3->second._hfile.Streamer(R__b);
2590 R__b.SetByteCount(R__c, kTRUE);
2604 void RooWorkspace::Streamer(TBuffer &R__b)
2606 if (R__b.IsReading()) {
2608 R__b.ReadClassBuffer(RooWorkspace::Class(),
this);
2611 RooFIter fiter = _allOwnedNodes.fwdIterator() ;
2613 while((node=fiter.next())) {
2614 node->ioStreamerPass2() ;
2616 RooAbsArg::ioStreamerPass2Finalize() ;
2620 TIterator* iter = _allOwnedNodes.createIterator() ;
2621 while((node=(RooAbsArg*)iter->Next())) {
2622 node->setExpensiveObjectCache(_eocache) ;
2623 node->setWorkspace(*
this);
2624 if (node->IsA()->InheritsFrom(RooAbsOptTestStatistic::Class())) {
2625 RooAbsOptTestStatistic *tmp = (RooAbsOptTestStatistic *)node;
2626 if (tmp->isSealed() && tmp->sealNotice() && strlen(tmp->sealNotice()) > 0) {
2627 cout <<
"RooWorkspace::Streamer(" << GetName() <<
") " << node->IsA()->GetName() <<
"::" << node->GetName()
2628 <<
" : " << tmp->sealNotice() << endl;
2639 map<RooAbsArg*,vector<RooAbsArg *> > extClients, extValueClients, extShapeClients ;
2641 TIterator* iter = _allOwnedNodes.createIterator() ;
2643 while((tmparg=(RooAbsArg*)iter->Next())) {
2646 std::vector<RooAbsArg *> clientsTmp{tmparg->_clientList.begin(), tmparg->_clientList.end()};
2647 for (
auto client : clientsTmp) {
2648 if (!_allOwnedNodes.containsInstance(*client)) {
2650 const auto refCount = tmparg->_clientList.refCount(client);
2651 auto& bufferVec = extClients[tmparg];
2653 bufferVec.insert(bufferVec.end(), refCount, client);
2654 tmparg->_clientList.Remove(client,
true);
2659 clientsTmp.assign(tmparg->_clientListValue.begin(), tmparg->_clientListValue.end());
2660 for (
auto vclient : clientsTmp) {
2661 if (!_allOwnedNodes.containsInstance(*vclient)) {
2662 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" << GetName() <<
") element " << tmparg->GetName()
2663 <<
" has external value client link to " << vclient <<
" (" << vclient->GetName() <<
") with ref count " << tmparg->_clientListValue.refCount(vclient) << endl ;
2665 const auto refCount = tmparg->_clientListValue.refCount(vclient);
2666 auto& bufferVec = extValueClients[tmparg];
2668 bufferVec.insert(bufferVec.end(), refCount, vclient);
2669 tmparg->_clientListValue.Remove(vclient,
true);
2674 clientsTmp.assign(tmparg->_clientListShape.begin(), tmparg->_clientListShape.end());
2675 for (
auto sclient : clientsTmp) {
2676 if (!_allOwnedNodes.containsInstance(*sclient)) {
2677 cxcoutD(ObjectHandling) <<
"RooWorkspace::Streamer(" << GetName() <<
") element " << tmparg->GetName()
2678 <<
" has external shape client link to " << sclient <<
" (" << sclient->GetName() <<
") with ref count " << tmparg->_clientListShape.refCount(sclient) << endl ;
2680 const auto refCount = tmparg->_clientListShape.refCount(sclient);
2681 auto& bufferVec = extShapeClients[tmparg];
2683 bufferVec.insert(bufferVec.end(), refCount, sclient);
2684 tmparg->_clientListShape.Remove(sclient,
true);
2691 R__b.WriteClassBuffer(RooWorkspace::Class(),
this);
2696 for (
auto iterx : extClients) {
2697 for (
auto client : iterx.second) {
2698 iterx.first->_clientList.Add(client);
2702 for (
auto iterx : extValueClients) {
2703 for (
auto client : iterx.second) {
2704 iterx.first->_clientListValue.Add(client);
2708 for (
auto iterx : extShapeClients) {
2709 for (
auto client : iterx.second) {
2710 iterx.first->_clientListShape.Add(client);
2723 std::string RooWorkspace::CodeRepo::listOfClassNames()
const
2726 map<TString,ClassRelInfo>::const_iterator iter = _c2fmap.begin() ;
2727 while(iter!=_c2fmap.end()) {
2731 ret += iter->first ;
2739 UInt_t crc32(
const char* data, ULong_t sz, UInt_t crc)
2744 static const UInt_t crctab[256] = { 0x00000000,
2745 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
2746 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
2747 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
2748 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
2749 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
2750 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
2751 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
2752 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
2753 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
2754 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
2755 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
2756 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
2757 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
2758 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
2759 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
2760 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
2761 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
2762 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
2763 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
2764 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
2765 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
2766 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
2767 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
2768 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
2769 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
2770 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
2771 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
2772 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
2773 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
2774 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
2775 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
2776 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
2777 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
2778 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
2779 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
2780 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
2781 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
2782 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
2783 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
2784 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
2785 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
2786 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
2787 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
2788 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
2789 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
2790 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
2791 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
2792 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
2793 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
2794 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
2795 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
2799 while (sz--) crc = (crc << 8) ^ UInt_t(*data++) ^ crctab[crc >> 24];
2804 UInt_t crc32(
const char* data)
2807 unsigned long sz = strlen(data);
2808 switch (strlen(data)) {
2814 return (data[0] << 8) | data[1];
2816 return (data[0] << 16) | (data[1] << 8) | data[2];
2818 return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
2820 return crc32(data + 4, sz - 4, (data[0] << 24) | (data[1] << 16) |
2821 (data[2] << 8) | data[3]);
2836 Bool_t RooWorkspace::CodeRepo::compileClasses()
2838 Bool_t haveDir=kFALSE ;
2841 string dirName = Form(_classFileExportDir.c_str(),_wspace->uuid().AsString(),_wspace->GetName()) ;
2843 Bool_t writeExtraHeaders(kFALSE) ;
2846 map<TString,ClassRelInfo>::iterator iter = _c2fmap.begin() ;
2847 while(iter!=_c2fmap.end()) {
2849 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing class " << iter->first.Data() << endl ;
2852 if (gClassTable->GetDict(iter->first.Data())) {
2853 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Embedded class "
2854 << iter->first <<
" already in ROOT class table, skipping" << endl ;
2863 if (!gSystem->AccessPathName(dirName.c_str())) {
2864 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() reusing code export directory " << dirName.c_str()
2865 <<
" to extract coded embedded in workspace" << endl ;
2867 if (gSystem->MakeDirectory(dirName.c_str())==0) {
2868 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() creating code export directory " << dirName.c_str()
2869 <<
" to extract coded embedded in workspace" << endl ;
2871 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR creating code export directory " << dirName.c_str()
2872 <<
" to extract coded embedded in workspace" << endl ;
2881 if (!writeExtraHeaders) {
2882 writeExtraHeaders = kTRUE ;
2884 map<TString,ExtraHeader>::iterator eiter = _ehmap.begin() ;
2885 while(eiter!=_ehmap.end()) {
2888 Bool_t needEHWrite=kTRUE ;
2889 string fdname = Form(
"%s/%s",dirName.c_str(),eiter->second._hname.Data()) ;
2890 ifstream ifdecl(fdname.c_str()) ;
2894 while (ifdecl.getline(buf, 64000)) {
2898 UInt_t crcFile = crc32(contents.Data());
2899 UInt_t crcWS = crc32(eiter->second._hfile.Data());
2900 needEHWrite = (crcFile != crcWS);
2905 oocoutI(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting extra header file "
2909 gSystem->MakeDirectory(gSystem->DirName(fdname.c_str()));
2911 ofstream fdecl(fdname.c_str());
2913 oocoutE(_wspace, ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file " << fdname
2914 <<
" for writing" << endl;
2917 fdecl << eiter->second._hfile.Data();
2926 ClassFiles& cfinfo = _fmap[iter->second._fileBase] ;
2928 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() now processing file with base " << iter->second._fileBase << endl ;
2931 if (cfinfo._extracted) {
2932 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() file with base name " << iter->second._fileBase
2933 <<
" has already been extracted, skipping to next class" << endl ;
2938 Bool_t needDeclWrite=kTRUE ;
2939 string fdname = Form(
"%s/%s.%s",dirName.c_str(),iter->second._fileBase.Data(),cfinfo._hext.Data()) ;
2940 ifstream ifdecl(fdname.c_str()) ;
2944 while (ifdecl.getline(buf, 64000)) {
2948 UInt_t crcFile = crc32(contents.Data()) ;
2949 UInt_t crcWS = crc32(cfinfo._hfile.Data()) ;
2950 needDeclWrite = (crcFile!=crcWS) ;
2954 if (needDeclWrite) {
2955 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting declaration code of class " << iter->first <<
", file " << fdname << endl ;
2956 ofstream fdecl(fdname.c_str()) ;
2958 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file "
2959 << fdname <<
" for writing" << endl ;
2962 fdecl << cfinfo._hfile ;
2967 Bool_t needImplWrite=kTRUE ;
2968 string finame = Form(
"%s/%s.cxx",dirName.c_str(),iter->second._fileBase.Data()) ;
2969 ifstream ifimpl(finame.c_str()) ;
2973 while (ifimpl.getline(buf, 64000)) {
2977 UInt_t crcFile = crc32(contents.Data()) ;
2978 UInt_t crcWS = crc32(cfinfo._cxxfile.Data()) ;
2979 needImplWrite = (crcFile!=crcWS) ;
2983 if (needImplWrite) {
2984 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Extracting implementation code of class " << iter->first <<
", file " << finame << endl ;
2985 ofstream fimpl(finame.c_str()) ;
2987 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR opening file"
2988 << finame <<
" for writing" << endl ;
2991 fimpl << cfinfo._cxxfile ;
2996 cfinfo._extracted = kTRUE ;
2997 oocxcoutD(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() marking code unit " << iter->second._fileBase <<
" as extracted" << endl ;
3000 oocoutI(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() Compiling code unit " << iter->second._fileBase.Data() <<
" to define class " << iter->first << endl ;
3001 Bool_t ok = gSystem->CompileMacro(finame.c_str(),
"k") ;
3004 oocoutE(_wspace,ObjectHandling) <<
"RooWorkspace::CodeRepo::compileClasses() ERROR compiling class " << iter->first.Data() <<
", to fix this you can do the following: " << endl
3005 <<
" 1) Fix extracted source code files in directory " << dirName.c_str() <<
"/" << endl
3006 <<
" 2) In clean ROOT session compiled fixed classes by hand using '.x " << dirName.c_str() <<
"/ClassName.cxx+'" << endl
3007 <<
" 3) Reopen file with RooWorkspace with broken source code in UPDATE mode. Access RooWorkspace to force loading of class" << endl
3008 <<
" Broken instances in workspace will _not_ be compiled, instead precompiled fixed instances will be used." << endl
3009 <<
" 4) Reimport fixed code in workspace using 'RooWorkspace::importClassCode(\"*\",kTRUE)' method, Write() updated workspace to file and close file" << endl
3010 <<
" 5) Reopen file in clean ROOT session to confirm that problems are fixed" << endl ;
3025 void RooWorkspace::WSDir::InternalAppend(TObject* obj)
3027 TDirectory::Append(obj,kFALSE) ;
3034 void RooWorkspace::WSDir::Add(TObject* obj,Bool_t)
3036 if (dynamic_cast<RooAbsArg*>(obj) || dynamic_cast<RooAbsData*>(obj)) {
3037 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" << GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << endl ;
3039 InternalAppend(obj) ;
3047 void RooWorkspace::WSDir::Append(TObject* obj,Bool_t)
3049 if (dynamic_cast<RooAbsArg*>(obj) || dynamic_cast<RooAbsData*>(obj)) {
3050 coutE(ObjectHandling) <<
"RooWorkspace::WSDir::Add(" << GetName() <<
") ERROR: Directory is read-only representation of a RooWorkspace, use RooWorkspace::import() to add objects" << endl ;
3052 InternalAppend(obj) ;
3062 void RooWorkspace::exportToCint(
const char* nsname)
3066 coutE(ObjectHandling) <<
"RooWorkspace::exportToCint(" << GetName() <<
") WARNING: repeated calls to exportToCint() have no effect" << endl ;
3074 if (!nsname) nsname = GetName() ;
3075 _exportNSName = nsname ;
3077 coutI(ObjectHandling) <<
"RooWorkspace::exportToCint(" << GetName()
3078 <<
") INFO: references to all objects in this workspace will be created in CINT in 'namespace " << _exportNSName <<
"'" << endl ;
3081 TIterator* iter = _allOwnedNodes.createIterator() ;
3083 while((wobj=iter->Next())) {
3087 iter = _dataList.MakeIterator() ;
3088 while((wobj=iter->Next())) {
3098 void RooWorkspace::exportObj(TObject* wobj)
3101 if (!_doExport) return ;
3104 if (wobj->IsA() == RooConstVar::Class()) {
3112 if (!isValidCPPID(wobj->GetName())) {
3113 cxcoutD(ObjectHandling) <<
"RooWorkspace::exportObj(" << GetName() <<
") INFO: Workspace object name " << wobj->GetName() <<
" is not a valid C++ identifier and is not exported to CINT" << endl ;
3118 string cintExpr = Form(
"namespace %s { %s& %s = *(%s *)0x%lx ; }",_exportNSName.c_str(),wobj->IsA()->GetName(),wobj->GetName(),wobj->IsA()->GetName(),(ULong_t)wobj) ;
3119 gROOT->ProcessLine(cintExpr.c_str()) ;
3127 Bool_t RooWorkspace::isValidCPPID(
const char* name)
3129 string oname(name) ;
3130 if (isdigit(oname[0])) {
3133 for (UInt_t i=0 ; i<oname.size() ; i++) {
3135 if (!isalnum(c) && (c!=
'_')) {
3146 void RooWorkspace::unExport()
3149 TIterator *iter = _allOwnedNodes.createIterator();
3151 while ((wobj = iter->Next())) {
3152 if (isValidCPPID(wobj->GetName())) {
3153 strlcpy(buf, Form(
"%s::%s", _exportNSName.c_str(), wobj->GetName()), 64000);
3154 gInterpreter->DeleteVariable(buf);
3164 void RooWorkspace::RecursiveRemove(TObject *removedObj)
3166 _dataList.RecursiveRemove(removedObj);
3167 if (removedObj == _dir) _dir =
nullptr;
3169 _allOwnedNodes.RecursiveRemove(removedObj);
3171 _dataList.RecursiveRemove(removedObj);
3172 _embeddedDataList.RecursiveRemove(removedObj);
3173 _views.RecursiveRemove(removedObj);
3174 _snapshots.RecursiveRemove(removedObj);
3175 _genObjects.RecursiveRemove(removedObj);
3176 _studyMods.RecursiveRemove(removedObj);
3178 for(
auto c : _namedSets) {
3179 c.second.RecursiveRemove(removedObj);
3182 _eocache.RecursiveRemove(removedObj);