CMS 3D CMS Logo

HcalDCCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author J. Mans -- UMD
3  */
7 #include <cstring>
8 #include <cstdint>
9 
10 const int HcalDCCHeader::SPIGOT_COUNT = 15;
11 
13 
14 unsigned int HcalDCCHeader::getTotalLengthBytes() const {
15  unsigned int totalSize = sizeof(HcalDCCHeader);
16  for (int i = 0; i < SPIGOT_COUNT; i++)
17  totalSize += (spigotInfo[i] & 0x3FF) * 4;
18  return totalSize;
19 }
20 
21 void HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool) const {
22  edm::LogWarning("HCAL-Unpacker")
23  << "Using unsafe getSpigotData without length controls. Not recommended! Replace with new getSpigotData call";
24  getSpigotData(nspigot, decodeTool, 10000000);
25 }
26 
27 int HcalDCCHeader::getSpigotData(int nspigot, HcalHTRData& decodeTool, int validSize) const {
28  const uint16_t* base = ((const uint16_t*)this) + sizeof(HcalDCCHeader) / sizeof(uint16_t);
29  int offset = 0, i, len = 0;
30  for (i = 0; i <= nspigot; i++) {
31  offset += len;
32  len = (spigotInfo[i] & 0x3FF) * 2;
33  }
34  if ((offset + len + sizeof(HcalDCCHeader) / sizeof(uint16_t)) < (validSize / sizeof(uint16_t))) {
35  decodeTool.adoptData(base + offset, len);
36  return 0;
37  } else {
38  return -1;
39  }
40 }
41 
44  commondataformat1 = 0x50000000u;
47  dcch0 = 0x1; // format version 1
48  dcch1 = 0;
49  for (int i = 0; i < 18; i++)
50  spigotInfo[i] = 0;
51 }
52 
53 void HcalDCCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
54  commondataformat0 = 0x8 | ((sourceid & 0xFFF) << 8) | ((bcn & 0xFFF) << 20);
55  commondataformat1 = 0x50000000u | (l1aN & 0xFFFFFF);
56  commondataformat2 = ((orbN & 0xFFFFFFF) << 4);
57  commondataformat3 = ((orbN >> 28) & 0xF);
58 }
59 
60 void HcalDCCHeader::copySpigotData(unsigned int spigot_id,
61  const HcalHTRData& data,
62  bool valid,
63  unsigned char LRB_error_word) {
64  if (spigot_id >= (unsigned int)SPIGOT_COUNT)
65  return;
66  // construct the spigot info
67  spigotInfo[spigot_id] = (data.getRawLength() / 2) | 0xc000;
68  if (valid)
69  spigotInfo[spigot_id] |= 0x2000;
70  spigotInfo[spigot_id] |= (LRB_error_word << 16) | ((data.getErrorsWord() & 0xFF) << 24);
71  // status info...
72  if (valid)
73  dcch0 |= (1 << (spigot_id + 14));
74  // copy
75  unsigned int lenSoFar = 0;
76  for (unsigned int i = 0; i < spigot_id; i++)
77  lenSoFar += getSpigotDataLength(i);
78  unsigned short* startingPoint =
79  ((unsigned short*)this) + sizeof(HcalDCCHeader) / sizeof(unsigned short) + lenSoFar * 2;
80  memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
81  // update the trailer...
82  lenSoFar += data.getRawLength() / 2; // 32-bit words
83  uint32_t* trailer = ((uint32_t*)this) + sizeof(HcalDCCHeader) / sizeof(uint32_t) + lenSoFar;
84  int len64 = sizeof(HcalDCCHeader) / 8 + lenSoFar / 2 + 1;
85  trailer[1] = 0;
86  trailer[0] = 0xA0000000u | len64;
87 }
88 
89 std::ostream& operator<<(std::ostream& s, const HcalDCCHeader& head) {
90  for (int i = 0; i < HcalDCCHeader::SPIGOT_COUNT; i++) {
91  s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
92  if (head.getSpigotEnabled(i))
93  s << "E";
94  if (head.getSpigotPresent(i))
95  s << "P";
96  if (head.getSpigotValid(i))
97  s << "V";
98  s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << "," << int(head.getLRBErrorBits(i))
99  << std::dec;
100  s << std::endl;
101  }
102  return s;
103 }
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
uint32_t spigotInfo[18]
base
Main Program
Definition: newFWLiteAna.py:92
uint32_t dcch0
void copySpigotData(unsigned int spigot_id, const HcalHTRData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given HcalHTRData as the given spigot&#39;s data. This should be done in increasing spigot order!...
uint32_t commondataformat0
unsigned char getLRBErrorBits(unsigned int nspigot) const
Access the Link Receiver Board error bits (decoding tbd)
uint32_t commondataformat3
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
uint32_t dcch1
uint32_t commondataformat2
bool getSpigotValid(unsigned int nspigot) const
Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN.
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:46
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
uint32_t commondataformat1
std::ostream & operator<<(std::ostream &s, const HcalDCCHeader &head)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
unsigned int getTotalLengthBytes() const
Log< level::Warning, false > LogWarning
unsigned int getSpigotDataLength(int nspigot) const
Definition: HcalDCCHeader.h:97
bool getSpigotEnabled(unsigned int nspigot) const
Read the "ENABLED" bit for this spigot.