#ifndef MRAWEVTPIXELITER_H
#define MRAWEVTPIXELITER_H

#ifndef MAGIC_H
#include "../MBase/MAGIC.h"
#endif
#ifndef ROOT_TIterator
#include <TIterator.h>
#endif

class MRawEvtData;

class MRawEvtPixelIter : public TIterator
{
private:
    UShort_t fNumHiGainEntry;   //! actual number of entry in fHiGainPixId
    UShort_t fNumLoGainEntry;   //! actual number of entry in fLoGainPixId

    UShort_t *fHiGainId;        //! actual entry of fHiGainPixId
    UShort_t *fLoGainId;        //! actual entry of fLoGainPixId

    Byte_t   *fHiGainPos;       //! pointer to hi-gain samples of actual pixel
    Byte_t   *fLoGainPos;       //! pointer to lo-gain samples of actual pixel

    MRawEvtData *fData;         //! pointer to object which we are iterating

public:
    MRawEvtPixelIter(MRawEvtData *dat) : fData(dat)
    {
        //
        // WARNING: The Iterator now points to the FIRST entry.
        //          This means that you have to use a do...while loop
        //          NOT a while() loop.
        //
        Reset();
    }

    TObject *Next();

    UShort_t GetPixelId() const
    {
        //
        // return Id of actual pixel
        //
        return *fHiGainId;
    }

    Byte_t *GetHiGainFadcSamples() const
    {
        //
        // return a pointer to the fadc samples of the hi gains
        // WARNING: Don't forget to get the number of valid entries
        //          (GetNumSamples) to know how many entries of the array
        //          belong to the actual pixel
        //
        return fHiGainPos;
    }

    Bool_t IsLoGain() const
    {
        //
        // return kTRUE  the lo gains exist for the actual pixel, else return kFALSE
        //
        return *fHiGainId==*fLoGainId;
    }

    Byte_t *GetLoGainFadcSamples() const
    {
        //
        // return a pointer to the fadc samples of the lo gains if they exist
        // for the actual pixel, else return zero
        //
        return IsLoGain() ? fLoGainPos : NULL;
    }

    void Reset();

    ClassDef(MRawEvtPixelIter, 1)
};

#endif
