Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 8565)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 8571)
@@ -47,4 +47,8 @@
 //
 //
+//   Version 7
+//   ------------------
+//    + UShort_t fNumBytesPerSample;
+//
 //   Version 6
 //   ------------------
@@ -148,5 +152,5 @@
     // value set so far. So we use the old methid to determin the
     // numbers and calculate them from the length of the arrays.
-    return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
+    return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/(fHiGainPixId->GetSize()*fNumBytesPerSample) : 0;
 }
 
@@ -160,5 +164,5 @@
     // value set so far. So we use the old methid to determin the
     // numbers and calculate them from the length of the arrays.
-    return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
+    return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/(fLoGainPixId->GetSize()*fNumBytesPerSample) : 0;
 }
 
@@ -189,4 +193,6 @@
     const UShort_t nLoSamp = GetNumLoGainSamples();
 
+    const UShort_t bps     = GetNumBytesPerSample();
+
     fLog->unsetf(ios::showbase);
 
@@ -212,16 +218,16 @@
         *fLog << (manip?dec:hex) << setfill(manip?' ':'0');
 
-        const Byte_t *hi = pixel.GetHiGainSamples();
-        const Byte_t *lo = pixel.GetLoGainSamples();
-
-        for (int j=0; j<nHiSamp; j++)
+        const Byte_t *hi = (Byte_t*)pixel.GetHiGainSamples();
+        const Byte_t *lo = (Byte_t*)pixel.GetLoGainSamples();
+
+        for (int j=0; j<nHiSamp*bps; j++)
         {
             *fLog << setw(manip?3:2);
-            *fLog << ((UShort_t)hi[j]&0xff);
+            *fLog << (hi[j]&0xff);
             if (manip)
                 *fLog << ' ';
         }
 
-        for (int j=0; j<nLoSamp; j++)
+        for (int j=0; j<nLoSamp*bps; j++)
         {
             *fLog << setw(manip?3:2);
@@ -270,6 +276,6 @@
     }
 
-    const Byte_t *higains = pix.GetHiGainSamples();
-    const Byte_t *logains = pix.GetLoGainSamples();
+    const void *higains = pix.GetHiGainSamples();
+    const void *logains = pix.GetLoGainSamples();
 
     const Int_t nh = GetNumHiGainSamples();
@@ -289,7 +295,7 @@
 
         for (int i=0; i<nh; i++)
-            graphhi->SetPoint(graphhi->GetN(), i, higains[i]);
+            graphhi->SetPoint(graphhi->GetN(), i, GetSample(higains, i));
         for (int i=0; i<nl; i++)
-            graphhi->SetPoint(graphhi->GetN(), i+nh, logains[i]);
+            graphhi->SetPoint(graphhi->GetN(), i+nh, GetSample(logains, i));
 
         graphhi->SetMaximum(256);
@@ -321,7 +327,7 @@
         histh->SetDirectory(NULL);
         for (int i=0; i<nh; i++)
-            histh->Fill(i, higains[i]);
+            histh->Fill(i, GetSample(higains, i));
         for (int i=0; i<nl; i++)
-            histh->Fill(i, logains[i]);
+            histh->Fill(i, GetSample(logains, i));
         histh->SetBit(kCanDelete);
         histh->Draw(same ? "same" : "");
@@ -330,5 +336,5 @@
     }
 
-    *fLog << warn << dbginf << "Warning - You must specify either 'GRAPH' or 'HIST'" << endl;
+    *fLog << warn << dbginf << "WARNING - You must specify either 'GRAPH' or 'HIST'" << endl;
 }
 
@@ -341,10 +347,12 @@
 {
     // fRunHeader should not be set only in the constructor!
-    const Int_t numhi = fRunHeader ? fRunHeader->GetNumSamplesHiGain() : -1;
-    const Int_t numlo = fRunHeader ? fRunHeader->GetNumSamplesLoGain() : -1;
+    const Int_t numhi  = fRunHeader ? fRunHeader->GetNumSamplesHiGain()  : 0;
+    const Int_t numlo  = fRunHeader ? fRunHeader->GetNumSamplesLoGain()  : 0;
+
+    fNumBytesPerSample = fRunHeader ? fRunHeader->GetNumBytesPerSample() : 1;
 
     fHiGainPixId       = new MArrayS(numconnected);
     fLoGainPixId       = new MArrayS(0);
-    fHiGainFadcSamples = new MArrayB(numconnected*(numhi+numlo));
+    fHiGainFadcSamples = new MArrayB(numconnected*(numhi+numlo)*fNumBytesPerSample);
     fLoGainFadcSamples = new MArrayB(0);
 
@@ -466,7 +474,4 @@
     const UInt_t ns = fRunHeader->GetNumSamples();
 
-    // position in higain array
-    Byte_t *pos = fHiGainFadcSamples->GetArray() + fConnectedPixels*ns;
-
     // bytes per sample
     const Int_t bps = fRunHeader->GetNumBytesPerSample();
@@ -475,20 +480,12 @@
     const Int_t nb = ns*bps;
 
+    // position in higain array
+    Byte_t *pos = fHiGainFadcSamples->GetArray() + fConnectedPixels*nb;
+
     // Set pixel index
     fHiGainPixId->AddAt(npix, fConnectedPixels++);
 
     // Read data for one pixel
-    if (bps==1)
-    {
-        fin.read((char*)pos, nb);
-        return;
-    }
-
-    // Read data for one pixel
-    Byte_t arr[nb];
-    fin.read((char*)arr, nb);
-
-    for (Byte_t *p=arr+bps-1; p<arr+nb; p+=bps)
-        *pos++ = *p;
+    fin.read((char*)pos, nb);
 }
 
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 8565)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 8571)
@@ -36,4 +36,6 @@
     MArrayB *fABFlags;            //-> A information about the exact trigger position
 
