Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:16

0001 #ifndef EventFilter_CSCRawToDigi_CSCALCTHeader_h
0002 #define EventFilter_CSCRawToDigi_CSCALCTHeader_h
0003 
0004 /** documented in  flags
0005   http://www.phys.ufl.edu/~madorsky/alctv/alct2000_spec.PDF
0006 */
0007 #include <bitset>
0008 #include <vector>
0009 #include <iosfwd>
0010 #ifndef LOCAL_UNPACK
0011 #include <atomic>
0012 #endif
0013 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
0014 #include "DataFormats/CSCDigi/interface/CSCALCTStatusDigi.h"
0015 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0016 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader2006.h"
0017 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader2007.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 #include <boost/dynamic_bitset.hpp>
0021 
0022 class CSCALCTHeader {
0023 public:
0024   explicit CSCALCTHeader(int chamberType);  ///for packing
0025 
0026   explicit CSCALCTHeader(const unsigned short *buf);
0027 
0028   CSCALCTHeader(const CSCALCTStatusDigi &digi);  /// to access data by via status digis
0029 
0030   /// turns on the debug flag for this class
0031   static void setDebug(bool value) { debug = value; };
0032 
0033   void setEventInformation(const CSCDMBHeader &);  ///for packing
0034   unsigned short int nLCTChipRead() const;
0035 
0036   std::vector<CSCALCTDigi> ALCTDigis() const;
0037 
0038   ///some accessors here are only applicable to 2006 header
0039   ///some to both 2006 and 2007
0040 
0041   enum FIFO_MODE { NO_DUMP, FULL_DUMP, LOCAL_DUMP };
0042   unsigned short int FIFOMode() const { return header2006.fifoMode; }
0043   unsigned short int NTBins() const {
0044 #ifdef LOCAL_UNPACK
0045     switch (firmwareVersion) {
0046 #else
0047     switch (firmwareVersion.load()) {
0048 #endif
0049       case 2006:
0050         return header2006.nTBins;
0051       case 2007:
0052         return header2007.rawBins;
0053       default:
0054         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0055             << "trying to access NTBINs: ALCT firmware version is bad/not defined!";
0056         return 0;
0057     }
0058   }
0059   unsigned short int BoardID() const { return header2006.boardID; }
0060   unsigned short int ExtTrig() const { return header2006.extTrig; }
0061   unsigned short int CSCID() const { return header2006.cscID; }
0062   unsigned short int BXNCount() const {
0063 #ifdef LOCAL_UNPACK
0064     switch (firmwareVersion) {
0065 #else
0066     switch (firmwareVersion.load()) {
0067 #endif
0068       case 2006:
0069         return header2006.bxnCount;
0070       case 2007:
0071         return header2007.bxnCount;
0072       default:
0073         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0074             << "trying to access BXNcount: ALCT firmware version is bad/not defined!";
0075         return 0;
0076     }
0077   }
0078 
0079   void setBXNCount(unsigned int bxn) {
0080 #ifdef LOCAL_UNPACK
0081     switch (firmwareVersion) {
0082 #else
0083     switch (firmwareVersion.load()) {
0084 #endif
0085       case 2006:
0086         header2006.bxnCount = bxn % 0xFFF;
0087         break;
0088       case 2007:
0089         header2007.bxnCount = bxn % 0xFFF;
0090         break;
0091       default:
0092         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0093             << "trying to set BXNcount: ALCT firmware version is bad/not defined!";
0094         break;
0095     }
0096   }
0097 
0098   unsigned short int L1Acc() const {
0099 #ifdef LOCAL_UNPACK
0100     switch (firmwareVersion) {
0101 #else
0102     switch (firmwareVersion.load()) {
0103 #endif
0104       case 2006:
0105         return header2006.l1Acc;
0106       case 2007:
0107         return header2007.l1aCounter;
0108       default:
0109         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0110             << "trying to access L1Acc: ALCT firmware version is bad/not defined!";
0111         return 0;
0112     }
0113   }
0114 
0115   void setL1Acc(unsigned int l1a) {
0116 #ifdef LOCAL_UNPACK
0117     switch (firmwareVersion) {
0118 #else
0119     switch (firmwareVersion.load()) {
0120 #endif
0121       case 2006:
0122         header2006.l1Acc = l1a % 0xF;
0123         break;
0124       case 2007:
0125         header2007.l1aCounter = l1a % 0xFFF;
0126         break;
0127       default:
0128         edm::LogError("CSCALCTHeader|CSCRawToDigi") << "trying to set L1Acc: ALCT firmware version is bad/not defined!";
0129         break;
0130     }
0131   }
0132 
0133   unsigned short int L1AMatch() const { return header2006.l1aMatch; }
0134   unsigned short int ActiveFEBs() const { return header2006.activeFEBs; }
0135   unsigned short int Promote1() const { return header2006.promote1; }
0136   unsigned short int Promote2() const { return header2006.promote2; }
0137   unsigned short int LCTChipRead() const { return header2006.lctChipRead; }
0138   unsigned short int alctFirmwareVersion() const { return firmwareVersion; }
0139   unsigned short int alctFirmwareRevision() const {
0140 #ifdef LOCAL_UNPACK
0141     switch (firmwareVersion) {
0142 #else
0143     switch (firmwareVersion.load()) {
0144 #endif
0145       case 2006:
0146         return 0;
0147       case 2007:
0148         return header2007.firmwareVersion;
0149       default:
0150         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0151             << "trying to access ALCT firmware revision bits: ALCT firmware version is bad/not defined!";
0152         return 0;
0153     }
0154   }
0155 
0156   std::vector<CSCShowerDigi> alctShowerDigis() const {
0157     std::vector<CSCShowerDigi> results;
0158     results.clear();
0159 #ifdef LOCAL_UNPACK
0160     switch (firmwareVersion) {
0161 #else
0162     switch (firmwareVersion.load()) {
0163 #endif
0164       case 2006:
0165         return results;
0166       case 2007:
0167         // if (alctFirmwareRevision() >= 0) // TODO: Need ALCT Run3 firmware revision to properly detect presense of HMT bits in data format
0168         // {
0169         if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
0170           for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
0171             results.push_back(CSCShowerDigi(theALCTs[bx * 2].reserved & 0x3, 0, bx));
0172           }
0173           return results;
0174         } else
0175           return results;
0176         // } else return results;
0177       default:
0178         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0179             << "trying to access ALCT HMT Shower Digis bits: ALCT firmware version is bad/not defined!";
0180         return results;
0181     }
0182   }
0183 
0184   std::vector<unsigned short int> alctHMTs() const {
0185     std::vector<unsigned short int> results;
0186     results.clear();
0187 #ifdef LOCAL_UNPACK
0188     switch (firmwareVersion) {
0189 #else
0190     switch (firmwareVersion.load()) {
0191 #endif
0192       case 2006:
0193         return results;
0194       case 2007:
0195         // if (alctFirmwareRevision() >= 0) // TODO: Need ALCT Run3 firmware revision to properly detect presense of HMT bits in data format
0196         // {
0197         if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
0198           for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
0199             results.push_back(theALCTs[bx * 2].reserved & 0x3);
0200           }
0201           return results;
0202         } else
0203           return results;
0204         // } else return results;
0205       default:
0206         edm::LogError("CSCALCTHeader|CSCRawToDigi")
0207             << "trying to access ALCT HMT bits: ALCT firmware version is bad/not defined!";
0208         return results;
0209     }
0210   }
0211 
0212   void setDAVForChannel(int wireGroup) {
0213     if (firmwareVersion == 2006) {
0214       header2006.setDAV((wireGroup - 1) / 16);
0215     }
0216   }
0217 
0218   CSCALCTHeader2007 alctHeader2007() const { return header2007; }
0219   CSCALCTHeader2006 alctHeader2006() const { return header2006; }
0220 
0221   unsigned short int *data() { return theOriginalBuffer; }
0222 
0223   /// in 16-bit words
0224   int sizeInWords() {
0225 #ifdef LOCAL_UNPACK
0226     switch (firmwareVersion) {
0227 #else
0228     switch (firmwareVersion.load()) {
0229 #endif
0230       case 2006:
0231         return 8;
0232       case 2007:
0233         return sizeInWords2007_;
0234       default:
0235         edm::LogError("CSCALCTHeader|CSCRawToDigi") << "SizeInWords(): ALCT firmware version is bad/not defined!";
0236         return 0;
0237     }
0238   }
0239 
0240   bool check() const {
0241 #ifdef LOCAL_UNPACK
0242     switch (firmwareVersion) {
0243 #else
0244     switch (firmwareVersion.load()) {
0245 #endif
0246       case 2006:
0247         return header2006.flag_0 == 0xC;
0248       case 2007:
0249         return header2007.flag1 == 0xDB0A;
0250       default:
0251         edm::LogError("CSCALCTHeader|CSCRawToDigi") << "check(): ALCT firmware version is bad/not defined!";
0252         return false;
0253     }
0254   }
0255 
0256   void add(const std::vector<CSCALCTDigi> &digis);
0257   /// Add Run3 ALCT HMT shower bits
0258   void addShower(const std::vector<CSCShowerDigi> &digis);
0259 
0260   boost::dynamic_bitset<> pack();
0261 
0262   /// tests that we unpack what we packed
0263   static void selfTest(int firmware);
0264 
0265 private:
0266   CSCALCTHeader2006 header2006;
0267   CSCALCTHeader2007 header2007;
0268   std::vector<CSCALCT> theALCTs;
0269   CSCALCTs2006 alcts2006;
0270   CSCVirtexID virtexID;
0271   CSCConfigurationRegister configRegister;
0272   std::vector<CSCCollisionMask> collisionMasks;
0273   std::vector<CSCHotChannelMask> hotChannelMasks;
0274 
0275   //raw data also stored in this buffer
0276   //maximum header size is 116 words
0277   unsigned short int theOriginalBuffer[116];
0278 
0279 #ifdef LOCAL_UNPACK
0280   static bool debug;
0281   static unsigned short int firmwareVersion;
0282 #else
0283   static std::atomic<bool> debug;
0284   static std::atomic<unsigned short int> firmwareVersion;
0285 #endif
0286 
0287   ///size of the 2007 header in words
0288   unsigned short int sizeInWords2007_, bxn0, bxn1;
0289 };
0290 
0291 std::ostream &operator<<(std::ostream &os, const CSCALCTHeader &header);
0292 
0293 #endif