Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5297)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5298)
@@ -20,8 +20,27 @@
                                                  -*-*- END OF LINE -*-*-
 
- 2004/10/20: Markus Gaug
+ 2004/10/20: Thomas Bretz
 
    * msignal/MExtractTimeFastSpline.cc:
      - fixed a compiler warning: Unused variable
+
+   * mjob/MJPedestal.cc:
+     - added "DisableOutput" as a resource option
+
+   * mbase/MArrayF.h:
+     - added a new Reset(Float_t) member function
+
+   * msignal/MExtractTimeAndChargeDigitalFilter.[h,cc]:
+     - enrolled some if-else blocks
+     - fixed includes
+     - enhanced error handling when a file is read
+     - moved output from PostProcess to PreProcess
+     - fixed and enhanced ReadEnv
+
+   * mjob/MJCalibrateSignal.cc:
+     - enabled variance display for tabs showing signal
+
+   * mhist/MHCamera.cc:
+     - fixed returning GetBinError for kProfile mode switched on
 
 
@@ -130,5 +149,5 @@
  2004/10/08: R. DelosReyes
 
-  * mbase/MrunIter.h
+  * mbase/MRunIter.h
     - changed the name of the Sort() function name by SortRuns() 
       to avoid conflicts with the Sort() function in the MDirIter class.
Index: trunk/MagicSoft/Mars/mbase/MArrayF.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArrayF.h	(revision 5297)
+++ trunk/MagicSoft/Mars/mbase/MArrayF.h	(revision 5298)
@@ -96,4 +96,10 @@
     }
 
+    void Reset(Float_t f)
+    {
+        for (UInt_t i=0; i<fN; i++)
+            fArray[i] = f;
+    }
+
     void Set(UInt_t n)
     {
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 5297)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 5298)
@@ -1162,10 +1162,9 @@
     }
     else
-      {
+    {
         rc = TH1D::GetBinError(bin);
-	rc = Profile(rc);
-      }
-
-    return rc;
+    }
+
+    return Profile(rc);
 }
 
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5297)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5298)
@@ -332,6 +332,8 @@
     MHCamEvent evt6(0, "Times",       "Arrival Time;;T [slice]");
     evt0.EnableVariance();
+    evt1.EnableVariance();
     evt2.EnableVariance();
     evt3.EnableVariance();
+    evt4.EnableVariance();
     evt6.EnableVariance();
 
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5297)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5298)
@@ -17,5 +17,5 @@
 !
 !   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
-!              Markus Gaug ,04/2004 <mailto:markus@ifae.es>
+!   Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
@@ -84,4 +84,5 @@
 const Float_t  MJPedestal::fgRefPedRmsExtraGalacticOuter = 3.35;
 const Float_t  MJPedestal::fgRefPedRmsGalacticOuter      = 4.2;
+
 // --------------------------------------------------------------------------
 //
@@ -99,10 +100,8 @@
       fDataCheck(kFALSE), fUseData(kFALSE)
 {
-
-  fName  = name  ? name  : "MJPedestal";
-  fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
-  
-  SetNormalStorage();
-
+    fName  = name  ? name  : "MJPedestal";
+    fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
+
+    SetNormalStorage();
 }
 
