Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8345)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8346)
@@ -61,4 +61,8 @@
      - increased file format version from 5 to 6
 
+   * mraw/MRawEvtPixelIter.[h,cc]:
+     - made aware of handling the new and old format
+     - added range to GetIdxMax*
+
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8345)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8346)
@@ -2,4 +2,11 @@
 
  *** <cvs>
+
+   - merpp: Implemented file format version 8 (MUX FADC data). The 16-bit
+     data containing only 10-bit information is still cooked down to
+     8-bit, by cutting away the lowest 8-bit.
+
+   - merpp: When reading raw data the data is now stored in a single
+     array. The lo-gain array is obsolete. The interface stays the same.
 
    - callisto: Improved binning for the pulse position check histogram
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 8345)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 8346)
@@ -71,30 +71,4 @@
 // --------------------------------------------------------------------------
 //
-// return kTRUE  the lo gains exist for the actual pixel, else return kFALSE
-//
-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;
-
-    if (fNumLoGainEntry>fData->fLoGainPixId->GetSize())
-        return kFALSE;
-
-    Bool_t rc = *fHiGainId!=*fLoGainId;
-
-    if (rc)
-        return kFALSE;
-
-    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)
@@ -110,24 +84,25 @@
 
     //
-    // if we are already at the last entry there is no 'next' entry anymore
-    //
-    if (HasLoGain())
+    // For old MC data which stores hi- and lo-gain in two arrays
+    // we have to use the old algorithm
+    //
+    if (fData->fLoGainPixId->GetSize())
     {
-        //
-        // 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
-        //
+        fNumHiGainEntry++;
+        fHiGainId++;
+        fHiGainPos += fNumHiGainSamples;
+
         fNumLoGainEntry++;
         fLoGainId++;
         fLoGainPos += fNumLoGainSamples;
     }
-
-    //
-    // here we have to move the pointer to the next entry in the hi gains
-    //
-    fNumHiGainEntry++;
-    fHiGainId++;
-    fHiGainPos += fNumHiGainSamples;
+    else
+    {
+        fNumLoGainEntry = ++fNumHiGainEntry;
+        fLoGainId       = ++fHiGainId;
+
+        fHiGainPos     += fNumHiGainSamples+fNumLoGainSamples;
+        fLoGainPos      = fHiGainPos + fNumHiGainSamples;
+    }
 
     //
@@ -152,9 +127,23 @@
     // set pointer to first entry of arrays
     //
-    fHiGainId   = fData->fHiGainPixId->GetArray()-1;
-    fLoGainId   = fData->fLoGainPixId->GetArray();
-    fHiGainPos  = fData->fHiGainFadcSamples->GetArray()-fNumHiGainSamples;
-    fLoGainPos  = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
-    fABFlags    = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
+    fHiGainId = fData->fHiGainPixId->GetArray()-1;
+    fABFlags  = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
+
+    //
+    // For old MC data which stores hi- and lo-gain in two arrays
+    // we have to use the old algorithm
+    //
+    if (fData->fLoGainPixId->GetSize())
+    {
+        fLoGainId  = fData->fLoGainPixId->GetArray();
+        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumHiGainSamples;
+        fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
+    }
+    else
+    {
+        fLoGainId  = fHiGainId;
+        fLoGainPos = fHiGainPos+fNumHiGainSamples;
+        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumHiGainSamples+fNumLoGainSamples);
+    }
 
     //
