Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:11

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