CMS 3D CMS Logo

HcalDTCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author J. Mans -- UMD
3  */
6 #include <cstring>
7 #include <cstdint>
8 
9 const int HcalDTCHeader::SLOT_COUNT = 12;
10 const int HcalDTCHeader::MINIMUM_SLOT = 1;
11 const int HcalDTCHeader::MAXIMUM_SLOT = 12;
12 
14 
15 unsigned int HcalDTCHeader::getTotalLengthBytes() const {
16  unsigned int totalSize = sizeof(HcalDTCHeader);
17  for (int i = 0; i < SLOT_COUNT; i++)
18  totalSize += (slotInfo[i] & 0xFFF) * sizeof(uint16_t);
19  return totalSize;
20 }
21 
22 int HcalDTCHeader::getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const {
23  const uint16_t* base = ((const uint16_t*)this) + sizeof(HcalDTCHeader) / sizeof(uint16_t);
24  int offset = 0, i, len = 0;
25  for (i = 1; i <= nslot; i++) {
26  offset += len;
27  len = (slotInfo[i - 1] & 0xFFF);
28  }
29  if ((offset + len + sizeof(HcalDTCHeader) / sizeof(uint16_t)) < (validSize / sizeof(uint16_t))) {
30  decodeTool.adoptData(base + offset, len);
31  return 0;
32  } else {
33  return -1;
34  }
35 }
36 
39  commondataformat1 = 0x50000000u;
42  dcch0 = 0x1; // format version 1
43  dcch1 = 0;
44  for (int i = 0; i < SLOT_COUNT; i++)
45  slotInfo[i] = 0;
46 }
47 
48 void HcalDTCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
49  commondataformat0 = 0x8 | ((sourceid & 0xFFF) << 8) | ((bcn & 0xFFF) << 20);
50  commondataformat1 = 0x50000000u | (l1aN & 0xFFFFFF);
51 }
52 
53 void HcalDTCHeader::copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid) {
54  if (slot_id == 0 || slot_id > (unsigned int)SLOT_COUNT)
55  return;
56  // construct the slot info
57  slotInfo[slot_id - 1] = (data.getRawLength()) | 0xc000;
58  if (valid)
59  slotInfo[slot_id - 1] |= 0x2000;
60  // status info...
61  // if (valid) dcch0|=(1<<(slot_id+14));
62  // copy
63  unsigned int lenSoFar = 0;
64  for (unsigned int i = 1; i < slot_id; i++)
65  lenSoFar += getSlotDataLength(i);
66  unsigned short* startingPoint = ((unsigned short*)this) + sizeof(HcalDTCHeader) / sizeof(unsigned short) + lenSoFar;
67  memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
68  // update the trailer...
69  lenSoFar += data.getRawLength();
70  uint32_t* trailer = ((uint32_t*)this) + sizeof(HcalDTCHeader) / sizeof(uint32_t) + lenSoFar / 2;
71  int len64 = sizeof(HcalDTCHeader) / 8 + lenSoFar / 4 + 1;
72  trailer[1] = 0;
73  trailer[0] = 0xA0000000u | len64;
74 }
75 
76 std::ostream& operator<<(std::ostream& s, const HcalDTCHeader& head) {
77  for (int i = 0; i < HcalDTCHeader::SLOT_COUNT; i++) {
78  s << "Slot " << i << " : " << head.getSlotDataLength(i) << " bytes, ";
79  if (head.getSlotEnabled(i))
80  s << "E";
81  if (head.getSlotPresent(i))
82  s << "P";
83  if (head.getSlotValid(i))
84  s << "V";
85  if (head.getSlotCRCError(i))
86  s << "C";
87  // s << ". Error codes: " << std::hex << int(head.getSlotErrorBits(i)) << "," << int(head.getLRBErrorBits(i)) << std::dec;
88  s << std::endl;
89  }
90  return s;
91 }
void copySlotData(unsigned int slot_id, const HcalHTRData &data, bool valid=true)
Add the given HcalHTRData as the given slot&#39;s data. This should be done in increasing slot order! ...
bool getSlotEnabled(unsigned int nslot) const
Read the "ENABLED" bit for this slot.
Definition: HcalDTCHeader.h:81
uint16_t slotInfo[12]
static const int MINIMUM_SLOT
Definition: HcalDTCHeader.h:21
uint32_t commondataformat0
uint32_t commondataformat2
uint32_t dcch1
bool getSlotCRCError(unsigned int nslot) const
Read the "CRC-Mismatch" bit for this slot.
Definition: HcalDTCHeader.h:93
bool getSlotPresent(unsigned int nslot) const
Read the "PRESENT" bit for this slot.
Definition: HcalDTCHeader.h:85
unsigned int getTotalLengthBytes() const
std::ostream & operator<<(std::ostream &s, const HcalDTCHeader &head)
unsigned int getSlotDataLength(int nslot) const
Definition: HcalDTCHeader.h:76
uint32_t commondataformat1
uint32_t dcch0
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:46
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
uint32_t commondataformat3
int getSlotData(int nslot, HcalHTRData &decodeTool, int validSize) const
bool getSlotValid(unsigned int nslot) const
Read the "VALID" bit for this slot; TTC EvN matched HTR EvN.
Definition: HcalDTCHeader.h:89
static const int SLOT_COUNT
Definition: HcalDTCHeader.h:20
static const int MAXIMUM_SLOT
Definition: HcalDTCHeader.h:22
void setHeader(int sourceid, int bcn, int l1aN, int orbN)