Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-02 08:36:04

0001 #ifndef EventFilter_CSCRawToDigi_CSCTMBHeader_h
0002 #define EventFilter_CSCRawToDigi_CSCTMBHeader_h
0003 
0004 ///A.Tumanov Sept 18, 07
0005 
0006 #include <iosfwd>
0007 #include <vector>
0008 #include <memory>
0009 #include "DataFormats/CSCDigi/interface/CSCTMBStatusDigi.h"
0010 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
0011 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
0012 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
0013 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0014 #include "DataFormats/GEMDigi/interface/GEMPadDigiCluster.h"
0015 #include "EventFilter/CSCRawToDigi/interface/CSCVTMBHeaderFormat.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 
0018 #ifndef LOCAL_UNPACK
0019 #include <atomic>
0020 #endif
0021 class CSCDMBHeader;
0022 struct CSCTMBHeader2006;
0023 struct CSCTMBHeader2007;
0024 struct CSCTMBHeader2007_rev0x50c3;
0025 struct CSCTMBHeader2013;
0026 struct CSCTMBHeader2020_TMB;
0027 struct CSCTMBHeader2020_CCLUT;
0028 struct CSCTMBHeader2020_GEM;
0029 struct CSCTMBHeader2020_Run2;
0030 
0031 class CSCTMBHeader {
0032 public:
0033   CSCTMBHeader(int firmwareVersion, int firmwareRevision);
0034   CSCTMBHeader(const CSCTMBStatusDigi& digi);
0035   CSCTMBHeader(const unsigned short* buf);
0036 
0037   /// fills fields like bxn and l1a
0038   void setEventInformation(const CSCDMBHeader& dmbHeader) { theHeaderFormat->setEventInformation(dmbHeader); }
0039 
0040   int FirmwareVersion() const { return theFirmwareVersion; }
0041   int FirmwareRevision() const { return theHeaderFormat->firmwareRevision(); }
0042 
0043   uint16_t BXNCount() const { return theHeaderFormat->BXNCount(); }
0044   uint16_t ALCTMatchTime() const { return theHeaderFormat->ALCTMatchTime(); }
0045   void setALCTMatchTime(uint16_t alctmatchtime) { theHeaderFormat->setALCTMatchTime(alctmatchtime); }
0046   uint16_t CLCTOnly() const { return theHeaderFormat->CLCTOnly(); }
0047   uint16_t ALCTOnly() const { return theHeaderFormat->ALCTOnly(); }
0048   uint16_t TMBMatch() const { return theHeaderFormat->TMBMatch(); }
0049 
0050   uint16_t Bxn0Diff() const { return theHeaderFormat->Bxn0Diff(); }
0051   uint16_t Bxn1Diff() const { return theHeaderFormat->Bxn1Diff(); }
0052 
0053   uint16_t L1ANumber() const { return theHeaderFormat->L1ANumber(); }
0054 
0055   uint16_t sizeInBytes() const { return theHeaderFormat->sizeInWords() * 2; }
0056 
0057   uint16_t L1AMatchTime() const { return theHeaderFormat->L1AMatchTime(); }
0058   /// will throw if the cast fails
0059   CSCTMBHeader2007 tmbHeader2007() const;
0060   CSCTMBHeader2007_rev0x50c3 tmbHeader2007_rev0x50c3() const;
0061   CSCTMBHeader2006 tmbHeader2006() const;
0062   CSCTMBHeader2013 tmbHeader2013() const;
0063   CSCTMBHeader2020_TMB tmbHeader2020_TMB() const;
0064   CSCTMBHeader2020_CCLUT tmbHeader2020_CCLUT() const;
0065   CSCTMBHeader2020_GEM tmbHeader2020_GEM() const;
0066   CSCTMBHeader2020_Run2 tmbHeader2020_Run2() const;
0067 
0068   uint16_t NTBins() const { return theHeaderFormat->NTBins(); }
0069   uint16_t NCFEBs() const { return theHeaderFormat->NCFEBs(); }
0070 
0071   uint16_t syncError() const { return theHeaderFormat->syncError(); }
0072   uint16_t syncErrorCLCT() const { return theHeaderFormat->syncErrorCLCT(); }
0073   uint16_t syncErrorMPC0() const { return theHeaderFormat->syncErrorMPC0(); }
0074   uint16_t syncErrorMPC1() const { return theHeaderFormat->syncErrorMPC1(); }
0075 
0076   void setNCFEBs(uint16_t ncfebs) { theHeaderFormat->setNCFEBs(ncfebs); }
0077 
0078   /// == Run 3 CSC-GEM Trigger Format
0079   uint16_t clct0_ComparatorCode() const { return theHeaderFormat->clct0_ComparatorCode(); }
0080   uint16_t clct1_ComparatorCode() const { return theHeaderFormat->clct1_ComparatorCode(); }
0081   uint16_t clct0_xky() const { return theHeaderFormat->clct0_xky(); }
0082   uint16_t clct1_xky() const { return theHeaderFormat->clct1_xky(); }
0083   uint16_t hmt_nhits() const { return theHeaderFormat->hmt_nhits(); }
0084   uint16_t hmt_ALCTMatchTime() const { return theHeaderFormat->hmt_ALCTMatchTime(); }
0085   uint16_t alctHMT() const { return theHeaderFormat->alctHMT(); }
0086   uint16_t clctHMT() const { return theHeaderFormat->clctHMT(); }
0087   uint16_t gem_enabled_fibers() const { return theHeaderFormat->gem_enabled_fibers(); }
0088   uint16_t gem_fifo_tbins() const { return theHeaderFormat->gem_fifo_tbins(); }
0089   uint16_t gem_fifo_pretrig() const { return theHeaderFormat->gem_fifo_pretrig(); }
0090   uint16_t gem_zero_suppress() const { return theHeaderFormat->gem_zero_suppress(); }
0091   uint16_t gem_sync_dataword() const { return theHeaderFormat->gem_sync_dataword(); }
0092   uint16_t gem_timing_dataword() const { return theHeaderFormat->gem_timing_dataword(); }
0093   uint16_t run3_CLCT_patternID() const { return theHeaderFormat->run3_CLCT_patternID(); }
0094   ///returns Run3 lct Shower Digi for HMT
0095   CSCShowerDigi showerDigi(uint32_t idlayer) const { return theHeaderFormat->showerDigi(idlayer); }
0096   ///returns Run3 anode Shower Digi for HMT
0097   CSCShowerDigi anodeShowerDigi(uint32_t idlayer) const { return theHeaderFormat->anodeShowerDigi(idlayer); }
0098   ///returns Run3 cathode Shower Digi for HMT
0099   CSCShowerDigi cathodeShowerDigi(uint32_t idlayer) const { return theHeaderFormat->cathodeShowerDigi(idlayer); }
0100 
0101   ///returns CLCT digis
0102   std::vector<CSCCLCTDigi> CLCTDigis(uint32_t idlayer) { return theHeaderFormat->CLCTDigis(idlayer); }
0103 
0104   ///returns CorrelatedLCT digis
0105   std::vector<CSCCorrelatedLCTDigi> CorrelatedLCTDigis(uint32_t idlayer) const {
0106     return theHeaderFormat->CorrelatedLCTDigis(idlayer);
0107   }
0108 
0109   /// in 16-bit words.  Add olne because we include beginning(b0c) and
0110   /// end (e0c) flags
0111   unsigned short int sizeInWords() const { return theHeaderFormat->sizeInWords(); }
0112 
0113   unsigned short int NHeaderFrames() const { return theHeaderFormat->NHeaderFrames(); }
0114 
0115   unsigned short* data() { return theHeaderFormat->data(); }
0116 
0117   /** turns on/off debug flag for this class */
0118   static void setDebug(const bool value) { debug = value; }
0119 
0120   bool check() const { return theHeaderFormat->check(); }
0121 
0122   /// for data packing
0123   void addCLCT0(const CSCCLCTDigi& digi) { theHeaderFormat->addCLCT0(digi); }
0124   void addCLCT1(const CSCCLCTDigi& digi) { theHeaderFormat->addCLCT1(digi); }
0125   void addALCT0(const CSCALCTDigi& digi) { theHeaderFormat->addALCT0(digi); }
0126   void addALCT1(const CSCALCTDigi& digi) { theHeaderFormat->addALCT1(digi); }
0127   void addCorrelatedLCT0(const CSCCorrelatedLCTDigi& digi) { theHeaderFormat->addCorrelatedLCT0(digi); }
0128   void addCorrelatedLCT1(const CSCCorrelatedLCTDigi& digi) { theHeaderFormat->addCorrelatedLCT1(digi); }
0129   // Add Run3 lct Shower digi for HMT
0130   void addShower(const CSCShowerDigi& digi) { theHeaderFormat->addShower(digi); }
0131   // Add Run3 anode Shower digi for HMT
0132   void addAnodeShower(const CSCShowerDigi& digi) { theHeaderFormat->addAnodeShower(digi); }
0133   // Add Run3 cathode Shower digi for HMT
0134   void addCathodeShower(const CSCShowerDigi& digi) { theHeaderFormat->addCathodeShower(digi); }
0135 
0136   /// these methods need more brains to figure which one goes first
0137   void add(const std::vector<CSCCLCTDigi>& digis);
0138   void add(const std::vector<CSCCorrelatedLCTDigi>& digis);
0139   void add(const std::vector<CSCShowerDigi>& digis);
0140 
0141   /// tests that packing and unpacking give same results
0142   static void selfTest(int firmwwareVersion, int firmwareRevision);
0143 
0144   friend std::ostream& operator<<(std::ostream& os, const CSCTMBHeader& hdr);
0145 
0146 private:
0147   //void swapCLCTs(CSCCLCTDigi& digi1, CSCCLCTDigi& digi2);
0148 
0149 #ifdef LOCAL_UNPACK
0150   static bool debug;
0151 #else
0152   static std::atomic<bool> debug;
0153 #endif
0154 
0155   std::shared_ptr<CSCVTMBHeaderFormat> theHeaderFormat;
0156   int theFirmwareVersion;
0157 };
0158 
0159 #endif