50using std::string, std::vector, std::list;
71 arg->attachToVStore(*
this) ;
85 realVec->setNativeBuffer();
89 fullVec->setNativeBuffer();
93 catVec->setNativeBuffer();
110 ret.remove(*wgt,
true,
true) ;
150 _realStoreList.push_back(new RealVector(*realVec, static_cast<RooAbsReal*>(_varsww.find(realVec->_nativeReal->GetName())))) ;
154 _realfStoreList.push_back(new RealFullVector(*realFullVec, static_cast<RooAbsReal*>(_varsww.find(realFullVec->_nativeReal->GetName())))) ;
158 _catStoreList.push_back(new CatVector(*catVec, static_cast<RooAbsCategory*>(_varsww.find(catVec->_cat->GetName())))) ;
174 for (
const auto arg :
_varsww) {
175 arg->attachToVStore(*
this) ;
208 auto real = static_cast<RooAbsReal*>(vars.find(realVec->bufArg()->GetName()));
211 _realStoreList.push_back(new RealVector(*realVec, real)) ;
213 real->attachToVStore(*this) ;
217 auto forwardIter = other._realfStoreList.begin() ;
218 for (; forwardIter!=other._realfStoreList.end() ; ++forwardIter) {
222 _realfStoreList.push_back(
new RealFullVector(**forwardIter,real)) ;
229 for (; citer!=other._catStoreList.end() ; ++citer) {
233 _catStoreList.push_back(
new CatVector(**citer,cat)) ;
239 setAllBuffersNative() ;
248 std::size_t nStart, std::size_t nStop) {
254 return std::make_unique<RooVectorDataStore>(
name, title, *
this, tmp, cutVar, cutRange, nStart, nStop, wgtVarName);
263 std::size_t nStart, std::size_t nStop,
const char* wgtVarName) :
269 for (
const auto arg :
_varsww) {
270 arg->attachToVStore(*
this) ;
276 std::unique_ptr<RooFormulaVar> cloneVar;
279 cloneVar->attachDataStore(tds) ;
287 loadValues(&tds,cloneVar.get(),cutRange,nStart,nStop);
351 if (index < 0 ||
static_cast<std::size_t
>(index) >=
size())
return nullptr;
358 fullRealP->load(index);
367 for (
auto var :
_vars) {
368 var->setValueDirty();
403 return (
_wgtVar->getAsymErrorHi() -
_wgtVar->getAsymErrorLo() ) / 2 ;
404 }
else if (
_wgtVar->hasError(
false)) {
431 throw string(
Form(
"RooDataHist::weightError(%s) error type Auto not allowed here",
GetName())) ;
435 throw string(
Form(
"RooDataHist::weightError(%s) error type Expected not allowed here",
GetName())) ;
471 lo =
_wgtVar->getAsymErrorLo() ;
498 std::unique_ptr<RooFormulaVar> selectClone;
500 selectClone.reset(
static_cast<RooFormulaVar*
>(select->cloneTree()) );
501 selectClone->recursiveRedirectServers(*ads->
get()) ;
509 const auto numEntr =
static_cast<std::size_t
>(ads->
numEntries());
510 const std::size_t nevent = nStop < numEntr ? nStop : numEntr;
516 bool weightRename(
false) ;
517 const bool newWeightVar =
_wgtVar ?
_wgtVar->getAttribute(
"NewWeight") : false ;
519 if (
_wgtVar && vectorDS && vectorDS->_wgtVar) {
520 if (std::string(
_wgtVar->GetName()) != vectorDS->_wgtVar->GetName() && !newWeightVar) {
524 if (
_wgtVar && treeDS && treeDS->_wgtVar) {
525 if (std::string(
_wgtVar->GetName()) != treeDS->_wgtVar->GetName() && !newWeightVar) {
530 std::vector<std::string> ranges;
536 for(
auto i=nStart; i < nevent ; ++i) {
540 if (selectClone && selectClone->getVal()==0) {
547 otherVarsww = &treeDS->_varsww;
549 _wgtVar->setVal(treeDS->_wgtVar->getVal()) ;
551 }
else if (vectorDS) {
552 otherVarsww = &vectorDS->_varsww;
554 _wgtVar->setVal(vectorDS->_wgtVar->getVal()) ;
557 otherVarsww = ads->
get();
561 bool allValid =
true;
562 for (
const auto arg : *otherVarsww) {
563 allValid &= arg->isValid();
564 if (allValid && !ranges.empty()) {
567 allValid &= std::any_of(ranges.begin(), ranges.end(), [arg](
const std::string& range){
568 return arg->inRange(range.c_str());});
623 auto valHolder = std::unique_ptr<RooAbsArg>{newVar.
createFundamental()}.release();
625 if(!valHolder->isFundamental()) {
626 coutE(InputArguments) <<
GetName() <<
"::addColumn: holder argument is not fundamental: \""
627 << valHolder->GetName() <<
"\"" << std::endl;
632 const std::size_t numEvt =
size();
635 std::unique_ptr<RooAbsArg> newVarClone{newVar.
cloneTree()};
636 newVarClone->recursiveRedirectServers(
_vars,
false) ;
639 valHolder->attachToVStore(*
this) ;
640 _vars.add(*valHolder) ;
655 for (std::size_t i=0; i < numEvt; i++) {
658 newVarClone->syncCache(&
_vars) ;
659 valHolder->copyCache(newVarClone.get()) ;
661 if (rv) rv->
write(i) ;
662 if (cv) cv->
write(i) ;
680 const auto nevt = dstoreList.front()->numEntries();
682 for (
int i=0 ; i<nevt ; i++) {
688 for (list<RooAbsDataStore*>::iterator iter = dstoreList.begin() ; iter!=dstoreList.end() ; ++iter) {
693 mergedStore->
fill() ;
721 for (
int i=0 ; i<nevt ; i++) {
772 vector<RooAbsArg*> trackArgs;
773 for (
const auto arg : newVarSetCopy) {
774 if (arg->getAttribute(
"ConstantExpression") && !arg->getAttribute(
"NOCacheAndTrack")) {
775 orderedArgs.
add(*arg) ;
782 if (arg->dependsOn(
_vars) && !arg->getAttribute(
"NOCacheAndTrack")) {
783 trackArgs.push_back(arg) ;
793 if (left == right) return false;
794 return right->dependsOn(*left);
798 for (
const auto trackedArg : trackArgs) {
799 orderedArgs.
add(*trackedArg);
809 std::vector<std::unique_ptr<RooArgSet>> vlist;
812 for (
const auto var : orderedArgs) {
815 auto newVarCloneList = std::make_unique<RooArgSet>();
817 RooAbsArg* newVarClone = newVarCloneList->find(var->GetName()) ;
820 vlist.emplace_back(std::move(newVarCloneList));
821 cloneSet.
add(*newVarClone) ;
830 std::vector<RooArgSet*> nsetList ;
831 std::vector<std::unique_ptr<RooArgSet>> argObsList ;
834 for (
const auto arg : cloneSet) {
835 arg->attachToVStore(*newCache) ;
837 if(nset) argObsList.emplace_back(arg->getObservables(*nset));
838 else argObsList.emplace_back(arg->getVariables());
839 RooArgSet* argObs = argObsList.back().get();
842 const char* catNset = arg->getStringAttribute(
"CATNormSet") ;
850 const char* catCset = arg->getStringAttribute(
"CATCondSet") ;
855 argObs->
remove(acset,
true,
true) ;
863 nsetList.push_back(normSet) ;
868 const std::size_t numEvt =
size();
870 for (std::size_t i=0; i < numEvt; i++) {
872 if (
weight()!=0 || !skipZeroWeights) {
873 for (
unsigned int j = 0; j < cloneSet.
size(); ++j) {
874 auto& cloneArg = cloneSet[j];
875 auto argNSet = nsetList[j];
877 cloneArg.syncCache(argNSet ? argNSet : nset) ;
887 for (
const auto arg : orderedArgs) {
888 arg->attachToVStore(*newCache) ;
891 if (!arg->getAttribute(
"ConstantExpression") &&
dynamic_cast<RooAbsReal*
>(arg)) {
894 arg->getParameters(&
_vars, deps);
901 coutI(Optimization) <<
"RooVectorDataStore::cacheArg() element " << arg->GetName() <<
" has change tracking enabled on parameters " << deps << std::endl ;
925 std::vector<RooVectorDataStore::RealVector *> tv;
926 tv.reserve(
static_cast<std::size_t
>(
_cache->_realStoreList.size() * 0.7));
929 for (
const auto realVec :
_cache->_realStoreList) {
931 tv.push_back(realVec);
945 std::unique_ptr<RooArgSet> ownedNset;
947 if (projectedArgs && !projectedArgs->
empty()) {
948 ownedNset = std::make_unique<RooArgSet>();
949 _vars.snapshot(*ownedNset,
false) ;
950 ownedNset->remove(*projectedArgs,
false,
true);
951 usedNset = ownedNset.get();
957 for (
int i=firstEvent ; i<lastEvent ; i+=stepSize) {
959 bool zeroWeight = (
weight()==0) ;
960 if (!zeroWeight || !skipZeroWeights) {
961 for (
auto realVector : tv) {
962 realVector->_nativeReal->_valueDirty =
true;
963 realVector->_nativeReal->getValV(realVector->_nset ? realVector->_nset : usedNset);
964 realVector->write(i);
969 for (
auto realVector : tv) {
985 std::vector<RealVector*> cacheElements(
_cache->realStoreList());
986 cacheElements.insert(cacheElements.end(),
_cache->_realfStoreList.begin(),
_cache->_realfStoreList.end());
988 for (
const auto elm : cacheElements) {
989 auto real =
static_cast<RooAbsReal*
>(cachedVarsIn.
find(elm->bufArg()->GetName()));
996 for (
const auto catVec :
_cache->_catStoreList) {
997 auto cat =
static_cast<RooAbsCategory*
>(cachedVarsIn.
find(catVec->bufArg()->GetName()));
1055 arg->attachToVStore(*
this);
1065 std::cout <<
"RooVectorDataStor::dump()" << std::endl ;
1067 std::cout <<
"_varsww = " << std::endl ;
_varsww.Print(
"v") ;
1068 std::cout <<
"realVector list is" << std::endl ;
1071 std::cout <<
"RealVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName() <<
" bufptr = " << elm->_buf << std::endl ;
1072 std::cout <<
" values : " ;
1073 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1074 for (
Int_t i=0 ; i<imax ; i++) {
1075 std::cout << elm->_vec[i] <<
" " ;
1077 std::cout << std::endl ;
1081 std::cout <<
"RealFullVector " << elm <<
" _nativeReal = " << elm->_nativeReal <<
" = " << elm->_nativeReal->GetName()
1082 <<
" bufptr = " << elm->_buf <<
" errbufptr = " << elm->bufE() << std::endl ;
1084 std::cout <<
" values : " ;
1085 Int_t imax = elm->_vec.size()>10 ? 10 : elm->_vec.size() ;
1086 for (
Int_t i=0 ; i<imax ; i++) {
1087 std::cout << elm->_vec[i] <<
" " ;
1089 std::cout << std::endl ;
1091 std::cout <<
" errors : " ;
1092 for (
Int_t i=0 ; i<imax ; i++) {
1093 std::cout << elm->dataE()[i] <<
" " ;
1095 std::cout << std::endl ;
1137 auto emplace = [
this,&evalData,first,len](
const RealVector* realVec) {
1138 auto span = realVec->getRange(first, first + len);
1139 auto result = evalData.emplace(realVec->_nativeReal, span);
1140 if (result.second ==
false || result.first->second.size() != len) {
1141 const auto size = result.second ? result.first->second.size() : 0;
1142 coutE(DataHandling) <<
"A batch of data for '" << realVec->_nativeReal->GetName()
1143 <<
"' was requested from " << first <<
" to " << first+len
1144 <<
", but only the events [" << first <<
", " << first +
size <<
") are available." << std::endl;
1146 if (realVec->_real) {
1149 evalData.emplace(realVec->_real, span);
1161 for (
const auto realVec :
_cache->_realStoreList) {
1164 for (
const auto realVec :
_cache->_realfStoreList) {
1176 auto emplace = [
this,&evalData,first,len](
const CatVector* catVec) {
1177 auto span = catVec->getRange(first, first + len);
1178 auto result = evalData.emplace(catVec->_cat, span);
1179 if (result.second ==
false || result.first->second.size() != len) {
1180 const auto size = result.second ? result.first->second.size() : 0;
1181 coutE(DataHandling) <<
"A batch of data for '" << catVec->_cat->GetName()
1182 <<
"' was requested from " << first <<
" to " << first+len
1183 <<
", but only the events [" << first <<
", " << first +
size <<
") are available." << std::endl;
1207 auto findWeightVar = [
this](
const RealVector* realVec) {
1208 return realVec->_nativeReal ==
_wgtVar || realVec->_nativeReal->GetName() ==
_wgtVar->GetName();
1213 return (*storageIter)->getRange(first, first + len);
1217 return (*fstorageIter)->getRange(first, first + len);
1219 throw std::logic_error(
"RooVectorDataStore::getWeightBatch(): Could not retrieve data for _wgtVar.");
1229 if (std::string(catVec->bufArg()->GetName())==cat->
GetName()) {
1245 if (realVec->bufArg()->namePtr()==real->
namePtr()) {
1252 if (fullVec->bufArg()->namePtr()==real->
namePtr()) {
1269 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1281 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1282 return fullVec->bufE();
1293 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1294 return fullVec->bufEL();
1305 if (std::string(fullVec->bufArg()->GetName())==real->
GetName()) {
1312 if (std::string(realVec->bufArg()->GetName())==real->
GetName()) {
1336 double const* arr =
nullptr;
1341 const std::string wgtName =
_wgtVar->GetName();
1343 if(wgtName == real->_nativeReal->
GetName())
1344 arr = real->_vec.data();
1347 if(wgtName == real->_nativeReal->
GetName())
1348 arr = real->_vec.data();
1351 if(arr ==
nullptr) {
1368 out.
reals.emplace_back(real->_nativeReal->
GetName(), real->_vec.data());
1371 std::string
name = realf->_nativeReal->GetName();
1372 out.
reals.emplace_back(
name, realf->_vec.data());
1373 if(realf->bufE()) out.
reals.emplace_back(
name +
"Err", realf->dataE().data());
1374 if(realf->bufEL()) out.
reals.emplace_back(
name +
"ErrLo", realf->dataEL().data());
1375 if(realf->bufEH()) out.
reals.emplace_back(
name +
"ErrHi", realf->dataEH().data());
1378 out.
cats.emplace_back(cat->_cat->
GetName(), cat->_vec.data());
int Int_t
Signed integer 4 bytes (int).
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
bool recursiveRedirectServers(const RooAbsCollection &newSet, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
virtual RooFit::OwningPtr< RooAbsArg > createFundamental(const char *newname=nullptr) const =0
Create a fundamental-type object that stores our type of value.
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
virtual void attachToVStore(RooVectorDataStore &vstore)=0
A space to attach TBranches.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
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
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual const RooArgSet * get(Int_t index) const =0
virtual void checkInit() const
bool _doDirtyProp
Switch do (de)activate dirty state propagation when loading a data point.
virtual double weight() const =0
virtual Int_t numEntries() const =0
std::map< RooFit::Detail::DataKey, std::span< const double > > RealSpans
std::map< RooFit::Detail::DataKey, std::span< const RooAbsCategory::value_type > > CategorySpans
Abstract base class for objects that represent a real value and implements functionality common to al...
void attachToVStore(RooVectorDataStore &vstore) override
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
static const RooHistError & instance()
Return a reference to a singleton object that is created the first time this method is called.
bool getPoissonInterval(Int_t n, double &mu1, double &mu2, double nSigma=1) const
Calculate a confidence interval for the expected number of events given n observed (unweighted) event...
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
TTree-backed data storage.
const RooArgSet * get(Int_t index) const override
Load the n-th data point (n='index') in memory and return a pointer to the internal RooArgSet holding...
Int_t numEntries() const override
void write(std::size_t i)
void resize(Int_t newSize)
void setNset(RooArgSet *newNset)
void setDependents(const RooArgSet &deps)
void resize(Int_t newSize)
void resetCache() override
void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, bool skipZeroWeights) override
void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars) override
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches.
std::vector< RealFullVector * > _realfStoreList
Int_t numEntries() const override
RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true) override
Add a new column to the data set which holds the pre-calculated values of 'newVar'.
RooVectorDataStore * _cache
! Optimization cache
const double * _extWgtErrHiArray
! External weight array - high error
std::span< const double > getWeightBatch(std::size_t first, std::size_t len) const override
Return the weights of all events in the range [first, first+len).
~RooVectorDataStore() override
Destructor.
void resetBuffers() override
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=nullptr, bool skipZeroWeights=true) override
Cache given RooAbsArgs: The tree is given direct write access of the args internal cache the args val...
RooRealVar * _wgtVar
Pointer to weight variable (if set).
std::vector< RealVector * > _realStoreList
CatVector * addCategory(RooAbsCategory *cat)
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=nullptr, const char *rangeName=nullptr, std::size_t nStart=0, std::size_t nStop=std::numeric_limits< std::size_t >::max()) override
RealFullVector * addRealFull(RooAbsReal *real)
double weight() const override
Return the weight of the last-retrieved data point.
RooAbsData::RealSpans getBatches(std::size_t first, std::size_t len) const override
Return batches of the data columns for the requested events.
ULong64_t _currentWeightIndex
bool isFullReal(RooAbsReal *real)
Int_t fill() override
Interface function to TTree::Fill.
const double * _extWgtErrLoArray
! External weight array - low error
bool _forcedUpdate
! Request for forced cache update
void append(RooAbsDataStore &other) override
bool hasError(RooAbsReal *real)
std::vector< CatVector * > _catStoreList
void setArgStatus(const RooArgSet &set, bool active) override
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn't result...
void setAllBuffersNative()
double weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const override
Return the error of the current weight.
void attachBuffers(const RooArgSet &extObs) override
friend class RooAbsCategory
ArraysStruct getArrays() const
Exports all arrays in this RooVectorDataStore into a simple datastructure to be used by RooFit intern...
RooAbsData::CategorySpans getCategoryBatches(std::size_t, std::size_t len) const override
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore * > dstoreList) override
Merge columns of supplied data set(s) with this data set.
RealVector * addReal(RooAbsReal *real)
bool hasAsymError(RooAbsReal *real)
bool changeObservableName(const char *from, const char *to) override
void forceCacheUpdate() override
const double * _extSumW2Array
! External sum of weights array
void recomputeSumWeight()
Trigger a recomputation of the cached weight sums.
std::size_t size() const
Get size of stored dataset.
std::unique_ptr< RooAbsDataStore > reduce(RooStringView name, RooStringView title, const RooArgSet &vars, const RooFormulaVar *cutVar, const char *cutRange, std::size_t nStart, std::size_t nStop) override
virtual const RooArgSet * get() const
const double * _extWgtArray
! External weight array
void Streamer(TBuffer &) override
Stream an object of class RooVectorDataStore.
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
RooAbsArg * _cacheOwner
! Cache owner
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
RooArgSet selectFromArgSet(RooArgSet const &, std::string const &names)
Output struct for the RooVectorDataStore::getArrays() helper function.
std::vector< ArrayInfo< double > > reals
std::vector< ArrayInfo< RooAbsCategory::value_type > > cats