#include <FillIterator.h>
Inheritance diagram for FillIterator:
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; };
Changelog
Author: Jenny Böhme, Benno List
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 FillIterator * | getIterator () const |
Returns pointer to iterator = itself. | |
Protected Member Functions | |
virtual | ~FillIterator () |
Protected destructor to ensure creation on the heap. |
|
Constructor from a C style string, serves as default constructor.
Definition at line 94 of file FillIterator.h. |
|
Constructor from a C++ string.
Definition at line 98 of file FillIterator.h. |