Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4737)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4738)
@@ -26,4 +26,19 @@
      - changed calculation of sign of SignificanceLiMaSigned due to
        bug #131
+
+   * readdaq.cc, readraw.cc:
+     - updated to support MRawEvtData2
+     
+   * mraw/MRawEvtData.[h,cc], mraw/MRawFileRead.cc, 
+     mraw/MRawFileWrite.[h,cc], mraw/MRawRead.[h,cc], 
+     mraw/MRawSocketRead.cc:
+     - updated to support negative pixel ids
+
+   * mraw/MRawRunHeader.[h,cc]:
+     - increased max format version to 4
+     - added GetNumNormalPixels
+     - added GetNumSpecialPixels
+     - added GetMinPixId
+     - added GetMaxPixId
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 4737)
+++ trunk/MagicSoft/Mars/NEWS	(revision 4738)
@@ -37,4 +37,7 @@
    - added program doing the calibration and the signal extraction
      and signal calibration: callisto
+
+   - implemented support for pixels with negative IDs (Raw file format
+     version 4)
 
 
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 4738)
@@ -100,4 +100,5 @@
 //
 MRawEvtData::MRawEvtData(const char *name, const char *title)
+    : fRunHeader(0)
 {
     fName  = name  ? name  : "MRawEvtData";
@@ -185,6 +186,7 @@
 
     *fLog << dec << all;
-    *fLog << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
-    *fLog << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples";;
+    *fLog << GetDescriptor() << ": " << endl;
+    *fLog << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples  ";
+    *fLog << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples";
 
     TString str(opt);
@@ -361,24 +363,17 @@
 // --------------------------------------------------------------------------
 //
-// Deletes all arrays describing the pixel Id and Samples in pixels.
-// The flag is for future usage.
-//
-void MRawEvtData::DeletePixels(Bool_t flag)
-{
-    if (fRunHeader && flag)
-    {
-        //const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
-        const int npix = fRunHeader->GetNumConnectedPixels();
-
-        if (fArraySize == npix)
-        {
-            fPosInArray = 0;
-            fConnectedPixels = 0;
-            return;
-        }
-    }
-
-    DeleteArrays();
-    InitArrays(flag);
+//  Deletes all the arrays
+//  The flag is for future usage.
+//
+void MRawEvtData::InitArrays(UShort_t numconnected, UShort_t maxid)
+{
+    fHiGainPixId       = new MArrayS(numconnected);
+    fLoGainPixId       = new MArrayS(numconnected);
+    fHiGainFadcSamples = new MArrayB(numconnected*fRunHeader->GetNumSamplesHiGain());
+    fLoGainFadcSamples = new MArrayB(numconnected*fRunHeader->GetNumSamplesLoGain());
+
+    fABFlags           = new MArrayB(maxid/8+1);
+
+    fConnectedPixels   = 0;
 }
 
@@ -398,34 +393,18 @@
 // --------------------------------------------------------------------------
 //
-//  Deletes all the arrays
-//  The flag is for future usage.
-//
-void MRawEvtData::InitArrays(Bool_t flag)
-{
-    if (flag && fRunHeader)
-    {
-        const int npix = fRunHeader->GetNumConnectedPixels();
-
-        fHiGainPixId       = new MArrayS(npix);
-        fLoGainPixId       = new MArrayS(npix);
-        fHiGainFadcSamples = new MArrayB(npix*fRunHeader->GetNumSamplesHiGain());
-        fLoGainFadcSamples = new MArrayB(npix*fRunHeader->GetNumSamplesLoGain());
-        fABFlags           = new MArrayB(fRunHeader->GetMaxPixId()/8+1);
-
-        fArraySize  = npix;
-    }
-    else
-    {
-        fHiGainPixId       = new MArrayS(0);
-        fLoGainPixId       = new MArrayS(0);
-        fHiGainFadcSamples = new MArrayB(0);
-        fLoGainFadcSamples = new MArrayB(0);
-        fABFlags           = new MArrayB(0);
-
-        fArraySize = 0;
-    }
-
-    fPosInArray = 0;
-    fConnectedPixels = 0;
+// Deletes all arrays describing the pixel Id and Samples in pixels.
+// The flag is for future usage.
+//
+void MRawEvtData::ResetPixels(UShort_t numconnected, UShort_t maxid)
+{
+    //const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
+    if (fHiGainPixId && fHiGainPixId->GetSize()==numconnected && (UShort_t)fABFlags->GetSize()==(maxid/8+1))
+    {
+        fConnectedPixels = 0;
+        return;
+    }
+
+    DeleteArrays();
+    InitArrays(numconnected, maxid);
 }
 
@@ -475,4 +454,34 @@
 }
 
+void MRawEvtData::ReadPixel(istream &fin, Int_t npix, Bool_t ab)
+{
+    Byte_t *poshi = fHiGainFadcSamples->GetArray() + fConnectedPixels*fRunHeader->GetNumSamplesHiGain();
+    Byte_t *poslo = fLoGainFadcSamples->GetArray() + fConnectedPixels*fRunHeader->GetNumSamplesLoGain();
+
+    // Read data for one pixel
+    fin.read((char*)poshi, fRunHeader->GetNumSamplesHiGain());
+    fin.read((char*)poslo, fRunHeader->GetNumSamplesLoGain());
+
+    //
+    //  This is to fill the data of one pixel to the MRawEvtHeader Class.
+    //  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
+    //  Add to lo gains if lflag = 1
+    //
+    fHiGainPixId->AddAt(npix, fConnectedPixels);
+
+    // FIXME: Not implemented in the raw files yet
+    //if (IsLoGainOn(i, j))
+    //{
+    fLoGainPixId->AddAt(npix, fConnectedPixels);
+    //}
+
+    if (ab)
+        SETBIT((*fABFlags)[npix/8], npix%8);
+    else
+        CLRBIT((*fABFlags)[npix/8], npix%8);
+
+    fConnectedPixels++;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -480,25 +489,18 @@
 //   WARNING: you have to use Init() before you can do this
 //
-void MRawEvtData::ReadEvt(istream &fin)
-{
-    const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
-    const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
+/*
+void MRawEvtData::ReadEvt(istream &fin, Int_t posinarray)
+{
 
     const UShort_t npic = fRunHeader->GetNumPixInCrate();
 
-    const UShort_t npos = npic*fPosInArray;
-
-    const Byte_t ab = fCrateArray->GetEntry(fPosInArray)->GetABFlags();
-
-    Byte_t *higainsam = fHiGainFadcSamples->GetArray()+nhi*fConnectedPixels;
-    Byte_t *logainsam = fLoGainFadcSamples->GetArray()+nlo*fConnectedPixels;
-
-    for (int i=0; i<npic; i++)
-    {
-        fin.read((char*)higainsam, nhi);
-        fin.read((char*)logainsam, nlo);
-
+    const UShort_t npos = npic*posinarray;
+
+    //const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
+
+    for (int i=npos; i<npic+npos; i++)
+    {
         // calc the spiral hardware pixel number
-        const UShort_t ipos = npos+i;
+        const UShort_t ipos = i;
 
         // Get Hardware Id
@@ -506,35 +508,19 @@
 
         // Check whether the pixel is connected or not
-        if (hwid<=0)
-            continue;
+        if (hwid==0)
+        {
+            const UShort_t n = fRunHeader->GetNumSamplesLoGain()+fRunHeader->GetNumSamplesHiGain();
+            fin.seekg(n, ios::cur);
+            return;
+        }
 
         // -1 converts the hardware pixel Id into the software pixel index
-        const Int_t npix = /*hwid>0 ?*/ (Int_t)hwid-1 /*: hwid*/;
-
-        //
-        //  This is to fill the data of one pixel to the MRawEvtHeader Class.
-        //  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
-        //  Add to lo gains if lflag = 1
-        //
-        fHiGainPixId->AddAt(npix, fConnectedPixels);
-        higainsam += nhi;
-
-        // FIXME: Not implemented in the raw files yet
-        //if (IsLoGainOn(i, j))
-        //{
-        fLoGainPixId->AddAt(npix, fConnectedPixels);
-        logainsam += nlo;
-        //}
-
-        if (TESTBIT(ab, i))
-            SETBIT((*fABFlags)[npix/8], npix%8);
-        else
-            CLRBIT((*fABFlags)[npix/8], npix%8);
-
-        fConnectedPixels++;
-    }
-
-    fPosInArray++;
-}
+        const Int_t npix = (Int_t)hwid-1;
+
+        const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
+        AddPixel(fin, npix, TESTBIT(ab, i-npos));
+    }
+}
+*/
 
 // --------------------------------------------------------------------------
