Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3414)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3417)
@@ -37,6 +37,7 @@
 //               Initialize pulser light wavelength
 //               
-//   ReInit:     MCalibrationCam::InitSize(NumPixels) is called which allocates
-//               memory in a TClonesArray of type MCalibrationChargePix
+//   ReInit:     MCalibrationCam::InitSize(NumPixels) is called from MGeomApply (which allocates
+//               memory in a TClonesArray of type MCalibrationChargePix)
+//               Initializes pointer to MBadPixelsCam
 //
 //   Process:    Nothing done by this class, histograms are filled by 
@@ -57,8 +58,9 @@
 //   MRawEvtData
 //   MPedestalCam
-//   MCalibrationCam
+//   MBadPixelsCam
 //
 //  Output Containers:
 //   MCalibrationCam
+//   MBadPixelsCam
 //
 //
@@ -174,7 +176,4 @@
 #include "MCalibrationChargeCalc.h"
 
-// FXIME: Usage of fstream is a preliminary workaround!
-#include <fstream>
-
 #include <TSystem.h>
 #include <TH1.h>
@@ -200,4 +199,7 @@
 #include "MExtractedSignalPix.h"
 
+#include "MBadPixelsCam.h"
+#include "MBadPixelsPix.h"
+
 
 ClassImp(MCalibrationChargeCalc);
@@ -211,5 +213,6 @@
 MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title)
     : fPedestals(NULL), fCam(NULL), 
-      fRawEvt(NULL), fRunHeader(NULL), fGeom(NULL), fEvtTime(NULL),
+      fRawEvt(NULL), fRunHeader(NULL), fGeom(NULL), 
+      fBadPixels(NULL), fEvtTime(NULL),
       fSignals(NULL), fPINDiode(NULL), fBlindPixel(NULL)
 {
@@ -235,5 +238,4 @@
     fNumLoGainSamples  = 0;
     fConversionHiLo    = 0;
-    fNumExcludedPixels = 0;
 
 }
@@ -323,16 +325,32 @@
     }
   
+  fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
+  if (!fBadPixels)
+    {
+      *fLog << err << "Could not find or create MBadPixelsCam ... aborting." << endl;
+      return kFALSE;
+    }
+  
   fCam->SetGeomCam(fGeom);
-
-  fNumHiGainSamples =  fSignals->GetNumUsedHiGainFADCSlices();
-  fNumLoGainSamples =  fSignals->GetNumUsedLoGainFADCSlices();
-  fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
-  
-  UInt_t npixels = fGeom->GetNumPixels();
+  fCam->SetBadPixelsCam(fBadPixels);
+
+  fNumHiGainSamples  =  fSignals->GetNumUsedHiGainFADCSlices();
+  fNumLoGainSamples  =  fSignals->GetNumUsedLoGainFADCSlices();
+  fSqrtHiGainSamples =  TMath::Sqrt((Float_t)fNumHiGainSamples);
+  
+  UInt_t npixels     = fGeom->GetNumPixels();
   
   for (UInt_t i=0; i<npixels; i++)
     {
       MCalibrationChargePix &pix = (*fCam)[i];
+      MBadPixelsPix         &bad = (*fBadPixels)[i];
+
       pix.DefinePixId(i);
+
+      if (bad.IsBad())
+        {
+          pix.SetExcluded();
+          continue;
+        }
       
       pix.SetAbsTimeBordersHiGain(fSignals->GetFirstUsedSliceHiGain(),
@@ -341,58 +359,4 @@
                                   fSignals->GetLastUsedSliceLoGain());
     }
-  
-  if (fExcludedPixelsFile.IsNull())
-        return kTRUE;
-
-    //
-    // Look for file to exclude pixels from analysis
-    //
-    gSystem->ExpandPathName(fExcludedPixelsFile);
-
-    //
-    // Initialize reading the file
-    //
-    ifstream in(fExcludedPixelsFile);
-    if (!in)
-    {
-        *fLog << warn << "Cannot open file '" << fExcludedPixelsFile << "'" << endl;
-        return kTRUE;
-    }
-
-    *fLog << inf << "Use excluded pixels from file: '" << fExcludedPixelsFile << "'" << endl;
-
-    //
-    // Read the file and count the number of entries
-    //
-    UInt_t pixel = 0;
-
-    while (++fNumExcludedPixels)
-    {
-        in >> pixel;
-        if (!in)
-            break;
-
-        //
-        // Check for out of range
-        //
-        if (pixel > npixels)
-        {
-            *fLog << warn << "WARNING: To be excluded pixel: " << pixel << " is out of range " << endl;
-            continue;
-        }
-        //
-        // Exclude pixel
-        //
-        MCalibrationChargePix &pix = (*fCam)[pixel];
-        pix.SetExcluded();
-
-        *fLog << GetDescriptor() << inf << ": Exclude Pixel: " << pixel << endl;
-
-    }
-
-    if (--fNumExcludedPixels == 0)
-        *fLog << warn << "WARNING: File '" << fExcludedPixelsFile << "'" << " is empty " << endl;
-    else
-        fCam->SetNumPixelsExcluded(fNumExcludedPixels);
 
     return kTRUE;
@@ -436,7 +400,4 @@
       const Float_t num    = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
 
-      if (ped == -1.) 
-	  pix.SetExcluded();
-      
       //
       // Check if the pixel has been excluded from the fits
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3414)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3417)
@@ -15,6 +15,4 @@
 #endif
 
-#include "TString.h"
-
 class MRawEvtData;
 class MRawRunHeader;
@@ -25,4 +23,5 @@
 class MGeomCam;
 class MExtractedSignalCam;
+class MBadPixelsCam;
 class MTime;
 class MCalibrationChargeCalc : public MTask
@@ -35,5 +34,6 @@
   MRawRunHeader              *fRunHeader;                 //! RunHeader information
   MGeomCam                   *fGeom;                      //! Geometry information
-
+  MBadPixelsCam              *fBadPixels;                 //! Bad Pixels information
+  
   MTime                      *fEvtTime;                   //! Time of the event
 
@@ -42,5 +42,4 @@
   MCalibrationChargeBlindPix *fBlindPixel;                // Calibration results of the Blind Pixel 
 
-  
   Byte_t  fNumHiGainSamples; 
   Byte_t  fNumLoGainSamples; 
@@ -49,7 +48,4 @@
   Float_t fConversionHiLo;
   Int_t   fFlags;                                // Flag for the fits used
-
-  TString fExcludedPixelsFile;
-  UInt_t  fNumExcludedPixels;
 
   enum  { kUseQualityChecks,
@@ -72,8 +68,4 @@
       {b ? CLRBIT(fFlags, kHiLoGainCalibration) : SETBIT(fFlags, kHiLoGainCalibration);}
 
-
-  // Exclude pixels from configuration file
-  void ExcludePixelsFromAsciiFile(const char *file) { fExcludedPixelsFile = file;  }
-  
   ClassDef(MCalibrationChargeCalc, 1)   // Task to fill the Calibration Containers from raw data
 };
Index: trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3414)
+++ trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3417)
@@ -23,5 +23,5 @@
 #
 INCLUDES = -I. -I../mbase -I../mhbase -I../mgui -I../mgeom -I../manalysis \
-	   -I../mraw -I../mtools -I../mmc -I../mimage -I../msignal
+	   -I../mraw -I../mtools -I../mmc -I../mimage -I../msignal -I../mbadpixels
 
 # mhbase:    MBinning MH 
