Index: trunk/MagicSoft/Mars/msignal/MC_calibration_weights_UV46.dat
===================================================================
--- trunk/MagicSoft/Mars/msignal/MC_calibration_weights_UV46.dat	(revision 7194)
+++ trunk/MagicSoft/Mars/msignal/MC_calibration_weights_UV46.dat	(revision 7194)
@@ -0,0 +1,124 @@
+# High Gain Weights: 4 10
+# (Amplitude)  (Time)
+-0.118587 -0.759939
+-0.263645 -0.75009
+-0.310214 -0.780472
+-0.463437 -0.711066
+-0.512875 -0.632303
+-0.540826 -0.498066
+-0.619144 -0.330405
+-0.677085 -0.119447
+-0.716893 0.216855
+-0.659267 0.801966
+-0.364716 1.56853
+-0.0164067 1.77302
+0.0977922 1.94953
+0.53287 2.07799
+0.703428 1.98081
+0.780245 1.66725
+1.02748 1.54473
+1.27718 1.39987
+1.58343 1.35047
+1.83609 1.33001
+2.04624 0.540095
+2.07248 0.0345484
+2.04722 -0.284436
+1.90993 -0.748188
+1.83718 -0.983809
+1.78393 -1.0628
+1.60923 -1.28475
+1.38147 -1.42858
+1.03132 -1.76524
+0.697112 -2.15254
+0.219843 -1.40928
+0.0677385 -1.03865
+0.0163863 -0.920451
+-0.0953869 -0.530027
+-0.0884961 -0.345785
+-0.118639 -0.213164
+-0.141397 -0.0617509
+-0.158478 0.0285188
+-0.151498 0.140743
+-0.120191 0.23417
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+0 0
+# Low Gain Weights: 6 10
+# (Amplitude)  (Time)
+0.0446612 -0.385273
+0.038191 -0.00418687
+0.0386966 0.0212324
+0.0402881 0.0744799
+0.0415794 0.229615
+0.0598731 0.44332
+0.0758477 0.661518
+0.101509 1.10641
+0.159323 1.64997
+0.497256 2.83685
+0.245087 3.27499
+0.140546 2.46177
+0.58086 2.2849
+0.632721 2.45587
+0.72819 2.52835
+0.889583 2.48099
+0.980812 2.50031
+1.09885 2.55892
+1.21374 2.78769
+1.61928 3.08069
+1.38544 1.95583
+1.31998 1.1792
+1.50633 0.591226
+1.50916 0.0793899
+1.5008 -0.33188
+1.47339 -0.575386
+1.45362 -0.915309
+1.40214 -1.31593
+1.34175 -1.77904
+1.0661 -2.05471
+1.31087 -1.49798
+1.33793 -1.34758
+1.10172 -1.21719
+1.08133 -1.09356
+1.04007 -0.981455
+0.976745 -1.08299
+0.930979 -1.14774
+0.874203 -1.18348
+0.816708 -1.20126
+0.587354 -1.92869
+0.783078 -1.89621
+0.792771 -1.03439
+0.622278 -0.781807
+0.61184 -0.745831
+0.578792 -0.683741
+0.537336 -0.596328
+0.51443 -0.592858
+0.482294 -0.560586
+0.462351 -0.827587
+0.317989 -1.05649
+0.459672 -0.775035
+0.468287 -0.619961
+0.374182 -0.31635
+0.376946 -0.225242
+0.367075 -0.347444
+0.340737 -0.393231
+0.321054 -0.187384
+0.320654 -0.225558
+0.302148 -0.399499
+0.232954 -0.607578
Index: trunk/MagicSoft/Mars/msignal/MC_cosmics_weights46.dat
===================================================================
--- trunk/MagicSoft/Mars/msignal/MC_cosmics_weights46.dat	(revision 7194)
+++ trunk/MagicSoft/Mars/msignal/MC_cosmics_weights46.dat	(revision 7194)
@@ -0,0 +1,104 @@
+# High Gain Weights: 4 10
+# (Amplitude)  (Time)
+-0.483688 -0.498619
+-0.52105 -0.409251
+-0.551668 -0.347732
+-0.588621 -0.297486
+-0.661896 -0.2371
+-0.754507 -0.0572828
+-0.809786 0.380243
+-0.569956 1.15886
+-0.0188177 1.56188
+0.366116 1.43988
+0.560145 1.24361
+0.659133 1.09171
+0.743506 1.01359
+0.842199 0.994443
+1.03659 1.08537
+1.27803 1.17221
+1.52592 1.11221
+1.87086 0.786182
+1.9451 0.195753
+1.84721 -0.202808
+1.74892 -0.438476
+1.6951 -0.598997
+1.63854 -0.777709
+1.55247 -1.00352
+1.32498 -1.37711
+1.00846 -1.77543
+0.590272 -2.03408
+-0.111902 -1.86442
+-0.42886 -1.06692
+-0.383767 -0.46555
+-0.258546 -0.122314
+-0.237253 -0.0243087
+-0.234402 0.036867
+-0.236007 0.0905807
+-0.22029 0.156137
+-0.191449 0.235519
+-0.139186 0.309597
+-0.0270788 0.320152
+0.0388423 0.213534
+0.0424905 0.116622
+# Low Gain Weights: 6 10
+# (Amplitude)  (Time)
+0.0446612 -0.385273
+0.038191 -0.00418687
+0.0386966 0.0212324
+0.0402881 0.0744799
+0.0415794 0.229615
+0.0598731 0.44332
+0.0758477 0.661518
+0.101509 1.10641
+0.159323 1.64997
+0.497256 2.83685
+0.245087 3.27499
+0.140546 2.46177
+0.58086 2.2849
+0.632721 2.45587
+0.72819 2.52835
+0.889583 2.48099
+0.980812 2.50031
+1.09885 2.55892
+1.21374 2.78769
+1.61928 3.08069
+1.38544 1.95583
+1.31998 1.1792
+1.50633 0.591226
+1.50916 0.0793899
+1.5008 -0.33188
+1.47339 -0.575386
+1.45362 -0.915309
+1.40214 -1.31593
+1.34175 -1.77904
+1.0661 -2.05471
+1.31087 -1.49798
+1.33793 -1.34758
+1.10172 -1.21719
+1.08133 -1.09356
+1.04007 -0.981455
+0.976745 -1.08299
+0.930979 -1.14774
+0.874203 -1.18348
+0.816708 -1.20126
+0.587354 -1.92869
+0.783078 -1.89621
+0.792771 -1.03439
+0.622278 -0.781807
+0.61184 -0.745831
+0.578792 -0.683741
+0.537336 -0.596328
+0.51443 -0.592858
+0.482294 -0.560586
+0.462351 -0.827587
+0.317989 -1.05649
+0.459672 -0.775035
+0.468287 -0.619961
+0.374182 -0.31635
+0.376946 -0.225242
+0.367075 -0.347444
+0.340737 -0.393231
+0.321054 -0.187384
+0.320654 -0.225558
+0.302148 -0.399499
+0.232954 -0.607578
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7188)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7194)
@@ -70,4 +70,5 @@
 #include "MRawRunHeader.h"
 #include "MCalibrationPattern.h"
