/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooDataHistSliceIter.cxx 24269 2008-06-13 15:37:03Z 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"

#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,hist.bname()) ;
  _baseIndex = hist.calcTreeIndex() ;
  _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins(hist.bname()) ;

  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), 
  _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;
}

Last change: Wed Jun 25 08:32:31 2008
Last generated: 2008-06-25 08:32

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.