+    UShort_t fNumBytesPerSample;
+
     Int_t fConnectedPixels;       //!
 
@@ -42,4 +44,15 @@
 
     Int_t GetNumBytes() const;
+
+    UInt_t GetSample(const void *ptr, Int_t n) // Helper for Draw
+    {
+        switch (n)
+        {
+        case 1: return *(Byte_t*)ptr;
+        case 2: return *(UShort_t*)ptr;
+        case 3: return *(Int_t*)ptr;
+        }
+        return 0;
+    }
 
 public:
@@ -68,4 +81,7 @@
     UShort_t GetNumPixels() const;
 
+    UShort_t GetNumBytesPerSample() const { return fNumBytesPerSample; }
+    UInt_t   GetScale() const { return 1<<((fNumBytesPerSample-1)*8); }
+
     void ReadPixel(istream &fin, Int_t npix);
     void SetABFlag(Int_t npix, Bool_t ab);
@@ -86,5 +102,5 @@
         ;
 
-    ClassDef(MRawEvtData, 6) //Container to store the raw Event Data
+    ClassDef(MRawEvtData, 7) //Container to store the raw Event Data
 };
 
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 8565)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 8571)
@@ -63,6 +63,6 @@
 MRawEvtPixelIter::MRawEvtPixelIter(MRawEvtData *dat) : fABFlags(0), fData(dat)
 {
-    fNumHiGainSamples = dat->GetNumHiGainSamples();
-    fNumLoGainSamples = dat->GetNumLoGainSamples();
+    fNumBytesHiGain  = dat->GetNumHiGainSamples()*dat->GetNumBytesPerSample();
+    fNumBytesLoGain  = dat->GetNumLoGainSamples()*dat->GetNumBytesPerSample();
 
     Reset();
@@ -91,9 +91,9 @@
         fNumHiGainEntry++;
         fHiGainId++;
-        fHiGainPos += fNumHiGainSamples;
+        fHiGainPos += fNumBytesHiGain;
 
         fNumLoGainEntry++;
         fLoGainId++;
-        fLoGainPos += fNumLoGainSamples;
+        fLoGainPos += fNumBytesLoGain;
     }
     else
@@ -102,6 +102,6 @@
         fLoGainId       = ++fHiGainId;
 
-        fHiGainPos     += fNumHiGainSamples+fNumLoGainSamples;
-        fLoGainPos      = fHiGainPos + fNumHiGainSamples;
+        fHiGainPos     += fNumBytesHiGain+fNumBytesLoGain;
+        fLoGainPos      = fHiGainPos + fNumBytesHiGain;
     }
 
@@ -137,12 +137,12 @@
     {
         fLoGainId  = fData->fLoGainPixId->GetArray();
-        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumHiGainSamples;
-        fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
+        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumBytesHiGain;
+        fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumBytesLoGain;
     }
     else
     {
         fLoGainId  = fHiGainId;
-        fLoGainPos = fHiGainPos+fNumHiGainSamples;
-        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumHiGainSamples+fNumLoGainSamples);
+        fLoGainPos = fHiGainPos+fNumBytesHiGain;
+        fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumBytesHiGain+fNumBytesLoGain);
     }
 
@@ -163,212 +163,2 @@
     fData->Draw(Form("%s%d", t, *fHiGainId));
 }
