////////////////////////////////////////////////////////////////////
/// \class RAT:ChannelFlagsProc
///
/// \brief   Check the channel flags for issues
///
/// \author Tanner Kaptanoglu <tannerk@sas.upenn.edu>
///
/// \details This processor loops through all hit channels and
///          checks whether the channel has a error flags set
///          corresponding to that channel dropping data or being
///          out of sync.
///
////////////////////////////////////////////////////////////////////

#ifndef __RAT__ChannelFlagsProc__
#define __RAT__ChannelFlagsProc__

#include <RAT/Processor.hh>
#include <RAT/DS/Entry.hh>
#include <RAT/DB.hh>

namespace RAT
{
  class ChannelFlagsProc : public Processor
  {
    public:

      ChannelFlagsProc();
      virtual ~ChannelFlagsProc(){};

      virtual void BeginOfRun(DS::Run&);
      virtual void EndOfRun(DS::Run& run);

      virtual void SetI(const std::string& param, const int value);

      virtual Processor::Result DSEvent(DS::Run&, DS::Entry& ds);
      virtual Processor::Result Event(DS::Entry&, DS::EV& ev);

    protected:

      // Skip counting channels, just count syncs
      int fFindSyncMode;

      // Keep track of the run ranges
      int fRunRangeSync16;
      int fRunRangeSync24;

      // Used to check whether the run was resyced
      int fEventCounter;
      int fResync;

      // Keep track of the syncs in the run
      int fCountSync16;
      int fCountSync24;
      int fSync16Occured;
      int fSync24Occured;

      // Parameters for missed count burst
      double fTimeCut;
      unsigned int fNChannelsBurst;
      ULong64_t fTimeZero;
      unsigned int fGTIDZero;
      unsigned int fMissedCountBurstCount;
      std::vector<int> fBurstChannelCount;
      std::vector<int> fBurstGTID;

      // Keep track of channels with missed count
      std::vector<int> fMissedCountCut;

      // Keep track of out of sync channels
      std::vector<int> fCGTSync24;
      std::vector<int> fCMOSSync16;
      std::vector<int> fCGTSync24PreviousRuns;
      std::vector<int> fCMOSSync16PreviousRuns;
      std::vector<int> fCountAllSync16;
      std::vector<int> fCountAllSync24;
  };
}//namespace RAT
#endif