Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6003)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6004)
@@ -62,4 +62,9 @@
 
  2005/01/25 Markus Gaug
+
+   * mcalib/MCalibrationPattern.[h,cc]
+   * mcalib/MCalibrationPatternDecode.[h,cc]
+     - New Decoder task for the calibration pattern from the 
+       digital modules
 
    * mbadpixels/MBadPixelsPix.h
Index: trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 6003)
+++ trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 6004)
@@ -8,4 +8,6 @@
 #pragma link C++ class MCalibColorSteer+;
 #pragma link C++ class MCalibCalcFromPast+;
+#pragma link C++ class MCalibrationPattern+;
+#pragma link C++ class MCalibrationPatternDecode+;
 
 #pragma link C++ class MCalibrate+;
@@ -19,5 +21,4 @@
 #pragma link C++ class MCalibrationIntensityRelTimeCam+;
 #pragma link C++ class MCalibrationIntensityTestCam+;
-#pragma link C++ class MCalibrationIntensityHiLoCam+;
 #pragma link C++ class MCalibrationCam+;
 #pragma link C++ class MCalibrationPix+;
Index: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 6003)
+++ trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 6004)
@@ -54,5 +54,4 @@
 #include "MCalibrationIntensityQECam.h"
 #include "MCalibrationIntensityRelTimeCam.h"
-#include "MCalibrationIntensityHiLoCam.h"
 
 #include "MBadPixelsIntensityCam.h"
@@ -206,24 +205,4 @@
   }
       
-  // 
-  // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the 
-  // corresponding IntensityCam
-  //
-  /*
-  if (pList->FindObject(AddSerialNumber("MHCalibrationHiLoCam")))
-  {
-
-    fIntensHiLo = (MCalibrationIntensityHiLoCam*)pList->FindCreateObj("MCalibrationIntensityHiLoCam");
-
-    *fLog << inf << "Found MHCalibrationHiLoCam ... " << flush;
-
-    if (!fIntensHiLo)
-      {
-        *fLog << err << "Could not find nor create MCalibrationIntensityHiLoCam abort... " << endl;
-        return kFALSE;
-      }
-  }
-  */
-
   fNumCam    = 0;
   fNumEvents = 0;
@@ -254,5 +233,4 @@
   if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam ready" << flush;
   if (Finalize("MHCalibrationRelTimeCam"))     *fLog << "MHCalibrationRelTimeCam ready" << flush;  
-  //  if (Finalize("MHCalibrationHiLoCam"))        *fLog << "MHCalibrationHiLoCam ready" << flush;  
 
   //
Index: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h	(revision 6003)
+++ trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h	(revision 6004)
@@ -16,5 +16,4 @@
 class MCalibrationIntensityQECam;
 class MCalibrationIntensityRelTimeCam;
-class MCalibrationIntensityHiLoCam;
 class MBadPixelsIntensityCam;
 class MCalibCalcFromPast : public MTask
@@ -30,5 +29,4 @@
   MCalibrationIntensityQECam      *fIntensQE;        //! Intensity QE     Cam (to be created)
   MCalibrationIntensityRelTimeCam *fIntensRelTime;   //! Intensity Rel. Time Cam (to be created)
