CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 }
int getSpigotData(int nspigot, CastorCORData &decodeTool, int validSize) const
tuple base
Main Program
Definition: newFWLiteAna.py:92
bool getSpigotValid(unsigned int nspigot) const
Read the &quot;VALID&quot; bit for this spigot; TTC EvN matched HTR EvN.
void adoptData(const unsigned short *data, int length)
bool getSpigotEnabled(unsigned int nspigot) const
Read the &quot;ENABLED&quot; bit for this spigot.
unsigned int getTotalLengthBytes() const
const int getRawLength() const
Get the length of the raw data.
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
unsigned int getErrorsWord() const
Get the errors word.
unsigned int getErrorsWord() const
Get the errors word.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
static const int SPIGOT_COUNT
unsigned int commondataformat0
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
void copyMergerData(const CastorMergerData &data, bool valid)
unsigned int spigotInfo[4]
unsigned int getSpigotDataLength(int nspigot) const
unsigned int commondataformat2
unsigned int commondataformat1
const unsigned short * getRawData() const
Get a pointer to the raw data.
const int getRawLength() const
Get the length of the raw data.
Definition: CastorCORData.h:39
const unsigned short * getRawData() const
Get a pointer to the raw data.
Definition: CastorCORData.h:36
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int ctdch1
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
unsigned int ctdch0