@@ -608,6 +594,4 @@
     *evt.fABFlags = *fABFlags;
 
-    evt.fPosInArray      = fPosInArray;
     evt.fConnectedPixels = fConnectedPixels;
-    evt.fArraySize       = fArraySize;
-}
+}
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 4738)
@@ -25,5 +25,4 @@
 private:
     MRawRunHeader  *fRunHeader;   //! provides information about numbers
-    MRawCrateArray *fCrateArray;  //! provides information about ab flag
 
     // FIXME: COMMENT ABOUT ORDERING
@@ -37,9 +36,7 @@
     MArrayB *fABFlags;            //-> A information about the exact trigger position
 
-    Int_t fPosInArray;        //!
     Int_t fConnectedPixels;   //!
-    Int_t fArraySize;         //!
 
-    void InitArrays(Bool_t flag=kFALSE);
+    void InitArrays(UShort_t numconnected=0, UShort_t maxid=0);
     void DeleteArrays();
 
@@ -50,5 +47,5 @@
     ~MRawEvtData();
 
-    void InitRead(MRawRunHeader *rh, MRawCrateArray *arr)
+    void InitRead(MRawRunHeader *rh)
     {
         //
@@ -57,5 +54,4 @@
         //
         fRunHeader  = rh;
-        fCrateArray = arr;
     }
 
