Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 6280)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 6321)
@@ -189,5 +189,5 @@
 //
 MExtractPedestal::MExtractPedestal(const char *name, const char *title)
-    : fRandomCalculation(kTRUE), fGeom(NULL), fPedestalsIn(NULL), fPedestalsOut(NULL), 
+    : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL), 
       fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0)
 {
@@ -199,6 +199,8 @@
     AddToBranchList("fHiGainFadcSamples");
     AddToBranchList("fLoGainFadcSamples");
-
-    SetPedestalUpdate(kTRUE);
+ 
+    SetIntermediateStorage( kFALSE );
+    SetPedestalUpdate     ( kTRUE  );
+    SetRandomCalculation  ( kTRUE  );
 
     SetNamePedestalCamIn();
@@ -239,6 +241,4 @@
 // - fRunHeader to NULL
 // - fEvtHeader to NULL
-// - fPedestalsIn to NULL
-// - fPedestalsOut to NULL
 //
 void MExtractPedestal::Clear(const Option_t *o)
@@ -347,4 +347,11 @@
           return kFALSE;
       }
+  }
+
+  if (!fPedestalsInter && fIntermediateStorage)
+  {
+      fPedestalsInter = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamInter));
+      if (!fPedestalsInter)
+          return kFALSE;
   }
 
@@ -447,6 +454,6 @@
 Int_t MExtractPedestal::PostProcess()
 {
-    fPedestalsIn = NULL;
-    return kTRUE;
+  fPedestalsIn = NULL;
+  return kTRUE;
 }
 
@@ -493,4 +500,10 @@
     }
 
+    if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
+    {
+        SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
+        rc = kTRUE;
+    }
+
     // find resource for random calculation
     if (IsEnvDefined(env, prefix, "RandomCalculation", print))
@@ -523,4 +536,10 @@
     }
 
+    if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
+    {
+        SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
+        rc = kTRUE;
+    }
+
     if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
     {
@@ -651,5 +670,7 @@
     *fLog << GetDescriptor() << ":" << endl;
     *fLog << "Name of input  MPedestalCam:  " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
+    *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl;
     *fLog << "Name of output MPedestalCam:  " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
+    *fLog << "Intermediate Storage is       " << (fIntermediateStorage?"on":"off") << endl;
     *fLog << "Pedestal Update is            " << (fPedestalUpdate?"on":"off") << endl;
     if (fPedestalUpdate)
Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 6280)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 6321)
@@ -26,45 +26,49 @@
   static const TString  fgNamePedestalCam;  //! "MPedestalCam"
 
-  TString fNamePedestalCamIn;   // name of the incoming 'MPedestalCam' container
-  TString fNamePedestalCamOut;  // name of the outgoing 'MPedestalCam' container  
+  TString fNamePedestalCamIn;        // Name of the incoming 'MPedestalCam' container
+  TString fNamePedestalCamOut;       // Name of the outgoing 'MPedestalCam' container
+  TString fNamePedestalCamInter;     // Name of the intermediate 'MPedestalCam' container  
 
-  Bool_t  fRandomCalculation;  // Is pedestalextraction by extractor random?
-
+  Bool_t  fRandomCalculation;        // Is pedestalextraction by extractor random?
+  
 protected:
   
-  MGeomCam      *fGeom;         //! Camera geometry
-  MPedestalCam  *fPedestalsIn;  //! Pedestals of all pixels in the camera
-  MPedestalCam  *fPedestalsOut; //! Pedestals of all pixels in the camera
-  MRawEvtData   *fRawEvt;       //! Raw event data (time slices)
-  MRawRunHeader *fRunHeader;    //! RunHeader information
-  MRawEvtHeader *fEvtHeader;    //! EvtHeader information
-  MExtractTimeAndCharge *fExtractor; // Possible Extractor used
+  Bool_t  fIntermediateStorage;      // Is pedestal stored every event?
+
+  MGeomCam      *fGeom;              //! Camera geometry
+  MPedestalCam  *fPedestalsIn;       //! Pedestals of all pixels in the camera (incoming)
+  MPedestalCam  *fPedestalsInter;    //! Pedestals of all pixels in the camera (intermediate)
+  MPedestalCam  *fPedestalsOut;      //! Pedestals of all pixels in the camera (outgoing)
+  MRawEvtData   *fRawEvt;            //! Raw event data (time slices)
+  MRawRunHeader *fRunHeader;         //! RunHeader information
+  MRawEvtHeader *fEvtHeader;         //! EvtHeader information
+  MExtractTimeAndCharge *fExtractor; //  Possible Extractor
   
-  UShort_t fExtractWinFirst;    // First FADC slice to extract pedestal from
-  UShort_t fExtractWinSize;     // Number of slices to calculate the pedestal from
-  UShort_t fExtractWinLast;     // Last FADC slice to extract pedestal from 
+  UShort_t fExtractWinFirst;         // First FADC slice to extract pedestal from
+  UShort_t fExtractWinSize;          // Number of slices to calculate the pedestal from
+  UShort_t fExtractWinLast;          // Last FADC slice to extract pedestal from 
+                                     
+  UInt_t  fNumEventsDump;            // Number of event after which MPedestalCam gets updated
+  UInt_t  fNumAreasDump;             // Number of events after which averaged areas gets updated
+  UInt_t  fNumSectorsDump;           // Number of events after which averaged sectors gets updated
+ 
+  Bool_t  fPedestalUpdate;           // Flag if the pedestal shall be updated after every fNumEventsDump
 
