#ifndef gregsStHbtMuDstReader_hh
#define gregsStHbtMuDstReader_hh

#include <string>

#include "StMaker.h"
#include "StChain.h"
#include "St_DataSetIter.h"

#include "StThreeVector.hh"
#include "StThreeVectorF.hh"

#include "StMuDSTMaker/COMMON/StMuDstMaker.h"
#include "StMuDSTMaker/COMMON/StMuEvent.h"
#include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h" //Needed for the primary vertex loop

#include "Base/StHbtEventReader.hh"
#include "StHbtMaker/Infrastructure/StHbtEvent.hh"

class StMuEvent;
class StMuDst;
class StMuCut;
class StMuPrimaryVertex;

class StEvent;
class StTrackNode;
class StTrack;
class StRichSpectra;
class StDetectorState;
class StL3AlgorithmInfo;

class StuProbabilityPidAlgorithm;

class StMuCut;
class TFile;
class TTree;
class TChain;
class TClonesArray;

//!class ioMode;//!enum ioMode {ioRead, ioWrite};
//!class ioNameMode;//!enum ioNameMode {ioFix, ioAuto};

//_________________
class gregsStHbtMuDstReader : public StHbtEventReader {

 public:
  gregsStHbtMuDstReader(StMuDstMaker* maker);
  ~gregsStHbtMuDstReader();
  
  //Standard methods
  int Init();
  int Init(const char* ReadWrite, StHbtString& Message) { 
    return StHbtEventReader::Init(ReadWrite,Message);
  }//WarnOff
  void Clear();
  void Finish();

  //Reader methods

  void clear();

  StMuDst* muDst();
  StHbtEvent* ReturnHbtEvent();
  bool readTracks();
  bool readV0s();
  unsigned int trackType(); 

  void setProbabilityPidFile(const char* file);
  void setTrackType(unsigned int);
  void setReadTracks(bool);
  void setReadV0s(bool);
  void AddTriggerId(const unsigned int& id);
  void SetProcessAllVertices(bool);

  enum ioMode {ioRead, ioWrite};
  enum ioNameMode {ioFix, ioAuto};

 private:
 
  StMuDst* mMuDst;
  StMuDstMaker      *mMuDstMaker;
  StMuPrimaryVertex *mPrimVert;   //For the vertex loop
  StHbtEvent        *mHbtEvent;
  StuProbabilityPidAlgorithm* mProbabilityPidAlgorithm;
  int mEventCounter;

  vector<unsigned int> mTriggerIdCollection;

  ioMode mIoMode;
  ioNameMode mIoNameMode;
  string mDirName;
  string mFileName;
  string mFilter;
  int mMaxFiles;

  unsigned int mTrackType;
  bool mReadTracks;
  bool mReadV0s;
  bool mFinish;
  bool mProcessAllVertices;

  TFile* mCurrentFile;
  string mCurrentFileName;

  bool IsGoodTrigger(StMuEvent *event);
  bool IsGoodPrimaryVertex(StMuPrimaryVertex *vertex,
			   Float_t vpdVz);
  bool IsGoodTrack(StMuTrack *track, unsigned short vertInd);

  ClassDef(gregsStHbtMuDstReader, 1)
};

inline StMuDst* gregsStHbtMuDstReader::muDst() { return mMuDst;}
inline void gregsStHbtMuDstReader::setTrackType(unsigned int t) {mTrackType=t;}
inline unsigned int gregsStHbtMuDstReader::trackType() {return mTrackType;}

inline bool gregsStHbtMuDstReader::readTracks() { return mReadTracks;}
inline bool gregsStHbtMuDstReader::readV0s() { return mReadV0s;}
inline void gregsStHbtMuDstReader::setReadTracks(bool b) { mReadTracks=b;}
inline void gregsStHbtMuDstReader::setReadV0s(bool b) { mReadV0s=b;}
inline void gregsStHbtMuDstReader::AddTriggerId(const unsigned int& id) { 
  mTriggerIdCollection.push_back(id);
}
inline void gregsStHbtMuDstReader::SetProcessAllVertices(bool b) {
  mProcessAllVertices = b;
}

#endif
