ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooDataHistSliceIter.cxx 36209 2010-10-08 21:37:36Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
// 
// BEGIN_HTML
// RooDataHistSliceIter iterates over all bins in a RooDataHist that
// occur in a slice defined by the bin coordinates of the input
// sliceSet.
// END_HTML
//

#include "RooFit.h"

#if ROOT_VERSION_CODE <= ROOT_VERSION(5,19,04)
#ifndef nullptr
#define nullptr 0
#endif
#endif

#include "RooDataHist.h"
#include "RooArgSet.h"
#include "RooAbsLValue.h"
#include "RooDataHistSliceIter.h"

ClassImp(RooDataHistSliceIter)
;



//_____________________________________________________________________________
RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
{
  // Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
  // by the values of the arguments in 'sliceArg'

  // Calculate base index (for 0th bin) for slice    
  RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
  dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;

  if (hist._vars.getSize()>1) {
    _baseIndex = hist.calcTreeIndex() ;  
  } else {
    _baseIndex = 0 ;
  }

  _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;

  hist._iterator->Reset() ;
  RooAbsArg* arg ;
  Int_t i=0 ;
  while((arg=(RooAbsArg*)hist._iterator->Next())) {
    if (arg==sliceArgInt) break ;
    i++ ;
  }
  _stepSize = hist._idxMult[i] ;  
  _curStep = 0 ;  

}



//_____________________________________________________________________________
RooDataHistSliceIter::RooDataHistSliceIter(const RooDataHistSliceIter& other) : 
  TIterator(other), 
  _hist(other._hist), 
  _sliceArg(other._sliceArg),   
  _baseIndex(other._baseIndex),
  _stepSize(other._stepSize),
  _nStep(other._nStep), 
  _curStep(other._curStep)
{
  // Copy constructor
}



//_____________________________________________________________________________
RooDataHistSliceIter::~RooDataHistSliceIter() 
{
  // Destructor
}



//_____________________________________________________________________________
const TCollection* RooDataHistSliceIter::GetCollection() const 
{
  // Dummy
  return 0 ;
}




//_____________________________________________________________________________
TObject* RooDataHistSliceIter::Next() 
{  
  // Iterator increment operator

  if (_curStep==_nStep) {
    return 0 ;
  }
  
  // Select appropriate entry in RooDataHist 
  _hist->get(_baseIndex + _curStep*_stepSize) ;

  // Increment iterator position 
  _curStep++ ;

  return _sliceArg ;
}



//_____________________________________________________________________________
void RooDataHistSliceIter::Reset() 
{
  // Reset iterator position to beginning
  _curStep=0 ;
}



//_____________________________________________________________________________
TObject *RooDataHistSliceIter::operator*() const
{
  // Iterator dereference operator, not functional for this iterator

   Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
   // Select appropriate entry in RooDataHist 
   _hist->get(_baseIndex + step*_stepSize) ;

   return _sliceArg ;
}