+#include "MExtractedSignalCam.h"
 
 #include "MPedestalPix.h"
@@ -142,11 +143,11 @@
   if (fWindowSizeHiGain > availhirange)
   {
-      // Please simplify this!
-      *fLog << warn << GetDescriptor() 
-            << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain,
-                    " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl;
+      *fLog << warn << GetDescriptor() << ": Hi Gain window size: " << Form("%2i",fWindowSizeHiGain);
+      *fLog << " is bigger than available range: [" << Form("%2i", (int)fHiGainFirst);
+      *fLog << "," << Form("%21", (int)fHiGainLast) << "]" << endl;
+
       fHiGainLast = fHiGainFirst + fWindowSizeHiGain;
-      *fLog << warn << GetDescriptor() 
-            << ": Will set the upper range to: " << (int)fHiGainLast << endl;
+
+      *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fHiGainLast << endl;
     }
   
@@ -163,11 +164,11 @@
       if (fWindowSizeLoGain > availlorange)
         {
-      // Please simplify this!
-          *fLog << warn << GetDescriptor() 
-                << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain,
-                        " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl;
-          fLoGainLast = fLoGainFirst + fWindowSizeLoGain;
-          *fLog << warn << GetDescriptor() 
-            << ": Will set the upper range to: " << (int)fLoGainLast << endl;
+            *fLog << warn << GetDescriptor() << ": Lo Gain window size: " << Form("%2i",fWindowSizeLoGain);
+            *fLog << " is bigger than available range: [" << Form("%2i", (int)fLoGainFirst);
+            *fLog << "," << Form("%21", (int)fLoGainLast) << "]" << endl;
+
+            fLoGainLast = fLoGainFirst + fWindowSizeLoGain;
+
+            *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fLoGainLast << endl;
         }
       