-  UInt_t  fNumEventsDump;       // Number of event after which MPedestalCam gets updated
-  UInt_t  fNumAreasDump;        // Number of events after which averaged areas gets updated
-  UInt_t  fNumSectorsDump;      // Number of events after which averaged sectors gets updated
-
-  Bool_t  fPedestalUpdate;     // Flag if the pedestal shall be updated after every fNumEventsDump
-
-  MArrayD fSumx;               // sum of values
-  MArrayD fSumx2;              // sum of squared values
-  MArrayD fSumAB0;             // sum of ABFlag=0 slices
-  MArrayD fSumAB1;             // sum of ABFlag=1 slices
-  MArrayD fAreaSumx;           // averaged sum of values per area idx
-  MArrayD fAreaSumx2;          // averaged sum of squared values per area idx
-  MArrayD fAreaSumAB0;         // averaged sum of ABFlag=0 slices per area idx
-  MArrayD fAreaSumAB1;         // averaged sum of ABFlag=1 slices per area idx
-  MArrayI fAreaFilled;         // number of valid entries with area idx
-  MArrayI fAreaValid;          // number of valid pixels  within area idx
-  MArrayD fSectorSumx;         // averaged sum of values per sector
-  MArrayD fSectorSumx2;        // averaged sum of squared values per sector
-  MArrayD fSectorSumAB0;       // averaged sum of ABFlag=0 slices per sector
-  MArrayD fSectorSumAB1;       // averaged sum of ABFlag=1 slices per sector 
-  MArrayI fSectorFilled;       // number of valid entries with sector idx
-  MArrayI fSectorValid;        // number of valid pixels within sector idx
+  MArrayD fSumx;                     // sum of values
+  MArrayD fSumx2;                    // sum of squared values
+  MArrayD fSumAB0;                   // sum of ABFlag=0 slices
+  MArrayD fSumAB1;                   // sum of ABFlag=1 slices
+  MArrayD fAreaSumx;                 // averaged sum of values per area idx
+  MArrayD fAreaSumx2;                // averaged sum of squared values per area idx
+  MArrayD fAreaSumAB0;               // averaged sum of ABFlag=0 slices per area idx
+  MArrayD fAreaSumAB1;               // averaged sum of ABFlag=1 slices per area idx
+  MArrayI fAreaFilled;               // number of valid entries with area idx
+  MArrayI fAreaValid;                // number of valid pixels  within area idx
+  MArrayD fSectorSumx;               // averaged sum of values per sector
+  MArrayD fSectorSumx2;              // averaged sum of squared values per sector
+  MArrayD fSectorSumAB0;             // averaged sum of ABFlag=0 slices per sector
+  MArrayD fSectorSumAB1;             // averaged sum of ABFlag=1 slices per sector 
+  MArrayI fSectorFilled;             // number of valid entries with sector idx
+  MArrayI fSectorValid;              // number of valid pixels within sector idx
 
   // MTask virtual functions
@@ -92,18 +96,24 @@
   Bool_t SetExtractWindow(UShort_t first, UShort_t size);
 
-  void SetNumEventsDump(UInt_t dumpevents=500)  { fNumEventsDump  = dumpevents; }
-  void SetNumAreasDump(UInt_t dumpevents=500)  { fNumAreasDump   = dumpevents; }
+  void SetNumEventsDump (UInt_t dumpevents=500)  { fNumEventsDump  = dumpevents; }
+  void SetNumAreasDump  (UInt_t dumpevents=500)  { fNumAreasDump   = dumpevents; }
   void SetNumSectorsDump(UInt_t dumpevents=500)  { fNumSectorsDump = dumpevents; }
-  void SetNumDump(UInt_t n=500) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; }
-  void SetPedestalUpdate (Bool_t pedupdate=kTRUE) { fPedestalUpdate = pedupdate;  }
+  void SetNumDump       (UInt_t n=500) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; }
 
-  void SetNamePedestalCamIn(const char *name=fgNamePedestalCam.Data())  { fNamePedestalCamIn = name; }
-  void SetNamePedestalCamOut(const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamOut = name; }
+  // names
+  void SetNamePedestalCamIn   (const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamIn    = name; }
+  void SetNamePedestalCamInter(const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamInter = name; }  
+  void SetNamePedestalCamOut  (const char *name=fgNamePedestalCam.Data()) { fNamePedestalCamOut   = name; }
 
-  void SetPedestalsIn(MPedestalCam *pedcam) { fPedestalsIn = pedcam; }
-  void SetPedestalsOut(MPedestalCam *pedcam) { fPedestalsOut = pedcam; }
+  // pointers
+  void SetExtractor     ( MExtractTimeAndCharge *e) { fExtractor      = e; }
+  void SetPedestalsIn   ( MPedestalCam *pedcam    ) { fPedestalsIn    = pedcam; }
+  void SetPedestalsInter( MPedestalCam *pedcam    ) { fPedestalsInter = pedcam; }
+  void SetPedestalsOut  ( MPedestalCam *pedcam    ) { fPedestalsOut   = pedcam; }
 
-  void SetExtractor(MExtractTimeAndCharge *e) { fExtractor = e; }
-  void SetRandomCalculation(Bool_t b=kTRUE) { fRandomCalculation = b; }
+  // flags
+  void SetIntermediateStorage (Bool_t b=kTRUE) { fIntermediateStorage = b; }
+  void SetPedestalUpdate      (Bool_t b=kTRUE) { fPedestalUpdate      = b; }
+  void SetRandomCalculation   (Bool_t b=kTRUE) { fRandomCalculation   = b; }
 
   ClassDef(MExtractPedestal, 0)   // Base class for pedestal extractors
