#include "TMHistogramming.h"
#include "event.h"

//_____________________________________________________________________
TMHistogramming::TMHistogramming() :
  fNrEvents(0), fLastEventNumber(0), fAutoReset(kFALSE), fPaused(kFALSE), 
  fNeedRedraw(kFALSE), fNeedRedump(kFALSE), fEventAccept(kTRUE)
{
  fTrigMask[0] = 0xffffffff;
  fTrigMask[1] = 0xffffffff;
}
//_____________________________________________________________________
TMHistogramming::~TMHistogramming() {}
//_____________________________________________________________________
ULong_t TMHistogramming::GetTriggerMask(UInt_t index) {
  if (index<2) return fTrigMask[index];
  else {
    printf("ERROR TMHistogramming::GetTriggerMask index (%d) out of bounds\n",index);
    return 0;
  }
}
//_____________________________________________________________________
void TMHistogramming::SetTriggerMask(ULong_t word0, ULong_t word1) {
  fTrigMask[0] = word0;
  fTrigMask[1] = word1;
}
//_____________________________________________________________________
void TMHistogramming::ProcessPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::ProcessCluster(Float_t x, Float_t y, Float_t z, UInt_t module, UInt_t size, UInt_t widz, UInt_t widphi, UInt_t type) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::ProcessClusters(HenrikClusterFinderSPD* clFinder) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::ProcessEvent(eventHeaderStruct *event) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::StartEvent(eventHeaderStruct *event, UInt_t globalEventNumber) {
  if (fPaused) {
    fEventAccept = kFALSE;
  }
  else {
    if ( 
	((event->eventTriggerPattern[0] & fTrigMask[0]) != 0) || 
	((event->eventTriggerPattern[1] & fTrigMask[1]) != 0)
	) {
      fEventAccept = kTRUE;
    }
    else {
      fEventAccept = kFALSE;
    }
  }
}
//_____________________________________________________________________
void TMHistogramming::EndEvent(AliITSRawStreamSPD *str, UInt_t globalEventNumber) {
  if (fEventAccept) {
    fNrEvents++;
    fLastEventNumber=globalEventNumber;
  }
}
//_____________________________________________________________________
void TMHistogramming::Draw(TPad *pad) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::Dump(TGTextView *textview) {
  // do nothing in this class
}
//_____________________________________________________________________
void TMHistogramming::Reset() {
  fNrEvents = 0;
}
//______________________________________________________________________
void TMHistogramming::ResetAuto() {
  if (fAutoReset && fEventAccept) {
    Reset();
  }
}