@@ -128,40 +127,39 @@
 Bool_t MJPedestal::ReadPedestalCam()
 {
-
-  if (IsNoStorage())
-    return kFALSE;
-  
-  const TString fname = GetOutputFile();
-  
-  if (gSystem->AccessPathName(fname, kFileExists))
-    {
-      *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
-      return kFALSE;
-    }
-  
-  *fLog << inf << "Reading from file: " << fname << endl;
-  
-  TFile file(fname, "READ");
-  if (fPedestalCam.Read()<=0)
-    {
-      *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
-      return kFALSE;
-    }
-  
-  if (file.FindKey("MBadPixelsCam"))
-    {
-      MBadPixelsCam bad;
+    if (IsNoStorage())
+        return kFALSE;
+
+    const TString fname = GetOutputFile();
+
+    if (gSystem->AccessPathName(fname, kFileExists))
+    {
+        *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf << "Reading from file: " << fname << endl;
+
+    TFile file(fname, "READ");
+    if (fPedestalCam.Read()<=0)
+    {
+        *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
+        return kFALSE;
+    }
+
+    if (file.FindKey("MBadPixelsCam"))
+    {
+        MBadPixelsCam bad;
         if (bad.Read()<=0)
-          {
+        {
             *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
             return kFALSE;
-          }
+        }
         fBadPixels.Merge(bad);
     }
 
-  if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
-    fDisplay->Read();
-  
-  return kTRUE;
+    if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
+        fDisplay->Read();
+
+    return kTRUE;
 }
 
@@ -371,5 +369,4 @@
 void  MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
 {
-
   Double_t x = cam->GetNbinsX();
   
@@ -441,5 +438,4 @@
 void MJPedestal::FixDataCheckHist(TH1D *hist) const 
 {
-
     hist->SetDirectory(NULL);
     hist->SetStats(0);
@@ -459,6 +455,6 @@
     xaxe->SetLabelSize(0.05);
     yaxe->SetLabelSize(0.05);    
-
-}
+}
+
 /*
 Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
@@ -494,4 +490,5 @@
 //   Prefix.DataCheck:        Yes, No
 //   Prefix.UseData:          Yes, No
+//   Prefix.DisableOutput:    Yes, No
 //
 Bool_t MJPedestal::CheckEnvLocal()
@@ -502,4 +499,5 @@
     SetDataCheck(GetEnv("DataCheck", fDataCheck));
     SetUseData(GetEnv("UseData", fUseData));
+    SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
 
     return kTRUE;
@@ -516,41 +514,40 @@
 Bool_t MJPedestal::WriteResult()
 {
-  
-  if (IsNoStorage())
+    if (IsNoStorage())
+        return kTRUE;
+
+    if (fPathOut.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
+    if (!file.IsOpen())
+    {
+        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
+        return kFALSE;
+    }
+
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
+        return kFALSE;
+    }
+
+    if (fPedestalCam.Write()<=0)
+    {
+        *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
+        return kFALSE;
+    }
+
+    if (fBadPixels.Write()<=0)
+    {
+        *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
+        return kFALSE;
+    }
+
     return kTRUE;
-
-  if (fPathOut.IsNull())
-    return kTRUE;
-  
-  const TString oname(GetOutputFile());
-  
-  *fLog << inf << "Writing to file: " << oname << endl;
-
-  TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
-  if (!file.IsOpen())
-    {
-      *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
-      return kFALSE;
-    }
-  
-  if (fDisplay && fDisplay->Write()<=0)
-    {
-      *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
-      return kFALSE;
-    }
-
-  if (fPedestalCam.Write()<=0)
-    {
-      *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
-      return kFALSE;
-    }
-
-  if (fBadPixels.Write()<=0)
-    {
-      *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
-      return kFALSE;
-    }
-
-  return kTRUE;
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5297)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5298)
@@ -51,16 +51,17 @@
 #include "MExtractTimeAndChargeDigitalFilter.h"
 
+#include <errno.h>
+#include <fstream>
+
+#include <TFile.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TString.h>
+#include <TMatrix.h>
+
 #include "MLog.h"
 #include "MLogManip.h"
 
 #include "MPedestalPix.h"
-
-#include "TFile.h" 
-#include "TH1F.h" 
-#include "TH2F.h" 
-#include "TString.h"
-#include "TMatrix.h"
-
-#include <fstream>
 
 ClassImp(MExtractTimeAndChargeDigitalFilter);
@@ -78,4 +79,5 @@
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain = 4;
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain = 4;
+
 // --------------------------------------------------------------------------
 //
@@ -91,16 +93,14 @@
 MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title) 
 {
-
-  fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
-  fTitle = title ? title : "Digital Filter";
-
-  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
-  SetWindowSize();
-  SetBinningResolution();
-  SetSignalStartBin();
-
-  ReadWeightsFile("");
+    fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
+    fTitle = title ? title : "Digital Filter";
+
+    SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
+    SetWindowSize();
+    SetBinningResolution();
+    SetSignalStartBin();
+
+    ReadWeightsFile("");
 }
-
 
 // ---------------------------------------------------------------------------------------
@@ -129,5 +129,6 @@
 
   if (fWindowSizeHiGain > availhirange)
-    {
+  {
+      // Please simplify this!
       *fLog << warn << GetDescriptor() 
             << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain,
@@ -150,4 +151,5 @@
       if (fWindowSizeLoGain > availlorange)
         {
+      // Please simplify this!
           *fLog << warn << GetDescriptor() 
                 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain,
@@ -182,22 +184,32 @@
 Bool_t MExtractTimeAndChargeDigitalFilter::ReInit(MParList *pList)
 {
-
-  if (!MExtractTimeAndCharge::ReInit(pList))
-    return kFALSE;
-
-  Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
-
-  fHiGainSignal.Set(range);
-
-  range = fLoGainLast - fLoGainFirst + 1;
-
-  fLoGainSignal.Set(range);
-
-  fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
-  fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain;
-
-  return kTRUE;
+    if (!MExtractTimeAndCharge::ReInit(pList))
+        return kFALSE;
+
+    fHiGainSignal.Set(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
+    fLoGainSignal.Set(fLoGainLast - fLoGainFirst + 1);
+
+    fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
+    fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain;
+
+    return kTRUE;
 }
 
+Int_t MExtractTimeAndChargeDigitalFilter::PreProcess(MParList *pList)
+{
+    *fLog << endl;
+    *fLog << inf << "Using the following weights: " << endl;
+    *fLog << "Hi-Gain:" << endl;
+
+    for (Int_t i=0; i<fBinningResolutionHiGain*fWindowSizeHiGain; i++)
+        *fLog << " " << fAmpWeightsHiGain[i] << " \t " << fTimeWeightsHiGain[i] << endl;
+
+    *fLog << "Lo-Gain:" << endl;
+
+    for (Int_t i=0; i<fBinningResolutionLoGain*fWindowSizeLoGain; i++)
+        *fLog << " " << fAmpWeightsLoGain[i] << " \t " << fTimeWeightsLoGain[i] << endl;
+
+    return MExtractTimeAndCharge::PreProcess(pList);
+}
 
 void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Float_t &dsum, 
@@ -267,7 +279,7 @@
   const Float_t ABoffs = ped.GetPedestalABoffset();
 	
-  Float_t PedMean[2];
-  PedMean[0] = pedes + ABoffs;
-  PedMean[1] = pedes - ABoffs;
+  Float_t pedmean[2];
+  pedmean[0] = pedes + ABoffs;
+  pedmean[1] = pedes - ABoffs;
 
   //
@@ -286,5 +298,5 @@
       {
         const Int_t   idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain;
-        const Float_t pex = fHiGainSignal[sample+i]-PedMean[(sample+i+abflag) & 0x1];
+        const Float_t pex = fHiGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
 	sum              += fAmpWeightsHiGain [idx]*pex; 
 	time_sum         += fTimeWeightsHiGain[idx]*pex;
@@ -298,52 +310,49 @@
       }
     } /*   for (Int_t i=0;i<range-fWindowSizeHiGain;i++) */
-  
-  if (fmax!=0)
-    {
-      ftime_max        /= fmax;
-      Int_t t_iter      = Int_t(ftime_max*fBinningResolutionHiGain);
-      Int_t sample_iter = 0;
-
-      while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain )
-        {
-          if (t_iter > fBinningResolutionHalfHiGain-1)
-            {
-              t_iter -= fBinningResolutionHiGain;
-              max_p--; 
-              sample_iter--;
-            }
-          if (t_iter < -fBinningResolutionHalfHiGain)
-            {
-              t_iter += fBinningResolutionHiGain;
-              max_p++; 
-              sample_iter++;
-            }
-        }
-      
-      sum = 0.;
-      //
-      // Slide with a window of size fWindowSizeHiGain over the sample 
-      // and multiply the entries with the corresponding weights
-      //
-      for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
-      {
-        const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
-        const Int_t   ids = max_p + sample;
-        const Float_t pex = ids < 0 ? 0. : 
-          ( ids > range ? 0. : fHiGainSignal[ids]-PedMean[(ids+abflag) & 0x1]);
-	sum              += fAmpWeightsHiGain [idx]*pex; 
-	time_sum         += fTimeWeightsHiGain[idx]*pex;
-      }
-
-      if (sum != 0.)
-	time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */
-             - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum;
-      else 
-        time = 0.;
-    } /* if (max!=0) */ 
-    else 
-      time=0.;
-    
-  return;
+
+  time = 0;
+  if (fmax==0)
+      return;
+
+  ftime_max        /= fmax;
+  Int_t t_iter      = Int_t(ftime_max*fBinningResolutionHiGain);
+  Int_t sample_iter = 0;
+
+  while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain )
+    {
+      if (t_iter > fBinningResolutionHalfHiGain-1)
+        {
+          t_iter -= fBinningResolutionHiGain;
+          max_p--; 
+          sample_iter--;
+        }
+      if (t_iter < -fBinningResolutionHalfHiGain)
+        {
+          t_iter += fBinningResolutionHiGain;
+          max_p++; 
+          sample_iter++;
+        }
+    }
+  
+  sum = 0.;
+  //
+  // Slide with a window of size fWindowSizeHiGain over the sample 
+  // and multiply the entries with the corresponding weights
+  //
+  for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
+  {
+    const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
+    const Int_t   ids = max_p + sample;
+    const Float_t pex = ids < 0 ? 0. : 
+      ( ids > range ? 0. : fHiGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
+    sum              += fAmpWeightsHiGain [idx]*pex; 
+    time_sum         += fTimeWeightsHiGain[idx]*pex;
+  }
+
+  if (sum == 0)
+      return;
+
+  time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */
+      - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum;
 }
 