-
-/*
-// --------------------------------------------------------------------------
-//
-// Returns the index of the FADC slice the maximum signal in. If the highest
-// slices have the same value the first 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 first 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;
-}
-
-// --------------------------------------------------------------------------
-//
-// returns the sum of all hi gain fadc samples of the actual pixel
-//
-ULong_t MRawEvtPixelIter::GetSumHiGainSamples() const
-{
-    //
-    // return the sum of the hi gain samples of the present pixel
-    //
-    Byte_t *ptr = fHiGainPos;
-    const Byte_t *end = fHiGainPos + fNumHiGainSamples;
-
-    ULong_t sum=0;
-
-    do sum += *ptr++;
-    while (ptr != end);
-
-    return sum;
-}
-
-// --------------------------------------------------------------------------
-//
-// returns the sum of squares of all hi gain fadc sample of the actual pixel
-//
-ULong_t MRawEvtPixelIter::GetSumSqrHiGainSamples() const
-{
-    //
-    // return the sum of the squares of the hi gain samples of the present pixel
-    //
-    Byte_t *ptr = fHiGainPos;
-    const Byte_t *end = fHiGainPos + fNumHiGainSamples;
-
-    ULong_t sum=0;
-
-    do sum += (*ptr)*(*ptr);
-    while (++ptr != end);
-
-    return sum;
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the variance (sigma^2) of the HiGainSamples
-//
-Float_t MRawEvtPixelIter::GetVarHiGainSamples() const
-{
-    Byte_t *ptr = fHiGainPos;
-    const Byte_t *end = fHiGainPos + fNumHiGainSamples;
-
-    ULong_t sum=0;
-    ULong_t sqsum=0;
-
-    do {
-        sum += *ptr;
-        sqsum += (*ptr)*(*ptr);
-    } while (++ptr != end);
-
-    return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the index of the maximum FADC slice from high gain at first. If 
-// high gain is saturated it returns the low gain one.
-// If no lo-gains are existing and the hi-gains have saturating values
-// a negative value (-1) is returned.
-//
-Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
-{
-    Byte_t max  = 0;
-    Char_t maxi = 0;
-
-    for (int i=fNumHiGainSamples-1; i>=0; i--)
-        if (fHiGainPos[i]>max)
-        {
-            max  = fHiGainPos[i];
-            maxi = i;
-        }
-
-    return max<0xff ? maxi : GetIdxMaxLoGainSample();
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the maximum signal of all sliced in the hi gain samples
-//
-Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
-{
-    Byte_t max = 0;
-
-    for (int i=fNumLoGainSamples-1; i>=0; i--)
-        if (fLoGainPos[i]>max)
-            max = fLoGainPos[i];
-
-    return max;
-}
-
-// --------------------------------------------------------------------------
-//
-// returns the sum of all lo gain fadc samples of the actual pixel.
-// if no lo gain information is available 0 is returned.
-//
-ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
-{
-    //
-    // return the sum of the lo gain samples of the present pixel
-    //
-    if (!HasLoGain())
-        return 0;
-
-    Byte_t *ptr = fLoGainPos;
-    const Byte_t *end = fLoGainPos + fNumLoGainSamples;
-
-    ULong_t sum=0;
-
-    do sum += *ptr++;
-    while (ptr != end);
-
-    return sum;
-}
-
-// --------------------------------------------------------------------------
-//
-// returns the sum of squares of all hi gain fadc sample of the actual pixel
-//
-ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
-{
-    //
-    // return the sum of the lo gain samples squares of the present pixel
-    //
-    if (!HasLoGain())
-        return 0;
-
-    Byte_t *ptr = fLoGainPos;
-    const Byte_t *end = fLoGainPos + fNumLoGainSamples;
-
-    ULong_t sum=0;
-
-    do sum += (*ptr)*(*ptr);
-    while (++ptr != end);
-
-    return sum;
-}
-*/
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 8565)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 8571)
@@ -30,6 +30,8 @@
     UShort_t  fNumEntry;
 
-    Byte_t fNumHiGainSamples;   //!
-    Byte_t fNumLoGainSamples;   //!
+    Byte_t fNumBytesHiGain;   //!
+    Byte_t fNumBytesLoGain;   //!
+
+    UShort_t fNumBytesPerSample; //!
 
     MRawEvtData *fData;         //! pointer to object which we are iterating
@@ -66,5 +68,5 @@
     }
 
-    Byte_t *GetHiGainSamples() const
+    void *GetHiGainSamples() const
     {
         //
@@ -77,38 +79,7 @@
     }
 
-    /*
-     This function is dangerous as long as MC with split hi-/lo-gain are used
-    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  GetNumBytes() const { return fNumBytesHiGain+fNumBytesLoGain; }
 
-//    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  GetMaxLoGainSample() const;
-//    Short_t GetIdxMaxHiLoGainSample() const;
-
-//    ULong_t GetSumLoGainSamples() const;
-//    ULong_t GetSumSqrLoGainSamples() const;
-
-    Bool_t HasLoGain() const { return fNumLoGainSamples>0; }
+    Bool_t HasLoGain() const { return fNumBytesLoGain>0; }
     Bool_t IsABFlagValid() const { return fABFlags ? kTRUE : kFALSE; }
     Bool_t HasABFlag() const
@@ -127,5 +98,5 @@
     }
 
-    Byte_t *GetLoGainSamples() const
+    void *GetLoGainSamples() const
     {
         //
