Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 7440)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 7441)
@@ -33,7 +33,7 @@
      forest.
 
-   - general: Between the rund 53300 and 68754 six pixels were not 
-     correctly assigned in the raw data assignement table. A fix to
-     correct the assignment tabel have been implemented.
+   - general: Between the rund 53300 and 68754 the pixels 553-558 were not 
+     correctly assigned in the raw data assignement table. A fix to correct 
+     the assignment tabel have been implemented.
 
    - StatusDisplay: Fixed the algorithm to calculate the size ratio
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 7440)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 7441)
@@ -129,4 +129,106 @@
 // --------------------------------------------------------------------------
 //
+// Swap the assignment of the pixels with hardware id id0 and id1
+//
+Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
+{
+    const Int_t n = fPixAssignment->GetSize();
+
+    // Look-up-table
+    UShort_t *lut = fPixAssignment->GetArray();
+
+    // Search for one of the hardware indices to get exchanged
+    int i;
+    for (i=0; i<n; i++)
+        if (lut[i]==id0 || lut[i]==id1)
+            break;
+
+    // Check if one of the two pixels were found
+    if (i==n)
+    {
+        *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
+        *fLog << " should be exchanged, but none were found." << endl;
+        return kFALSE;
+    }
+
+    // Store first index
+    const Int_t idx0 = i;
+
+    // Search for the other hardware indices to get exchanged
+    for (i++; i<n; i++)
+        if (lut[i]==id0 || lut[i]==id1)
+            break;
+
+    // Check if the second pixel was found
+    if (i==n)
+    {
+        *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
+        *fLog << " should be exchanged, but only one was found." << endl;
+        return kFALSE;
+    }
+
+    const Int_t idx1 = i;
+
+    const Short_t p0 = lut[idx0];
+    const Short_t p1 = lut[idx1];
+
+    lut[idx0] = p1;
+    lut[idx1] = p0;
+
+    *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// This implements a fix of the pixel assignment before 25.9.2005
+//
+// From magic_online (the pixel numbers are hardware indices):
+// --------------------------------------------------------------------------
+//   From: Florian Goebel <fgoebel@mppmu.mpg.de>
+//   Date: Sun Sep 25 2005 - 05:13:19 CEST
+//   
+//   [...]
+//   - problem 2: pixels were swaped
+//   - cause: opical fibers were wrongly connected to receiver board
+//      554 <-> 559
+//      555 <-> 558
+//      556 <-> 557
+//   - action: reconnect correctly
+//   - result: ok now
+//   - comment: I don't know when this error was introduced, so backward
+//      correction of the data is difficult.
+//      Fortunately the effect is not too large since the affected 6 pixels are
+//      on the outermost edge of the camera
+//      Since this board has special pixels the optical fibers have been
+//      unplugged several times.
+//   !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
+//   !!!!! sure you connect them back correctly. !!!!!
+//   !!!!! Always contact me before you do so and if you have any doubts !!!!!
+//   !!!!! how to reconnect the fibers ask me. !!!!!
+//      These swapped pixels have only been found by chance when doing the
+//      flatfielding.
+//   [...]
+//
+Bool_t MRawRunHeader::FixAssignment()
+{
+    if (fRunNumber<53300 || fRunNumber>68754)
+        return kTRUE;
+
+    if (!SwapAssignment(554, 559))
+        return kFALSE;
+
+    if (!SwapAssignment(555, 558))
+        return kFALSE;
+
+    if (!SwapAssignment(556, 557))
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Read in one run header from the binary file
 //
@@ -199,5 +301,5 @@
     fin.read((char*)&dummy, 16);
 
-    return kTRUE;
+    return FixAssignment();
 }
 
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 7440)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 7441)
@@ -55,4 +55,7 @@
     MTime     fRunStop;
     MArrayS  *fPixAssignment;
+
+    Bool_t SwapAssignment(Short_t id0, Short_t id1);
+    Bool_t FixAssignment();
 
 public:
