File indexing completed on 2024-04-06 12:10:43
0001
0002
0003
0004 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
0005 #include "EventFilter/HcalRawToDigi/interface/HcalDTCHeader.h"
0006 #include <cstring>
0007 #include <cstdint>
0008
0009 const int HcalDTCHeader::SLOT_COUNT = 12;
0010 const int HcalDTCHeader::MINIMUM_SLOT = 1;
0011 const int HcalDTCHeader::MAXIMUM_SLOT = 12;
0012
0013 HcalDTCHeader::HcalDTCHeader() {}
0014
0015 unsigned int HcalDTCHeader::getTotalLengthBytes() const {
0016 unsigned int totalSize = sizeof(HcalDTCHeader);
0017 for (int i = 0; i < SLOT_COUNT; i++)
0018 totalSize += (slotInfo[i] & 0xFFF) * sizeof(uint16_t);
0019 return totalSize;
0020 }
0021
0022 int HcalDTCHeader::getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const {
0023 const uint16_t* base = ((const uint16_t*)this) + sizeof(HcalDTCHeader) / sizeof(uint16_t);
0024 int offset = 0, i, len = 0;
0025 for (i = 1; i <= nslot; i++) {
0026 offset += len;
0027 len = (slotInfo[i - 1] & 0xFFF);
0028 }
0029 if ((offset + len + sizeof(HcalDTCHeader) / sizeof(uint16_t)) < (validSize / sizeof(uint16_t))) {
0030 decodeTool.adoptData(base + offset, len);
0031 return 0;
0032 } else {
0033 return -1;
0034 }
0035 }
0036
0037 void HcalDTCHeader::clear() {
0038 commondataformat0 = 0;
0039 commondataformat1 = 0x50000000u;
0040 commondataformat2 = 0;
0041 commondataformat3 = 0;
0042 dcch0 = 0x1;
0043 dcch1 = 0;
0044 for (int i = 0; i < SLOT_COUNT; i++)
0045 slotInfo[i] = 0;
0046 }
0047
0048 void HcalDTCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
0049 commondataformat0 = 0x8 | ((sourceid & 0xFFF) << 8) | ((bcn & 0xFFF) << 20);
0050 commondataformat1 = 0x50000000u | (l1aN & 0xFFFFFF);
0051 }
0052
0053 void HcalDTCHeader::copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid) {
0054 if (slot_id == 0 || slot_id > (unsigned int)SLOT_COUNT)
0055 return;
0056
0057 slotInfo[slot_id - 1] = (data.getRawLength()) | 0xc000;
0058 if (valid)
0059 slotInfo[slot_id - 1] |= 0x2000;
0060
0061
0062
0063 unsigned int lenSoFar = 0;
0064 for (unsigned int i = 1; i < slot_id; i++)
0065 lenSoFar += getSlotDataLength(i);
0066 unsigned short* startingPoint = ((unsigned short*)this) + sizeof(HcalDTCHeader) / sizeof(unsigned short) + lenSoFar;
0067 memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
0068
0069 lenSoFar += data.getRawLength();
0070 uint32_t* trailer = ((uint32_t*)this) + sizeof(HcalDTCHeader) / sizeof(uint32_t) + lenSoFar / 2;
0071 int len64 = sizeof(HcalDTCHeader) / 8 + lenSoFar / 4 + 1;
0072 trailer[1] = 0;
0073 trailer[0] = 0xA0000000u | len64;
0074 }
0075
0076 std::ostream& operator<<(std::ostream& s, const HcalDTCHeader& head) {
0077 for (int i = 0; i < HcalDTCHeader::SLOT_COUNT; i++) {
0078 s << "Slot " << i << " : " << head.getSlotDataLength(i) << " bytes, ";
0079 if (head.getSlotEnabled(i))
0080 s << "E";
0081 if (head.getSlotPresent(i))
0082 s << "P";
0083 if (head.getSlotValid(i))
0084 s << "V";
0085 if (head.getSlotCRCError(i))
0086 s << "C";
0087
0088 s << std::endl;
0089 }
0090 return s;
0091 }