Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3831)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3832)
@@ -18,4 +18,17 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/04/26: Markus Gaug
+
+   * mjobs/MJCalibration.[h,cc]
+     - moved colour finder from the macros into this class with the 
+       function FindColor()
+
+   * macros/calibration.C
+   * macros/calibrate_data.C
+   * macros/pedphotcalc.C
+   * macros/bootcampstandardanalysis.C
+     - removed function FindColor()
+
 
  2004/04/26: Abelardo Moralejo
Index: trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C
===================================================================
--- trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3831)
+++ trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3832)
@@ -71,36 +71,4 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
-  MCalibrationCam::PulserColor_t color;
-
-  if (crun1 < 20000)
-    color = MCalibrationCam::kCT1;
-  else
-    color = FindColor((MDirIter*)&cruns);
-
-  if (color == MCalibrationCam::kNONE)
-    {
-      TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-      
-      while (1)
-        {
-          timer.TurnOn();
-          TString input = Getline("Could not find the correct colour: Type 'q' to exit, "
-                                  "green, blue, uv or ct1 to go on: ");
-          timer.TurnOff();
-          
-          if (input=="q\n")
-            return ;
-          
-          if (input=="green")
-            color = MCalibrationCam::kGREEN;
-          if (input=="blue")
-            color = MCalibrationCam::kBLUE;
-          if (input=="uv")
-            color = MCalibrationCam::kUV;
-          if (input=="ct1")
-            color = MCalibrationCam::kCT1;
-        }
-    }
-  
   if (drun2==0)
     druns.AddRun(drun1,inpath);
@@ -149,5 +117,4 @@
   MCalibrationQECam qecam;
   MJCalibration     calloop;
-  calloop.SetColor(color);
   calloop.SetInput(&cruns);
   //
@@ -364,72 +331,2 @@
 }
 
-MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 
-{
-  
-  MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE;
-
-  TString filenames;
-
-  while (!(filenames=run->Next()).IsNull())
-    {
-
-      filenames.ToLower();
-
-      if (filenames.Contains("green"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Green  in " << filenames << endl;
-            col = MCalibrationCam::kGREEN;
-          }
-        else if (col != MCalibrationCam::kGREEN)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("blue"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Blue  in " << filenames << endl;
-            col = MCalibrationCam::kBLUE;
-          }
-        else if (col != MCalibrationCam::kBLUE)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("uv"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Uv  in " << filenames << endl;
-            col = MCalibrationCam::kUV;
-          }
-        else if (col != MCalibrationCam::kUV)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("ct1"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Ct1  in " << filenames << endl;
-            col = MCalibrationCam::kCT1;
-          }
-        else if (col != MCalibrationCam::kCT1)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-      
-    }
-  
-
-      
-  if (col == MCalibrationCam::kNONE)
-    cout <<  "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 
-         << "... abort" << endl;
-  
-  return col;      
-}
Index: trunk/MagicSoft/Mars/macros/calibrate_data.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibrate_data.C	(revision 3831)
+++ trunk/MagicSoft/Mars/macros/calibrate_data.C	(revision 3832)
@@ -56,35 +56,4 @@
   }
 
-  MCalibrationCam::PulserColor_t color;
-
-  if (calruns[0] < 20000)
-    color = MCalibrationCam::kCT1;
-  else
-    color = FindColor((MDirIter*)&cruns);
-
-  if (color == MCalibrationCam::kNONE)
-    {
-      TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-      
-      while (1)
-        {
-          timer.TurnOn();
-          TString input = Getline("Could not find the correct colour: Type 'q' to exit, "
-                                  "green, blue, uv or ct1 to go on: ");
-          timer.TurnOff();
-          
-          if (input=="q\n")
-            return ;
-          
-          if (input=="green")
-            color = MCalibrationCam::kGREEN;
-          if (input=="blue")
-            color = MCalibrationCam::kBLUE;
-          if (input=="uv")
-            color = MCalibrationCam::kUV;
-          if (input=="ct1")
-            color = MCalibrationCam::kCT1;
-        }
-    }
 
   MStatusDisplay *display = new MStatusDisplay;
@@ -110,4 +79,5 @@
   //
   // badcam.AsciiRead("badpixels.dat");
+
 
   plist1.AddToList(&pedcam);
@@ -150,5 +120,4 @@
   MCalibrationQECam qecam;
   MJCalibration     calloop;
-  calloop.SetColor(color);
   calloop.SetInput(&cruns);
   //  calloop.SetFullDisplay();