@@ -386,7 +395,7 @@
   const Float_t ABoffs = ped.GetPedestalABoffset();
 	
-  Float_t PedMean[2];
-  PedMean[0] = pedes + ABoffs;
-  PedMean[1] = pedes - ABoffs;
+  Float_t pedmean[2];
+  pedmean[0] = pedes + ABoffs;
+  pedmean[1] = pedes - ABoffs;
 
   //
@@ -405,5 +414,5 @@
       {
         const Int_t   idx = fBinningResolutionLoGain*sample+fBinningResolutionHalfLoGain;
-        const Float_t pex = fLoGainSignal[sample+i]-PedMean[(sample+i+abflag) & 0x1];
+        const Float_t pex = fLoGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
 	sum              += fAmpWeightsLoGain [idx]*pex; 
 	time_sum         += fTimeWeightsLoGain[idx]*pex;
@@ -417,102 +426,110 @@
       }
     } /*   for (Int_t i=0;i<range-fWindowSizeLoGain;i++) */
-  
-  if (fmax!=0)
-    {
-      ftime_max        /= fmax;
-      Int_t t_iter      = Int_t(ftime_max*fBinningResolutionLoGain);
-      Int_t sample_iter = 0;
-
-      while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain )
-        {
-          if (t_iter > fBinningResolutionHalfLoGain-1)
-            {
-              t_iter -= fBinningResolutionLoGain;
-              max_p--; 
-              sample_iter--;
-            }
-          if (t_iter < -fBinningResolutionHalfLoGain)
-            {
-              t_iter += fBinningResolutionLoGain;
-              max_p++; 
-              sample_iter++;
-            }
-        }
-      
-      sum = 0.;
-      //
-      // Slide with a window of size fWindowSizeLoGain over the sample 
-      // and multiply the entries with the corresponding weights
-      //
-      for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
-      {
-        const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
-        const Int_t   ids = max_p + sample;
-        const Float_t pex = ids < 0 ? 0. : 
-          ( ids > range ? 0. : fLoGainSignal[ids]-PedMean[(ids+abflag) & 0x1]);
-	sum              += fAmpWeightsLoGain [idx]*pex; 
-	time_sum         += fTimeWeightsLoGain[idx]*pex;
-      }
-
-      if (sum != 0.)
-	time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */
-             - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum;
-      else 
-        time = 0.;
-    } /* if (max!=0) */ 
-    else 
-      time=0.;
-    
-  return;
+
+  time = 0;
+  if (fmax==0)
+      return;
+
+  ftime_max        /= fmax;
+  Int_t t_iter      = Int_t(ftime_max*fBinningResolutionLoGain);
+  Int_t sample_iter = 0;
+
+  while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain )
+    {
+      if (t_iter > fBinningResolutionHalfLoGain-1)
+        {
+          t_iter -= fBinningResolutionLoGain;
+          max_p--; 
+          sample_iter--;
+        }
+      if (t_iter < -fBinningResolutionHalfLoGain)
+        {
+          t_iter += fBinningResolutionLoGain;
+          max_p++; 
+          sample_iter++;
+        }
+    }
+  
+  sum = 0.;
+
+  //
+  // Slide with a window of size fWindowSizeLoGain over the sample 
+  // and multiply the entries with the corresponding weights
+  //
+  for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
+  {
+    const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
+    const Int_t   ids = max_p + sample;
+    const Float_t pex = ids < 0 ? 0. : 
+      ( ids > range ? 0. : fLoGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
+    sum              += fAmpWeightsLoGain [idx]*pex; 
+    time_sum         += fTimeWeightsLoGain[idx]*pex;
+  }
+
+  if (sum == 0)
+      return;
+
+  time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */
+      - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum;
 }
 
