// -*- mode: C++ -*-
//
// Pibero Djawotho <pibero@indiana.edu>
// Indiana University
// Nov 18 2007
//

#ifndef ST_HEAVY_TRIGGER_MAKER_H
#define ST_HEAVY_TRIGGER_MAKER_H

// ROOT
class TH1;
class TH2;

// STAR
class StBemcTables;
class StEmcDecoder;
//struct TrgDataType2007;
struct TrgDataType2008;

// Local
class StHeavyTrigger;

// STAR
#include "StMaker.h"

class StHeavyTriggerMaker : public StMaker {
public:
  StHeavyTriggerMaker(const char* name = "StHeavyTriggerMaker") : StMaker(name) {}
  ~StHeavyTriggerMaker() {}

  void Clear(Option_t* option = "");
  int InitRun(int runNumber);
  int Init();
  int Make();
  int FinishRun(int runNumber);
  int Finish();

  void printBemcTable(ostream& out);
  void printLocalBemcTable(ostream& out);
  void setTriggerId(int val) {mTriggerId = val;}
private:
  enum { NTOWERS = 4800, NPATCHES = 300 };

  // From event
  unsigned short mAdc[NTOWERS];

  // From database
  float mPedestal[NTOWERS];
  int mTowerStatus[NTOWERS];
  int mHighTowerStatus[NPATCHES];
  int mTriggerPatchStatus[NPATCHES];
  int mBitConvMode[NPATCHES];
  int mFormula[NPATCHES];
  int mParameters[NPATCHES][6];
  int mPedestalShift;
  int mTriggerId;

  // Computed in Make()
  int mHT[NPATCHES];
  int mTP[NPATCHES];
  int mNumberOfMaskedTowers[NPATCHES];

  TrgDataType2008* mTriggerData;
 //TrgDataType2007* mTriggerData;
  
  unsigned short* mBemcData;

  StBemcTables* mBemcTables;
  StEmcDecoder* mEmcDecoder;

  StHeavyTrigger* mTrigger;

  TH1* mHighTowerFreq;
  TH1* mTriggerPatchFreq;

  TH2* mHighTowerCorr;
  TH2* mTriggerPatchCorr;

  TH2* mHighTowerAdc;
  TH2* mTriggerPatchAdc;

  ClassDef(StHeavyTriggerMaker, 1);
};

#endif