@@ -205,30 +206,34 @@
 // --------------------------------------------------------------------------
 //
-// InitArrays
-//
-// Gets called in the ReInit() and initialized the arrays
-//
-Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays()
-{
-    if (!fRunHeader)
+// The weights are determined using GetAutimaticWeights().
+//
+// kFALSE is returned if it returned an error.
+// kTRUE  is returned if no new weights were set.
+//
+// If new weights are set
+//  fTimeShiftHiGain
+//  fTimeShiftLoGain
+//  fNumHiGainSamples
+//  fNumLoGainSamples
+//  fSqrtHiGainSamples
+//  fSqrtLoGainSamples
+// and
+//  fSignals->SetUsedFADCSlices(...)
+// is updated accordingly.
+//
+Bool_t MExtractTimeAndChargeDigitalFilter::GetWeights()
+{
+    switch (GetAutomaticWeights())
+    {
+    case kERROR: // An error occured
         return kFALSE;
-
-    const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
-    const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
-
-    fHiGainSignal.Set(rangehi);
-    fLoGainSignal.Set(rangelo);
-
-    // Try to get automatic weights
-    if (!ReadAutomaticWeightsFile())
-        return kFALSE;
-
-    // If still no weights set try conservative way
-    if (fNameWeightsFileSet.IsNull())
-        if (!ReadWeightsFile(fNameWeightsFile))
-            return kFALSE;
-
-    fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
+    case kFALSE: // No new weights set
+        return kTRUE;
+    }
+
+    // New weights set
+    fTimeShiftHiGain = 0.5 + 1./fBinningResolutionHiGain + fHiGainFirst;
     fTimeShiftLoGain = 0.5 + 1./fBinningResolutionLoGain;
+
     //
     // We need here the effective number of samples which is about 2.5 in the case of a window
@@ -240,5 +245,46 @@
     fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
 
+    // From MExtractTimeAndCharge::ReInit
+    if (fSignals)
+        fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
+                                    fLoGainFirst, fLoGainLast, fNumLoGainSamples);
     return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// InitArrays
+//
+// Gets called in the ReInit() and initialized the arrays
+//
+Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays()
+{
+    if (!fRunHeader)
+        return kFALSE;
+
+    const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
+    const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
+
+    fHiGainSignal.Set(rangehi);
+    fLoGainSignal.Set(rangelo);
+
+    return GetWeights();
+}
+
+// --------------------------------------------------------------------------
+//
+// Check if reading a new weights file is necessary because the calibration
+// pattern has changed. (Cannot be done in ReInit, because at this time
+// the calibration pattern is not available.
+// Then process the event.
+//
+Int_t MExtractTimeAndChargeDigitalFilter::Process()
+{
+    // Change Weights if the calibration patter changes
+    if (!GetWeights())
+        return kERROR;
+
+    // Process event
+    return MExtractTimeAndCharge::Process();
 }
 
@@ -643,4 +689,22 @@
 //----------------------------------------------------------------------------
 //
+// If automatic weights are requested, no default weights (name.IsNull())
+// are requested, fRunHeader is available and fRunHeader->IsMonteCarloRun()
+// is true prepend "MC_" in from of the name.
+//
+// return poth+name;
+//
+TString MExtractTimeAndChargeDigitalFilter::CompileWeightFileName(TString path, const TString &name) const
+{
+    if (fAutomaticWeights && !name.IsNull() && fRunHeader && fRunHeader->IsMonteCarloRun())
+        path += "MC_";
+
+    path += name;
+
+    return path;
+}
+
+//----------------------------------------------------------------------------
+//
 // Read a pre-defined weights file into the class. 
 // This is mandatory for the extraction
@@ -648,29 +712,32 @@
 // If filenname is empty, then all weights will be set to 1.
 //
-Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename)
-{
-  
-    // This is a fix for TEnv files edited with windows editors
-    filename.ReplaceAll("\015", "");
-
-    fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
-    fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
-    fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
-    fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
-
-    if (fNameWeightsFile.IsNull() || fNameWeightsFile=="-")
-    {
+// Returns:
+//  kTRUE:  new weights set
+//  kFALSE: no  weights set
+//  kERROR: error
+//
+Int_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename, TString path)
+{
+    if (filename.IsNull())
+    {
+        fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
+        fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
+        fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
+        fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
+
         fAmpWeightsHiGain.Reset(1);
         fTimeWeightsHiGain.Reset(1);
         fAmpWeightsLoGain.Reset(1);
         fTimeWeightsLoGain.Reset(1);
-        fNameWeightsFileSet = "-";
         return kTRUE;
     }
 
+    // Add "MC_" in front of the filename if necessary
+    filename = CompileWeightFileName(path, filename);
+
     //filename = MJob::ExpandPath(filename);
 
     if (fNameWeightsFileSet==filename)
-        return kTRUE;
+        return kFALSE; // No file read
 
     ifstream fin(filename.Data());
@@ -679,8 +746,8 @@
         *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": ";
         *fLog << strerror(errno) << endl;
-        return kFALSE;
-    }
-
-    *fLog << all << "DigitalFilter: Reading weights in " << filename << "..." << flush;
+        return kERROR;
+    }
+
+    *fLog << all << GetDescriptor() << ": Reading weights in " << filename << "..." << flush;
 
     Int_t len = 0;
