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 }
operator<<
std::ostream & operator<<(std::ostream &s, const CastorCTDCHeader &head)
Definition: CastorCTDCHeader.cc:108
mps_fire.i
i
Definition: mps_fire.py:428
CastorMergerData
Definition: CastorMergerData.h:14
MessageLogger.h
CastorCTDCHeader
Definition: CastorCTDCHeader.h:17
CastorCORData::adoptData
void adoptData(const unsigned short *data, int length)
Definition: CastorCORData.cc:51
CastorCTDCHeader::clear
void clear()
Definition: CastorCTDCHeader.cc:37
CastorCTDCHeader::commondataformat1
unsigned int commondataformat1
Definition: CastorCTDCHeader.h:145
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CastorCTDCHeader::CastorCTDCHeader
CastorCTDCHeader()
Definition: CastorCTDCHeader.cc:13
CastorCTDCHeader::getSpigotEnabled
bool getSpigotEnabled(unsigned int nspigot) const
Read the "ENABLED" bit for this spigot.
Definition: CastorCTDCHeader.h:91
CastorCORData
Definition: CastorCORData.h:14
CastorCTDCHeader::commondataformat0
unsigned int commondataformat0
Definition: CastorCTDCHeader.h:144
CastorCTDCHeader::getSpigotValid
bool getSpigotValid(unsigned int nspigot) const
Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN.
Definition: CastorCTDCHeader.h:103
CastorCTDCHeader::getSpigotPresent
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
Definition: CastorCTDCHeader.h:95
CastorCTDCHeader.h
CastorCTDCHeader::ctdch1
unsigned int ctdch1
Definition: CastorCTDCHeader.h:149
createfilelist.int
int
Definition: createfilelist.py:10
CastorCTDCHeader::SPIGOT_COUNT
static const int SPIGOT_COUNT
Definition: CastorCTDCHeader.h:19
CastorMergerData.h
CastorCTDCHeader::commondataformat3
unsigned int commondataformat3
Definition: CastorCTDCHeader.h:147
CastorCTDCHeader::copyMergerData
void copyMergerData(const CastorMergerData &data, bool valid)
Definition: CastorCTDCHeader.cc:83
CastorCTDCHeader::setHeader
void setHeader(int sourceid, int bcn, int l1aN, int orbN)
Definition: CastorCTDCHeader.cc:49
CastorCTDCHeader::ctdch0
unsigned int ctdch0
Definition: CastorCTDCHeader.h:148
CastorCTDCHeader::getSpigotData
int getSpigotData(int nspigot, CastorCORData &decodeTool, int validSize) const
Definition: CastorCTDCHeader.cc:22
CastorCTDCHeader::spigotInfo
unsigned int spigotInfo[4]
Definition: CastorCTDCHeader.h:150
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
CastorCTDCHeader::getSpigotErrorBits
unsigned char getSpigotErrorBits(unsigned int nspigot) const
Access the HTR error bits (decoding tbd)
Definition: CastorCTDCHeader.h:115
CastorCTDCHeader::getSpigotDataLength
unsigned int getSpigotDataLength(int nspigot) const
Definition: CastorCTDCHeader.h:86
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
CastorCTDCHeader::copySpigotData
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's data. This should be done in increasing spigot orde...
Definition: CastorCTDCHeader.cc:54
CastorCTDCHeader::commondataformat2
unsigned int commondataformat2
Definition: CastorCTDCHeader.h:146
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
CastorCORData.h
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
CastorCTDCHeader::getTotalLengthBytes
unsigned int getTotalLengthBytes() const
Definition: CastorCTDCHeader.cc:15