@@ -64,6 +60,5 @@
     void Draw (Option_t * = NULL);
 
-    void DeletePixels(Bool_t flag=kFALSE);
-    void ResetPixels() { DeletePixels(kTRUE); }
+    void ResetPixels(UShort_t npix, UShort_t maxid);
     void AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag=kFALSE);
 
@@ -72,5 +67,6 @@
     UShort_t GetNumPixels() const;
 
-    void ReadEvt(istream &fin);
+    void ReadPixel(istream &fin, Int_t npix, Bool_t ab);
+    //void ReadEvt(istream &fin, Int_t posinarray);
     void SkipEvt(istream &fin);
 
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 4738)
@@ -207,5 +207,6 @@
     //
     fRawEvtHeader->InitRead(fRawRunHeader, fRawEvtTime);
-    fRawEvtData  ->InitRead(fRawRunHeader, fRawCrateArray);
+    fRawEvtData1 ->InitRead(fRawRunHeader);
+    fRawEvtData2 ->InitRead(fRawRunHeader);
 
     //
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 4738)
@@ -31,5 +31,10 @@
 //
 //  Input Containers:
-//   MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime
+//   MRawRunHeader
+//   MRawEvtHeader
+//   MRawEvtData
+//   MRawEvtData2 [MRawEvtData]
+//   MRawCrateArray
+//   MTime
 //
 //  Output Containers:
@@ -61,9 +66,8 @@
 // Default constructor. It opens the output file (root-file)
 //
