47 ClassImp(RooVectorDataStore);
48 ClassImp(RooVectorDataStore::RealVector);
57 RooVectorDataStore::RooVectorDataStore() :
85 RooVectorDataStore::RooVectorDataStore(
const char* name,
const char* title,
const RooArgSet& vars,
const char* wgtVarName) :
86 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
88 _wgtVar(weightVar(vars,wgtVarName)),
106 _forcedUpdate(kFALSE)
108 for (
auto arg : _varsww) {
109 arg->attachToVStore(*
this) ;
112 setAllBuffersNative() ;
120 void RooVectorDataStore::setAllBuffersNative()
122 for (
auto realVec : _realStoreList) {
123 realVec->setNativeBuffer();
126 for (
auto fullVec : _realfStoreList) {
127 fullVec->setNativeBuffer();
130 for (
auto catVec : _catStoreList) {
131 catVec->setNativeBuffer();
142 RooArgSet RooVectorDataStore::varsNoWeight(
const RooArgSet& allVars,
const char* wgtName)
144 RooArgSet ret(allVars) ;
146 RooAbsArg* wgt = allVars.find(wgtName) ;
148 ret.remove(*wgt,kTRUE,kTRUE) ;
160 RooRealVar* RooVectorDataStore::weightVar(
const RooArgSet& allVars,
const char* wgtName)
163 RooRealVar* wgt =
dynamic_cast<RooRealVar*
>(allVars.find(wgtName)) ;
175 RooVectorDataStore::RooVectorDataStore(
const RooVectorDataStore& other,
const char* newname) :
176 RooAbsDataStore(other,newname),
177 _varsww(other._varsww),
178 _wgtVar(other._wgtVar),
181 _nEntries(other._nEntries),
182 _sumWeight(other._sumWeight),
183 _sumWeightCarry(other._sumWeightCarry),
184 _extWgtArray(other._extWgtArray),
185 _extWgtErrLoArray(other._extWgtErrLoArray),
186 _extWgtErrHiArray(other._extWgtErrHiArray),
187 _extSumW2Array(other._extSumW2Array),
188 _curWgt(other._curWgt),
189 _curWgtErrLo(other._curWgtErrLo),
190 _curWgtErrHi(other._curWgtErrHi),
191 _curWgtErr(other._curWgtErr),
194 _forcedUpdate(kFALSE)
196 for (
const auto realVec : other._realStoreList) {
197 _realStoreList.push_back(
new RealVector(*realVec, (RooAbsReal*)_varsww.find(realVec->_nativeReal->GetName()))) ;
200 for (
const auto realFullVec : other._realfStoreList) {
201 _realfStoreList.push_back(
new RealFullVector(*realFullVec, (RooAbsReal*)_varsww.find(realFullVec->_nativeReal->GetName()))) ;
205 for (
const auto catVec : other._catStoreList) {
206 _catStoreList.push_back(
new CatVector(*catVec, (RooAbsCategory*)_varsww.find(catVec->_cat->GetName()))) ;
210 setAllBuffersNative() ;
212 _firstRealF = _realfStoreList.size()>0 ? &_realfStoreList.front() : 0 ;
213 _firstCat = _catStoreList.size()>0 ? &_catStoreList.front() : 0 ;
220 RooVectorDataStore::RooVectorDataStore(
const RooTreeDataStore& other,
const RooArgSet& vars,
const char* newname) :
221 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
223 _wgtVar(weightVar(vars,other._wgtVar?other._wgtVar->GetName():0)),
232 _extWgtErrLoArray(0),
233 _extWgtErrHiArray(0),
241 _forcedUpdate(kFALSE)
243 TIterator* iter = _varsww.createIterator() ;
245 while((arg=(RooAbsArg*)iter->Next())) {
246 arg->attachToVStore(*
this) ;
250 setAllBuffersNative() ;
253 reserve(other.numEntries());
254 for (Int_t i=0 ; i<other.numEntries() ; i++) {
256 _varsww = other._varsww ;
267 RooVectorDataStore::RooVectorDataStore(
const RooVectorDataStore& other,
const RooArgSet& vars,
const char* newname) :
268 RooAbsDataStore(other,varsNoWeight(vars,other._wgtVar?other._wgtVar->GetName():0),newname),
270 _wgtVar(other._wgtVar?weightVar(vars,other._wgtVar->GetName()):0),
273 _nEntries(other._nEntries),
274 _sumWeight(other._sumWeight),
275 _sumWeightCarry(other._sumWeightCarry),
276 _extWgtArray(other._extWgtArray),
277 _extWgtErrLoArray(other._extWgtErrLoArray),
278 _extWgtErrHiArray(other._extWgtErrHiArray),
279 _extSumW2Array(other._extSumW2Array),
280 _curWgt(other._curWgt),
281 _curWgtErrLo(other._curWgtErrLo),
282 _curWgtErrHi(other._curWgtErrHi),
283 _curWgtErr(other._curWgtErr),
285 _forcedUpdate(kFALSE)
287 for (
const auto realVec : other._realStoreList) {
288 auto real =
static_cast<RooAbsReal*
>(vars.find(realVec->bufArg()->GetName()));
291 _realStoreList.push_back(
new RealVector(*realVec, real)) ;
293 real->attachToVStore(*
this) ;
297 vector<RealFullVector*>::const_iterator fiter = other._realfStoreList.begin() ;
298 for (; fiter!=other._realfStoreList.end() ; ++fiter) {
299 RooAbsReal* real = (RooAbsReal*) vars.find((*fiter)->bufArg()->GetName()) ;
302 _realfStoreList.push_back(
new RealFullVector(**fiter,real)) ;
304 real->attachToVStore(*
this) ;
309 vector<CatVector*>::const_iterator citer = other._catStoreList.begin() ;
310 for (; citer!=other._catStoreList.end() ; ++citer) {
311 RooAbsCategory* cat = (RooAbsCategory*) vars.find((*citer)->bufArg()->GetName()) ;
314 _catStoreList.push_back(
new CatVector(**citer,cat)) ;
316 cat->attachToVStore(*
this) ;
321 setAllBuffersNative() ;
323 _firstRealF = _realfStoreList.size()>0 ? &_realfStoreList.front() : 0 ;
324 _firstCat = _catStoreList.size()>0 ? &_catStoreList.front() : 0 ;
335 RooVectorDataStore::RooVectorDataStore(
const char *name,
const char *title, RooAbsDataStore& tds,
336 const RooArgSet& vars,
const RooFormulaVar* cutVar,
const char* cutRange,
337 Int_t nStart, Int_t nStop, Bool_t ,
const char* wgtVarName) :
339 RooAbsDataStore(name,title,varsNoWeight(vars,wgtVarName)),
341 _wgtVar(weightVar(vars,wgtVarName)),
350 _extWgtErrLoArray(0),
351 _extWgtErrHiArray(0),
358 _forcedUpdate(kFALSE)
360 TIterator* iter = _varsww.createIterator() ;
362 while((arg=(RooAbsArg*)iter->Next())) {
363 arg->attachToVStore(*
this) ;
367 setAllBuffersNative() ;
370 RooFormulaVar* cloneVar = 0;
372 cloneVar = (RooFormulaVar*) cutVar->cloneTree() ;
373 cloneVar->attachDataStore(tds) ;
376 RooVectorDataStore* vds =
dynamic_cast<RooVectorDataStore*
>(&tds) ;
377 if (vds && vds->_cache) {
378 _cache =
new RooVectorDataStore(*vds->_cache) ;
381 loadValues(&tds,cloneVar,cutRange,nStart,nStop);
395 RooVectorDataStore::~RooVectorDataStore()
397 for (
auto elm : _realStoreList) {
401 for (
auto elm : _realfStoreList) {
405 for (
auto elm : _catStoreList) {
420 Bool_t RooVectorDataStore::valid()
const
431 Int_t RooVectorDataStore::fill()
433 for (
auto realVec : _realStoreList) {
437 for (
auto fullVec : _realfStoreList) {
441 for (
auto catVec : _catStoreList) {
445 Double_t y = (_wgtVar ? _wgtVar->getVal() : 1.) - _sumWeightCarry;
446 Double_t t = _sumWeight + y;
447 _sumWeightCarry = (t - _sumWeight) - y;
461 const RooArgSet* RooVectorDataStore::get(Int_t index)
const
463 if (index>=_nEntries)
return 0 ;
465 for (
const auto realV : _realStoreList) {
470 for (Int_t i=0 ; i<_nRealF ; i++) {
471 (*(_firstRealF+i))->get(index) ;
476 for (Int_t i=0 ; i<_nCat ; i++) {
477 (*(_firstCat+i))->get(index) ;
483 for (
auto var : _vars) {
484 var->setValueDirty();
492 _curWgt = _extWgtArray[index] ;
493 _curWgtErrLo = _extWgtErrLoArray[index] ;
494 _curWgtErrHi = _extWgtErrHiArray[index] ;
495 _curWgtErr = sqrt(_extSumW2Array[index]) ;
497 }
else if (_wgtVar) {
500 _curWgt = _wgtVar->getVal() ;
501 _curWgtErrLo = _wgtVar->getAsymErrorLo() ;
502 _curWgtErrHi = _wgtVar->getAsymErrorHi() ;
503 _curWgtErr = _wgtVar->hasAsymError() ? ((_wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo())/2) : _wgtVar->getError() ;
528 const RooArgSet* RooVectorDataStore::getNative(Int_t index)
const
530 if (index>=_nEntries)
return 0 ;
532 for (
const auto realV : _realStoreList) {
533 realV->getNative(index) ;
537 for (Int_t i=0 ; i<_nRealF ; i++) {
538 (*(_firstRealF+i))->getNative(index) ;
543 for (Int_t i=0 ; i<_nCat ; i++) {
544 (*(_firstCat+i))->getNative(index) ;
550 for (
auto var : _vars) {
551 var->setValueDirty() ;
559 _curWgt = _extWgtArray[index] ;
560 _curWgtErrLo = _extWgtErrLoArray[index] ;
561 _curWgtErrHi = _extWgtErrHiArray[index] ;
562 _curWgtErr = sqrt(_extSumW2Array[index]) ;
564 }
else if (_wgtVar) {
567 _curWgt = _wgtVar->getVal() ;
568 _curWgtErrLo = _wgtVar->getAsymErrorLo() ;
569 _curWgtErrHi = _wgtVar->getAsymErrorHi() ;
570 _curWgtErr = _wgtVar->hasAsymError() ? ((_wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo())/2) : _wgtVar->getError() ;
583 _cache->getNative(index) ;
594 Double_t RooVectorDataStore::weight(Int_t index)
const
605 Double_t RooVectorDataStore::weight()
const
616 Double_t RooVectorDataStore::weightError(RooAbsData::ErrorType etype)
const
624 weightError(lo,hi,etype) ;
627 }
else if (_wgtVar) {
630 if (_wgtVar->hasAsymError()) {
631 return ( _wgtVar->getAsymErrorHi() - _wgtVar->getAsymErrorLo() ) / 2 ;
632 }
else if (_wgtVar->hasError(kFALSE)) {
633 return _wgtVar->getError() ;
650 void RooVectorDataStore::weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype)
const
657 case RooAbsData::Auto:
658 throw string(Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",GetName())) ;
661 case RooAbsData::Expected:
662 throw string(Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",GetName())) ;
665 case RooAbsData::Poisson:
667 if (_curWgtErrLo>=0) {
675 RooHistError::instance().getPoissonInterval(Int_t(weight()+0.5),ym,yp,1) ;
680 case RooAbsData::SumW2:
685 case RooAbsData::None:
691 }
else if (_wgtVar) {
694 if (_wgtVar->hasAsymError()) {
695 hi = _wgtVar->getAsymErrorHi() ;
696 lo = _wgtVar->getAsymErrorLo() ;
698 hi = _wgtVar->getError() ;
699 lo = _wgtVar->getError() ;
716 void RooVectorDataStore::loadValues(
const RooAbsDataStore *ads,
const RooFormulaVar* select,
const char* rangeName, Int_t nStart, Int_t nStop)
723 RooFormulaVar* selectClone(0) ;
725 selectClone = (RooFormulaVar*) select->cloneTree() ;
726 selectClone->recursiveRedirectServers(*ads->get()) ;
727 selectClone->setOperMode(RooAbsArg::ADirty,kTRUE) ;
734 Int_t nevent = nStop < ads->numEntries() ? nStop : ads->numEntries() ;
736 Bool_t isTDS =
dynamic_cast<const RooTreeDataStore*
>(ads) ;
737 Bool_t isVDS =
dynamic_cast<const RooVectorDataStore*
>(ads) ;
740 Bool_t weightRename(kFALSE) ;
741 Bool_t newWeightVar = _wgtVar ? _wgtVar->getAttribute(
"NewWeight") : kFALSE ;
743 if (_wgtVar && isVDS && ((RooVectorDataStore*)(ads))->_wgtVar) {
744 if (
string(_wgtVar->GetName())!=((RooVectorDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
748 if (_wgtVar && isTDS && ((RooTreeDataStore*)(ads))->_wgtVar) {
749 if (
string(_wgtVar->GetName())!=((RooTreeDataStore*)(ads))->_wgtVar->GetName() && !newWeightVar) {
754 std::vector<std::string> ranges;
756 ranges = RooHelpers::tokenise(rangeName,
",");
759 reserve(numEntries() + (nevent - nStart));
760 for(Int_t i=nStart; i < nevent ; ++i) {
764 if (selectClone && selectClone->getVal()==0) {
770 _varsww.assignValueOnly(((RooTreeDataStore*)ads)->_varsww) ;
772 _wgtVar->setVal(((RooTreeDataStore*)ads)->_wgtVar->getVal()) ;
775 _varsww.assignValueOnly(((RooVectorDataStore*)ads)->_varsww) ;
777 _wgtVar->setVal(((RooVectorDataStore*)ads)->_wgtVar->getVal()) ;
780 _varsww.assignValueOnly(*ads->get()) ;
784 bool allValid =
true;
785 for (
const auto arg : _varsww) {
786 allValid = arg->isValid() && (ranges.empty() || std::any_of(ranges.begin(), ranges.end(),
787 [arg](
const std::string& range){
return arg->inRange(range.c_str());}) );
801 SetTitle(ads->GetTitle());
810 Bool_t RooVectorDataStore::changeObservableName(
const char* ,
const char* )
838 RooAbsArg* RooVectorDataStore::addColumn(RooAbsArg& newVar, Bool_t )
841 RooAbsArg* valHolder= newVar.createFundamental();
843 if(!valHolder->isFundamental()) {
844 coutE(InputArguments) << GetName() <<
"::addColumn: holder argument is not fundamental: \""
845 << valHolder->GetName() <<
"\"" << endl;
850 RooAbsArg* newVarClone = newVar.cloneTree() ;
851 newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
854 valHolder->attachToVStore(*
this) ;
855 _vars.add(*valHolder) ;
856 _varsww.add(*valHolder) ;
861 if (dynamic_cast<RooAbsReal*>(valHolder)) {
862 rv = addReal((RooAbsReal*)valHolder);
863 rv->resize(numEntries()) ;
864 }
else if (dynamic_cast<RooAbsCategory*>((RooAbsCategory*)valHolder)) {
865 cv = addCategory((RooAbsCategory*)valHolder) ;
866 cv->resize(numEntries()) ;
869 for (
int i=0 ; i<numEntries() ; i++) {
872 newVarClone->syncCache(&_vars) ;
873 valHolder->copyCache(newVarClone) ;
875 if (rv) rv->write(i) ;
876 if (cv) cv->write(i) ;
890 RooArgSet* RooVectorDataStore::addColumns(
const RooArgList& varList)
892 TIterator* vIter = varList.createIterator() ;
899 RooArgSet* holderSet =
new RooArgSet ;
901 while((var=(RooAbsArg*)vIter->Next())) {
903 RooAbsArg* valHolder= var->createFundamental();
904 holderSet->add(*valHolder) ;
907 if(!valHolder->isFundamental()) {
908 coutE(InputArguments) << GetName() <<
"::addColumn: holder argument is not fundamental: \""
909 << valHolder->GetName() <<
"\"" << endl;
914 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
915 if (!newVarCloneList) {
916 coutE(InputArguments) <<
"RooTreeDataStore::RooTreeData(" << GetName()
917 <<
") Couldn't deep-clone variable " << var->GetName() <<
", abort." << endl ;
920 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
921 newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
922 newVarClone->recursiveRedirectServers(*holderSet,kFALSE) ;
924 cloneSetList.Add(newVarCloneList) ;
925 cloneSet.add(*newVarClone) ;
928 valHolder->attachToVStore(*
this) ;
929 _vars.add(*valHolder) ;
934 TIterator* cIter = cloneSet.createIterator() ;
935 TIterator* hIter = holderSet->createIterator() ;
936 RooAbsArg *cloneArg, *holder ;
939 while((holder = (RooAbsArg*)hIter->Next())) {
940 if (dynamic_cast<RooAbsReal*>(holder)) {
941 addReal((RooAbsReal*)holder)->resize(numEntries()) ;
943 addCategory((RooAbsCategory*)holder)->resize(numEntries()) ;
948 for (
int i=0 ; i<numEntries() ; i++) {
953 while((cloneArg=(RooAbsArg*)cIter->Next())) {
954 holder = (RooAbsArg*)hIter->Next() ;
956 cloneArg->syncCache(&_vars) ;
958 holder->copyCache(cloneArg) ;
960 if (dynamic_cast<RooAbsReal*>(holder)) {
961 addReal((RooAbsReal*)holder)->write(i) ;
963 addCategory((RooAbsCategory*)holder)->write(i) ;
971 cloneSetList.Delete() ;
984 RooAbsDataStore* RooVectorDataStore::merge(
const RooArgSet& allVars, list<RooAbsDataStore*> dstoreList)
986 RooVectorDataStore* mergedStore =
new RooVectorDataStore(
"merged",
"merged",allVars) ;
988 Int_t nevt = dstoreList.front()->numEntries() ;
989 mergedStore->reserve(nevt);
990 for (
int i=0 ; i<nevt ; i++) {
993 mergedStore->_vars = *
get(i) ;
996 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
997 const RooArgSet* partSet = (*iter)->get(i) ;
998 mergedStore->_vars = *partSet ;
1001 mergedStore->fill() ;
1003 return mergedStore ;
1008 void RooVectorDataStore::reserve(Int_t nEvts)
1010 for (
auto elm : _realStoreList) {
1011 elm->reserve(nEvts);
1014 for (
auto elm : _realfStoreList) {
1015 elm->reserve(nEvts);
1018 for (
auto elm : _catStoreList) {
1019 elm->reserve(nEvts);
1025 void RooVectorDataStore::append(RooAbsDataStore& other)
1027 Int_t nevt = other.numEntries() ;
1028 reserve(nevt + numEntries());
1029 for (
int i=0 ; i<nevt ; i++) {
1030 _vars = *other.get(i) ;
1032 _wgtVar->setVal(other.weight()) ;
1043 Int_t RooVectorDataStore::numEntries()
const
1052 void RooVectorDataStore::reset()
1055 _sumWeight=_sumWeightCarry=0 ;
1057 for (
auto elm : _realStoreList) {
1061 for (
auto elm : _realfStoreList) {
1065 for (
auto elm : _catStoreList) {
1079 void RooVectorDataStore::cacheArgs(
const RooAbsArg* owner, RooArgSet& newVarSet,
const RooArgSet* nset, Bool_t skipZeroWeights)
1088 RooArgSet newVarSetCopy(newVarSet);
1089 RooArgSet orderedArgs;
1090 vector<RooAbsArg*> trackArgs;
1091 for (
const auto arg : newVarSetCopy) {
1092 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
1093 orderedArgs.add(*arg) ;
1100 if (arg->dependsOn(_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
1101 trackArgs.push_back(arg) ;
1103 newVarSet.remove(*arg) ;
1109 std::sort(trackArgs.begin(), trackArgs.end(), [](RooAbsArg* left, RooAbsArg* right){
1110 return right->dependsOn(*left);
1114 for (
const auto trackedArg : trackArgs) {
1115 orderedArgs.add(*trackedArg);
1125 std::vector<RooArgSet*> vlist;
1126 RooArgList cloneSet;
1128 for (
const auto var : orderedArgs) {
1131 RooArgSet* newVarCloneList = (RooArgSet*) RooArgSet(*var).snapshot() ;
1132 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
1133 newVarClone->recursiveRedirectServers(_vars,kFALSE) ;
1135 vlist.push_back(newVarCloneList) ;
1136 cloneSet.add(*newVarClone) ;
1139 _cacheOwner = (RooAbsArg*) owner ;
1140 RooVectorDataStore* newCache =
new RooVectorDataStore(
"cache",
"cache",orderedArgs) ;
1143 RooAbsArg::setDirtyInhibit(kTRUE) ;
1145 std::vector<RooArgSet*> nsetList ;
1146 std::vector<RooArgSet*> argObsList ;
1149 RooArgSet *anset(0), *acset(0) ;
1150 for (
const auto arg : cloneSet) {
1151 arg->attachToVStore(*newCache) ;
1153 RooArgSet* argObs = nset ? arg->getObservables(*nset) : arg->getVariables() ;
1154 argObsList.push_back(argObs) ;
1156 RooArgSet* normSet(0) ;
1157 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
1161 rns.setNameList(catNset) ;
1162 anset = rns.select(nset?*nset:RooArgSet()) ;
1163 normSet = (RooArgSet*) anset->selectCommon(*argObs) ;
1166 const char* catCset = arg->getStringAttribute(
"CATCondSet") ;
1170 rns.setNameList(catCset) ;
1171 acset = rns.select(nset?*nset:RooArgSet()) ;
1173 argObs->remove(*acset,kTRUE,kTRUE) ;
1181 nsetList.push_back(normSet) ;
1186 newCache->reserve(numEntries());
1187 for (
int i=0 ; i<numEntries() ; i++) {
1189 if (weight()!=0 || !skipZeroWeights) {
1190 for (std::size_t j = 0; j < cloneSet.size(); ++j) {
1191 auto& cloneArg = cloneSet[j];
1192 auto argNSet = nsetList[j];
1194 cloneArg.syncCache(argNSet ? argNSet : nset) ;
1200 RooAbsArg::setDirtyInhibit(kFALSE) ;
1204 for (
const auto arg : orderedArgs) {
1205 arg->attachToVStore(*newCache) ;
1208 if (!arg->getAttribute(
"ConstantExpression") &&
dynamic_cast<RooAbsReal*
>(arg)) {
1209 RealVector* rv = newCache->addReal((RooAbsReal*)arg) ;
1210 RooArgSet* deps = arg->getParameters(_vars) ;
1211 rv->setDependents(*deps) ;
1215 Int_t idx = cloneSet.index(arg->GetName()) ;
1217 coutI(Optimization) <<
"RooVectorDataStore::cacheArg() element " << arg->GetName() <<
" has change tracking enabled on parameters " << *deps << endl ;
1218 rv->setNset(nsetList[idx]) ;
1225 for (
auto set : vlist) {
1228 for (
auto set : argObsList) {
1233 _cache->setDirtyProp(_doDirtyProp) ;
1237 void RooVectorDataStore::forceCacheUpdate()
1239 if (_cache) _forcedUpdate = kTRUE ;
1246 void RooVectorDataStore::recalculateCache(
const RooArgSet *projectedArgs, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
1248 if (!_cache) return ;
1250 std::vector<RooVectorDataStore::RealVector *> tv;
1251 tv.reserve(static_cast<std::size_t>(_cache->_realStoreList.size() * 0.7));
1254 for (
const auto realVec : _cache->_realStoreList) {
1255 if (_forcedUpdate || realVec->needRecalc()) {
1256 tv.push_back(realVec);
1257 realVec->_nativeReal->setOperMode(RooAbsArg::ADirty);
1258 realVec->_nativeReal->_operMode = RooAbsArg::Auto;
1261 _forcedUpdate = kFALSE ;
1270 RooArgSet* ownedNset = 0 ;
1271 RooArgSet* usedNset = 0 ;
1272 if (projectedArgs && projectedArgs->getSize()>0) {
1273 ownedNset = (RooArgSet*) _vars.snapshot(kFALSE) ;
1274 ownedNset->remove(*projectedArgs,kFALSE,kTRUE);
1275 usedNset = ownedNset ;
1281 for (
int i=firstEvent ; i<lastEvent ; i+=stepSize) {
1283 Bool_t zeroWeight = (weight()==0) ;
1284 if (!zeroWeight || !skipZeroWeights) {
1285 for (
auto realVector : tv) {
1286 realVector->_nativeReal->_valueDirty = kTRUE;
1287 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
1288 realVector->write(i);
1293 for (
auto realVector : tv) {
1294 realVector->_nativeReal->setOperMode(RooAbsArg::AClean);
1306 void RooVectorDataStore::attachCache(
const RooAbsArg* newOwner,
const RooArgSet& cachedVarsIn)
1309 if (!_cache) return ;
1312 std::vector<RealVector*> cacheElements(_cache->realStoreList());
1313 cacheElements.insert(cacheElements.end(), _cache->_realfStoreList.begin(), _cache->_realfStoreList.end());
1315 for (
const auto elm : cacheElements) {
1316 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.find(elm->bufArg()->GetName()));
1319 real->attachToVStore(*_cache) ;
1323 for (
const auto catVec : _cache->_catStoreList) {
1324 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.find(catVec->bufArg()->GetName()));
1327 cat->attachToVStore(*_cache) ;
1331 _cacheOwner = (RooAbsArg*) newOwner ;
1339 void RooVectorDataStore::resetCache()
1343 _cacheOwner =
nullptr;
1355 void RooVectorDataStore::setArgStatus(
const RooArgSet& , Bool_t )
1365 void RooVectorDataStore::attachBuffers(
const RooArgSet& extObs)
1367 for (
auto arg : _varsww) {
1368 RooAbsArg* extArg = extObs.find(arg->GetName()) ;
1370 extArg->attachToVStore(*
this) ;
1379 void RooVectorDataStore::resetBuffers()
1381 for (
auto arg : _varsww) {
1382 arg->attachToVStore(*
this);
1390 void RooVectorDataStore::dump()
1392 cout <<
"RooVectorDataStor::dump()" << endl ;
1394 cout <<
"_varsww = " << endl ; _varsww.Print(
"v") ;
1395 cout <<
"realVector list is" << endl ;
1397 for (
const auto elm : _realStoreList) {
1398 cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << endl ;
1399 cout <<
" values : " ;
1400 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1401 for (Int_t i=0 ; i<imax ; i++) {
1402 cout << elm->_vec[i] <<
" " ;
1407 for (
const auto elm : _realfStoreList) {
1408 cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1409 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->_bufE << endl ;
1411 cout <<
" values : " ;
1412 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1413 for (Int_t i=0 ; i<imax ; i++) {
1414 cout << elm->_vec[i] <<
" " ;
1418 cout <<
" errors : " ;
1419 for (Int_t i=0 ; i<imax ; i++) {
1420 cout << (*elm->_vecE)[i] <<
" " ;
1432 void RooVectorDataStore::Streamer(TBuffer &R__b)
1434 if (R__b.IsReading()) {
1435 R__b.ReadClassBuffer(RooVectorDataStore::Class(),
this);
1437 if (_realfStoreList.size() > 0)
1438 _firstRealF = &_realfStoreList.front() ;
1439 if (_catStoreList.size() > 0)
1440 _firstCat = &_catStoreList.front() ;
1442 for (
auto elm : _realStoreList) {
1443 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1444 arg->attachToVStore(*
this) ;
1446 for (
auto elm : _realfStoreList) {
1447 RooAbsArg* arg = _varsww.find(elm->_nativeReal->GetName()) ;
1448 arg->attachToVStore(*
this) ;
1450 for (
auto elm : _catStoreList) {
1451 RooAbsArg* arg = _varsww.find(elm->_cat->GetName()) ;
1452 arg->attachToVStore(*
this) ;
1456 R__b.WriteClassBuffer(RooVectorDataStore::Class(),
this);
1465 void RooVectorDataStore::RealVector::Streamer(TBuffer &R__b)
1467 if (R__b.IsReading()) {
1468 R__b.ReadClassBuffer(RooVectorDataStore::RealVector::Class(),
this);
1470 R__b.WriteClassBuffer(RooVectorDataStore::RealVector::Class(),
this);
1477 void RooVectorDataStore::RealFullVector::Streamer(TBuffer &R__b)
1479 if (R__b.IsReading()) {
1480 R__b.ReadClassBuffer(RooVectorDataStore::RealFullVector::Class(),
this);
1485 if (_vecE && _vecE->empty()) {
delete _vecE ; _vecE = 0 ; }
1486 if (_vecEL && _vecEL->empty()) {
delete _vecEL ; _vecEL = 0 ; }
1487 if (_vecEH && _vecEH->empty()) {
delete _vecEH ; _vecEH = 0 ; }
1489 R__b.WriteClassBuffer(RooVectorDataStore::RealFullVector::Class(),
this);
1496 void RooVectorDataStore::CatVector::Streamer(TBuffer &R__b)
1498 if (R__b.IsReading()) {
1499 R__b.ReadClassBuffer(RooVectorDataStore::CatVector::Class(),
this);
1500 _vec0 = _vec.size()>0 ? &_vec.front() : 0 ;
1502 R__b.WriteClassBuffer(RooVectorDataStore::CatVector::Class(),
this);
1509 std::vector<RooSpan<const double>> RooVectorDataStore::getBatch(std::size_t firstEvent, std::size_t lastEvent)
const
1511 std::vector<RooSpan<const double>> ret;
1513 ret.reserve(_realStoreList.size());
1515 for (
const auto realVec : _realStoreList) {
1516 ret.emplace_back(realVec->getRange(firstEvent, lastEvent));
1520 ret.reserve(ret.size() + _cache->_realStoreList.size());
1522 for (
const auto realVec : _cache->_realStoreList) {
1523 ret.emplace_back(realVec->getRange(firstEvent, lastEvent));
1534 RooSpan<const double> RooVectorDataStore::getWeightBatch(std::size_t first, std::size_t last)
const
1537 return RooSpan<const double>(_extWgtArray + first, _extWgtArray + last);
1542 return _wgtVar->getValBatch(first, last);
1546 static double dummyWeight = 1.;
1547 return RooSpan<const double>(&dummyWeight, 1);