+// --------------------------------------------------------------------------
+//
+// Read the setup from a TEnv, eg:
+//   MJPedestal.MExtractor.WindowSizeHiGain: 6
+//   MJPedestal.MExtractor.WindowSizeLoGain: 6
+//   MJPedestal.MExtractor.BinningResolutionHiGain: 10
+//   MJPedestal.MExtractor.BinningResolutionLoGain: 10
+//   MJPedestal.MExtractor.WeightsFile: filename
+//
 Int_t MExtractTimeAndChargeDigitalFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
 {
-  
-  Byte_t hw = fWindowSizeHiGain;
-  Byte_t lw = fWindowSizeLoGain;
-  Bool_t rc = kFALSE;
-  
-  if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
-    {
-      hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
-      rc = kTRUE;
-    }
-  if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
-    {
-      lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
-      rc = kTRUE;
-    }
-  
-  if (rc)
-    SetWindowSize(hw, lw);
-    
-  if (IsEnvDefined(env, prefix, "BinningResolution", print))
-    {
-      SetBinningResolution(GetEnvValue(env, prefix, "BinningResolutionHiGain", fBinningResolutionHiGain),
-                           GetEnvValue(env, prefix, "BinningResolutionLoGain", fBinningResolutionLoGain));
-      rc = kTRUE;
-    }
-  
-  rc = MExtractor::ReadEnv(env, prefix, print) ? kTRUE : rc;
-  
-  return rc;
-}
-
-Int_t  MExtractTimeAndChargeDigitalFilter::PostProcess()
-{
-  
-  *fLog << endl;
-  *fLog << inf << "Used High Gain weights in the extractor: " << endl;
-  
-  for (Int_t i=0;i<fBinningResolutionHiGain*fWindowSizeHiGain; i++)
-    *fLog << inf << fAmpWeightsHiGain[i] << "   " << fTimeWeightsHiGain[i] << endl;
-
-  *fLog << endl;
-  *fLog << inf << "Used Low Gain weights in the extractor: " << endl;
-  for (Int_t i=0;i<fBinningResolutionLoGain*fWindowSizeLoGain; i++)
-    *fLog << inf << fAmpWeightsLoGain[i] << "   " << fTimeWeightsLoGain[i] << endl;
-  
-  return kTRUE;
+    Byte_t hw = fWindowSizeHiGain;
+    Byte_t lw = fWindowSizeLoGain;
+    Bool_t rc = kFALSE;
+
+    if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
+    {
+        hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
+    {
+        lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
+        rc = kTRUE;
+    }
+
+    if (rc)
+        SetWindowSize(hw, lw);
+
+    Bool_t rc2 = kFALSE;
+    Int_t brh = fBinningResolutionHiGain;
+    Int_t brl = fBinningResolutionLoGain;
+
+    if (IsEnvDefined(env, prefix, "BinningResolutionHiGain", print))
+    {
+        brh = GetEnvValue(env, prefix, brh);
+        rc2 = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "BinningResolutionLoGain", print))
+    {
+        brl = GetEnvValue(env, prefix, brl);
+        rc2 = kTRUE;
+    }
+
+    if (rc2)
+    {
+        SetBinningResolution(brh, brl);
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "WeightsFile", print))
+    {
+        if (!ReadWeightsFile(GetEnvValue(env, prefix, "WeightsFile", "")))
+            return kERROR;
+        rc = kTRUE;
+    }
+
+    return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc;
 }
 