-MRawFileWrite::MRawFileWrite(const char *fname,
-                             const Option_t *opt,
-                             const char *ftitle,
-                             const Int_t comp,
-                             const char *name, const char *title) : fSplit(kFALSE)
+MRawFileWrite::MRawFileWrite(const char *fname,  const Option_t *opt,
+                             const char *ftitle, const Int_t comp,
+                             const char *name, const char *title)
+    : fTData(0), fSplit(kFALSE)
 {
     fName  = name  ? name  : "MRawFileWrite";
@@ -82,19 +86,22 @@
 MRawFileWrite::~MRawFileWrite()
 {
-    if (fOut != fTData->GetCurrentFile())
-    {
-        *fLog << warn << endl;
-        *fLog << "WARNING - MWriteRootFile:   Root's  TTree/TFile   has  opened   a  new  file" << endl;
-        *fLog << "  automatically.  You can change this behaviour using TTree::SetMaxTreeSize." << endl;
-        *fLog << "  You won't be able to read splitted  files  correctly with MReadMarsFile if" << endl;
-        *fLog << "  they have more than one entry in 'RunHeaders' or you try to read more than" << endl;
-        *fLog << "  one of such sequences at once." << endl;
-        *fLog << endl;
-    }
-
-    //
-    // For more information see TTree:ChangeFile()
-    //
-    fOut = fTData->GetCurrentFile();
+    if (fTData)
+    {
+        if (fOut != fTData->GetCurrentFile())
+        {
+            *fLog << warn << endl;
+            *fLog << "WARNING - MWriteRootFile:   Root's  TTree/TFile   has  opened   a  new  file" << endl;
+            *fLog << "  automatically.  You can change this behaviour using TTree::SetMaxTreeSize." << endl;
+            *fLog << "  You won't be able to read splitted  files  correctly with MReadMarsFile if" << endl;
+            *fLog << "  they have more than one entry in 'RunHeaders' or you try to read more than" << endl;
+            *fLog << "  one of such sequences at once." << endl;
+            *fLog << endl;
+        }
+
+        //
+        // For more information see TTree:ChangeFile()
+        //
+        fOut = fTData->GetCurrentFile();
+    }
 
     //
@@ -147,12 +154,18 @@
     if (!fRawEvtHeader)
     {
-        *fLog << err << dbginf << "MRawEvtHeader not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
-    if (!fRawEvtData)
-    {
-        *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
+        *fLog << err << "MRawEvtHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawEvtData1 = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    if (!fRawEvtData1)
+    {
+        *fLog << err << "MRawEvtData not found... aborting." << endl;
+        return kFALSE;
+    }
+    fRawEvtData2 = (MRawEvtData*)pList->FindObject("MRawEvtData2", "MRawEvtData");
+    if (!fRawEvtData2)
+    {
+        *fLog << err << "MRawEvtData2 [MRawEvtData] not found... aborting." << endl;
         return kFALSE;
     }
@@ -161,5 +174,5 @@
     if (!fRawCrateArray)
     {
-        *fLog << err << dbginf << "MRawCrateArray not found... aborting." << endl;
+        *fLog << err << "MRawCrateArray not found... aborting." << endl;
         return kFALSE;
     }
@@ -168,5 +181,5 @@
     if (!fTime)
     {
-        *fLog << err << dbginf << "MTime not found... aborting." << endl;
+        *fLog << err << "MTime not found... aborting." << endl;
         return kFALSE;
     }
@@ -175,5 +188,5 @@
     if (!fRawRunHeader)
     {
-        *fLog << err << dbginf << "MRawRunHeader not found... aborting." << endl;
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
         return kFALSE;
     }
@@ -220,5 +233,6 @@
     fTData->Branch("MTime.",          "MTime",          &fTime,          32000);
     fTData->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
-    fTData->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
+    fTData->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData1,   320000);
+    fTData->Branch("MRawEvtData2.",   "MRawEvtData",    &fRawEvtData2,   320000);
     fTData->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
     if (!fSplit)
@@ -229,6 +243,8 @@
     fTPedestal   ->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
     fTCalibration->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
-    fTPedestal   ->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
-    fTCalibration->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
+    fTPedestal   ->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData1,   320000);
+    fTCalibration->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData1,   320000);
+    fTPedestal   ->Branch("MRawEvtData2.",   "MRawEvtData",    &fRawEvtData2,   320000);
+    fTCalibration->Branch("MRawEvtData2.",   "MRawEvtData",    &fRawEvtData2,   320000);
     fTPedestal   ->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
     fTCalibration->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 4738)
