Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

FillIterator Class Reference

#include <FillIterator.h>

Inheritance diagram for FillIterator:

Inheritance graph
[legend]
Collaboration diagram for FillIterator:

Collaboration graph
[legend]
List of all members.

Detailed Description

Abstract base class for iterators used to fill self-filling histograms.

A FillIterator object has to know how many entries for a given event should be made. If, for example, we have n D* meson candidates in an event, operator() should return a value between 0 (first D*) and n-1 (last D*). "-1" means "no D* available, or past the last D*".

To iterate over all values, use code like this (iter is a pointer to a FillIterator, and may be 0, meaning "exactly 1 entry per event"):

  if (!iter || iter->reset()) {
  do {
    if (!cut || (*cut)()) {
      float w = wfun ? (*wfun)() : 1.;
      this->TH1F::Fill ((*xfun)(), w);
    } 
  } while (iter && iter->next());  
 *

If FillIterator objects are used, the corresponding FloatFun and BaseCut objects normally have to store a pointer to the iterator, so that a DStarMass object can ask the iterator the mass of which D* meson is to be plotted.

The destructor is protected to ensure FillIterator objects can only be created on the heap (with "new"). The resulting memory leak is acknowledged.

Normally, a concrete subclass of FillIterator will look something like this:

 class MyIterator: public FillIterator {
 public:
   MyIterator(): index(0) {}
   virtual int getN () const { return NUMBEROFENTRIES;};
   virtual int operator() () const {
     return (index < getN()) ? index : -1;
   }
   virtual bool next() {
     if (index++ >= getN()) {
       index = -1;
       return false;
     }
     return true;
   }
   virtual bool reset() {
     If (getN() <= 0) {
       index = -1;
       return false;
     }
     index = 0;
     return true;
   }
   virtual bool isValid() const {
     return (index >= 0) && index < getN();
   }
 protected:
   ~MyIterator() {};
   int index;
 };
Here getN() has to be implemented in a way that it returns the number of entries, e.g. D* mesons, for the current event. This will typically need a pointer to some Tree entry that contains the number of D* mesons.

Changelog

Author: Jenny Böhme, Benno List

Date
2005/06/04 16:27:51
Author
blist

Definition at line 90 of file FillIterator.h.

Public Member Functions

 FillIterator (const char *name_="?")
 Constructor from a C style string, serves as default constructor.

 FillIterator (const std::string &name_)
 Constructor from a C++ string.

virtual int operator() () const=0
 Returns iterator value, starting at 0; "-1" means "invalid".

virtual bool next ()=0
 Increments iterator; returns false if iterator cannot be incremented.

virtual bool reset ()=0
 Resets iterator; returns false if iterator value range is empty.

virtual bool isValid () const=0
 Returns whether current value of iterator is valid.

virtual const FillIteratorgetIterator () const
 Returns pointer to iterator = itself.


Protected Member Functions

virtual ~FillIterator ()
 Protected destructor to ensure creation on the heap.


Constructor & Destructor Documentation

FillIterator::FillIterator const char *  name_ = "?"  )  [inline, explicit]
 

Constructor from a C style string, serves as default constructor.

Parameters:
name_  The object's name

Definition at line 94 of file FillIterator.h.

FillIterator::FillIterator const std::string &  name_  )  [inline, explicit]
 

Constructor from a C++ string.

Parameters:
name_  The object's name

Definition at line 98 of file FillIterator.h.


The documentation for this class was generated from the following file:
Generated on Thu Oct 26 12:54:33 2006 for SFH by doxygen 1.3.2