Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 5725)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 5728)
@@ -71,4 +71,62 @@
 // --------------------------------------------------------------------------
 //
+// return kTRUE  the lo gains exist for the actual pixel, else return kFALSE
+//
+#include <iostream>
+Bool_t MRawEvtPixelIter::HasLoGain() const
+{
+    // We have no lo-gain at all
+    if (!fLoGainId)
+        return kFALSE;
+
+    // This is to make the first call of this function in Next()
+    // work properly! NEVER call this function before Next()
+    if (fNumLoGainEntry==0)
+        return kTRUE;
+
+//    cout << fNumLoGainEntry << " " << flush;
+//    cout << fData->fLoGainPixId->GetSize() << " " << flush;
+
+    if (fNumLoGainEntry>fData->fLoGainPixId->GetSize())
+        return kFALSE;
+
+/*
+    cout << fNumLoGainEntry << " " << flush;
+    cout << fData->fLoGainPixId->GetSize() << " " << flush;
+    cout << fData->fLoGainPixId->GetArray() << " " << flush;
+    cout << fLoGainId << endl;
+    */
+//    cout << (int)(fLoGainId-fData->fLoGainPixId->GetArray()) << " " << flush;
+//    cout << (int)(fHiGainId-fData->fHiGainPixId->GetArray()) << " " << flush;
+
+    Bool_t rc = *fHiGainId!=*fLoGainId;
+
+//    cout << "done." << endl;
+
+
+    if (rc)
+        return kFALSE;
+    /*
+    // We have no lo-gain at all
+    if (!fLoGainId)
+        return kFALSE;
+
+    // This is to make the first call of this function in Next()
+    // work properly! NEVER call this function before Next()
+    if (fNumLoGainEntry==0)
+        return kTRUE;
+
+    // Make sure, that we don't exceed the last entry in the array!
+    if (fNumLoGainEntry==fData->fLoGainPixId->GetSize())
+        return kFALSE;
+
+    // Check whether the current position in lo-gain fits the hi-gain
+    return *fHiGainId!=*fLoGainId;
+     */
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // It steps to the next pixel. If there is no next pixel NULL is returned.
 // If a next pixel where found, a pointer to the primary given (constructor)
@@ -86,16 +144,15 @@
     // if we are already at the last entry there is no 'next' entry anymore
     //
-    if (fNumLoGainEntry != fData->fLoGainPixId->GetSize())
-        if (HasLoGain())
-        {
-            //
-            // if higainpixid and logainpixid of the actual pixel are
-            // identical then we have to move the pointer to the next
-            // entry in the lo gains
-            //
-            fNumLoGainEntry++;
-            fLoGainId++;
-            fLoGainPos += fNumLoGainSamples;
-        }
+    if (HasLoGain())
+    {
+        //
+        // if higainpixid and logainpixid of the actual pixel are
+        // identical then we have to move the pointer to the next
+        // entry in the lo gains
+        //
+        fNumLoGainEntry++;
+        fLoGainId++;
+        fLoGainPos += fNumLoGainSamples;
+    }
 
     //
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 5725)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 5728)
@@ -90,11 +90,5 @@
     Short_t GetIdxMaxHiLoGainSample() const;
 
-    Bool_t HasLoGain() const
-    {
-        //
-        // return kTRUE  the lo gains exist for the actual pixel, else return kFALSE
-        //
-        return fLoGainId && *fHiGainId==*fLoGainId;
-    }
+    Bool_t HasLoGain() const;
     Bool_t IsABFlagValid() const { return fABFlags ? kTRUE : kFALSE; }
     Bool_t HasABFlag() const
