#ifndef L1Trigger_CSCTriggerPrimitives_CSCMuonPortCard_h
#define L1Trigger_CSCTriggerPrimitives_CSCMuonPortCard_h

//-----------------------------------------------------------------------------
//
//   Class: CSCMuonPortCard
//
//   Description:
//    Simulates the functionality of the Muon Port Card (MPC).  Each MPC
//    is responsible for 9 Trigger Mother Boards (TMBs).  It takes the up to
//    18 LCTs (2/TMB) in each (sub)sector every bunch crossing, sorts them,
//    selects up to three best, and puts them into an output collection.
//
//   Author List: Benn Tannenbaum 30 August 1999.
//                Based on code by Nick Wisniewski.
//
//
//   Modifications: Numerous later improvements by Jason Mumford and
//                  Slava Valuev (see cvs in ORCA).
//   Porting/reworking from ORCA by L. Gray (UF), June 2006.
//
//   Update for Run-II data taking by Sven Dildick (TAMU), May 2016.
//   CSC MPC sends all 18 stubs from 9 TMBs. Stubs are no longer sorted by quality
//   Invalid or low-quality stubs are not removed either.
//
//-----------------------------------------------------------------------------

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
#include "DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h"
#include "DataFormats/L1CSCTrackFinder/interface/TrackStub.h"
#include "L1Trigger/CSCTriggerPrimitives/interface/LCTQualityControl.h"

#include <vector>

class CSCMuonPortCard {
public:
  typedef CSCTriggerContainer<csctf::TrackStub> TrackStubList;

  CSCMuonPortCard(unsigned endcap, unsigned station, unsigned sector, const edm::ParameterSet& conf);

  CSCMuonPortCard();

  // clear the stub vector
  void clear();

  // Method to load the content of the digi container into a trigger
  // container.  This allows us to sort per BX more easily.
  void loadLCTs(const CSCCorrelatedLCTDigiCollection& thedigis);

  // Method to sort all Correlated LCTs generated by the TMB.
  void sortLCTs();

  // Method to sort all Correlated LCTs generated by the TMB in a subsector and BX
  void sortLCTs(const unsigned subsector, const int bx);

  // Returns a vector of TrackStubs indexed by [sorting]
  std::vector<csctf::TrackStub> getLCTs() const { return selectedStubs_; }

private:
  /** Chamber id (trigger-type labels). */
  unsigned theEndcap;
  unsigned theStation;
  unsigned theSector;

  // internal stubs
  CSCTriggerContainer<csctf::TrackStub> stubs_;

  // selected stubs
  std::vector<csctf::TrackStub> selectedStubs_;

  // CSC expert options
  bool sort_stubs_;
  bool drop_invalid_stubs_;
  bool drop_low_quality_stubs_;
  unsigned max_stubs_;

  int minBX_, maxBX_;  // min and max BX to sort.

  std::string vmeName_;
};

#endif