@@ -22,5 +22,6 @@
     MRawRunHeader  *fRawRunHeader;
     MRawEvtHeader  *fRawEvtHeader;
-    MRawEvtData    *fRawEvtData;
+    MRawEvtData    *fRawEvtData1;
+    MRawEvtData    *fRawEvtData2;
     MRawCrateArray *fRawCrateArray;
 
@@ -40,8 +41,6 @@
 
 public:
-    MRawFileWrite(const char *fname,
-                  const Option_t *opt="RECREATE",
-                  const char *ftitle="Untitled",
-                  const Int_t comp=2,
+    MRawFileWrite(const char *fname, const Option_t *opt="RECREATE",
+                  const char *ftitle="Untitled", const Int_t comp=2,
                   const char *name=NULL, const char *title=NULL);
     ~MRawFileWrite();
Index: trunk/MagicSoft/Mars/mraw/MRawRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 4738)
@@ -24,21 +24,22 @@
 
 //////////////////////////////////////////////////////////////////////////////
-//                                                                          
+//
 //  MRawRead
-//                                                                          
-//  This tasks reads the raw binary file like specified in the TDAS???      
-//  and writes the data in the corresponding containers which are           
-//  either retrieved from the parameter list or created and added.          
-//                                                                          
-//  Input Containers:                                                       
-//   -/-                                                                    
-//                                                                          
+//
+//  This tasks reads the raw binary file like specified in the TDAS???
+//  and writes the data in the corresponding containers which are
+//  either retrieved from the parameter list or created and added.
+//
+//  Input Containers:
+//   -/-
+//
 //  Output Containers:                                                      
 //   MRawRunHeader
 //   MRawEvtHeader
 //   MRawEvtData
+//   MRawEvtData2 [MRawEvtData]
 //   MRawCrateArray
-//   MRawEvtTime
-//                                                                          
+//   MTime
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MRawRead.h"
@@ -105,6 +106,10 @@
         return kFALSE;
 
-    fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
-    if (!fRawEvtData)
+    fRawEvtData1 = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
+    if (!fRawEvtData1)
+        return kFALSE;
+
+    fRawEvtData2 = (MRawEvtData*)pList->FindCreateObj("MRawEvtData", "MRawEvtData2");
+    if (!fRawEvtData2)
         return kFALSE;
 
@@ -180,5 +185,6 @@
     // Delete arrays which stores the pixel information (time slices)
     //
-    fRawEvtData->ResetPixels();
+    fRawEvtData1->ResetPixels(fRawRunHeader->GetNumNormalPixels(),  fRawRunHeader->GetMaxPixId());
+    fRawEvtData2->ResetPixels(fRawRunHeader->GetNumSpecialPixels(), fRawRunHeader->GetMinPixId());
 
     //
@@ -189,6 +195,12 @@
 
     //
+    // Calculate the number of byte to be skipped in a file if a pixel is not connected
+    //
+    const UShort_t nskip = fRawRunHeader->GetNumSamplesLoGain()+fRawRunHeader->GetNumSamplesHiGain();
+
+    //
     // read the CRATE DATA (see specification) from file
     //