@@ -175,4 +164,69 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Returns the index of the FADC slice the maximum signal in. If the highest
+// slices have the same value the last one is returned.
+//
+Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample(const Byte_t hifirst, const Byte_t hilast) const
+{
+    const Int_t l = hilast>fNumHiGainSamples  ? fNumHiGainSamples : hilast+1;
+
+    Byte_t *beg = fHiGainPos+hifirst;
+
+    Byte_t *ptr = beg+1;
+    Byte_t *max = beg;
+    const Byte_t *end = fHiGainPos + l;
+
+    do if (*ptr>*max) max = ptr;
+    while (++ptr != end);
+
+    return max-fHiGainPos;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the index of the FADC slice the maximum signal in. If no lo-gains
+// are available -1 is returned. If the highest slices have the same value the
+// last one is returned.
+//
+Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample(const Byte_t lofirst, const Byte_t lolast) const
+{
+    if (!HasLoGain())
+        return -1; // means: not found
+
+    const Int_t l = lolast>fNumLoGainSamples  ? fNumLoGainSamples : lolast+1;
+
+    Byte_t *beg = fLoGainPos+lofirst;
+
+    Byte_t *ptr = beg+1;
+    Byte_t *max = beg;
+    const Byte_t *end = fLoGainPos + l;
+
+    do if (*ptr>*max) max = ptr;
+    while (++ptr != end);
+
+    return max-fLoGainPos;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the maximum signal of all sliced in the hi gain samples
+//
+Byte_t MRawEvtPixelIter::GetMaxHiGainSample(const Byte_t hifirst, const Byte_t hilast) const
+{
+    Byte_t max = 0;
+
+    const Int_t f = hifirst;
+    const Int_t l = hilast>fNumHiGainSamples  ? fNumHiGainSamples : hilast+1;
+
+    for (int i=f; i<l; i++)
+        if (fHiGainPos[i]>max)
+            max = fHiGainPos[i];
+
+    return max;
+}
+
+/*
 // --------------------------------------------------------------------------
 //
@@ -233,42 +287,4 @@
 
     return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the index of the FADC slice the maximum signal in. If the highest
-// slices have the same value the last one is returned.
-//
-Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample() const
-{
-    Byte_t *ptr = fHiGainPos+1;
-    Byte_t *max = fHiGainPos;
-    const Byte_t *end = fHiGainPos + fNumHiGainSamples;
-
-    do if (*ptr>*max) max = ptr;
-    while (++ptr != end);
-
-    return max-fHiGainPos;
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the index of the FADC slice the maximum signal in. If no lo-gains
-// are available -1 is returned. If the highest slices have the same value the
-// last one is returned.
-//
-Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample(const Byte_t lofirst) const
-{
-    if (!HasLoGain())
-        return -1; // means: not found
-
-    Byte_t *ptr = fLoGainPos+lofirst+1;
-    Byte_t *max = fLoGainPos+lofirst;
-    const Byte_t *end = fLoGainPos + fNumLoGainSamples;
-
-    do if (*ptr>*max) max = ptr;
-    while (++ptr != end);
-
-    return max-fLoGainPos;
 }
 
@@ -299,19 +315,4 @@
 // Returns the maximum signal of all sliced in the hi gain samples
 //
-Byte_t MRawEvtPixelIter::GetMaxHiGainSample() const
-{
-    Byte_t max = 0;
-
-    for (int i=0; i<fNumHiGainSamples; i++)
-        if (fHiGainPos[i]>max)
-            max = fHiGainPos[i];
-
-    return max;
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the maximum signal of all sliced in the hi gain samples
-//
 Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
 {
@@ -371,2 +372,3 @@
     return sum;
 }
+*/
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 8345)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 8346)
@@ -74,21 +74,41 @@
         //          belong to the actual pixel
         //
+        //
+        // Use is deprecated!
+        //
         return fHiGainPos;
     }
 
-    Byte_t  GetNumHiGainSamples() const { return fNumHiGainSamples ; }
-    Byte_t  GetNumLoGainSamples() const { return fNumLoGainSamples ; }
+    Byte_t *GetSamples() 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;
+    }
 
+    Byte_t  GetNumHiGainSamples() const { return fNumHiGainSamples ; }// Use is deprecated!
+    Byte_t  GetNumLoGainSamples() const { return fNumLoGainSamples ; }// Use is deprecated!
+    Byte_t  GetNumSamples() const { return fNumHiGainSamples+fNumLoGainSamples; }
+
+    Byte_t  GetIdxMaxHiGainSample(const Byte_t hifirst=0, const Byte_t hilast=0xff) const;
+    Short_t GetIdxMaxLoGainSample(const Byte_t lofirst=0, const Byte_t lolast=0xff) const;
+
+    Byte_t  GetMaxHiGainSample(const Byte_t hifirst=0, const Byte_t hilast=0xff) const;
+/*
     ULong_t GetSumHiGainSamples() const;
     ULong_t GetSumSqrHiGainSamples() const;
     Float_t GetVarHiGainSamples() const;
 
-    Byte_t  GetMaxHiGainSample() const;
     Byte_t  GetMaxLoGainSample() const;
-    Byte_t  GetIdxMaxHiGainSample() const;
-    Short_t GetIdxMaxLoGainSample(const Byte_t lofirst=0) const;
     Short_t GetIdxMaxHiLoGainSample() const;
 
-    Bool_t HasLoGain() const;
+    ULong_t GetSumLoGainSamples() const;
+    ULong_t GetSumSqrLoGainSamples() const;
+  */
+    Bool_t HasLoGain() const { return fNumLoGainSamples>0; }
     Bool_t IsABFlagValid() const { return fABFlags ? kTRUE : kFALSE; }
     Bool_t HasABFlag() const
@@ -116,7 +136,4 @@
     }
 
-    ULong_t GetSumLoGainSamples() const;
-    ULong_t GetSumSqrLoGainSamples() const;
-
     void Reset();
 