@@ -705,5 +772,5 @@
             {
                 *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl;
-                return kFALSE;
+                return kERROR;
             }
 
@@ -712,5 +779,5 @@
                 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
                 *fLog << str << endl;
-                return kFALSE;
+                return kERROR;
             }
 
@@ -727,5 +794,5 @@
             {
                 *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl;
-                return kFALSE;
+                return kERROR;
             }
 
@@ -734,5 +801,5 @@
                 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
                 *fLog << str << endl;
-                return kFALSE;
+                return kERROR;
             }
 
@@ -758,5 +825,5 @@
             *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
             *fLog << str << endl;
-            return kFALSE;
+            return kERROR;
         }
 
@@ -770,12 +837,12 @@
     if (cnt != len)
     {
-        *fLog << err << "Size mismatch in weights file " << filename << endl;
-        return kFALSE;
+        *fLog << err << "ERROR - Size mismatch in weights file " << filename << endl;
+        return kERROR;
     }
 
     if (!hi)
     {
-        *fLog << err << "No correct header found in weights file " << filename << endl;
-        return kFALSE;
+        *fLog << err << "ERROR - No correct header found in weights file " << filename << endl;
+        return kERROR;
     }
 
@@ -824,63 +891,104 @@
 //----------------------------------------------------------------------------
 //
