Logo ROOT   6.10/09
Reference Guide
RooVectorDataStore.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_VECTOR_DATA_STORE
17 #define ROO_VECTOR_DATA_STORE
18 
19 #include <list>
20 #include <vector>
21 #include <string>
22 #include <algorithm>
23 #include "RooAbsDataStore.h"
24 #include "TString.h"
25 #include "RooCatType.h"
26 #include "RooAbsCategory.h"
27 #include "RooAbsReal.h"
28 #include "RooChangeTracker.h"
29 
30 #define VECTOR_BUFFER_SIZE 1024
31 
32 class RooAbsArg ;
33 class RooArgList ;
34 class TTree ;
35 class RooFormulaVar ;
36 class RooArgSet ;
37 
39 public:
40 
42 
43  // Empty ctor
44  RooVectorDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName=0) ;
45  virtual RooAbsDataStore* clone(const char* newname=0) const { return new RooVectorDataStore(*this,newname) ; }
46  virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooVectorDataStore(*this,vars,newname) ; }
47 
48  RooVectorDataStore(const RooVectorDataStore& other, const char* newname=0) ;
49  RooVectorDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
50  RooVectorDataStore(const RooVectorDataStore& other, const RooArgSet& vars, const char* newname=0) ;
51 
52 
53  RooVectorDataStore(const char *name, const char *title, RooAbsDataStore& tds,
54  const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
55  Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
56 
57  virtual ~RooVectorDataStore() ;
58 
59  RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName) ;
60  RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName) ;
61 
62  // Write current row
63  virtual Int_t fill() ;
64 
65  // reserve storage for nEvt entries
66  virtual void reserve(Int_t nEvt);
67 
68  // Retrieve a row
69  using RooAbsDataStore::get ;
70  virtual const RooArgSet* get(Int_t index) const ;
71  virtual const RooArgSet* getNative(Int_t index) const ;
72  virtual Double_t weight() const ;
74  virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const ;
75  virtual Double_t weight(Int_t index) const ;
76  virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
77 
78  // Change observable name
79  virtual Bool_t changeObservableName(const char* from, const char* to) ;
80 
81  // Add one or more columns
82  virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
83  virtual RooArgSet* addColumns(const RooArgList& varList) ;
84 
85  // Merge column-wise
86  RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
87 
88  // Add rows
89  virtual void append(RooAbsDataStore& other) ;
90 
91  // General & bookkeeping methods
92  virtual Bool_t valid() const ;
93  virtual Int_t numEntries() const ;
94  virtual Double_t sumEntries() const { return _sumWeight ; }
95  virtual void reset() ;
96 
97  // Buffer redirection routines used in inside RooAbsOptTestStatistics
98  virtual void attachBuffers(const RooArgSet& extObs) ;
99  virtual void resetBuffers() ;
100 
101 
102  // Constant term optimizer interface
103  virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
104  virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0, Bool_t skipZeroWeights=kTRUE) ;
105  virtual void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
106  virtual void resetCache() ;
107  virtual void recalculateCache(const RooArgSet* /*proj*/, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights) ;
108 
109  virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
110 
111  const RooVectorDataStore* cache() const { return _cache ; }
112 
113  void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000) ;
114 
115  void dump() ;
116 
117  void setExternalWeightArray(Double_t* arrayWgt, Double_t* arrayWgtErrLo, Double_t* arrayWgtErrHi, Double_t* arraySumW2) {
118  _extWgtArray = arrayWgt ;
119  _extWgtErrLoArray = arrayWgtErrLo ;
120  _extWgtErrHiArray = arrayWgtErrHi ;
121  _extSumW2Array = arraySumW2 ;
122  }
123 
124  virtual void setDirtyProp(Bool_t flag) {
125  _doDirtyProp = flag ;
126  if (_cache) {
127  _cache->setDirtyProp(flag) ;
128  }
129  }
130 
131  //virtual void checkInit() const;
132 
133  const RooArgSet& row() { return _varsww ; }
134 
135  class RealVector {
136  public:
137  RealVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(Double_t))) :
138  _nativeReal(0), _real(0), _buf(0), _nativeBuf(0), _vec0(0), _tracker(0), _nset(0) {
139  _vec.reserve(initialCapacity);
140  }
141 
142  RealVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(Double_t))) :
143  _nativeReal(arg), _real(0), _buf(0), _nativeBuf(0), _vec0(0), _tracker(0), _nset(0) {
144  _vec.reserve(initialCapacity);
145  }
146 
147  virtual ~RealVector() {
148  delete _tracker;
149  if (_nset) delete _nset ;
150  }
151 
152  RealVector(const RealVector& other, RooAbsReal* real=0) :
153  _vec(other._vec), _nativeReal(real?real:other._nativeReal), _real(real?real:other._real), _buf(other._buf), _nativeBuf(other._nativeBuf), _nset(0) {
154  _vec0 = _vec.size()>0 ? &_vec.front() : 0 ;
155  if (other._tracker) {
156  _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",other._tracker->parameters()) ;
157  } else {
158  _tracker = 0 ;
159  }
160  if (other._nset) {
161  _nset = new RooArgSet(*other._nset) ;
162  }
163  }
164 
165  RealVector& operator=(const RealVector& other) {
166  if (&other==this) return *this;
167  _nativeReal = other._nativeReal;
168  _real = other._real;
169  _buf = other._buf;
170  _nativeBuf = other._nativeBuf;
171  if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(Double_t))) {
172  std::vector<Double_t> tmp;
173  tmp.reserve(std::max(other._vec.size(), VECTOR_BUFFER_SIZE / sizeof(Double_t)));
174  tmp.assign(other._vec.begin(), other._vec.end());
175  _vec.swap(tmp);
176  } else {
177  _vec = other._vec;
178  }
179  _vec0 = _vec.size()>0 ? &_vec.front() : 0;
180  return *this;
181  }
182 
183  void setNset(RooArgSet* newNset) { _nset = newNset ? new RooArgSet(*newNset) : 0 ; }
184 
185  RooArgSet* nset() const { return _nset ; }
186 
187  void setBufArg(RooAbsReal* arg) { _nativeReal = arg ; }
188  const RooAbsReal* bufArg() const { return _nativeReal ; }
189 
190  void setBuffer(RooAbsReal* real, Double_t* newBuf) {
191  _real = real ;
192  _buf = newBuf ;
193  if (_nativeBuf==0) {
194  _nativeBuf=newBuf ;
195  }
196  }
197 
198  void setNativeBuffer(Double_t* newBuf=0) {
199  _nativeBuf = newBuf ? newBuf : _buf ;
200  }
201 
202  void setDependents(const RooArgSet& deps) {
203  if (_tracker) {
204  delete _tracker ;
205  }
206  _tracker = new RooChangeTracker(Form("track_%s",_nativeReal->GetName()),"tracker",deps) ;
207  }
208 
210  if (!_tracker) return kFALSE ;
211  return _tracker->hasChanged(kTRUE) ;
212  }
213 
214  void fill() {
215  _vec.push_back(*_buf) ;
216  _vec0 = &_vec.front() ;
217  } ;
218 
219  void write(Int_t i) {
220 /* std::cout << "write(" << this << ") [" << i << "] nativeReal = " << _nativeReal << " = " << _nativeReal->GetName() << " real = " << _real << " buf = " << _buf << " value = " << *_buf << " native getVal() = " << _nativeReal->getVal() << " getVal() = " << _real->getVal() << std::endl ; */
221  _vec[i] = *_buf ;
222  }
223 
224  void reset() {
225  // make sure the vector releases the underlying memory
226  std::vector<Double_t> tmp;
227  _vec.swap(tmp);
228  _vec0 = 0;
229  }
230 
231  inline void get(Int_t idx) const {
232  *_buf = *(_vec0+idx) ;
233  }
234 
235  inline void getNative(Int_t idx) const {
236  *_nativeBuf = *(_vec0+idx) ;
237  }
238 
239  Int_t size() const { return _vec.size() ; }
240 
241  void resize(Int_t siz) {
242  if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(Double_t))) {
243  // do an expensive copy, if we save at least a factor 2 in size
244  std::vector<Double_t> tmp;
245  tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(Double_t))));
246  if (!_vec.empty())
247  tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
248  if (Int_t(tmp.size()) != siz)
249  tmp.resize(siz);
250  _vec.swap(tmp);
251  } else {
252  _vec.resize(siz);
253  }
254  _vec0 = _vec.size() > 0 ? &_vec.front() : 0;
255  }
256 
257  void reserve(Int_t siz) {
258  _vec.reserve(siz);
259  _vec0 = _vec.size() > 0 ? &_vec.front() : 0;
260  }
261 
262  protected:
263  std::vector<Double_t> _vec ;
264 
265  private:
266  friend class RooVectorDataStore ;
269  Double_t* _buf ; //!
273  RooArgSet* _nset ; //!
274  ClassDef(RealVector,1) // STL-vector-based Data Storage class
275  } ;
276 
277 
278  class RealFullVector : public RealVector {
279  public:
280  RealFullVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(Double_t))) : RealVector(initialCapacity),
281  _bufE(0), _bufEL(0), _bufEH(0),
282  _nativeBufE(0), _nativeBufEL(0), _nativeBufEH(0),
283  _vecE(0), _vecEL(0), _vecEH(0) {
284  }
285 
286  RealFullVector(RooAbsReal* arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(Double_t))) :
287  RealVector(arg,initialCapacity),
288  _bufE(0), _bufEL(0), _bufEH(0),
289  _nativeBufE(0), _nativeBufEL(0), _nativeBufEH(0),
290  _vecE(0), _vecEL(0), _vecEH(0) {
291  }
292 
293  virtual ~RealFullVector() {
294  if (_vecE) delete _vecE ;
295  if (_vecEL) delete _vecEL ;
296  if (_vecEH) delete _vecEH ;
297  }
298 
299  RealFullVector(const RealFullVector& other, RooAbsReal* real=0) : RealVector(other,real),
300  _bufE(other._bufE), _bufEL(other._bufEL), _bufEH(other._bufEH),
301  _nativeBufE(other._nativeBufE), _nativeBufEL(other._nativeBufEL), _nativeBufEH(other._nativeBufEH) {
302  _vecE = (other._vecE) ? new std::vector<Double_t>(*other._vecE) : 0 ;
303  _vecEL = (other._vecEL) ? new std::vector<Double_t>(*other._vecEL) : 0 ;
304  _vecEH = (other._vecEH) ? new std::vector<Double_t>(*other._vecEH) : 0 ;
305  }
306 
307  RealFullVector(const RealVector& other, RooAbsReal* real=0) : RealVector(other,real),
308  _bufE(0), _bufEL(0), _bufEH(0),
309  _nativeBufE(0), _nativeBufEL(0), _nativeBufEH(0) {
310  _vecE = 0 ;
311  _vecEL = 0 ;
312  _vecEH = 0 ;
313  }
314 
316  if (&other==this) return *this;
317  RealVector::operator=(other);
318  _bufE = other._bufE;
319  _bufEL = other._bufEL;
320  _bufEH = other._bufEH;
321  _nativeBufE = other._nativeBufE;
322  _nativeBufEL = other._nativeBufEL;
323  _nativeBufEH = other._nativeBufEH;
324  std::vector<Double_t>* src[3] = { other._vecE, other._vecEL, other._vecEH };
325  std::vector<Double_t>* dst[3] = { _vecE, _vecEL, _vecEH };
326  for (unsigned i = 0; i < 3; ++i) {
327  if (src[i]) {
328  if (dst[i]) {
329  if (dst[i]->size() <= src[i]->capacity() / 2 &&
330  src[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(Double_t))) {
331  std::vector<Double_t> tmp;
332  tmp.reserve(std::max(src[i]->size(), VECTOR_BUFFER_SIZE / sizeof(Double_t)));
333  tmp.assign(src[i]->begin(), src[i]->end());
334  dst[i]->swap(tmp);
335  } else {
336  *dst[i] = *src[i];
337  }
338  } else {
339  dst[i] = new std::vector<Double_t>(*src[i]);
340  }
341  } else {
342  delete dst[i];
343  dst[i] = 0;
344  }
345  }
346  return *this;
347  }
348 
349  void setErrorBuffer(Double_t* newBuf) {
350 /* std::cout << "setErrorBuffer(" << _nativeReal->GetName() << ") newBuf = " << newBuf << std::endl ; */
351  _bufE = newBuf ;
352  if (!_vecE) _vecE = new std::vector<Double_t> ;
353  _vecE->reserve(_vec.capacity()) ;
354  if (!_nativeBufE) _nativeBufE = _bufE ;
355  }
356  void setAsymErrorBuffer(Double_t* newBufL, Double_t* newBufH) {
357  _bufEL = newBufL ; _bufEH = newBufH ;
358  if (!_vecEL) {
359  _vecEL = new std::vector<Double_t> ;
360  _vecEH = new std::vector<Double_t> ;
361  _vecEL->reserve(_vec.capacity()) ;
362  _vecEH->reserve(_vec.capacity()) ;
363  }
364  if (!_nativeBufEL) {
365  _nativeBufEL = _bufEL ;
366  _nativeBufEH = _bufEH ;
367  }
368  }
369 
370  inline void getNative(Int_t idx) const {
371  RealVector::getNative(idx) ;
372  if (_vecE) {
373  *_nativeBufE = (*_vecE)[idx] ;
374  }
375  if (_vecEL) {
376  *_nativeBufEL = (*_vecEL)[idx] ;
377  *_nativeBufEH = (*_vecEH)[idx] ;
378  }
379  }
380 
381  void fill() {
382  RealVector::fill() ;
383  if (_vecE) _vecE->push_back(*_bufE) ;
384  if (_vecEL) _vecEL->push_back(*_bufEL) ;
385  if (_vecEH) _vecEH->push_back(*_bufEH) ;
386  } ;
387 
388  void write(Int_t i) {
389  RealVector::write(i) ;
390  if (_vecE) (*_vecE)[i] = *_bufE ;
391  if (_vecEL) (*_vecEL)[i] = *_bufEL ;
392  if (_vecEH) (*_vecEH)[i] = *_bufEH ;
393  }
394 
395  void reset() {
397  if (_vecE) {
398  std::vector<Double_t> tmp;
399  _vecE->swap(tmp);
400  }
401  if (_vecEL) {
402  std::vector<Double_t> tmp;
403  _vecEL->swap(tmp);
404  }
405  if (_vecEH) {
406  std::vector<Double_t> tmp;
407  _vecEH->swap(tmp);
408  }
409  }
410 
411  inline void get(Int_t idx) const {
412  RealVector::get(idx) ;
413  if (_vecE) *_bufE = (*_vecE)[idx];
414  if (_vecEL) *_bufEL = (*_vecEL)[idx] ;
415  if (_vecEH) *_bufEH = (*_vecEH)[idx] ;
416  }
417 
418  void resize(Int_t siz) {
419  RealVector::resize(siz);
420  std::vector<Double_t>* vlist[3] = { _vecE, _vecEL, _vecEH };
421  for (unsigned i = 0; i < 3; ++i) {
422  if (!vlist[i]) continue;
423  if (vlist[i]) {
424  if (siz < Int_t(vlist[i]->capacity()) / 2 && vlist[i]->capacity() > (VECTOR_BUFFER_SIZE / sizeof(Double_t))) {
425  // if we gain a factor of 2 in memory, we copy and swap
426  std::vector<Double_t> tmp;
427  tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(Double_t))));
428  if (!vlist[i]->empty())
429  tmp.assign(vlist[i]->begin(),
430  std::min(_vec.end(), _vec.begin() + siz));
431  if (Int_t(tmp.size()) != siz)
432  tmp.resize(siz);
433  vlist[i]->swap(tmp);
434  } else {
435  vlist[i]->resize(siz);
436  }
437  }
438  }
439  }
440 
441  void reserve(Int_t siz) {
442  RealVector::reserve(siz);
443  if (_vecE) _vecE->reserve(siz);
444  if (_vecEL) _vecEL->reserve(siz);
445  if (_vecEH) _vecEH->reserve(siz);
446  }
447 
448  private:
449  friend class RooVectorDataStore ;
456  std::vector<Double_t> *_vecE, *_vecEL, *_vecEH ;
457  ClassDef(RealFullVector,1) // STL-vector-based Data Storage class
458  } ;
459 
460 
461  class CatVector {
462  public:
463  CatVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(RooCatType))) :
464  _cat(0), _buf(0), _nativeBuf(0), _vec0(0)
465  {
466  _vec.reserve(initialCapacity);
467  }
468 
469  CatVector(RooAbsCategory* cat, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE / sizeof(RooCatType))) :
470  _cat(cat), _buf(0), _nativeBuf(0), _vec0(0)
471  {
472  _vec.reserve(initialCapacity);
473  }
474 
475  virtual ~CatVector() {
476  }
477 
478  CatVector(const CatVector& other, RooAbsCategory* cat=0) :
479  _cat(cat?cat:other._cat), _buf(other._buf), _nativeBuf(other._nativeBuf), _vec(other._vec)
480  {
481  _vec0 = _vec.size()>0 ? &_vec.front() : 0 ;
482  }
483 
484  CatVector& operator=(const CatVector& other) {
485  if (&other==this) return *this;
486  _cat = other._cat;
487  _buf = other._buf;
488  _nativeBuf = other._nativeBuf;
489  if (other._vec.size() <= _vec.capacity() / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(RooCatType))) {
490  std::vector<RooCatType> tmp;
491  tmp.reserve(std::max(other._vec.size(), VECTOR_BUFFER_SIZE / sizeof(RooCatType)));
492  tmp.assign(other._vec.begin(), other._vec.end());
493  _vec.swap(tmp);
494  } else {
495  _vec = other._vec;
496  }
497  _vec0 = _vec.size()>0 ? &_vec.front() : 0;
498  return *this;
499  }
500 
501  void setBuffer(RooCatType* newBuf) {
502  _buf = newBuf ;
503  if (_nativeBuf==0) _nativeBuf=newBuf ;
504  }
505 
506  void setNativeBuffer(RooCatType* newBuf=0) {
507  _nativeBuf = newBuf ? newBuf : _buf ;
508  }
509 
510  void fill() {
511  _vec.push_back(*_buf) ;
512  _vec0 = &_vec.front() ;
513  } ;
514  void write(Int_t i) {
515  _vec[i]=*_buf ;
516  } ;
517  void reset() {
518  // make sure the vector releases the underlying memory
519  std::vector<RooCatType> tmp;
520  _vec.swap(tmp);
521  _vec0 = 0;
522  }
523  inline void get(Int_t idx) const {
524  _buf->assignFast(*(_vec0+idx)) ;
525  }
526  inline void getNative(Int_t idx) const {
527  _nativeBuf->assignFast(*(_vec0+idx)) ;
528  }
529  Int_t size() const { return _vec.size() ; }
530 
531  void resize(Int_t siz) {
532  if (siz < Int_t(_vec.capacity()) / 2 && _vec.capacity() > (VECTOR_BUFFER_SIZE / sizeof(RooCatType))) {
533  // do an expensive copy, if we save at least a factor 2 in size
534  std::vector<RooCatType> tmp;
535  tmp.reserve(std::max(siz, Int_t(VECTOR_BUFFER_SIZE / sizeof(RooCatType))));
536  if (!_vec.empty())
537  tmp.assign(_vec.begin(), std::min(_vec.end(), _vec.begin() + siz));
538  if (Int_t(tmp.size()) != siz)
539  tmp.resize(siz);
540  _vec.swap(tmp);
541  } else {
542  _vec.resize(siz);
543  }
544  _vec0 = _vec.size() > 0 ? &_vec.front() : 0;
545  }
546 
547  void reserve(Int_t siz) {
548  _vec.reserve(siz);
549  _vec0 = _vec.size() > 0 ? &_vec.front() : 0;
550  }
551 
552  void setBufArg(RooAbsCategory* arg) { _cat = arg; }
553  const RooAbsCategory* bufArg() const { return _cat; }
554 
555  private:
556  friend class RooVectorDataStore ;
560  std::vector<RooCatType> _vec ;
562  ClassDef(CatVector,1) // STL-vector-based Data Storage class
563  } ;
564 
565 
566  protected:
567 
568  friend class RooAbsReal ;
569  friend class RooAbsCategory ;
570  friend class RooRealVar ;
571  std::vector<RealVector*>& realStoreList() { return _realStoreList ; }
572  std::vector<RealFullVector*>& realfStoreList() { return _realfStoreList ; }
573  std::vector<CatVector*>& catStoreList() { return _catStoreList ; }
574 
576 
577  CatVector* cv(0) ;
578 
579  // First try a match by name
580  std::vector<CatVector*>::iterator iter = _catStoreList.begin() ;
581  for (; iter!=_catStoreList.end() ; ++iter) {
582  if (std::string((*iter)->bufArg()->GetName())==cat->GetName()) {
583  cv = (*iter) ;
584  return cv ;
585  }
586  }
587 
588  // If nothing found this will make an entry
589  _catStoreList.push_back(new CatVector(cat)) ;
590  _nCat++ ;
591 
592  // Update cached ptr to first element as push_back may have reallocated
593  _firstCat = &_catStoreList.front() ;
594 
595  return _catStoreList.back() ;
596  }
597 
599 
600  RealVector* rv(0) ;
601 
602  // First try a match by name
603  std::vector<RealVector*>::iterator iter = _realStoreList.begin() ;
604  for (; iter!=_realStoreList.end() ; ++iter) {
605  //if (std::string((*iter)->bufArg()->GetName())==real->GetName()) {
606  if ((*iter)->bufArg()->namePtr()==real->namePtr()) {
607  rv = (*iter) ;
608  return rv ;
609  }
610  }
611 
612  // Then check if an entry already exists for a full real
613  std::vector<RealFullVector*>::iterator iter2 = _realfStoreList.begin() ;
614  for (; iter2!=_realfStoreList.end() ; ++iter2) {
615  //if (std::string((*iter2)->bufArg()->GetName())==real->GetName()) {
616  if ((*iter2)->bufArg()->namePtr()==real->namePtr()) {
617  // Return full vector as RealVector base class here
618  return (*iter2) ;
619  }
620  }
621 
622 
623  // If nothing found this will make an entry
624  _realStoreList.push_back(new RealVector(real)) ;
625  _nReal++ ;
626 
627  // Update cached ptr to first element as push_back may have reallocated
628  _firstReal = &_realStoreList.front() ;
629 
630 
631  return _realStoreList.back() ;
632  }
633 
635 
636  // First try a match by name
637  std::vector<RealFullVector*>::iterator iter = _realfStoreList.begin() ;
638  for (; iter!=_realfStoreList.end() ; ++iter) {
639  if (std::string((*iter)->bufArg()->GetName())==real->GetName()) {
640  return kTRUE ;
641  }
642  }
643  return kFALSE ;
644  }
645 
647 
648  // First try a match by name
649  std::vector<RealFullVector*>::iterator iter = _realfStoreList.begin() ;
650  for (; iter!=_realfStoreList.end() ; ++iter) {
651  if (std::string((*iter)->bufArg()->GetName())==real->GetName()) {
652  return (*iter)->_vecE ? kTRUE : kFALSE ;
653  }
654  }
655  return kFALSE ;
656  }
657 
659 
660  // First try a match by name
661  std::vector<RealFullVector*>::iterator iter = _realfStoreList.begin() ;
662  for (; iter!=_realfStoreList.end() ; ++iter) {
663  if (std::string((*iter)->bufArg()->GetName())==real->GetName()) {
664  return (*iter)->_vecEL ? kTRUE : kFALSE ;
665  }
666  }
667  return kFALSE ;
668  }
669 
671 
672  RealFullVector* rv(0) ;
673 
674  // First try a match by name
675  std::vector<RealFullVector*>::iterator iter = _realfStoreList.begin() ;
676  for (; iter!=_realfStoreList.end() ; ++iter) {
677  if (std::string((*iter)->bufArg()->GetName())==real->GetName()) {
678  rv = (*iter) ;
679  return rv ;
680  }
681  }
682 
683  // Then check if an entry already exists for a bare real
684  std::vector<RealVector*>::iterator iter2 = _realStoreList.begin() ;
685  for (; iter2!=_realStoreList.end() ; ++iter2) {
686  if (std::string((*iter2)->bufArg()->GetName())==real->GetName()) {
687 
688  // Convert element to full and add to full list
689  _realfStoreList.push_back(new RealFullVector(*(*iter2),real)) ;
690  _nRealF++ ;
691  _firstRealF = &_realfStoreList.front() ;
692 
693  // Delete bare element
694  RealVector* tmp = *iter2 ;
695  _realStoreList.erase(iter2) ;
696  delete tmp ;
697  if (_realStoreList.size() > 0)
698  _firstReal = &_realStoreList.front() ;
699  else
700  _firstReal = 0;
701  _nReal-- ;
702 
703  return _realfStoreList.back() ;
704  }
705  }
706 
707  // If nothing found this will make an entry
708  _realfStoreList.push_back(new RealFullVector(real)) ;
709  _nRealF++ ;
710 
711  // Update cached ptr to first element as push_back may have reallocated
712  _firstRealF = &_realfStoreList.front() ;
713 
714 
715  return _realfStoreList.back() ;
716  }
717 
718  virtual Bool_t hasFilledCache() const { return _cache ? kTRUE : kFALSE ; }
719 
720  void forceCacheUpdate() ;
721 
722  private:
724  RooRealVar* _wgtVar ; // Pointer to weight variable (if set)
725 
726  std::vector<RealVector*> _realStoreList ;
727  std::vector<RealFullVector*> _realfStoreList ;
728  std::vector<CatVector*> _catStoreList ;
729 
730  void setAllBuffersNative() ;
731 
736  RealVector** _firstReal ; //! do not persist
737  RealFullVector** _firstRealF ; //! do not persist
738  CatVector** _firstCat ; //! do not persist
741 
742  Double_t* _extWgtArray ; //! External weight array
743  Double_t* _extWgtErrLoArray ; //! External weight array - low error
744  Double_t* _extWgtErrHiArray ; //! External weight array - high error
745  Double_t* _extSumW2Array ; //! External sum of weights array
746 
747  mutable Double_t _curWgt ; // Weight of current event
748  mutable Double_t _curWgtErrLo ; // Weight of current event
749  mutable Double_t _curWgtErrHi ; // Weight of current event
750  mutable Double_t _curWgtErr ; // Weight of current event
751 
752  RooVectorDataStore* _cache ; //! Optimization cache
753  RooAbsArg* _cacheOwner ; //! Cache owner
754 
755  Bool_t _forcedUpdate ; //! Request for forced cache update
756 
757  ClassDef(RooVectorDataStore,2) // STL-vector-based Data Storage class
758 };
759 
760 
761 #endif
CatVector * addCategory(RooAbsCategory *cat)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual const RooArgSet * get() const
virtual Bool_t valid() const
Return true if currently loaded coordinate is considered valid within the current range definitions o...
RealFullVector & operator=(const RealFullVector &other)
RooAbsDataStore is the abstract base class for data collection that use a TTree as internal storage m...
CatVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(RooCatType)))
RealFullVector(RooAbsReal *arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(Double_t)))
Double_t * _extSumW2Array
External weight array - high error.
RooRealVar * weightVar(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return pointer to weight variable if it is defined.
const RooAbsCategory * bufArg() const
virtual Int_t fill()
Interface function to TTree::Fill.
virtual void cacheArgs(const RooAbsArg *owner, RooArgSet &varSet, const RooArgSet *nset=0, Bool_t skipZeroWeights=kTRUE)
Cache given RooAbsArgs with this tree: The tree is given direct write access of the args internal cac...
void setBuffer(RooCatType *newBuf)
void setNativeBuffer(Double_t *newBuf=0)
virtual RooAbsDataStore * clone(const char *newname=0) const
virtual void reserve(Int_t nEvt)
RealVector & operator=(const RealVector &other)
virtual void setDirtyProp(Bool_t flag)
void setDependents(const RooArgSet &deps)
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a new column to the data set which holds the pre-calculated values of &#39;newVar&#39;.
void setBuffer(RooAbsReal *real, Double_t *newBuf)
virtual void recalculateCache(const RooArgSet *, Int_t firstEvent, Int_t lastEvent, Int_t stepSize, Bool_t skipZeroWeights)
virtual void attachCache(const RooAbsArg *newOwner, const RooArgSet &cachedVars)
Initialize cache of dataset: attach variables of cache ArgSet to the corresponding TTree branches...
Bool_t hasChanged(Bool_t clearState)
Returns true if state has changes since last call with clearState=kTRUE If clearState is true...
virtual void append(RooAbsDataStore &other)
std::vector< RealVector * > & realStoreList()
Double_t _sumWeight
do not persist
Double_t * _extWgtErrLoArray
External weight array.
int Int_t
Definition: RtypesCore.h:41
const RooVectorDataStore * cache() const
bool Bool_t
Definition: RtypesCore.h:59
std::vector< RealFullVector * > & realfStoreList()
void setAsymErrorBuffer(Double_t *newBufL, Double_t *newBufH)
RooAbsArg * _cacheOwner
Optimization cache.
RooTreeDataStore is the abstract base class for data collection that use a TTree as internal storage ...
RealVector(const RealVector &other, RooAbsReal *real=0)
Double_t _curWgt
External sum of weights array.
std::vector< Double_t > _vec
Bool_t _doDirtyProp
Iterator over cached variables.
std::vector< RooCatType > _vec
virtual RooAbsDataStore * clone(const RooArgSet &vars, const char *newname=0) const
virtual RooArgSet * addColumns(const RooArgList &varList)
Utility function to add multiple columns in one call See addColumn() for details. ...
std::vector< RealFullVector * > _realfStoreList
RooArgSet varsNoWeight(const RooArgSet &allVars, const char *wgtName)
Utility function for constructors Return RooArgSet that is copy of allVars minus variable matching wg...
const RooArgSet & cachedVars() const
Bool_t _forcedUpdate
Cache owner.
#define ClassDef(name, id)
Definition: Rtypes.h:297
void loadValues(const RooAbsDataStore *tds, const RooFormulaVar *select=0, const char *rangeName=0, Int_t nStart=0, Int_t nStop=2000000000)
throw(std::string("RooVectorDataSore::loadValues() NOT IMPLEMENTED")) ;
std::vector< CatVector * > & catStoreList()
virtual Double_t sumEntries() const
void setNset(RooArgSet *newNset)
std::vector< RealVector * > _realStoreList
virtual Bool_t hasFilledCache() const
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
void setNativeBuffer(RooCatType *newBuf=0)
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:22
virtual void setArgStatus(const RooArgSet &set, Bool_t active)
Disabling of branches is (intentionally) not implemented in vector data stores (as the doesn&#39;t result...
std::vector< Double_t > * _vecEH
virtual Int_t numEntries() const
Bool_t hasError(RooAbsReal *real)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
CatVector ** _firstCat
do not persist
RealFullVector(const RealFullVector &other, RooAbsReal *real=0)
Bool_t hasAsymError(RooAbsReal *real)
RooArgSet parameters() const
RealFullVector(const RealVector &other, RooAbsReal *real=0)
virtual Bool_t isWeighted() const
virtual const RooArgSet * getNative(Int_t index) const
Load the n-th data point (n=&#39;index&#39;) in memory and return a pointer to the internal RooArgSet holding...
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual Double_t weight() const
Return the weight of the n-th data point (n=&#39;index&#39;) in memory.
RealVector(RooAbsReal *arg, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(Double_t)))
RealFullVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(Double_t)))
CatVector & operator=(const CatVector &other)
Double_t * _extWgtErrHiArray
External weight array - low error.
const Bool_t kFALSE
Definition: RtypesCore.h:92
RealVector ** _firstReal
std::vector< CatVector * > _catStoreList
RooVectorDataStore * _cache
virtual const RooAbsArg * cacheOwner()
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Bool_t isFullReal(RooAbsReal *real)
RealVector * addReal(RooAbsReal *real)
CatVector(const CatVector &other, RooAbsCategory *cat=0)
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
RealVector(UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(Double_t)))
virtual ~RooVectorDataStore()
Destructor.
RealFullVector * addRealFull(RooAbsReal *real)
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
const RooAbsReal * bufArg() const
std::vector< Double_t > * _vecEL
CatVector(RooAbsCategory *cat, UInt_t initialCapacity=(VECTOR_BUFFER_SIZE/sizeof(RooCatType)))
virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const
A TTree object has a header with a name and a title.
Definition: TTree.h:78
float type_of_call hi(const int &, const int &)
RealFullVector ** _firstRealF
do not persist
virtual void attachBuffers(const RooArgSet &extObs)
virtual Bool_t changeObservableName(const char *from, const char *to)
const RooArgSet & row()
#define VECTOR_BUFFER_SIZE
RooAbsDataStore * merge(const RooArgSet &allvars, std::list< RooAbsDataStore *> dstoreList)
Merge columns of supplied data set(s) with this data set.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
void setExternalWeightArray(Double_t *arrayWgt, Double_t *arrayWgtErrLo, Double_t *arrayWgtErrHi, Double_t *arraySumW2)
const Bool_t kTRUE
Definition: RtypesCore.h:91
void setBufArg(RooAbsCategory *arg)
const TNamed * namePtr() const
Definition: RooAbsArg.h:459
void getNative(Int_t idx) const