//_____________________________________________________________________________
bool RooDataHistSliceIter::operator!=(const TIterator &aIter) const
{
  // Returns true if position of this iterator differs from position
  // of iterator 'aIter'

   if (nullptr == &aIter)
      return false;

   if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
      const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
      return (_curStep != iter._curStep);
   }
   
   return false;
}
 RooDataHistSliceIter.cxx:1
 RooDataHistSliceIter.cxx:2
 RooDataHistSliceIter.cxx:3
 RooDataHistSliceIter.cxx:4
 RooDataHistSliceIter.cxx:5
 RooDataHistSliceIter.cxx:6
 RooDataHistSliceIter.cxx:7
 RooDataHistSliceIter.cxx:8
 RooDataHistSliceIter.cxx:9
 RooDataHistSliceIter.cxx:10
 RooDataHistSliceIter.cxx:11
 RooDataHistSliceIter.cxx:12
 RooDataHistSliceIter.cxx:13
 RooDataHistSliceIter.cxx:14
 RooDataHistSliceIter.cxx:15
 RooDataHistSliceIter.cxx:16
 RooDataHistSliceIter.cxx:17
 RooDataHistSliceIter.cxx:18
 RooDataHistSliceIter.cxx:19
 RooDataHistSliceIter.cxx:20
 RooDataHistSliceIter.cxx:21
 RooDataHistSliceIter.cxx:22
 RooDataHistSliceIter.cxx:23
 RooDataHistSliceIter.cxx:24
 RooDataHistSliceIter.cxx:25
 RooDataHistSliceIter.cxx:26
 RooDataHistSliceIter.cxx:27
 RooDataHistSliceIter.cxx:28
 RooDataHistSliceIter.cxx:29
 RooDataHistSliceIter.cxx:30
 RooDataHistSliceIter.cxx:31
 RooDataHistSliceIter.cxx:32
 RooDataHistSliceIter.cxx:33
 RooDataHistSliceIter.cxx:34
 RooDataHistSliceIter.cxx:35
 RooDataHistSliceIter.cxx:36
 RooDataHistSliceIter.cxx:37
 RooDataHistSliceIter.cxx:38
 RooDataHistSliceIter.cxx:39
 RooDataHistSliceIter.cxx:40
 RooDataHistSliceIter.cxx:41
 RooDataHistSliceIter.cxx:42
 RooDataHistSliceIter.cxx:43
 RooDataHistSliceIter.cxx:44
 RooDataHistSliceIter.cxx:45
 RooDataHistSliceIter.cxx:46
 RooDataHistSliceIter.cxx:47
 RooDataHistSliceIter.cxx:48
 RooDataHistSliceIter.cxx:49
 RooDataHistSliceIter.cxx:50
 RooDataHistSliceIter.cxx:51
 RooDataHistSliceIter.cxx:52
 RooDataHistSliceIter.cxx:53
 RooDataHistSliceIter.cxx:54
 RooDataHistSliceIter.cxx:55
 RooDataHistSliceIter.cxx:56
 RooDataHistSliceIter.cxx:57
 RooDataHistSliceIter.cxx:58
 RooDataHistSliceIter.cxx:59
 RooDataHistSliceIter.cxx:60
 RooDataHistSliceIter.cxx:61
 RooDataHistSliceIter.cxx:62
 RooDataHistSliceIter.cxx:63
 RooDataHistSliceIter.cxx:64
 RooDataHistSliceIter.cxx:65
 RooDataHistSliceIter.cxx:66
 RooDataHistSliceIter.cxx:67
 RooDataHistSliceIter.cxx:68
 RooDataHistSliceIter.cxx:69
 RooDataHistSliceIter.cxx:70
 RooDataHistSliceIter.cxx:71
 RooDataHistSliceIter.cxx:72
 RooDataHistSliceIter.cxx:73
 RooDataHistSliceIter.cxx:74
 RooDataHistSliceIter.cxx:75
 RooDataHistSliceIter.cxx:76
 RooDataHistSliceIter.cxx:77
 RooDataHistSliceIter.cxx:78
 RooDataHistSliceIter.cxx:79
 RooDataHistSliceIter.cxx:80
 RooDataHistSliceIter.cxx:81
 RooDataHistSliceIter.cxx:82
 RooDataHistSliceIter.cxx:83
 RooDataHistSliceIter.cxx:84
 RooDataHistSliceIter.cxx:85
 RooDataHistSliceIter.cxx:86
 RooDataHistSliceIter.cxx:87
 RooDataHistSliceIter.cxx:88
 RooDataHistSliceIter.cxx:89
 RooDataHistSliceIter.cxx:90
 RooDataHistSliceIter.cxx:91
 RooDataHistSliceIter.cxx:92
 RooDataHistSliceIter.cxx:93
 RooDataHistSliceIter.cxx:94
 RooDataHistSliceIter.cxx:95
 RooDataHistSliceIter.cxx:96
 RooDataHistSliceIter.cxx:97
 RooDataHistSliceIter.cxx:98
 RooDataHistSliceIter.cxx:99
 RooDataHistSliceIter.cxx:100
 RooDataHistSliceIter.cxx:101
 RooDataHistSliceIter.cxx:102
 RooDataHistSliceIter.cxx:103
 RooDataHistSliceIter.cxx:104
 RooDataHistSliceIter.cxx:105
 RooDataHistSliceIter.cxx:106
 RooDataHistSliceIter.cxx:107
 RooDataHistSliceIter.cxx:108
 RooDataHistSliceIter.cxx:109
 RooDataHistSliceIter.cxx:110
 RooDataHistSliceIter.cxx:111
 RooDataHistSliceIter.cxx:112
 RooDataHistSliceIter.cxx:113
 RooDataHistSliceIter.cxx:114
 RooDataHistSliceIter.cxx:115
 RooDataHistSliceIter.cxx:116
 RooDataHistSliceIter.cxx:117
 RooDataHistSliceIter.cxx:118
 RooDataHistSliceIter.cxx:119
 RooDataHistSliceIter.cxx:120
 RooDataHistSliceIter.cxx:121
 RooDataHistSliceIter.cxx:122
 RooDataHistSliceIter.cxx:123
 RooDataHistSliceIter.cxx:124
 RooDataHistSliceIter.cxx:125
 RooDataHistSliceIter.cxx:126
 RooDataHistSliceIter.cxx:127
 RooDataHistSliceIter.cxx:128
 RooDataHistSliceIter.cxx:129
 RooDataHistSliceIter.cxx:130
 RooDataHistSliceIter.cxx:131
 RooDataHistSliceIter.cxx:132
 RooDataHistSliceIter.cxx:133
 RooDataHistSliceIter.cxx:134
 RooDataHistSliceIter.cxx:135
 RooDataHistSliceIter.cxx:136
 RooDataHistSliceIter.cxx:137
 RooDataHistSliceIter.cxx:138
 RooDataHistSliceIter.cxx:139
 RooDataHistSliceIter.cxx:140
 RooDataHistSliceIter.cxx:141
 RooDataHistSliceIter.cxx:142
 RooDataHistSliceIter.cxx:143
 RooDataHistSliceIter.cxx:144
 RooDataHistSliceIter.cxx:145
 RooDataHistSliceIter.cxx:146
 RooDataHistSliceIter.cxx:147
 RooDataHistSliceIter.cxx:148
 RooDataHistSliceIter.cxx:149
 RooDataHistSliceIter.cxx:150
 RooDataHistSliceIter.cxx:151
 RooDataHistSliceIter.cxx:152
 RooDataHistSliceIter.cxx:153
 RooDataHistSliceIter.cxx:154
 RooDataHistSliceIter.cxx:155
 RooDataHistSliceIter.cxx:156
 RooDataHistSliceIter.cxx:157
 RooDataHistSliceIter.cxx:158
 RooDataHistSliceIter.cxx:159
 RooDataHistSliceIter.cxx:160
 RooDataHistSliceIter.cxx:161
 RooDataHistSliceIter.cxx:162
 RooDataHistSliceIter.cxx:163
 RooDataHistSliceIter.cxx:164
 RooDataHistSliceIter.cxx:165
 RooDataHistSliceIter.cxx:166