@@ -185,8 +154,12 @@
   if (!calloop.Process(pedcam))
     return;
+
+  badcam.Print();
   
   MBadPixelsCam          &badbad  = calloop.GetBadPixels();
   MCalibrationChargeCam  &calcam  = calloop.GetCalibrationCam();
   MCalibrationRelTimeCam &timecam = calloop.GetRelTimeCam();
+
+  badbad.Print();
 
   /************************************************************************/
@@ -414,72 +387,2 @@
 
 
-MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 
-{
-  
-  MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE;
-
-  TString filenames;
-
-  while (!(filenames=run->Next()).IsNull())
-    {
-
-      filenames.ToLower();
-
-      if (filenames.Contains("green"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Green  in " << filenames << endl;
-            col = MCalibrationCam::kGREEN;
-          }
-        else if (col != MCalibrationCam::kGREEN)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("blue"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Blue  in " << filenames << endl;
-            col = MCalibrationCam::kBLUE;
-          }
-        else if (col != MCalibrationCam::kBLUE)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("uv"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Uv  in " << filenames << endl;
-            col = MCalibrationCam::kUV;
-          }
-        else if (col != MCalibrationCam::kUV)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("ct1"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Ct1  in " << filenames << endl;
-            col = MCalibrationCam::kCT1;
-          }
-        else if (col != MCalibrationCam::kCT1)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-      
-    }
-  
-
-      
-  if (col == MCalibrationCam::kNONE)
-    cout <<  "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 
-         << "... abort" << endl;
-  
-  return col;      
-}
Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 3831)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 3832)
@@ -52,8 +52,8 @@
 // 
 /////////////////////////////////////////////////////////////////////////////
-const TString inpath = "/home/rootdata/BlindPixel/";
-const Int_t pedrun  = 20491;
-const Int_t calrun1 = 20494;
-const Int_t calrun2 = 20496;
+const TString inpath = "/home/rootdata/Calib/2004_04_16/";
+const Int_t pedrun  = 22265;
+const Int_t calrun1 = 22299;
+const Int_t calrun2 = 22300;
 
 void calibration(const Int_t prun=pedrun, const Int_t crun1=calrun1, const Int_t crun2=calrun2)
@@ -70,14 +70,4 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
-  MCalibrationCam::PulserColor_t color;
-
-  if (crun1 < 20000)
-    color = MCalibrationCam::kCT1;
-  else
-    color = FindColor((MDirIter*)&cruns);
-
-  if (color == MCalibrationCam::kNONE)
-    return;
-
   MCalibrationQECam qecam;
   MBadPixelsCam     badcam;
@@ -88,8 +78,4 @@
   //
   //  badcam.AsciiRead("badpixels.dat");
-
-  for (Int_t i=0;i<badcam.GetSize();i++)
-    if (badcam[i].IsBad())
-      cout << "Bad Pixel: " << i << endl;
 
   MStatusDisplay *display = new MStatusDisplay;
@@ -114,5 +100,5 @@
   //
   MJCalibration calloop;
-  calloop.SetColor(color);
+  //  calloop.SetColor(color);
 
   //
@@ -136,72 +122,2 @@
 }
 
-MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 
-{
-  
-  MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE;
-
-  TString filenames;
-
-  while (!(filenames=run->Next()).IsNull())
-    {
-
-      filenames.ToLower();
-
-      if (filenames.Contains("green"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Green  in " << filenames << endl;
-            col = MCalibrationCam::kGREEN;
-          }
-        else if (col != MCalibrationCam::kGREEN)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("blue"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Blue  in " << filenames << endl;
-            col = MCalibrationCam::kBLUE;
-          }
-        else if (col != MCalibrationCam::kBLUE)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("uv"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Uv  in " << filenames << endl;
-            col = MCalibrationCam::kUV;
-          }
-        else if (col != MCalibrationCam::kUV)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("ct1"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Ct1  in " << filenames << endl;
-            col = MCalibrationCam::kCT1;
-          }
-        else if (col != MCalibrationCam::kCT1)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-      
-    }
-  
-
-      
-  if (col == MCalibrationCam::kNONE)
-    cout <<  "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 
-         << "... abort" << endl;
-  
-  return col;      
-}
Index: trunk/MagicSoft/Mars/macros/pedphotcalc.C
===================================================================
--- trunk/MagicSoft/Mars/macros/pedphotcalc.C	(revision 3831)
+++ trunk/MagicSoft/Mars/macros/pedphotcalc.C	(revision 3832)
@@ -93,75 +93,4 @@
 const Bool_t usedisplay = kTRUE;
 
-static MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 
-{
-  
-  MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE;
-
-  TString filenames;
-
-  while (!(filenames=run->Next()).IsNull())
-    {
-
-      filenames.ToLower();
-
-      if (filenames.Contains("green"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Green  in " << filenames << endl;
-            col = MCalibrationCam::kGREEN;
-          }
-        else if (col != MCalibrationCam::kGREEN)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("blue"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Blue  in " << filenames << endl;
-            col = MCalibrationCam::kBLUE;
-          }
-        else if (col != MCalibrationCam::kBLUE)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("uv"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Uv  in " << filenames << endl;
-            col = MCalibrationCam::kUV;
-          }
-        else if (col != MCalibrationCam::kUV)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-
-      if (filenames.Contains("ct1"))
-        if (col == MCalibrationCam::kNONE)
-          {
-            cout << "Found colour: Ct1  in " << filenames << endl;
-            col = MCalibrationCam::kCT1;
-          }
-        else if (col != MCalibrationCam::kCT1)
-          {
-            cout << "Different colour found in " << filenames << "... abort" << endl;
-            return MCalibrationCam::kNONE;
-          }
-      
-    }
-  
-
-      
-  if (col == MCalibrationCam::kNONE)
-    cout <<  "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 
-         << "... abort" << endl;
-  
-  return col;      
-}
-
 
 
@@ -292,36 +221,4 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
-  MCalibrationCam::PulserColor_t color;
-
-  if (crun1 < 20000)
-    color = MCalibrationCam::kCT1;
-  else
-    color = FindColor((MDirIter*)&cruns);
-
-  if (color == MCalibrationCam::kNONE)
-    {
-      TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
-      
-      while (1)
-        {
-          timer.TurnOn();
-          TString input = Getline("Could not find the correct colour: Type 'q' to exit, "
-                                  "green, blue, uv or ct1 to go on: ");
-          timer.TurnOff();
-          
-          if (input=="q\n")
-            return ;
-          
-          if (input=="green")
-            color = MCalibrationCam::kGREEN;
-          if (input=="blue")
-            color = MCalibrationCam::kBLUE;
-          if (input=="uv")
-            color = MCalibrationCam::kUV;
-          if (input=="ct1")
-            color = MCalibrationCam::kCT1;
-        }
-    }
-
   //
   // Now setup the tasks and tasklist for the pedestals:
@@ -365,5 +262,4 @@
   //
   MJCalibration     calloop;
-  calloop.SetColor(color);
   calloop.SetInput(&cruns);
   //
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3831)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3832)
@@ -141,4 +141,5 @@
 using namespace std;
 
+const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
 // --------------------------------------------------------------------------
 //
@@ -863,4 +864,98 @@
 // --------------------------------------------------------------------------
 //
+// Find the colour of the pulsing LED:
+// - If the run number is smaller than gkIFAEBoxInaugurationRun, take MCalibrationCam::kCT1
+// - Otherwise find the colour out of the run name
+// - If no colour is found, return kFALSE
+// 
+Bool_t MJCalibration::FindColor() 
+{
+
+  const UInt_t nruns = fRuns->GetNumRuns();
+
+  if (nruns == 0)
+    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;
+
+  while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
+    {
+
+      filenames.ToLower();
+
+      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;
+}
+
+
+
+
+// --------------------------------------------------------------------------
+//
 // Retrieve the output file written by WriteResult()
 // 
@@ -891,4 +986,5 @@
 //
 // - Check if there are fRuns, otherwise return
+// - Check the colour of the files in fRuns (FindColor()), otherwise return
 // - Check for consistency between run numbers and number of files
 // - Add fRuns to MReadMarsFile
@@ -930,10 +1026,15 @@
   if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
     {
-      *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
+      *fLog << err << "Number of files found doesn't match number of runs... abort." 
+            << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
       return kFALSE;
     }
-  
+
   *fLog << inf;
   fLog->Separator(GetDescriptor());
+
+  if (!FindColor())
+    return kFALSE;
+  
   *fLog << "Calculate MCalibrationCam from Runs " << fRuns->GetRunsAsString() << endl;
   *fLog << endl;
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3831)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3832)
@@ -24,4 +24,6 @@
 {
 private:
+
+  static const Int_t gkIFAEBoxInaugurationRun;              // Run number of first IFAE box calibration
 
   TString fOutputPath;                                     // Path to the output files
@@ -52,5 +54,6 @@
   void   DisplayResult(MParList &plist);
   Bool_t WriteResult();
-
+  Bool_t FindColor();
+  
 public:
 
