CMS 3D CMS Logo

CastorCTDCHeader.cc
Go to the documentation of this file.
1 /*
2  * \author A. Campbell -- DESY
3  */
8 #include <cstring>
9 #include <cstdint>
10 
11 const int CastorCTDCHeader::SPIGOT_COUNT = 2; // COR spigots - does not include merger pay load
12 
14 
16  unsigned int totalSize = sizeof(CastorCTDCHeader);
17  for (int i = 0; i < SPIGOT_COUNT + 1; i++) // includes merger pay load
18  totalSize += (spigotInfo[i] & 0x3FF) * 4;
19  return totalSize; // doesn't include the trailer
20 }
21 
22 int CastorCTDCHeader::getSpigotData(int nspigot, CastorCORData& decodeTool, int validSize) const {
23  const uint16_t* base = ((const uint16_t*)this) + sizeof(CastorCTDCHeader) / sizeof(uint16_t);
24  int offset = 0, i, len = 0;
25  for (i = 0; i <= nspigot; i++) {
26  offset += len;
27  len = (spigotInfo[i] & 0x3FF) * 2;
28  }
29  if ((offset + len + sizeof(CastorCTDCHeader) / 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  ctdch0 = 0x1; // format version 1
43  ctdch1 = 0;
44  for (int i = 0; i < 3; i++)
45  spigotInfo[i] = 0;
46  spigotInfo[3] = 0x12345678; // end DCC header pattern
47 }
48 
49 void CastorCTDCHeader::setHeader(int sourceid, int bcn, int l1aN, int orbN) {
50  commondataformat0 = 0x8 | ((sourceid & 0xFFF) << 8) | ((bcn & 0xFFF) << 20);
51  commondataformat1 = 0x50000000u | (l1aN & 0xFFFFFF);
52 }
53 
54 void CastorCTDCHeader::copySpigotData(unsigned int spigot_id,
55  const CastorCORData& data,
56  bool valid,
57  unsigned char LRB_error_word) {
58  if (spigot_id >= (unsigned int)SPIGOT_COUNT)
59  return;
60  // construct the spigot info
61  spigotInfo[spigot_id] = (data.getRawLength() / 2) | 0xc000;
62  if (valid)
63  spigotInfo[spigot_id] |= 0x2000;
64  spigotInfo[spigot_id] |= (LRB_error_word << 16) | ((data.getErrorsWord() & 0xFF) << 24);
65  // status info...
66  if (valid)
67  ctdch0 |= (1 << (spigot_id + 14));
68  // copy
69  unsigned int lenSoFar = 0;
70  for (unsigned int i = 0; i < spigot_id; i++)
71  lenSoFar += getSpigotDataLength(i);
72  unsigned short* startingPoint =
73  ((unsigned short*)this) + sizeof(CastorCTDCHeader) / sizeof(unsigned short) + lenSoFar * 2;
74  memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
75  // update the trailer...
76  lenSoFar += data.getRawLength() / 2; // 32-bit words
77  uint32_t* trailer = ((uint32_t*)this) + sizeof(CastorCTDCHeader) / sizeof(uint32_t) + lenSoFar;
78  int len64 = sizeof(CastorCTDCHeader) / 8 + lenSoFar / 2 + 1;
79  trailer[1] = 0;
80  trailer[0] = 0xA0000000u | len64;
81 }
82 
84  unsigned int spigot_id = 2;
85  // construct the spigot info
86  spigotInfo[spigot_id] = (data.getRawLength() / 2) | 0xc000; // Enabled & Present
87  if (valid)
88  spigotInfo[spigot_id] |= 0x2000; // Valid
89  spigotInfo[spigot_id] |= ((data.getErrorsWord() & 0xFF) << 24);
90  // status info...
91  if (valid)
92  ctdch0 |= (1 << (spigot_id + 14));
93  // copy
94  unsigned int lenSoFar = 0;
95  for (unsigned int i = 0; i < spigot_id; i++)
96  lenSoFar += getSpigotDataLength(i);
97  unsigned short* startingPoint =
98  ((unsigned short*)this) + sizeof(CastorCTDCHeader) / sizeof(unsigned short) + lenSoFar * 2;
99  memcpy(startingPoint, data.getRawData(), sizeof(unsigned short) * data.getRawLength());
100  // update the trailer...
101  lenSoFar += data.getRawLength() / 2; // 32-bit words
102  uint32_t* trailer = ((uint32_t*)this) + sizeof(CastorCTDCHeader) / sizeof(uint32_t) + lenSoFar;
103  int len64 = sizeof(CastorCTDCHeader) / 8 + lenSoFar / 2 + 1;
104  trailer[1] = 0;
105  trailer[0] = 0xA0000000u | len64;
106 }
107 
108 std::ostream& operator<<(std::ostream& s, const CastorCTDCHeader& head) {
109  for (int i = 0; i < CastorCTDCHeader::SPIGOT_COUNT + 1; i++) {
110  s << "Spigot " << i << " : " << head.getSpigotDataLength(i) << " bytes, ";
111  if (head.getSpigotEnabled(i))
112  s << "E";
113  if (head.getSpigotPresent(i))
114  s << "P";
115  if (head.getSpigotValid(i))
116  s << "V";
117  s << ". Error codes: " << std::hex << int(head.getSpigotErrorBits(i)) << std::dec;
118  s << std::endl;
119  }
120  return s;
121 }
void adoptData(const unsigned short *data, int length)
bool getSpigotEnabled(unsigned int nspigot) const
Read the "ENABLED" bit for this spigot.
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
base
Main Program
Definition: newFWLiteAna.py:92
static const int SPIGOT_COUNT
unsigned int getTotalLengthBytes() const
unsigned int commondataformat0
int getSpigotData(int nspigot, CastorCORData &decodeTool, int validSize) const
void copySpigotData(unsigned int spigot_id, const CastorCORData &data, bool valid=true, unsigned char LRB_error_word=0)
Add the given CastorCORData as the given spigot&#39;s data. This should be done in increasing spigot orde...
unsigned int commondataformat3
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
void copyMergerData(const CastorMergerData &data, bool valid)
unsigned int spigotInfo[4]
unsigned int commondataformat2
unsigned int getSpigotDataLength(int nspigot) const
unsigned int commondataformat1
bool getSpigotValid(unsigned int nspigot) const
Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned int ctdch1
std::ostream & operator<<(std::ostream &s, const CastorCTDCHeader &head)
unsigned int ctdch0
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.