@@ -526,106 +543,133 @@
 Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename)
 {
-
-  fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain); 
-  fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain); 
-  fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain); 
-  fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain); 
-  
-  if (filename.IsNull())
-    {
-      for (UInt_t i=0; i<fAmpWeightsHiGain.GetSize(); i++)
-        {
-          fAmpWeightsHiGain [i] = 1.;
-          fTimeWeightsHiGain[i] = 1.;
-        }
-      for (UInt_t i=0; i<fAmpWeightsLoGain.GetSize(); i++)
-        {
-          fAmpWeightsLoGain [i] = 1.;
-          fTimeWeightsLoGain[i] = 1.;
-        }
-      return kTRUE;
-    }
-
-  ifstream fin(filename.Data());
-  
-  if (!fin)
-    {
-      *fLog << err << GetDescriptor()
-            << ": No weights file found: " << filename << endl;
-      return kFALSE;
-    }
-
-  Int_t len = 0;
-  Int_t cnt = 0;
-  Bool_t hi = kFALSE;
-  Bool_t lo = kFALSE;
-  
-  TString str;
-
-  while (1)
-    {
-
-      str.ReadLine(fin);
-      if (!fin)
-        break;
-      
-
-      if (str.Contains("# High Gain Weights:"))
-        {
-          str.ReplaceAll("# High Gain Weights:","");
-          sscanf(str.Data(),"%2i%2i",&fWindowSizeHiGain,&fBinningResolutionHiGain);
-          *fLog << inf << "Found number of High Gain slices: " << fWindowSizeHiGain 
-                       << " and High Gain resolution: " << fBinningResolutionHiGain << endl;
-          len = fBinningResolutionHiGain*fWindowSizeHiGain;
-          fAmpWeightsHiGain .Set(len); 
-          fTimeWeightsHiGain.Set(len); 
-          hi = kTRUE;
-          continue;
-        }
-      
-      if (str.Contains("# Low Gain Weights:"))
-        {
-          str.ReplaceAll("# Low Gain Weights:","");
-          sscanf(str.Data(),"%2i%2i",&fWindowSizeLoGain,&fBinningResolutionLoGain);
-          *fLog << inf << "Found number of Low Gain slices: " << fWindowSizeLoGain 
-                       << " and Low Gain resolution: " << fBinningResolutionLoGain << endl;
-          len = fBinningResolutionLoGain*fWindowSizeHiGain;
-          fAmpWeightsLoGain .Set(len); 
-          fTimeWeightsLoGain.Set(len); 
-          lo = kTRUE;
-          continue;
-        }
-      
-      if (str.Contains("#"))
-        continue;
-
-      if (len == 0)
-        continue;
-
-      sscanf(str.Data(),"\t%f\t%f",lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
-                                         lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]);
-
-      if (++cnt == len)
-        {
-          len = 0;
-          cnt = 0;
-        }
-    }
-
-  if (cnt != len)
-    {
-      *fLog << err << GetDescriptor()
-            << ": Size mismatch in weights file " << filename << endl;
-      return kFALSE;
-    }
-
-  if (!hi)
-    {
-      *fLog << err << GetDescriptor()
-            << ": No correct header found in weights file " << filename << endl;
-      return kFALSE;
-    }
-
-  return kTRUE;
+    fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
+    fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
+    fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
+    fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
+
+    if (filename.IsNull())
+    {
+        fAmpWeightsHiGain.Reset(1);
+        fTimeWeightsHiGain.Reset(1);
+        fAmpWeightsLoGain.Reset(1);
+        fTimeWeightsLoGain.Reset(1);
+        return kTRUE;
+    }
+
+    ifstream fin(filename.Data());
+    if (!fin)
+    {
+        *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": ";
+        *fLog << strerror(errno) << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf << "Reading weights file " << filename << "..." << flush;
+
+    Int_t len = 0;
+    Int_t cnt = 0;
+    Int_t line = 0;
+    Bool_t hi = kFALSE;
+    Bool_t lo = kFALSE;
+
+    TString str;
+
+    while (1)
+    {
+        str.ReadLine(fin);
+        if (!fin)
+            break;
+
+        line++;
+
+        if (str.Contains("# High Gain Weights:"))
+        {
+            if (hi)
+            {
+                *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl;
+                return kFALSE;
+            }
+
+            if (2!=sscanf(str.Data(), "# High Gain Weights:%2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain))
+            {
+                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
+                *fLog << str << endl;
+                return kFALSE;
+            }
+
+            len = fBinningResolutionHiGain*fWindowSizeHiGain;
+            fAmpWeightsHiGain .Set(len);
+            fTimeWeightsHiGain.Set(len);
+            hi = kTRUE;
+            continue;
+        }
+
+        if (str.Contains("# Low Gain Weights:"))
+        {
+            if (lo)
+            {
+                *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl;
+                return kFALSE;
+            }
+
+            if (2!=sscanf(str.Data(),"# Low Gain Weights:%2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain))
+            {
+                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
+                *fLog << str << endl;
+                return kFALSE;
+            }
+
+            len = fBinningResolutionLoGain*fWindowSizeHiGain;
+            fAmpWeightsLoGain .Set(len);
+            fTimeWeightsLoGain.Set(len);
+            lo = kTRUE;
+            continue;
+        }
+
+        // Handle lines with comments
+        if (str.Contains("#"))
+            continue;
+
+        // Nothing found so far
+        if (len == 0)
+            continue;
+
+        if (2!=sscanf(str.Data(), "%f %f",
+                      lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
+                      lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]))
+        {
+            *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
+            *fLog << str << endl;
+            return kFALSE;
+        }
+
+        if (++cnt == len)
+        {
+            len = 0;
+            cnt = 0;
+        }
+    }
+
+    if (cnt != len)
+    {
+        *fLog << err << "Size mismatch in weights file " << filename << endl;
+        return kFALSE;
+    }
+
+    if (!hi)
+    {
+        *fLog << err << "No correct header found in weights file " << filename << endl;
+        return kFALSE;
+    }
+
+    *fLog << "done." << endl;
+
+    *fLog << inf << " File contains " << fWindowSizeHiGain << " hi-gain slices ";
+    *fLog << "and with a resolution of " << fBinningResolutionHiGain << endl;
+
+    *fLog << inf << " File contains " << fWindowSizeLoGain << " lo-gain slices ";
+    *fLog << "and with a resolution of " << fBinningResolutionLoGain << endl;
+
+    return kTRUE;
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5297)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5298)
@@ -16,5 +16,4 @@
 {
 private:
-
   static const Byte_t fgHiGainFirst;
   static const Byte_t fgHiGainLast;
@@ -34,9 +33,9 @@
   Float_t fTimeShiftLoGain;
   
-  Int_t   fSignalStartBinHiGain;
-  Int_t   fSignalStartBinLoGain;
+  Int_t   fSignalStartBinHiGain; //!
+  Int_t   fSignalStartBinLoGain; //!
 
-  Int_t   fWindowSizeHiGain;            
-  Int_t   fWindowSizeLoGain;            
+  Int_t   fWindowSizeHiGain;
+  Int_t   fWindowSizeLoGain;
 
   Int_t   fBinningResolutionHiGain;
@@ -45,16 +44,15 @@
   Int_t   fBinningResolutionHalfLoGain;
   
-  MArrayF fAmpWeightsHiGain; 
-  MArrayF fTimeWeightsHiGain;
-  MArrayF fAmpWeightsLoGain; 
-  MArrayF fTimeWeightsLoGain;
+  MArrayF fAmpWeightsHiGain;     //!
+  MArrayF fTimeWeightsHiGain;    //!
+  MArrayF fAmpWeightsLoGain;     //!
+  MArrayF fTimeWeightsLoGain;    //!
 
-  Bool_t ReInit( MParList *pList );
-  Int_t PostProcess();  
-  
+  Bool_t ReInit(MParList *pList);
+  Int_t PreProcess(MParList *pList);
+
   Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
-  
+
 protected:
-
   virtual void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
                                        Float_t &time, Float_t &dtime,
@@ -89,9 +87,6 @@
   }
   
-  ClassDef(MExtractTimeAndChargeDigitalFilter, 0)   // Hendrik's digital filter
+  ClassDef(MExtractTimeAndChargeDigitalFilter, 1)   // Hendrik's digital filter
 };
 
 #endif
-
-
-
