#ifndef MARS_MPedCalcPedRun
#define MARS_MPedCalcPedRun

#ifndef MARS_MExtractPedestal
#include "MExtractPedestal.h"
#endif

#ifndef MARS_MArrayD
#include <MArrayD.h>
#endif

#ifndef MARS_MArrayI
#include <MArrayI.h>
#endif

class MRawEvtPixelIter;
class MPedestalPix;
class MPedCalcPedRun : public MExtractPedestal
{

  static const UShort_t fgExtractWinFirst;  // First FADC slice Hi-Gain (currently set to: 3)
  static const UShort_t fgExtractWinSize;   // Extraction Size Hi-Gain (currently set to: 14)
  static const UInt_t   gkFirstRunWithFinalBits; // First Run with pedestal trigger bit at place 3 
  
  UShort_t fOverlap;         // Number of overlapping slices from High-Gain to Low-Gain

  Bool_t  fFirstRun;         // Flag to tell if the first run out of many is used
  Bool_t  fSkip;             // Flag to tell if the Process has to be skipped 
  ULong_t fUsedEvents;       // Number of used (not skipped) events
  
  Bool_t IsPedBitSet();
  
  Bool_t ReInit     (MParList *pList);
  Int_t  Process    ();
  Int_t  PostProcess();
  
  void ResetArrays();
  void CalcSums   ( MRawEvtPixelIter *pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1);
  void CalcExtractor( MRawEvtPixelIter *pixel, Float_t &sum, MPedestalPix &ped);
  
public:

  MPedCalcPedRun(const char *name=NULL, const char *title=NULL);
  
  Int_t CallPostProcess();  

  void Print(Option_t *o="") const;
  
  ClassDef(MPedCalcPedRun, 1)   // Task to calculate pedestals from pedestal runs
};

#endif