+    Int_t posinarray=0;
     for (int i=0; i<nc; i++)
     {
@@ -197,7 +209,34 @@
             return kFALSE;
 
-        fRawEvtData->ReadEvt(fin);
+        //fRawEvtData1->ReadEvt(fin, posinarray++);
+
+        const UShort_t npic = fRawRunHeader->GetNumPixInCrate();
+        const Byte_t   ab   = fRawCrateArray->GetEntry(posinarray)->GetABFlags();
+        for (int j=0; j<npic; j++)
+        {
+            // calc the spiral hardware pixel number
+             const UShort_t ipos = posinarray*npic+j;
+
+            // Get Hardware Id
+            const Short_t hwid = fRawRunHeader->GetPixAssignment(ipos);
+
+            // Check whether the pixel is connected or not
+            if (hwid==0)
+            {
+                fin.seekg(nskip, ios::cur);
+                continue;
+            }
+
+            // -1 converts the hardware pixel Id into the software pixel index
+            if (hwid>0)
+                fRawEvtData1->ReadPixel(fin,   hwid-1,  TESTBIT(ab, j));
+            else
+                fRawEvtData2->ReadPixel(fin, -(hwid-1), TESTBIT(ab, j));
+
+        }
         if (!fin)
             return kFALSE;
+
+        posinarray++;
     }
 
@@ -226,5 +265,5 @@
     {
         fRawCrateArray->GetEntry(i)->SkipEvt(fin, ver);
-        fRawEvtData->SkipEvt(fin);
+        fRawEvtData1->SkipEvt(fin);
     }
 }
Index: trunk/MagicSoft/Mars/mraw/MRawRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRead.h	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawRead.h	(revision 4738)
@@ -18,5 +18,6 @@
     MRawRunHeader  *fRawRunHeader;  // run header information container to fill from file
     MRawEvtHeader  *fRawEvtHeader;  // event header information container to fill from file
-    MRawEvtData    *fRawEvtData;    // raw evt header infomation container to fill from file
+    MRawEvtData    *fRawEvtData1;   // raw evt data infomation container to fill from file
+    MRawEvtData    *fRawEvtData2;   // raw evt data for pixels with negative indices
     MRawCrateArray *fRawCrateArray; // crate information array container to fill from file
     MTime          *fRawEvtTime;    // raw evt time information container to fill from file
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 4738)
@@ -29,4 +29,12 @@
 // Root storage container for the RUN HEADER information
 //
+//  Format Version 4:
+//  -----------------
+//   - added support for pixels with negative IDs
+//
+//  Format Version 3:
+//  -----------------
+//   - ???
+//
 //  Format Version 2:
 //  -----------------
@@ -62,5 +70,5 @@
 
 const UShort_t MRawRunHeader::kMagicNumber      = 0xc0c0;
-const Byte_t   MRawRunHeader::kMaxFormatVersion =      3;
+const Byte_t   MRawRunHeader::kMaxFormatVersion =      4;
 
 // --------------------------------------------------------------------------
@@ -239,8 +247,8 @@
 // Return the assigned pixel number for the given FADC channel
 //
-UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
+Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
 {
     // FIXME: Do we need a range check here?
-    return (*fPixAssignment)[i];
+    return (Short_t)(*fPixAssignment)[i];
 }
 
@@ -248,7 +256,25 @@
 //
 // Return the number of pixel which are markes as connected in the
-// pix assignment (>0)
+// pix assignment (!=0)
 //
 UShort_t MRawRunHeader::GetNumConnectedPixels() const
