File indexing completed on 2024-04-06 12:10:21
0001 #ifndef EventFilter_CSCRawToDigi_CSCALCTHeader_h
0002 #define EventFilter_CSCRawToDigi_CSCALCTHeader_h
0003
0004
0005
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);
0025
0026 explicit CSCALCTHeader(const unsigned short *buf);
0027
0028 CSCALCTHeader(const CSCALCTStatusDigi &digi);
0029
0030
0031 static void setDebug(bool value) { debug = value; };
0032
0033 void setEventInformation(const CSCDMBHeader &);
0034 unsigned short int nLCTChipRead() const;
0035
0036 std::vector<CSCALCTDigi> ALCTDigis() const;
0037
0038
0039
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
0168
0169 if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
0170 for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
0171
0172
0173 results.push_back(
0174 CSCShowerDigi(theALCTs[bx * 2].reserved & 0x3, 0, 0, bx, CSCShowerDigi::ShowerType::kALCTShower, 0, 0));
0175 }
0176 return results;
0177 } else
0178 return results;
0179
0180 default:
0181 edm::LogError("CSCALCTHeader|CSCRawToDigi")
0182 << "trying to access ALCT HMT Shower Digis bits: ALCT firmware version is bad/not defined!";
0183 return results;
0184 }
0185 }
0186
0187 std::vector<unsigned short int> alctHMTs() const {
0188 std::vector<unsigned short int> results;
0189 results.clear();
0190 #ifdef LOCAL_UNPACK
0191 switch (firmwareVersion) {
0192 #else
0193 switch (firmwareVersion.load()) {
0194 #endif
0195 case 2006:
0196 return results;
0197 case 2007:
0198
0199
0200 if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
0201 for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
0202 results.push_back(theALCTs[bx * 2].reserved & 0x3);
0203 }
0204 return results;
0205 } else
0206 return results;
0207
0208 default:
0209 edm::LogError("CSCALCTHeader|CSCRawToDigi")
0210 << "trying to access ALCT HMT bits: ALCT firmware version is bad/not defined!";
0211 return results;
0212 }
0213 }
0214
0215 void setDAVForChannel(int wireGroup) {
0216 if (firmwareVersion == 2006) {
0217 header2006.setDAV((wireGroup - 1) / 16);
0218 }
0219 }
0220
0221 CSCALCTHeader2007 alctHeader2007() const { return header2007; }
0222 CSCALCTHeader2006 alctHeader2006() const { return header2006; }
0223
0224 unsigned short int *data() { return theOriginalBuffer; }
0225
0226
0227 int sizeInWords() {
0228 #ifdef LOCAL_UNPACK
0229 switch (firmwareVersion) {
0230 #else
0231 switch (firmwareVersion.load()) {
0232 #endif
0233 case 2006:
0234 return 8;
0235 case 2007:
0236 return sizeInWords2007_;
0237 default:
0238 edm::LogError("CSCALCTHeader|CSCRawToDigi") << "SizeInWords(): ALCT firmware version is bad/not defined!";
0239 return 0;
0240 }
0241 }
0242
0243 bool check() const {
0244 #ifdef LOCAL_UNPACK
0245 switch (firmwareVersion) {
0246 #else
0247 switch (firmwareVersion.load()) {
0248 #endif
0249 case 2006:
0250 return header2006.flag_0 == 0xC;
0251 case 2007:
0252 return header2007.flag1 == 0xDB0A;
0253 default:
0254 edm::LogError("CSCALCTHeader|CSCRawToDigi") << "check(): ALCT firmware version is bad/not defined!";
0255 return false;
0256 }
0257 }
0258
0259 void add(const std::vector<CSCALCTDigi> &digis);
0260
0261 void addShower(const std::vector<CSCShowerDigi> &digis);
0262
0263 boost::dynamic_bitset<> pack();
0264
0265
0266 static void selfTest(int firmware);
0267
0268 private:
0269 CSCALCTHeader2006 header2006;
0270 CSCALCTHeader2007 header2007;
0271 std::vector<CSCALCT> theALCTs;
0272 CSCALCTs2006 alcts2006;
0273 CSCVirtexID virtexID;
0274 CSCConfigurationRegister configRegister;
0275 std::vector<CSCCollisionMask> collisionMasks;
0276 std::vector<CSCHotChannelMask> hotChannelMasks;
0277
0278
0279
0280 unsigned short int theOriginalBuffer[116];
0281
0282 #ifdef LOCAL_UNPACK
0283 static bool debug;
0284 static unsigned short int firmwareVersion;
0285 #else
0286 static std::atomic<bool> debug;
0287 static std::atomic<unsigned short int> firmwareVersion;
0288 #endif
0289
0290
0291 unsigned short int sizeInWords2007_, bxn0, bxn1;
0292 };
0293
0294 std::ostream &operator<<(std::ostream &os, const CSCALCTHeader &header);
0295
0296 #endif