-  MCalibrationIntensityHiLoCam    *fIntensHiLo;      //! Intensity High-Vs.Low Cam (to be created)
   MBadPixelsIntensityCam          *fIntensBad;       //! Intensity Bad Pixels Cam (to be created)
   
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityHiLoCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityHiLoCam.cc	(revision 6003)
+++ 	(revision )
@@ -1,252 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
-! * Software. It is distributed to you in the hope that it can be a useful
-! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
-! * It is distributed WITHOUT ANY WARRANTY.
-! *
-! * Permission to use, copy, modify and distribute this software and its
-! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
-! * that both that copyright notice and this permission notice appear
-! * in supporting documentation. It is provided "as is" without express
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
-!
-!
-\* ======================================================================== */
-/////////////////////////////////////////////////////////////////////////////
-//                                                               
-// MCalibrationIntensityHiLoCam                                               
-//                                                               
-// Storage container for intensity charge calibration results. 
-// 
-// Individual MCalibrationHiLoCam's can be retrieved with: 
-// - GetCam() yielding the current cam.
-// - GetCam("name") yielding the current camera with name "name".
-// - GetCam(i) yielding the i-th camera.
-//
-// See also: MCalibrationIntensityCam, MCalibrationHiLoCam,
-//           MCalibrationHiLoPix, MCalibrationHiLoCalc, MCalibrationQECam
-//           MHCalibrationHiLoPix, MHCalibrationHiLoCam              
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationIntensityHiLoCam.h"
-#include "MCalibrationHiLoCam.h"
-#include "MCalibrationChargeCam.h"
-#include "MCalibrationHiLoPix.h"
-#include "MCalibrationChargePix.h"
-
-#include "MGeomCam.h"
-#include "MGeomPix.h"
-
-#include "MLogManip.h"
-
-#include <TOrdCollection.h>
-#include <TGraphErrors.h>
-
-ClassImp(MCalibrationIntensityHiLoCam);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default constructor. 
-//
-MCalibrationIntensityHiLoCam::MCalibrationIntensityHiLoCam(const char *name, const char *title)
-{
-
-  fName  = name  ? name  : "MCalibrationIntensityHiLoCam";
-  fTitle = title ? title : "Results of the Intensity Calibration";
-  
-  InitSize(1);
-}
-
-// -------------------------------------------------------------------
-//
-// Add MCalibrationHiLoCam's in the ranges from - to. 
-//
-void MCalibrationIntensityHiLoCam::Add(const UInt_t from, const UInt_t to)
-{
-  for (UInt_t i=from; i<to; i++)
-    fCams->AddAt(new MCalibrationHiLoCam,i);
-}
-
-TGraphErrors *MCalibrationIntensityHiLoCam::GetHiLoRatioVsCharge( const UInt_t pixid, const MCalibrationIntensityChargeCam &chargecam,
-                                  const MCalibrationCam::PulserColor_t col)
-{
-
-  if (chargecam.GetSize() != GetSize())
-    {
-      *fLog << err << GetDescriptor() << ": Size mismatch between MCalibrationIntensityHiLoCam "
-            << "and MCalibrationIntensityChargeCam. " << endl;
-      return NULL;
-    }
-  
-  Int_t size = CountNumEntries(col);
-  
-  if (size == 0)
-    return NULL;
-
-  if (size != chargecam.CountNumEntries(col))
-    {
-      *fLog << err << GetDescriptor() << ": Size mismatch in colour between MCalibrationIntensityHiLoCam "
-            << "and MCalibrationIntensityChargeCam. " << endl;
-      return NULL;
-    }
-  
-  const Int_t nvalid = chargecam.CountNumValidEntries(pixid,col);
-
-  if (nvalid == 0)
-    {
-      *fLog << err << GetDescriptor() << ": Only un-calibrated events in pixel: " << pixid << endl;
-      return NULL;
-    }
-
-  TArrayF ratio(nvalid);
-  TArrayF ratioerr(nvalid);
-  TArrayF sig(nvalid);
-  TArrayF sigerr(nvalid);
-
-  Int_t cnt = 0;
-  
-  for (Int_t i=0;i<GetSize();i++)
-    {
-      //
-      // Get the calibration cam from the intensity cam
-      //
-      MCalibrationChargeCam *cam     = (MCalibrationChargeCam*)chargecam.GetCam(i);
-      MCalibrationHiLoCam *hilocam = (MCalibrationHiLoCam*)GetCam(i);
-
-      if (col != MCalibrationCam::kNONE)
-        if (hilocam->GetPulserColor() != col)
-          continue;
-      //
-      // Get the calibration pix from the calibration cam
-      //
-      MCalibrationChargePix  &pix    = (MCalibrationChargePix&)(*cam)[pixid];
-      MCalibrationHiLoPix &relpix = (MCalibrationHiLoPix&)(*hilocam)[pixid];
-      //
-      // Don't use bad pixels
-      //
-      if (!pix.IsFFactorMethodValid())
-        continue;
-      //
-      ratio[cnt]    = relpix.GetHiLoChargeRatio();
-      ratioerr[cnt] = relpix.GetHiLoChargeRatioErr();
-      //
-      sig   [cnt] = pix.GetPheFFactorMethod();
-      sigerr[cnt] = pix.GetPheFFactorMethodErr();
-      cnt++;
-    }
-
-  TGraphErrors *gr = new TGraphErrors(nvalid,
-                                     sig.GetArray(),ratio.GetArray(),
-                                     sigerr.GetArray(),ratioerr.GetArray());
-  gr->SetTitle(Form("%s%3i","Pixel ",pixid));
-  gr->GetXaxis()->SetTitle("<Photo-electrons> [1]");
-  gr->GetYaxis()->SetTitle("HiLo Ratio [1]");      
-  return gr;
-}
-
-
-TGraphErrors *MCalibrationIntensityHiLoCam::GetHiLoRatioVsChargePerArea( const Int_t aidx,const MCalibrationIntensityChargeCam &chargecam, const MGeomCam &geom, const MCalibrationCam::PulserColor_t col)
-{
-  
-  Int_t size = CountNumEntries(col);
-  
-  if (size == 0)
-    return NULL;
-
-  if (size != chargecam.CountNumEntries(col))
-    {
-      *fLog << err << GetDescriptor() << ": Size mismatch in colour between MCalibrationIntensityHiLoCam "
-            << "and MCalibrationIntensityChargeCam. " << endl;
-      return NULL;
-    }
-  
-  TArrayF ratio(size);
-  TArrayF ratioerr(size);
-  TArrayF sig(size);
-  TArrayF sigerr(size);
-  
-  Int_t cnt = 0;
-
-  for (Int_t i=0;i<GetSize();i++)
-    {
-      //
-      // Get the calibration cam from the intensity cam
-      //
-      MCalibrationHiLoCam *hilocam = (MCalibrationHiLoCam*)GetCam(i);
-      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)chargecam.GetCam(i);
-
-      if (col != MCalibrationCam::kNONE)
-        if (hilocam->GetPulserColor() != col)
-          continue;
-
-      const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
-      const Float_t phe          = apix.GetPheFFactorMethod();
-      const Float_t pheerr       = apix.GetPheFFactorMethodErr();
-
-      sig[cnt]       = phe;
-      sigerr[cnt]    = pheerr;
-
-      Double_t ratiool  = 0.;
-      Double_t ratiool2 = 0.;
-      Double_t var    = 0.;
-      Int_t    num    = 0;
-     //
-      // Get the area calibration pix from the calibration cam
-      //
-      for (Int_t i=0; i<cam->GetSize(); i++)
-        {
-          const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*cam)[i];
-          const MCalibrationHiLoPix &relpix = (MCalibrationHiLoPix&)(*hilocam)[i];
-          //
-          // Don't use bad pixels
-          //
-          if (!pix.IsFFactorMethodValid())
-            continue;
-          //
-          //
-          if (aidx != geom[i].GetAidx())
-            continue;
-          
-          ratiool  += relpix.GetHiLoChargeRatio();
-          ratiool2 += relpix.GetHiLoChargeRatio()*relpix.GetHiLoChargeRatio();
-          num++;
-        }
-      
-      if (num > 1)
-        {
-          ratiool /= num;
-          var  = (ratiool2 - ratiool*ratiool*num) / (num-1);
-
-          ratio[cnt] = ratiool;
-          if (var > 0.)
-            ratioerr[cnt] = TMath::Sqrt(var);
-          else
-            ratioerr[cnt] = 0.;
-        }
-      else
-        {
-          ratio[cnt]    = -1.;
-          ratioerr[cnt] = 0.;
-        }
-      cnt++;
-    }
-  
-  TGraphErrors *gr = new TGraphErrors(size,
-                                      sig.GetArray(),ratio.GetArray(),
-                                      sigerr.GetArray(),ratioerr.GetArray());
-  gr->SetTitle(Form("%s%3i","Area Index ",aidx));
-  gr->GetXaxis()->SetTitle("<phes> [1]");
-  gr->GetYaxis()->SetTitle("HiLo Ratio [1]");      
-  return gr;
-}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityHiLoCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityHiLoCam.h	(revision 6003)
+++ 	(revision )
@@ -1,32 +1,0 @@
-#ifndef MARS_MCalibrationIntensityHiLoCam
-#define MARS_MCalibrationIntensityHiLoCam
-
-#ifndef MARS_MCalibrationIntensityCam
-#include "MCalibrationIntensityCam.h"
-#endif
-
-#ifndef MARS_MCalibrationIntensityChargeCam
-#include "MCalibrationIntensityChargeCam.h"
-#endif
-
-class TGraphErrors;
-class MCalibrationIntensityHiLoCam : public MCalibrationIntensityCam
-{
-private:
-
-  void Add(const UInt_t from, const UInt_t to);
-
-public:
-
-  MCalibrationIntensityHiLoCam(const char *name=NULL, const char *title=NULL);
-
-  TGraphErrors *GetHiLoRatioVsCharge( const UInt_t pixid, const MCalibrationIntensityChargeCam &chargecam,
-                                    const MCalibrationCam::PulserColor_t col=MCalibrationCam::kNONE);
-  TGraphErrors *GetHiLoRatioVsChargePerArea( const Int_t aidx, const MCalibrationIntensityChargeCam &chargecam,
-                                           const MGeomCam &geom,
-                                           const MCalibrationCam::PulserColor_t col=MCalibrationCam::kNONE);
-
-  ClassDef(MCalibrationIntensityHiLoCam, 1) // Container Intensity HiLo Calibration Results Camera
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.cc	(revision 6004)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.cc	(revision 6004)
@@ -0,0 +1,57 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Nicola Galante  12/2004 <mailto:nicola.galante@pi.infn.it>
+!   Author(s): Thomas Bretz  12/2004 <mailto:nicola.galante@pi.infn.it>
+!
+!   Copyright: MAGIC Software Development, 2004
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//   MCalibrationPattern
+//
+//  A container to store the decoded calibration pattern.
+//
+// The idea is, that this container will never change the meaning of its
+// variables, while the calibration pattern itself could.
+//
+// If new 'features' are necessary the decoding (MCalibrationPatternDecode)
+// must be changed to correctly decode the pattern into the existing
+// MCalibrationPattern. If new information is decoded you may have to
+// add new variables to this container. Don't forget to increase the
+// class version number (ClassDef) and document your change HERE.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationPattern.h"
+
+ClassImp(MCalibrationPattern);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor
+//
+MCalibrationPattern::MCalibrationPattern(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MCalibrationPattern";
+    fTitle = title ? title : "Container for decoded calibration pattern";
+
+    Reset();
+}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.h	(revision 6004)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPattern.h	(revision 6004)
@@ -0,0 +1,93 @@
+#ifndef MARS_MCalibrationPattern
+#define MARS_MCalibrationPattern
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef MARS_MCalibrationCam
+#include "MCalibrationCam.h"
+#endif
+
+class MCalibrationPattern : public MParContainer
+{
+    friend class MCalibrationPatternDecode;
+
+public:
+
+    enum CLColor_t 
+      {
+        kCLUV       = BIT(0),
+        kCLGreen    = BIT(1),
+        kCLAmber    = BIT(2),
+        kCLRed      = BIT(3),
+        kCLRedAmber   = kCLRed & kCLAmber,
+        kCLRedGreen   = kCLRed & kCLGreen,
+        kCLRedUV      = kCLRed & kCLUV   ,
+        kCLAmberGreen = kCLAmber & kCLGreen,
+        kCLAmberUV    = kCLAmber & kCLUV   ,
+        kCLGreenUV    = kCLGreen & kCLUV   ,
+        kCLRedAmberGreen = kCLRedAmber & kCLGreen,
+        kCLRedGreenUV    = kCLRedGreen & kCLUV,
+        kCLAmberGreenUV  = kCLAmberGreen & kCLUV,
+        kCLAll           = kCLRedAmberGreen & kCLUV,
+	kCLNone    = BIT(4)
+      };
+    
+    enum PulserColorCode_t 
+      {
+        kSlot1Green     = BIT(0),
+        kSlot2Green     = BIT(1),
+        kSlot3Blue      = BIT(2),
+        kSlot4UV        = BIT(3),
+        kSlot5UV        = BIT(4),
+        kSlot6Blue      = BIT(5),
+        kSlot7Blue      = BIT(6),
+        kSlot8Blue      = BIT(7),
+        kSlot9AttBlue   = BIT(8),
+        kSlot10Blue     = BIT(9),
+        kSlot11Blue     = BIT(10),
+        kSlot12UV       = BIT(11),
+        kSlot13UV       = BIT(12),
+        kSlot14Blue     = BIT(13),
+        kSlot15Green    = BIT(14),
+        kSlot16AttGreen = BIT(15),
+        kCT1Pulser      = BIT(16),
+        kAnyGreen       = kSlot1Green  | kSlot2Green | kSlot15Green | kSlot16AttGreen,
+        kAnyUV          = kSlot4UV     | kSlot5UV    | kSlot12UV    | kSlot13UV,
+        kAnyBlue        = kSlot3Blue   | kSlot6Blue  | kSlot7Blue   | kSlot8Blue 
+                        | kSlot9AttBlue| kSlot10Blue | kSlot11Blue  | kSlot14Blue, 
+        kGreenAndBlue   = kAnyGreen & kAnyBlue,
+        kBlueAndUV      = kAnyBlue  & kAnyUV,
+        kGreenAndUV     = kAnyGreen & kAnyUV,
+        kIFAEPulser     = kAnyGreen | kAnyBlue | kAnyUV,
+        kAny            = kAnyGreen | kAnyBlue | kAnyUV | kCT1Pulser
+      };
+
+private:
+
+    UShort_t  fCLStrength;     // Continuous light strenth  
+    CLColor_t fCLColor;        // Color (combinations) of the continuous light
+    Float_t   fPulserStrength; // Strength of the pulsed light (in nr. of equiv. LEDs)
+    
+    MCalibrationCam::PulserColor_t fPulserColor; // Colour of the pulsed light
+
+public:
+
+    MCalibrationPattern(const char *name=0, const char *title=0);
+
+    void Reset() { fCLStrength=0; fCLColor=kCLNone; fPulserColor=MCalibrationCam::kNONE; fPulserStrength=0.; }
+
+    UShort_t   GetCLStrength()     const { return fCLStrength; }
+    CLColor_t  GetCLColor()        const { return fCLColor; }
+    Float_t    GetPulserStrength() const { return fPulserStrength; }
+
+    const MCalibrationCam::PulserColor_t GetPulserColor() const { return fPulserColor; }
+
+    void SetPulserColor   ( const MCalibrationCam::PulserColor_t col) { fPulserColor = col; }
+    void SetPulserStrength( const Float_t strength ) { fPulserStrength = strength; }
+
+    ClassDef(MCalibrationPattern, 1) // Container storing the decoded calibration pattern
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.cc	(revision 6004)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.cc	(revision 6004)
@@ -0,0 +1,178 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Nicola Galante  12/2004 <mailto:nicola.galante@pi.infn.it>
+!   Author(s): Thomas Bretz 12/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2004
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//   MCalibrationPatternDecode
+//
+//  Decodes the trigger pattern from MRawEvtData into MCalibrationPattern.
+//
+// For files before file version 5 the trigger pattern is set to 00000000.
+// This can be changed using the information about the file-type.
+//
+// Input:
+//   MRawEvtData
+//
+// Output:
+//   MCalibrationPattern
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationPatternDecode.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MRawEvtHeader.h"
+#include "MRawRunHeader.h"
+#include "MCalibrationPattern.h"
+
+ClassImp(MCalibrationPatternDecode);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor
+//
+MCalibrationPatternDecode::MCalibrationPatternDecode(const char *name, const char *title)
+    : fRunHeader(0), fEvtHeader(0), fPattern(0)
+{
+    fName  = name  ? name  : "MCalibrationPatternDecode";
+    fTitle = title ? title : "Task to decode Trigger Pattern";
+}
+
+// --------------------------------------------------------------------------
+//
+Int_t MCalibrationPatternDecode::PreProcess(MParList *pList)
+{
+    fRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
+    if (!fRunHeader)
+    {
+	*fLog << err << "MRawRunHeader not found... abort." << endl;
+	return kFALSE;
+    }
+
+    fEvtHeader = (MRawEvtHeader *)pList->FindObject("MRawEvtHeader");
+    if (!fEvtHeader)
+    {
+	*fLog << err << "MRawEvtHeader not found... abort." << endl;
+	return kFALSE;
+    }
+
+    fPattern = (MCalibrationPattern*)pList->FindCreateObj("MCalibrationPattern");
+    if (!fPattern)
+    {
+	*fLog << err << "MCalibratinPattern not found... abort." << endl;
+	return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// For files before file version 5 the trigger pattern is set to 00000000.
+// This can be changed using the information about the file-type.
+//
+Int_t MCalibrationPatternDecode::Process()
+{
+    // No setting necessary because MCalibrationPattern::reset() has
+    // been called just before
+    if (fRunHeader->GetFormatVersion()<5)
+        return kTRUE;
+
+    UInt_t pattern = fEvtHeader->GetCalibrationPattern();
+
+    fPattern->fCLStrength = pattern & 0xff;
+    fPattern->fCLColor    = (MCalibrationPattern::CLColor_t)((pattern>>8)&0xf);
+    
+    const UInt_t pulserpattern = (pattern >> 16) & 0x1ffff;
+
+    fPattern->fPulserStrength =  MCalibrationCam::kNONE;    
+
+    if ((pulserpattern & kGreenAndBlue) || (pulserpattern & kBlueAndUV) || (pulserpattern & kGreenAndUV))
+      fPattern->fPulserStrength =  MCalibrationCam::kNONE;
+    if (pulserpattern & kCT1Pulser)
+      fPattern->fPulserStrength =  MCalibrationCam::kCT1;
+    if (pulserpattern & kAnyUV)
+      fPattern->fPulserStrength =  MCalibrationCam::kUV;
+    if (pulserpattern & kAnyGreen)
+      fPattern->fPulserStrength =  MCalibrationCam::kGREEN;
+    if (pulserpattern & kAnyBlue)
+      fPattern->fPulserStrength =  MCalibrationCam::kBLUE;
+
+    Float_t strength = 0.;
+
+    switch (fPattern->fPulserColor)
+      {
+      case MCalibrationCam::kNONE:
+	break;
+      case MCalibrationCam::kGREEN:
+        if (pattern & kSlot1Green)
+          strength += 5.;
+        if (pattern & kSlot2Green)
+          strength += 2.;
+        if (pattern & kSlot15Green)
+          strength += 1.;
+        if (pattern & kSlot16AttGreen)
+          strength += 0.2;
+	break;      
+      case MCalibrationCam::kBLUE:
+        if (pattern & kSlot3Blue)
+          strength += 5.;
+        if (pattern & kSlot6Blue)
+          strength += 5.;
+        if (pattern & kSlot7Blue)
+          strength += 5.;
+        if (pattern & kSlot8Blue)
+          strength += 2.;
+        if (pattern & kSlot9AttBlue)
+          strength += 0.2;
+        if (pattern & kSlot10Blue)
+          strength += 0.;
+        if (pattern & kSlot11Blue)
+          strength += 1.;
+        if (pattern & kSlot14Blue)
+          strength += 5.;
+	break;      
+      case MCalibrationCam::kUV:
+        if (pattern & kSlot4UV)
+          strength += 1.;
+        if (pattern & kSlot5UV)
+          strength += 2.;
+        if (pattern & kSlot12UV)
+          strength += 5.;
+        if (pattern & kSlot13UV)
+          strength += 5.;
+      break;      
+      case MCalibrationCam::kCT1:
+	strength = 20.;
+	break;      
+      }
+  
+    fPattern->fPulserStrength = strength;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.h	(revision 6004)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPatternDecode.h	(revision 6004)
@@ -0,0 +1,61 @@
+#ifndef MARS_MCalibrationPatternDecode
+#define MARS_MCalibrationPatternDecode
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MParList;
+class MRawEvtHeader;
+class MRawRunHeader;
+class MCalibrationPattern;
+
+class MCalibrationPatternDecode : public MTask
+{
+private:
+
+    enum PulserColorCode_t 
+      {
+        kSlot1Green     = BIT(0),
+        kSlot2Green     = BIT(1),
+        kSlot3Blue      = BIT(2),
+        kSlot4UV        = BIT(3),
+        kSlot5UV        = BIT(4),
+        kSlot6Blue      = BIT(5),
+        kSlot7Blue      = BIT(6),
+        kSlot8Blue      = BIT(7),
+        kSlot9AttBlue   = BIT(8),
+        kSlot10Blue     = BIT(9),
+        kSlot11Blue     = BIT(10),
+        kSlot12UV       = BIT(11),
+        kSlot13UV       = BIT(12),
+        kSlot14Blue     = BIT(13),
+        kSlot15Green    = BIT(14),
+        kSlot16AttGreen = BIT(15),
+        kCT1Pulser      = BIT(16),
+        kAnyGreen       = kSlot1Green  | kSlot2Green | kSlot15Green | kSlot16AttGreen,
+        kAnyUV          = kSlot4UV     | kSlot5UV    | kSlot12UV    | kSlot13UV,
+        kAnyBlue        = kSlot3Blue   | kSlot6Blue  | kSlot7Blue   | kSlot8Blue 
+                        | kSlot9AttBlue| kSlot10Blue | kSlot11Blue  | kSlot14Blue, 
+        kGreenAndBlue   = kAnyGreen & kAnyBlue,
+        kBlueAndUV      = kAnyBlue  & kAnyUV,
+        kGreenAndUV     = kAnyGreen & kAnyUV,
+        kIFAEPulser     = kAnyGreen | kAnyBlue | kAnyUV,
+        kAny            = kAnyGreen | kAnyBlue | kAnyUV | kCT1Pulser
+      };
+
+    MRawRunHeader   *fRunHeader;
+    MRawEvtHeader   *fEvtHeader;
+    MCalibrationPattern *fPattern;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+
+public:
+
+    MCalibrationPatternDecode(const char *name=0, const char *title=0);
+
+    ClassDef(MCalibrationPatternDecode, 1) // Task to decode the Trigger Pattern
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mcalib/Makefile	(revision 6003)
+++ trunk/MagicSoft/Mars/mcalib/Makefile	(revision 6004)
@@ -35,4 +35,6 @@
 	   MCalibCalcFromPast.cc \
 	   MCalibrateData.cc \
+	   MCalibrationPattern.cc \
+	   MCalibrationPatternDecode.cc \
 	   MCalibrateRelTimes.cc \
            MCalibrationIntensityCam.cc \
@@ -42,5 +44,4 @@
            MCalibrationIntensityRelTimeCam.cc \
            MCalibrationIntensityTestCam.cc \
-           MCalibrationIntensityHiLoCam.cc \
            MCalibrationCam.cc \
            MCalibrationPix.cc  \
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 6003)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 6004)
@@ -119,4 +119,5 @@
 #include "MCalibrationIntensityQECam.h"
 
+#include "MCalibrationPatternDecode.h"
 #include "MCalibrationCam.h"
 #include "MCalibrationQECam.h"
@@ -1621,4 +1622,5 @@
     // Other Tasks
     //
+    MCalibrationPatternDecode decode;
     MGeomApply               apply;
     apply.SetGeometry(fGeometry);
@@ -1693,4 +1695,5 @@
     taskenv.SetDefault(fExtractor);
 
+    tlist.AddToList(&decode);
     tlist.AddToList(&merge);
     tlist.AddToList(&apply);