-// If automatic weight disabled or run type is pedestal no action is taken
-// and kTRUE is returned.
-// 
-// Otherwise:
-//  - If runtype is kRTData and filename starts with "MC_weights" "MC" is
-//    replaced by "cosmics"
-//  - If runtype is kRTMonteCarlo and filename starts with "cosmics_weights"
-//    "cosmics" is replaced by "MC"
-//  - If name filename begins with "calibration_weights_" for blue and green
-//    "UV" is replaced by "blue"
-//  - If name filename begins with "calibration_weights_" for UV and CT1
-//    "blue" is replaced by "UV"
-//
-// The replacements are done in this order. If no match is found no
-// replacement is done. Afterwards ReadWeightsFile for the resulting
-// path-/filename is called.
-//
-Bool_t MExtractTimeAndChargeDigitalFilter::ReadAutomaticWeightsFile()
-{
-    if (!fAutomaticWeights || fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal)
-        return kTRUE;
-
-    if (fNameWeightsFile.IsNull())
-    {
-        *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl;
-        return kFALSE;
-    }
-
-    *fLog << dbg << endl;
-    *fLog << underline << GetDescriptor() << endl;
-    *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl;
-
+// The default (+ prepending possible "MC_") is read for:
+//
+//   - RunType: Pedestal (independant of fAutomaticWeights)
+//   - fAutomaticWeights disabled
+//
+//  if fAutomaticWeights enabled:
+//   - fNameWeightsFile.IsNull()
+//   - !fCalibPattern
+//   - fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE
+//
+// If automatic weights are enabled, the case above didn't take place and
+// fNameWeightsFile starts with "calibration_weights_"
+//   - the color (blue, UV) is replaced by the appropriate one
+//     taken from the calibration pattern
+//
+// In most cases a debug output is printed. Further output about the color
+// determination can be switched on with debug level > 5;
+//
+// Returns:
+//  kFALSE: No new weights set
+//  kTRUE:  New weights set
+//  kERROR: Error
+//
+Int_t MExtractTimeAndChargeDigitalFilter::GetAutomaticWeights()
+{
     const Ssiz_t pos = fNameWeightsFile.Last('/')+1;
     const Ssiz_t len = fNameWeightsFile.Length();
 
+    // Split file name in path and name
     TString path = fNameWeightsFile(0, pos>=0?pos:len);
     TString name = fNameWeightsFile(pos>=0?pos:0, len);
 
-    if (name.BeginsWith("cosmics_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTMonteCarlo)
-    {
-        name.Remove(0, 7);
-        name.Prepend("MC");
-        *fLog << "Run type: Monte Carlo data" << endl;
-    }
-    if (name.BeginsWith("MC_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTData)
-    {
-        name.Remove(0, 2);
-        name.Prepend("cosmics");
-        *fLog << "Run type: Cosmics data" << endl;
+    // Remove trailing "MC_" for automatic weights
+    if (fAutomaticWeights && name.BeginsWith("MC_"))
+        name.Remove(0, 3);
+
+    // In case of a pedetsal run no calibration pattern can be available
+    // the default weights are always used.
+    if (fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal)
+    {
+        *fLog << dbg << "Pedestal file... using default weights: " << fNameWeightsFile << endl;
+        return ReadWeightsFile(name, path);
+    }
+
+    // If automatic weights are switched off use default weights
+    if (!fAutomaticWeights)
+    {
+        *fLog << dbg << "Automatic weights switched off... using default weights: " << fNameWeightsFile << endl;
+        return ReadWeightsFile(name, path);
+    }
+
+    // If automatic weights are switched on but no filename is given raise error
+    if (fNameWeightsFile.IsNull())
+    {
+        *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl;
+        return kERROR;
+    }
+
+    // If this is no pedestal run, automatic weights are requested and a
+    // filename for the weights file is given pedestal-extraction from
+    // cosmics data is assumed.
+    if (!fCalibPattern)
+    {
+        *fLog << dbg << "No decoded calibration pattern available... using default weights: " << fNameWeightsFile << endl;
+        return ReadWeightsFile(name, path);
+    }
+
+    const Bool_t debug = gLog.GetDebugLevel()>5;
+
+    // If no calibration pattern is available do not change the
+    // current weighs or current weights file name.
+    if (fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE)
+    {
+        // If we are extracting data and the calibration pattern is kNONE
+        // we assume that it is a data file without interleaved events
+        // and calibration pattern information available.
+        if ((fRunHeader->GetRunType()!=MRawRunHeader::kRTData && !fRunHeader->IsMonteCarloRun()) || debug)
+            *fLog << dbg << "No calibration color set so far... guessing default: " << fNameWeightsFile << endl;
+
+        return ReadWeightsFile(name, path);
+    }
+
+    if (debug)
+    {
+        *fLog << dbg << endl;
+        *fLog << underline << GetDescriptor() << endl;
+        *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl;
+        *fLog << " Run type: ";
     }
 
     if (name.BeginsWith("calibration_weights_") && fCalibPattern)
     {
-        *fLog << " Run type: Calibration with color " << (int)fCalibPattern->GetPulserColor() << ", setting ";
+        if (debug)
+            *fLog << " Calibration with color " << fCalibPattern->GetPulserColorStr() << ", setting ";
         switch (fCalibPattern->GetPulserColor())
         {
         case MCalibrationCam::kBLUE:  // 2
         case MCalibrationCam::kGREEN: // 1
-            *fLog << "blue/green" << endl;
+            if (debug)
+                *fLog << "blue/green, ";
             name.ReplaceAll("UV", "blue");
             break;
@@ -888,18 +996,17 @@
         case MCalibrationCam::kUV:    // 3
         case MCalibrationCam::kCT1:   // 0
-            *fLog << "UV/CT1" << endl;
+            if (debug)
+                *fLog << "UV/CT1, ";
             name.ReplaceAll("blue", "UV");
             break;
         case MCalibrationCam::kNONE:
-            *fLog << "None" << endl;
             break;
-        default: // kNONE=4
-            *fLog << "???" << endl;
-        }
-    }
-
-    path += name;
-
-    return ReadWeightsFile(path);
+        default: // kNone + etc
+            *fLog << err << "ERROR - Cannot get automatic weights for " << fCalibPattern->GetPulserColorStr() << endl;
+            return kERROR;
+        }
+    }
+
+    return ReadWeightsFile(name, path);
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 7188)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 7194)
@@ -69,5 +69,8 @@
   // MExtractTimeAndChargeDigitalFilter
   void    CalcBinningResArrays();
-  Bool_t  ReadAutomaticWeightsFile();
+  Int_t   GetAutomaticWeights();
+  Bool_t  GetWeights();
+  Int_t   ReadWeightsFile(TString filename, TString path="");
+  TString CompileWeightFileName(TString path, const TString &name) const;
 
   // MExtractTimeAndCharge
@@ -76,4 +79,5 @@
   // MTask
   Int_t PreProcess(MParList *pList);
+  Int_t Process();
 
 protected:
@@ -85,6 +89,4 @@
   ~MExtractTimeAndChargeDigitalFilter() { }
 
-  Bool_t ReadWeightsFile(TString filename);
-  
   Bool_t WriteWeightsFile(TString filename,
                           TH1F *shapehi, TH2F *autocorrhi,
@@ -92,5 +94,6 @@
 
 
-  void SetNameWeightsFile(TString s="") { fNameWeightsFile = s; fNameWeightsFileSet=""; }
+  void SetNameWeightsFile(TString s="") { s.ReplaceAll("\015", ""); // This is a fix for TEnv files edited with windows editors
+      fNameWeightsFile = s; fNameWeightsFileSet=""; }
   void EnableAutomaticWeights(Bool_t b=kTRUE) { fAutomaticWeights = b; }
 
