Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3986)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3987)
@@ -20,4 +20,10 @@
 
  2004/05/05: Markus Gaug
+
+   * mpedestal/MPedCalcPedRun.cc
+     - fixed a small inconsistency in case that the range goes out of 
+       the high-gain samples and reaches into the low-gain samples. In 
+       that case, the last slice of the high-gain was not taken (but the 
+       window size correctly)
  
    * mjobs/MJExtractCalibTest.[h,cc]
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 3986)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 3987)
@@ -332,21 +332,6 @@
 {
   
-  Int_t lastdesired   = (Int_t)fHiGainLast;
-  Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
-  
-  if (lastdesired > lastavailable)
-    {
-      const Int_t diff = lastdesired - lastavailable;
-      *fLog << endl;
-      *fLog << warn << GetDescriptor()
-            << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
-                    (int)fHiGainFirst,",",lastdesired,
-                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
-      *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fHiGainLast - diff) << endl;
-      SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast);
-    }
-  
-  lastdesired   = (Int_t)(fLoGainLast);
-  lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
+  Int_t lastdesired   = (Int_t)(fLoGainLast);
+  Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
   
   if (lastdesired > lastavailable)
@@ -361,4 +346,41 @@
       SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
     }
+
+  lastdesired   = (Int_t)fHiGainLast;
+  lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
+  
+  if (lastdesired > lastavailable)
+    {
+      const Int_t diff = lastdesired - lastavailable;
+      *fLog << endl;
+      *fLog << warn << GetDescriptor()
+            << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain Range [",
+                    (int)fHiGainFirst,",",lastdesired,
+                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s",": Will possibly use ",diff," samples from the Low-Gain for the High-Gain range")
+            << endl;
+      fHiGainLast -= diff;
+      fHiLoLast    = diff;
+    }
+
+  lastdesired   = (Int_t)fHiGainFirst+fWindowSizeHiGain-1;
+  lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
+  
+  if (lastdesired > lastavailable)
+    {
+      const Int_t diff = lastdesired - lastavailable;
+      *fLog << endl;
+      *fLog << warn << GetDescriptor()
+            << Form("%s%2i%s%2i%s",": Selected Hi Gain FADC Window size ",
+                    (int)fWindowSizeHiGain,
+                    " ranges out of the available limits: [0,",lastavailable,"].") << endl;
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction")
+            << endl;
+      fWindowSizeHiGain -= diff;
+      fWindowSizeLoGain += diff;
+    }
+
 
   Int_t npixels  = fPedestals->GetSize();
