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 }
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
HcalDCCHeader::clear
void clear()
Definition: HcalDCCHeader.cc:42
HcalDCCHeader::commondataformat1
uint32_t commondataformat1
Definition: HcalDCCHeader.h:154
HcalDCCHeader::commondataformat0
uint32_t commondataformat0
Definition: HcalDCCHeader.h:153
HcalDCCHeader::getLRBErrorBits
unsigned char getLRBErrorBits(unsigned int nspigot) const
Access the Link Receiver Board error bits (decoding tbd)
Definition: HcalDCCHeader.h:130
HcalDCCHeader::commondataformat3
uint32_t commondataformat3
Definition: HcalDCCHeader.h:156
HcalDCCHeader::getSpigotErrorBits
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
Definition: HcalDCCHeader.h:126
HcalDCCHeader::getSpigotDataLength
unsigned int getSpigotDataLength(int nspigot) const
Definition: HcalDCCHeader.h:97
HcalDCCHeader::getSpigotEnabled
bool getSpigotEnabled(unsigned int nspigot) const
Read the "ENABLED" bit for this spigot.
Definition: HcalDCCHeader.h:102
HcalDCCHeader::SPIGOT_COUNT
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
validateGeometry_cfg.valid
valid
Definition: validateGeometry_cfg.py:21
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HcalDCCHeader::setHeader
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
Definition: HcalDCCHeader.cc:53
HcalDCCHeader::spigotInfo
uint32_t spigotInfo[18]
Definition: HcalDCCHeader.h:159
edm::LogWarning
Definition: MessageLogger.h:141
HcalDCCHeader::HcalDCCHeader
HcalDCCHeader()
Definition: HcalDCCHeader.cc:12
HcalDCCHeader::dcch0
uint32_t dcch0
Definition: HcalDCCHeader.h:157
HcalDCCHeader::commondataformat2
uint32_t commondataformat2
Definition: HcalDCCHeader.h:155
createfilelist.int
int
Definition: createfilelist.py:10
HcalDCCHeader::getSpigotPresent
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
Definition: HcalDCCHeader.h:106
HcalDCCHeader
Definition: HcalDCCHeader.h:17
HcalHTRData::adoptData
void adoptData(const unsigned short *data, int length)
Definition: HcalHTRData.cc:46
HcalDCCHeader::getTotalLengthBytes
unsigned int getTotalLengthBytes() const
Definition: HcalDCCHeader.cc:14
HcalDCCHeader::copySpigotData
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's data. This should be done in increasing spigot order!
Definition: HcalDCCHeader.cc:60
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
HcalDCCHeader.h
HcalDCCHeader::getSpigotValid
bool getSpigotValid(unsigned int nspigot) const
Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN.
Definition: HcalDCCHeader.h:114
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
HcalHTRData
Definition: HcalHTRData.h:16
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
HcalDCCHeader::dcch1
uint32_t dcch1
Definition: HcalDCCHeader.h:158
operator<<
std::ostream & operator<<(std::ostream &s, const HcalDCCHeader &head)
Definition: HcalDCCHeader.cc:89
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
HcalDCCHeader::getSpigotData
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
Definition: HcalDCCHeader.cc:27
HcalHTRData.h