Index: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc	(revision 8153)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc	(revision 8154)
@@ -1,3 +1,5 @@
 /* ======================================================================== *\
+! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.2 2006-10-24 08:18:07 tbretz Exp $
+! --------------------------------------------------------------------------
 !
 ! *
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.h	(revision 8154)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.h	(revision 8154)
@@ -0,0 +1,39 @@
+#ifndef MARS_MPedestalSubtract
+#define MARS_MPedestalSubtract
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MRawEvtData;
+class MPedestalCam;
+class MPedestalSubtractedEvt;
+
+class MPedestalSubtract : public MTask
+{
+private:
+    static const TString fgNamePedestalCam;            //! "MPedestalCam"
+    static const TString fgNamePedestalSubtractedEvt;  //! "MPedestalSubtractedEvt"
+
+    MRawEvtData            *fRawEvt;         //! Input Raw data
+    MPedestalCam           *fPedestals;      //! Pedestals of all pixels in the camera
+    MPedestalSubtractedEvt *fSignal;         //! Output container
+
+    TString  fNamePedestalCam;               // Name of the 'MPedestalCam' container
+    TString  fNamePedestalSubtractedEvt;     // Name of the 'MPedestalSubtractedEvt' container
+
+    Int_t  PreProcess(MParList *pList);
+    Int_t  Process();
+
+public:
+    MPedestalSubtract(const char *name=NULL, const char *title=NULL);
+
+    void SetPedestalCam(MPedestalCam *pedcam) { fPedestals = pedcam; }
+    void SetNamePedestalCam(const char *name=fgNamePedestalCam.Data()) { fNamePedestalCam  = name; }
+
+    void SetNamePedestalSubtractedEvt(const char *name=fgNamePedestalSubtractedEvt.Data()) { fNamePedestalSubtractedEvt = name; }
+
+    ClassDef(MPedestalSubtract, 0)   // Class to subtract pedestal including AB-noise
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc	(revision 8154)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc	(revision 8154)
@@ -0,0 +1,170 @@
+/* ======================================================================== *\
+! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.1 2006-10-24 08:22:41 tbretz Exp $
+! --------------------------------------------------------------------------
+!
+! *
+! * 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): Thomas Bretz, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2006
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MPedestalSubtractedEvt
+//
+//  Storage container to store the raw FADC values.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MPedestalSubtractedEvt.h"
+
+ClassImp(MPedestalSubtractedEvt);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initialize number of samples (per pixel) and number of pixels.
+//
+// Initialize the correct length of fSamples and fSamplesRaw
+//
+// And reset its contents to 0.
+//
+void MPedestalSubtractedEvt::InitSamples(UInt_t pixels, UInt_t samples)
+{
+    fNumSamples = samples;
+    fNumPixels  = pixels;
+
+    fSamples.Set(pixels*samples);
+    fSamplesRaw.Set(pixels*samples);
+
+    fSamples.Reset();
+    fSamplesRaw.Reset();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return a pointer to the first slice with subtracted pedestal of
+// the samples of the pixel with given pixel-index. If the number
+// exceeds the number of pixels NULL is returned.
+//
+// The user is responsible not to exceed the slices for one pixel!
+//
+Float_t *MPedestalSubtractedEvt::GetSamples(UInt_t pixel) const
+{
+    return pixel>=fNumPixels ? NULL : fSamples.GetArray()+pixel*fNumSamples;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return a pointer to the first slice of the raw-data samples of the pixel
+// with given pixel-index. If the number exceeds the number of
+// pixels NULL is returned.
+//
+// The user is responsible not to exceed the slices for one pixel!
+//
+Byte_t *MPedestalSubtractedEvt::GetSamplesRaw(UInt_t pixel) const
+{
+    return pixel>=fNumPixels ? NULL : fSamplesRaw.GetArray()+pixel*fNumSamples;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return some information about saturation in the raw-data of pixel idx.
+//
+// The search range is defined by [first,last]. Saturation is considered if
+// contents is >= limit.
+//
+// The number of saturating slices are returned and first/last are filled
+// with the first and last saturating slice index w.r.t. the beginning of
+// the raw-data of this pixel not first.
+//
+// Warning: No range checks and no sanity checks are done!
+//
+Int_t MPedestalSubtractedEvt::GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const
+{
+    // Determin saturation of hi-gains
+    Byte_t *p0 = GetSamplesRaw(idx);
+
+    Byte_t *sathi0 = 0; // first saturating hi-gain slice
+    Byte_t *sathi1 = 0; // last  saturating hi-gain slice
+
+    Int_t num = 0;
+
+    const Byte_t *end = p0+last;
+    for (Byte_t *ptr=p0+first; ptr<=end; ptr++)
+    {
+        if (*ptr>=limit)
+        {
+            sathi1 = ptr;
+            if (!sathi0)
+                sathi0 = ptr;
+            num++;
+        }
+    }
+
+    last  = sathi1 ? sathi1-p0 : -1;
+    first = sathi0 ? sathi0-p0 : -1;
+
+    return num;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the maximum of the slices [first,last] of pixel index.
+//
+// The position returned is the index of the position of the pedestal
+// subtracted maximum w.r.t. to first.
+// The value returned is the maximum of the raw-data.
+//
+// Warning: No range checks and no sanity checks are done!
+//
+Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Int_t &val) const
+{
+    // Get pointer to first slice to be considered
+    Byte_t  const *samb = GetSamplesRaw(idx);
+    Float_t const *samf = GetSamples(idx);
+
+    Byte_t  const *ptrb = samb+first;
+    Float_t const *ptrf = samf+first;
+
+    // The best information so far: the first slice is the maximum
+    const Byte_t  *maxb = ptrb;
+    const Float_t *maxf = ptrf;
+
+    // Store the pointer to the first slice
+//    const Byte_t  *begb = ptrb;
+    const Float_t *begf = ptrf;
+
+    // Calculate the last slice to be considered
+    const Byte_t  *endb = samb+last;
+
+    while (ptrb<endb)
+    {
+        // Pre-increment: check the second slice first
+        if (*++ptrb>*maxb)
+            maxb = ptrb;
+        if (*++ptrf>*maxf)
+            maxf = ptrf;
+    }
+
+    val = *maxb;
+    return maxf-begf;
+}
+
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h	(revision 8154)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h	(revision 8154)
@@ -0,0 +1,64 @@
+#ifndef MARS_MPedestalSubtractedEvt
+#define MARS_MPedestalSubtractedEvt
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+#ifndef MARS_MArrayF
+#include "MArrayF.h"
+#endif
+#ifndef MARS_MArrayB
+#include "MArrayB.h"
+#endif
+
+class MPedestalSubtractedEvt : public MParContainer, public MCamEvent
+{
+private:
+    MArrayF fSamples;        // list of all samples with pedestal subtracted
+    MArrayB fSamplesRaw;     // list of all samples (raw)
+
+    UInt_t fNumSamples;      // number of samples per pixel
+    UInt_t fNumPixels;       // number of pixels
+
+public:
+    MPedestalSubtractedEvt(const char *name=NULL, const char *title=NULL)
+        : fNumSamples(0), fNumPixels(0)
+    {
+    }
+
+    void InitSamples(UInt_t pixels, UInt_t samples);
+
+    Float_t *GetSamples(UInt_t pixel) const;
+    Byte_t *GetSamplesRaw(UInt_t pixel) const;
+
+    UInt_t   GetNumSamples() const { return fNumSamples; }
+    UShort_t GetNumPixels() const  { return fNumPixels; }
+
+    Int_t GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const;
+    Int_t GetMax(const Int_t pixidx, const Int_t first, const Int_t last, Int_t &val) const;
+    Int_t GetMax(const Int_t pixidx, const Int_t first, const Int_t last) const
+    {
+        Int_t val;
+        return GetMax(pixidx, first, last, val);
+    }
+    Int_t GetMax(const Int_t pixidx, Int_t &val) const
+    {
+        return GetMax(pixidx, 0, fNumSamples, val);
+    }
+
+    Int_t GetMax(const Int_t pixidx) const
+    {
+        Int_t val;
+        return GetMax(pixidx, 0, fNumSamples, val);
+    }
+
+    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const { return kTRUE; }
+    void   DrawPixelContent(Int_t num) const { }
+
+    ClassDef(MPedestalSubtractedEvt, 6) //Container to store the raw Event Data
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mpedestal/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/Makefile	(revision 8153)
+++ trunk/MagicSoft/Mars/mpedestal/Makefile	(revision 8154)
@@ -42,6 +42,5 @@
            MHPedestalCor.cc \
            MPedestalSubtract.cc \
-           MPedestalSubtractedEvt.cc \
-	   MPedCalcFromData.cc
+           MPedestalSubtractedEvt.cc
 
 ############################################################
Index: trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h	(revision 8153)
+++ trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h	(revision 8154)
@@ -19,5 +19,4 @@
 #pragma link C++ class MPedestalSubtract+;
 #pragma link C++ class MPedestalSubtractedEvt+;
-#pragma link C++ class MPedCalcFromData+;
 
 #pragma link C++ class MHPedestalCor+;
