Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4670)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4682)
@@ -95,4 +95,5 @@
 #include <TLatex.h>
 #include <TLegend.h>
+#include <TRegexp.h>
 #include <TPaveText.h>
 #include <TPaveStats.h>
@@ -1125,227 +1126,92 @@
 Bool_t MJCalibration::FindColor() 
 {
-  
-  if (fSequence)
-    {
-      fColor = MCalibrationCam::kCT1;
-      return kTRUE;
-    }
-  
-  const UInt_t nruns = fRuns->GetNumRuns();
-  
-  if (nruns == 0)
+    if (fSequence)
+    {
+        fColor = MCalibrationCam::kCT1;
+        return kTRUE;
+    }
+
+    const UInt_t nruns = fRuns->GetNumRuns();
+    if (nruns == 0)
+        return kFALSE;
+
+    fRuns->Reset();
+
+    TString filenames;
+    while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
+    {
+        MCalibrationCam::PulserColor_t newcolor = MCalibrationCam::kNONE;
+
+        TString number = filenames(TRegexp("[0-9]+_._.+[.]root$"));
+        Int_t num = atoi(number.Data());
+
+        if (num<gkIFAEBoxInaugurationRun)
+            newcolor = MCalibrationCam::kCT1;
+
+        switch (num)
+        {
+        case 26402:
+            newcolor = MCalibrationCam::kBLUE;
+            break;
+
+        case 30090:
+        case 20660:
+        case 20661:
+        case 26408:
+        case 26409:
+        case 26412:
+        case 26568:
+        case 26924:
+            newcolor = MCalibrationCam::kGREEN;
+            break;
+
+        case 27474:
+            newcolor = MCalibrationCam::kNONE;
+            *fLog << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
+            return kFALSE;
+
+        default:
+            if (filenames.Contains("green"))
+                newcolor = MCalibrationCam::kGREEN;
+            if (filenames.Contains("blue"))
+                newcolor = MCalibrationCam::kBLUE;
+            if (filenames.Contains("uv"))
+                newcolor = MCalibrationCam::kUV;
+            if (filenames.Contains("ct1"))
+                newcolor = MCalibrationCam::kCT1;
+        }
+
+        if (newcolor==MCalibrationCam::kNONE)
+        {
+            *fLog << err << "No color found for " << filenames << "... abort." << endl;
+            return kFALSE;
+        }
+
+        if (fColor == MCalibrationCam::kNONE)
+            fColor = newcolor;
+
+        if (fColor != newcolor)
+        {
+            *fLog << err << "Color mismatch found in " << filenames << "... abort." << endl;
+            return kFALSE;
+        }
+    }
+
+    *fLog << inf << "Found color: ";
+    switch (fColor)
+    {
+    case MCalibrationCam::kBLUE:  *fLog << "kBLUE";  break;
+    case MCalibrationCam::kGREEN: *fLog << "kGREEN"; break;
+    case MCalibrationCam::kUV:    *fLog << "kUV";    break;
+    case MCalibrationCam::kCT1:   *fLog << "kCT1";   break;
+    default:                      *fLog << "<none>"; break;
+    }
+    *fLog << endl;
+
+    if (fColor!=MCalibrationCam::kNONE)
+        return kTRUE;
+
+    *fLog <<  "No colour found in: " << fRuns->GetRunsAsString() << "... abort." << endl;
     return kFALSE;
-  
-  TArrayI arr = fRuns->GetRuns();
-
-  if (arr[nruns-1] < gkIFAEBoxInaugurationRun)
-    {
-      *fLog << "Found colour kCT1 in runs: " << fRuns->GetRunsAsString() << endl;
-      fColor = MCalibrationCam::kCT1;
-      return kTRUE;
-    }
-  
-  TString filenames;
-  ((MDirIter*)fRuns)->Reset();
-
-  while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
-    {
-
-      filenames.ToLower();
-
-      //
-      // Here starts the list of runs where the shifters did not put 
-      // a colour, but which have been found out by other means. 
-      // FIXME: This list has is only preliminary and has to move into the 
-      //        database!!
-      //
-      if (filenames.Contains("_30090_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kNONE)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_27474_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! "
-                  << "Selected runs were: " << filenames << endl;
-            fColor = MCalibrationCam::kNONE;
-            return kFALSE;
-          }
-        else if (fColor != MCalibrationCam::kNONE)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_26924_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-
-      if (filenames.Contains("_26568_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_26412_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-
-      if (filenames.Contains("_26409_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_26408_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-
-      if (filenames.Contains("_26402_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kBLUE  in " << filenames << endl;
-            fColor = MCalibrationCam::kBLUE;
-          }
-        else if (fColor != MCalibrationCam::kBLUE)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_20661_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("_20660_"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      //
-      // Here start the runs where the shifter put 
-      // the colour. 
-      //
-      if (filenames.Contains("green"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kGREEN  in " << filenames << endl;
-            fColor = MCalibrationCam::kGREEN;
-          }
-        else if (fColor != MCalibrationCam::kGREEN)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("blue"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kBLUE  in " << filenames << endl;
-            fColor = MCalibrationCam::kBLUE;
-          }
-        else if (fColor != MCalibrationCam::kBLUE)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("uv"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kUV in " << filenames << endl;
-            fColor = MCalibrationCam::kUV;
-          }
-        else if (fColor != MCalibrationCam::kUV)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-
-      if (filenames.Contains("ct1"))
-        if (fColor == MCalibrationCam::kNONE)
-          {
-            *fLog << "Found colour: kCT1  in " << filenames << endl;
-            fColor = MCalibrationCam::kCT1;
-          }
-        else if (fColor != MCalibrationCam::kCT1)
-          {
-            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
-            return kFALSE;
-          }
-      
-    }
-  
-  if (fColor == MCalibrationCam::kNONE)
-    {
-      *fLog <<  "No colour found in filenames of runs: " << fRuns->GetRunsAsString() 
-           << "... abort" << endl;
-      return kFALSE;      
-    }
-
-
-    return kTRUE;
 }
 
