File indexing completed on 2023-07-25 23:16:11
0001 #ifndef EventFilter_Phase2TrackerRawToDigi_utils_H
0002 #define EventFilter_Phase2TrackerRawToDigi_utils_H
0003
0004
0005 #include <iomanip>
0006 #include <ostream>
0007 #include <iostream>
0008 #include <cstdint>
0009 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0010
0011 namespace Phase2Tracker {
0012
0013
0014
0015
0016
0017
0018 static const uint16_t FED_ID_MIN = static_cast<uint16_t>(FEDNumbering::MINSiStripFEDID);
0019 static const uint16_t FED_ID_MAX = static_cast<uint16_t>(FEDNumbering::MAXSiStripFEDID);
0020 static const uint16_t CMS_FED_ID_MAX = static_cast<uint16_t>(FEDNumbering::MAXFEDID);
0021 static const uint16_t NUMBER_OF_FEDS = static_cast<uint16_t>(FED_ID_MAX - FED_ID_MIN + 1);
0022
0023
0024
0025 static const int MAX_FE_PER_FED = 16;
0026 static const int MAX_CBC_PER_FE = 16;
0027 static const int STRIPS_PER_CBC = 254;
0028 static const int STRIPS_PADDING = 2;
0029 static const int TRIGGER_SIZE = 0;
0030
0031
0032
0033 static const uint8_t INVALID = 0xFF;
0034
0035
0036
0037 inline void printNibbleValue(uint8_t value, std::ostream& os) {
0038 const std::ios_base::fmtflags originalFormatFlags = os.flags();
0039 os << std::hex << std::setw(1) << value;
0040 os.flags(originalFormatFlags);
0041 }
0042
0043 inline void printHexValue(const uint8_t value, std::ostream& os) {
0044 const std::ios_base::fmtflags originalFormatFlags = os.flags();
0045 os << std::hex << std::setfill('0') << std::setw(2);
0046 os << uint16_t(value);
0047 os.flags(originalFormatFlags);
0048 }
0049
0050 inline void printHexWord(const uint8_t* pointer, const size_t lengthInBytes, std::ostream& os) {
0051 size_t i = lengthInBytes - 1;
0052 do {
0053 printHexValue(pointer[i], os);
0054 if (i != 0)
0055 os << " ";
0056 } while (i-- != 0);
0057 }
0058
0059 inline void printHex(const void* pointer, const size_t lengthInBytes, std::ostream& os) {
0060 const uint8_t* bytePointer = reinterpret_cast<const uint8_t*>(pointer);
0061
0062 if (lengthInBytes <= 8) {
0063 printHexWord(bytePointer, lengthInBytes, os);
0064 }
0065
0066 else {
0067
0068 os << "word\tbyte\t \t\tbyte" << std::endl;
0069 ;
0070 const size_t words = lengthInBytes / 8;
0071 const size_t extraBytes = lengthInBytes - 8 * words;
0072
0073 for (size_t w = 0; w < words; w++) {
0074 const size_t startByte = w * 8;
0075 os << w << '\t' << startByte + 8 << '\t';
0076 printHexWord(bytePointer + startByte, 8, os);
0077 os << "\t\t" << startByte << std::endl;
0078 }
0079
0080 if (extraBytes) {
0081 const size_t startByte = words * 8;
0082 os << words << '\t' << startByte + 8 << '\t';
0083
0084 size_t p = 8;
0085 while (p-- > extraBytes) {
0086 os << "00 ";
0087 }
0088 printHexWord(bytePointer + startByte, extraBytes, os);
0089 os << "\t\t" << startByte << std::endl;
0090 }
0091 os << std::endl;
0092 }
0093 }
0094
0095
0096 enum FEDReadoutMode {
0097 READOUT_MODE_INVALID = INVALID,
0098 READOUT_MODE_SCOPE = 0x1,
0099 READOUT_MODE_VIRGIN_RAW = 0x2,
0100 READOUT_MODE_PROC_RAW = 0x6,
0101 READOUT_MODE_ZERO_SUPPRESSED = 0xA,
0102 READOUT_MODE_ZERO_SUPPRESSED_LITE = 0xC,
0103 READOUT_MODE_SPY = 0xE
0104 };
0105
0106
0107 std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value);
0108 inline std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value) {
0109 switch (value) {
0110 case READOUT_MODE_SCOPE:
0111 os << "Scope mode";
0112 break;
0113 case READOUT_MODE_VIRGIN_RAW:
0114 os << "Virgin raw";
0115 break;
0116 case READOUT_MODE_PROC_RAW:
0117 os << "Processed raw";
0118 break;
0119 case READOUT_MODE_ZERO_SUPPRESSED:
0120 os << "Zero suppressed";
0121 break;
0122 case READOUT_MODE_ZERO_SUPPRESSED_LITE:
0123 os << "Zero suppressed lite";
0124 break;
0125 case READOUT_MODE_SPY:
0126 os << "Spy channel";
0127 break;
0128 case READOUT_MODE_INVALID:
0129 os << "Invalid";
0130 break;
0131 default:
0132 os << "Unrecognized";
0133 os << " (";
0134 printHexValue(value, os);
0135 os << ")";
0136 break;
0137 }
0138 return os;
0139 }
0140
0141
0142 enum READ_MODE { READ_MODE_INVALID = INVALID, SUMMARY = 0, FULL_DEBUG = 1, CBC_ERROR = 2 };
0143
0144
0145 std::ostream& operator<<(std::ostream& os, const READ_MODE& value);
0146 inline std::ostream& operator<<(std::ostream& os, const READ_MODE& value) {
0147 switch (value) {
0148 case SUMMARY:
0149 os << "Summary mode";
0150 break;
0151 case FULL_DEBUG:
0152 os << "Full debug mode";
0153 break;
0154 case CBC_ERROR:
0155 os << "CBC error mode";
0156 break;
0157 default:
0158 os << "Unrecognized mode";
0159 os << " (";
0160 printHexValue(value, os);
0161 os << ")";
0162 break;
0163 }
0164 return os;
0165 }
0166
0167
0168 enum trackerHeader_m {
0169 VERSION_M = 0xF000000000000000,
0170 HEADER_FORMAT_M = 0x0C00000000000000,
0171 EVENT_TYPE_M = 0x03C0000000000000,
0172 GLIB_STATUS_M = 0x003FFFFFFFFF0000,
0173 FRONTEND_STAT_M = 0x000000000000FFFF,
0174 CBC_NUMBER_M = 0xFFFF000000000000
0175 };
0176
0177 enum trackerHeader_s {
0178 VERSION_S = 60,
0179 HEADER_FORMAT_S = 58,
0180 EVENT_TYPE_S = 54,
0181 GLIB_STATUS_S = 16,
0182 FRONTEND_STAT_S = 0,
0183 CBC_NUMBER_S = 48
0184 };
0185
0186
0187 inline uint64_t read64(int offset, const uint8_t* buffer) {
0188 return *reinterpret_cast<const uint64_t*>(buffer + offset);
0189 }
0190
0191
0192 inline uint64_t extract64(trackerHeader_m mask, trackerHeader_s shift, uint64_t data) {
0193
0194 data = (data & mask) >> shift;
0195 return data;
0196 }
0197
0198 }
0199
0200 #endif