+{
+    const Int_t num = fPixAssignment->GetSize();
+
+    UShort_t rc = 0;
+    for (int i=0; i<num; i++)
+    {
+        if (GetPixAssignment(i)!=0)
+            rc++;
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the number of pixel which are markes as connected and so-called
+// 'normal' pixels in the pix assignment (>0)
+//
+UShort_t MRawRunHeader::GetNumNormalPixels() const
 {
     const Int_t num = fPixAssignment->GetSize();
@@ -265,4 +291,22 @@
 // --------------------------------------------------------------------------
 //
+// Return the number of pixel which are markes as connected and so-called
+// 'special' pixels in the pix assignment (<0)
+//
+UShort_t MRawRunHeader::GetNumSpecialPixels() const
+{
+    const Int_t num = fPixAssignment->GetSize();
+
+    UShort_t rc = 0;
+    for (int i=0; i<num; i++)
+    {
+        if (GetPixAssignment(i)<0)
+            rc++;
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
 // Return the maximum id which exists in the pix assignment
 //
@@ -271,9 +315,24 @@
     const Int_t num = fPixAssignment->GetSize();
 
-    UShort_t rc = 0;
+    Short_t rc = 0;
     for (int i=0; i<num; i++)
         rc = TMath::Max(GetPixAssignment(i), rc);
 
     return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return minus th minimum id which exists in the pix assignment
+//
+UShort_t MRawRunHeader::GetMinPixId() const
+{
+    const Int_t num = fPixAssignment->GetSize();
+
+    Short_t rc = 0;
+    for (int i=0; i<num; i++)
+        rc = TMath::Min(GetPixAssignment(i), rc);
+
+    return (UShort_t)-rc;
 }
 
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 4738)
@@ -95,7 +95,10 @@
     const MTime &GetRunStart() const      { return fRunStart; }
     const MTime &GetRunEnd() const        { return fRunStop; }
-    UShort_t GetPixAssignment(UShort_t i) const;
+    Short_t GetPixAssignment(UShort_t i) const;
     UShort_t GetMaxPixId() const;
+    UShort_t GetMinPixId() const;
     UShort_t GetNumConnectedPixels() const;
+    UShort_t GetNumNormalPixels() const;
+    UShort_t GetNumSpecialPixels() const;
 
     UInt_t GetNumSamplesPerCrate() const
Index: trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 4738)
@@ -263,5 +263,6 @@
     //
     fRawEvtHeader->InitRead(fRawRunHeader, fRawEvtTime);
-    fRawEvtData  ->InitRead(fRawRunHeader, fRawCrateArray);
+    fRawEvtData1 ->InitRead(fRawRunHeader);
+    fRawEvtData2 ->InitRead(fRawRunHeader);
 
     if (!ReadEvent(*fIn))
Index: trunk/MagicSoft/Mars/readdaq.cc
===================================================================
--- trunk/MagicSoft/Mars/readdaq.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/readdaq.cc	(revision 4738)
@@ -143,4 +143,7 @@
     plist.AddToList(&evtdata);
 
+    MRawEvtData evtdata2("MRawEvtData2");
+    plist.AddToList(&evtdata2);
+
     MRawCrateArray cratearray;
     plist.AddToList(&cratearray);
@@ -162,4 +165,5 @@
     MPrint print3("MRawCrateArray", "", "PrintCrateArray");
     MPrint print4("MRawEvtData", kDecimal?"dec":"hex", "PrintEvtData");
+    MPrint print5("MRawEvtData2", kDecimal?"dec":"hex", "PrintEvtData2");
 
     tasks.AddToList(&print0);
@@ -169,4 +173,5 @@
         tasks.AddToList(&print3);
     tasks.AddToList(&print4);
+    tasks.AddToList(&print5);
 
     //
Index: trunk/MagicSoft/Mars/readraw.cc
===================================================================
--- trunk/MagicSoft/Mars/readraw.cc	(revision 4737)
+++ trunk/MagicSoft/Mars/readraw.cc	(revision 4738)
@@ -169,4 +169,5 @@
     MTime          *evttime   = NULL;
     MRawEvtData    *evtdata   = NULL;
+    MRawEvtData    *evtdata2  = NULL;
     MRawCrateArray *evtcrate  = NULL;
     MMcEvt         *evtmc     = NULL;
@@ -176,4 +177,5 @@
     EnableBranch(evttree, "MTime",          &evttime);
     EnableBranch(evttree, "MRawEvtData",    &evtdata);
+    EnableBranch(evttree, "MRawEvtData2",   &evtdata2);
     EnableBranch(evttree, "MRawCrateArray", &evtcrate);
     EnableBranch(evttree, "MMcEvt",         &evtmc);
@@ -209,4 +211,6 @@
         if (evtdata)
             evtdata->Print(kDecimal?"dec":"hex");
+        if (evtdata2)
+            evtdata2->Print(kDecimal?"dec":"hex");
 
         gLog << endl;
