Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:05

0001 /*  
0002  *  \author J. Mans -- UMD
0003  */
0004 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
0005 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <cstring>
0008 #include <cstdint>
0009 
0010 const int HcalDCCHeader::SPIGOT_COUNT = 15;
0011 
0012 HcalDCCHeader::HcalDCCHeader() {}
0013 
0014 unsigned int HcalDCCHeader::getTotalLengthBytes() const {
0015   unsigned int totalSize = sizeof(HcalDCCHeader);
0016   for (int i = 0; i < SPIGOT_COUNT; i++)
0017     totalSize += (spigotInfo[i] & 0x3FF) * 4;
0018   return totalSize;
0019 }
0020 
0021 void HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool) const {
0022   edm::LogWarning("HCAL-Unpacker")
0023       << "Using unsafe getSpigotData without length controls.  Not recommended!  Replace with new getSpigotData call";
0024   getSpigotData(nspigot, decodeTool, 10000000);
0025 }
0026 
0027 int HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool, int validSize) const {
0028   const uint16_t* base = ((const uint16_t*)this) + sizeof(HcalDCCHeader) / sizeof(uint16_t);
0029   int offset = 0, i, len = 0;
0030   for (i = 0; i <= nspigot; i++) {
0031     offset += len;
0032     len = (spigotInfo[i] & 0x3FF) * 2;
0033   }
0034   if ((offset + len + sizeof(HcalDCCHeader) / sizeof(uint16_t)) < (validSize / sizeof(uint16_t))) {
0035     decodeTool.adoptData(base + offset, len);
0036     return 0;
0037   } else {
0038     return -1;
0039   }
0040 }
0041 
0042 void HcalDCCHeader::clear() {
0043   commondataformat0 = 0;
0044   commondataformat1 = 0x50000000u;
0045   commondataformat2 = 0;
0046   commondataformat3 = 0;
0047   dcch0 = 0x1;  // format version 1
0048   dcch1 = 0;
0049   for (int i = 0; i < 18; i++)
0050     spigotInfo[i] = 0;
0051 }
0052 
0053 void HcalDCCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
0054   commondataformat0 = 0x8 | ((sourceid & 0xFFF) << 8) | ((bcn & 0xFFF) << 20);
0055   commondataformat1 = 0x50000000u | (l1aN & 0xFFFFFF);
0056   commondataformat2 = ((orbN & 0xFFFFFFF) << 4);
0057   commondataformat3 = ((orbN >> 28) & 0xF);
0058 }
0059 
0060 void HcalDCCHeader::copySpigotData(unsigned int spigot_id,
0061                                    const HcalHTRData& data,
0062                                    bool valid,
0063                                    unsigned char LRB_error_word) {
0064   if (spigot_id >= (unsigned int)SPIGOT_COUNT)
0065     return;
0066   // construct the spigot info
0067   spigotInfo[spigot_id] = (data.getRawLength() / 2) | 0xc000;
0068   if (valid)
0069     spigotInfo[spigot_id] |= 0x2000;
0070   spigotInfo[spigot_id] |= (LRB_error_word << 16) | ((data.getErrorsWord() & 0xFF) << 24);
0071   // status info...
0072   if (valid)
0073     dcch0 |= (1 << (spigot_id + 14));
0074   // copy
0075   unsigned int lenSoFar = 0;
0076   for (unsigned int i = 0; i < spigot_id; i++)
0077     lenSoFar += getSpigotDataLength(i);
0078   unsigned short* startingPoint =
0079       ((unsigned short*)this) + sizeof(HcalDCCHeader) / sizeof(unsigned short) + lenSoFar * 2;
0080   memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
0081   // update the trailer...
0082   lenSoFar += data.getRawLength() / 2;  // 32-bit words
0083   uint32_t* trailer = ((uint32_t*)this) + sizeof(HcalDCCHeader) / sizeof(uint32_t) + lenSoFar;
0084   int len64 = sizeof(HcalDCCHeader) / 8 + lenSoFar / 2 + 1;
0085   trailer[1] = 0;
0086   trailer[0] = 0xA0000000u | len64;
0087 }
0088 
0089 std::ostream& operator<<(std::ostream& s, const HcalDCCHeader& head) {
0090   for (int i = 0; i < HcalDCCHeader::SPIGOT_COUNT; i++) {
0091     s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
0092     if (head.getSpigotEnabled(i))
0093       s << "E";
0094     if (head.getSpigotPresent(i))
0095       s << "P";
0096     if (head.getSpigotValid(i))
0097       s << "V";
0098     s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << "," << int(head.getLRBErrorBits(i))
0099       << std::dec;
0100     s << std::endl;
0101   }
0102   return s;
0103 }