CMS 3D CMS Logo

L1GtfeExtWord.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iomanip>
20 #include <cstdint>
21 
22 // user include files
24 
27 
30 
31 // constructors
32 
33 // empty constructor, all members set to zero;
35  // empty
36 }
37 
38 // all members set to zero, m_bst has bstSizeBytes zero elements
39 L1GtfeExtWord::L1GtfeExtWord(int bstSizeBytes) : L1GtfeWord(), m_bstSource(0) { m_bst.resize(bstSizeBytes); }
40 
41 // constructor from unpacked values, m_bst size taken from bstValue
43  cms_uint16_t recordLength1Value,
44  cms_uint16_t recordLengthValue,
45  cms_uint16_t bxNrValue,
46  cms_uint32_t setupVersionValue,
47  cms_uint16_t activeBoardsValue,
48  cms_uint16_t altNrBxBoardValue,
49  cms_uint32_t totalTriggerNrValue, // end of L1GtfeWord
50  const std::vector<cms_uint16_t>& bstValue,
51  cms_uint16_t bstSourceValue)
52  : L1GtfeWord(boardIdValue,
53  recordLength1Value,
54  recordLengthValue,
55  bxNrValue,
56  setupVersionValue,
57  activeBoardsValue,
58  altNrBxBoardValue,
59  totalTriggerNrValue),
60  m_bst(bstValue),
61  m_bstSource(bstSourceValue)
62 
63 {
64  // empty
65 }
66 
67 // destructor
69  // empty now
70 }
71 
72 // equal operator
74  // base class
75 
76  const L1GtfeWord gtfeResult = result;
77  const L1GtfeWord gtfeThis = *this;
78 
79  if (gtfeThis != gtfeResult) {
80  return false;
81  }
82 
83  //
84 
85  for (unsigned int iB = 0; iB < m_bst.size(); ++iB) {
86  if (m_bst[iB] != result.m_bst[iB]) {
87  return false;
88  }
89  }
90 
91  if (m_bstSource != result.m_bstSource) {
92  return false;
93  }
94 
95  // all members identical
96  return true;
97 }
98 
99 // unequal operator
100 bool L1GtfeExtWord::operator!=(const L1GtfeExtWord& result) const { return !(result == *this); }
101 
102 // methods
103 
105  cms_uint64_t gpst = 0ULL;
106 
107  // return 0 if BST message too small
108  int bstSize = m_bst.size();
109  if (GpsTimeLastBlock >= bstSize) {
110  return gpst;
111  }
112 
113  for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
114  // keep capitalization for similarity with other functions
115  const int scaledIB = iB - GpsTimeFirstBlock;
116  const int BstShift = BstBitSize * scaledIB;
117 
118  gpst = gpst | ((static_cast<cms_uint64_t>(m_bst[iB])) << BstShift);
119  }
120 
121  return gpst;
122 }
123 
124 void L1GtfeExtWord::setGpsTime(const cms_uint64_t gpsTimeValue) {
125  // return if BST message too small
126  int bstSize = m_bst.size();
127  if (GpsTimeLastBlock >= bstSize) {
128  edm::LogError("L1GtfeExtWord") << "Error: BST message length " << bstSize
129  << " smaller than the required GpsTimeLastBlock " << GpsTimeLastBlock
130  << "\n Cannot set GpsTime" << std::endl;
131 
132  return;
133  }
134 
135  for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
136  // keep capitalization for similarity with other functions
137  const int scaledIB = iB - GpsTimeFirstBlock;
138  const int BstShift = BstBitSize * scaledIB;
139  const cms_uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
140 
141  m_bst[iB] = static_cast<cms_uint16_t>((gpsTimeValue & BstMask) >> BstShift);
142 
143  //LogTrace("L1GtfeExtWord")
144  //<< "BstShift: value [dec] = " << BstShift << "\n"
145  //<< "BstBlockMask: value [hex] = " << std::hex << BstBlockMask << "\n"
146  //<< "BstMask: value [hex] = "<< BstMask << std::dec
147  //<< std::endl;
148 
149  //LogTrace("L1GtfeExtWord")
150  //<< "BST block " << iB << ": value [hex] = " << std::hex << m_bst[iB] << std::dec
151  //<< std::endl;
152  }
153 }
154 
156  cms_uint16_t bms = 0;
157 
158  // return 0 if BST message too small
159  int bstSize = m_bst.size();
160  if (BstMasterStatusLastBlock >= bstSize) {
161  return bms;
162  }
163 
164  for (int iB = BstMasterStatusFirstBlock; iB <= BstMasterStatusLastBlock; ++iB) {
165  // keep capitalization for similarity with other functions
166  const int scaledIB = iB - BstMasterStatusFirstBlock;
167  const int BstShift = BstBitSize * scaledIB;
168 
169  bms = bms | (m_bst[iB] << BstShift);
170  }
171 
172  return bms;
173 }
174 
176  cms_uint32_t tcn = 0;
177 
178  // return 0 if BST message too small
179  int bstSize = m_bst.size();
180  if (TurnCountNumberLastBlock >= bstSize) {
181  return tcn;
182  }
183 
184  for (int iB = TurnCountNumberFirstBlock; iB <= TurnCountNumberLastBlock; ++iB) {
185  // keep capitalization for similarity with other functions
186  const int scaledIB = iB - TurnCountNumberFirstBlock;
187  const int BstShift = BstBitSize * scaledIB;
188 
189  tcn = tcn | ((static_cast<cms_uint32_t>(m_bst[iB])) << BstShift);
190  }
191 
192  return tcn;
193 }
194 
196  cms_uint32_t lhcfn = 0;
197 
198  // return 0 if BST message too small
199  int bstSize = m_bst.size();
200  if (LhcFillNumberLastBlock >= bstSize) {
201  return lhcfn;
202  }
203 
204  for (int iB = LhcFillNumberFirstBlock; iB <= LhcFillNumberLastBlock; ++iB) {
205  // keep capitalization for similarity with other functions
206  const int scaledIB = iB - LhcFillNumberFirstBlock;
207  const int BstShift = BstBitSize * scaledIB;
208 
209  lhcfn = lhcfn | ((static_cast<cms_uint32_t>(m_bst[iB])) << BstShift);
210  }
211 
212  return lhcfn;
213 }
214 
216  cms_uint16_t bm = 0;
217 
218  // return 0 if BST message too small
219  int bstSize = m_bst.size();
220  if (BeamModeLastBlock >= bstSize) {
221  return bm;
222  }
223 
224  for (int iB = BeamModeFirstBlock; iB <= BeamModeLastBlock; ++iB) {
225  // keep capitalization for similarity with other functions
226  const int scaledIB = iB - BeamModeFirstBlock;
227  const int BstShift = BstBitSize * scaledIB;
228 
229  bm = bm | (m_bst[iB] << BstShift);
230  }
231 
232  return bm;
233 }
234 
236  cms_uint16_t ptb = 0;
237 
238  // return 0 if BST message too small
239  int bstSize = m_bst.size();
240  if (ParticleTypeBeam1LastBlock >= bstSize) {
241  return ptb;
242  }
243 
244  for (int iB = ParticleTypeBeam1FirstBlock; iB <= ParticleTypeBeam1LastBlock; ++iB) {
245  // keep capitalization for similarity with other functions
246  const int scaledIB = iB - ParticleTypeBeam1FirstBlock;
247  const int BstShift = BstBitSize * scaledIB;
248 
249  ptb = ptb | (m_bst[iB] << BstShift);
250  }
251 
252  return ptb;
253 }
254 
256  cms_uint16_t ptb = 0;
257 
258  // return 0 if BST message too small
259  int bstSize = m_bst.size();
260  if (ParticleTypeBeam2LastBlock >= bstSize) {
261  return ptb;
262  }
263 
264  for (int iB = ParticleTypeBeam2FirstBlock; iB <= ParticleTypeBeam2LastBlock; ++iB) {
265  // keep capitalization for similarity with other functions
266  const int scaledIB = iB - ParticleTypeBeam2FirstBlock;
267  const int BstShift = BstBitSize * scaledIB;
268 
269  ptb = ptb | (m_bst[iB] << BstShift);
270  }
271 
272  return ptb;
273 }
274 
276  cms_uint16_t bm = 0;
277 
278  // return 0 if BST message too small
279  int bstSize = m_bst.size();
280  if (BeamMomentumLastBlock >= bstSize) {
281  return bm;
282  }
283 
284  for (int iB = BeamMomentumFirstBlock; iB <= BeamMomentumLastBlock; ++iB) {
285  // keep capitalization for similarity with other functions
286  const int scaledIB = iB - BeamMomentumFirstBlock;
287  const int BstShift = BstBitSize * scaledIB;
288 
289  bm = bm | (m_bst[iB] << BstShift);
290  }
291 
292  return bm;
293 }
294 
296  cms_uint32_t tib = 0;
297 
298  // return 0 if BST message too small
299  int bstSize = m_bst.size();
300  if (TotalIntensityBeam1LastBlock >= bstSize) {
301  return tib;
302  }
303 
304  for (int iB = TotalIntensityBeam1FirstBlock; iB <= TotalIntensityBeam1LastBlock; ++iB) {
305  // keep capitalization for similarity with other functions
306  const int scaledIB = iB - TotalIntensityBeam1FirstBlock;
307  const int BstShift = BstBitSize * scaledIB;
308 
309  tib = tib | ((static_cast<cms_uint32_t>(m_bst[iB])) << BstShift);
310  }
311 
312  return tib;
313 }
314 
316  cms_uint32_t tib = 0;
317 
318  // return 0 if BST message too small
319  int bstSize = m_bst.size();
320  if (TotalIntensityBeam2LastBlock >= bstSize) {
321  return tib;
322  }
323 
324  for (int iB = TotalIntensityBeam2FirstBlock; iB <= TotalIntensityBeam2LastBlock; ++iB) {
325  // keep capitalization for similarity with other functions
326  const int scaledIB = iB - TotalIntensityBeam2FirstBlock;
327  const int BstShift = BstBitSize * scaledIB;
328 
329  tib = tib | ((static_cast<cms_uint32_t>(m_bst[iB])) << BstShift);
330  }
331 
332  return tib;
333 }
334 
335 // get/set BST for block iB
336 const uint16_t L1GtfeExtWord::bst(int iB) const {
337  int NumberBstBlocks = m_bst.size();
338 
339  if (iB < 0 || iB >= NumberBstBlocks) {
340  throw cms::Exception("BstIndexError")
341  << "\nError: index for BST array out of range. Allowed range: [0, " << NumberBstBlocks << ") " << std::endl;
342 
343  } else {
344  return m_bst[iB];
345  }
346 }
347 
348 void L1GtfeExtWord::setBst(const uint16_t bstVal, const int iB) {
349  int NumberBstBlocks = m_bst.size();
350 
351  if (iB < 0 || iB >= NumberBstBlocks) {
352  throw cms::Exception("BstIndexError")
353  << "\nError: index for BST array out of range. Allowed range: [0, " << NumberBstBlocks << ") " << std::endl;
354 
355  } else {
356  m_bst[iB] = bstVal;
357  }
358 }
359 
360 // set the BST block for index iB from a 64-bits word
361 void L1GtfeExtWord::setBst(const cms_uint64_t& word64, const int iB) {
362  // keep capitalization for similarity with other functions //FIXME check it again
363  const int scaledIB = iB % (sizeof(word64) * 8 / BstBitSize);
364  const int BstShift = BstBitSize * scaledIB;
365  const cms_uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
366 
367  m_bst[iB] = static_cast<cms_uint16_t>((word64 & BstMask) >> BstShift);
368 }
369 
370 // set the BST block in a 64-bits word, having the index iWord
371 // in the GTFE raw record
372 void L1GtfeExtWord::setBstWord64(cms_uint64_t& word64, int iB, int iWord) {
373  // keep capitalization for similarity with other functions
374  const int scaledIB = iB % (sizeof(word64) * 8 / BstBitSize);
375  const int BstShift = BstBitSize * scaledIB;
376  const int BstWord = iB / (sizeof(word64) * 8 / BstBitSize) + BstFirstWord;
377 
378  if (iWord == BstWord) {
379  word64 = word64 | (static_cast<cms_uint64_t>(m_bst[iB]) << BstShift);
380  }
381 }
382 
383 // set the hex message indicating the source of BST message from a 64-bits word
385  m_bstSource = (word64 & BstSourceMask) >> BstSourceShift;
386 }
387 
388 // set hex message indicating the source of BST message in a 64-bits word,
389 // having the index iWord in the GTFE raw record
390 void L1GtfeExtWord::setBstSourceWord64(cms_uint64_t& word64, const int iWord) {
391  // BST always in the last word of GTFE extended - size must be correct!
392  int gtfeSize = this->getSize();
393 
394  int BstSourceWord = gtfeSize / 8 - 1; // counting starts at 0
395 
396  if (iWord == BstSourceWord) {
397  word64 = word64 | (static_cast<cms_uint64_t>(m_bstSource) << BstSourceShift);
398  }
399 }
400 
401 // get the size of the GTFE block in GT EVM record (in multiple of 8 bits)
402 const unsigned int L1GtfeExtWord::getSize() const {
403  L1GtfeWord gtfeWord;
404  unsigned int gtfeSize = gtfeWord.getSize();
405 
406  unsigned int gtfeExtSize;
407 
408  // 2 bytes to write if real BST message or simulated BST message
409  unsigned int bytesBstWriter = 2;
410 
411  // size of BST block, using rounded 64-bit words (8 bytes per 64-bit word)
412 
413  unsigned int bstSize = m_bst.size();
414 
415  if ((bstSize + bytesBstWriter) % 8 == 0) {
416  gtfeExtSize = gtfeSize + bstSize + bytesBstWriter;
417  } else {
418  gtfeExtSize = gtfeSize + bstSize + bytesBstWriter + (8 - (bstSize + bytesBstWriter) % 8);
419  }
420 
421  return gtfeExtSize;
422 }
423 
424 // resize the BST vector to get the right size of the block
425 void L1GtfeExtWord::resize(int bstSizeBytes) { m_bst.resize(bstSizeBytes); }
426 
427 // reset the content of a L1GtfeExtWord
430  m_bst.clear();
431 }
432 
433 // pretty print the content of a L1GtfeWord
434 void L1GtfeExtWord::print(std::ostream& myCout) const {
435  myCout << "\n L1GtfeExtWord::print \n" << std::endl;
436 
437  unsigned int sizeW64 = 64;
438  unsigned int dataBlocksPerLine = sizeW64 / 8; // 8x8 bits per line
439 
440  L1GtfeWord::print(myCout);
441 
442  unsigned int numberBstBlocks = m_bst.size();
443 
444  myCout << "\n BST ";
445 
446  if (numberBstBlocks == 0) {
447  myCout << "\n BST source [hex]: " << std::hex << std::setw(4) << std::setfill('0') << m_bstSource
448  << std::setfill(' ') << std::dec << std::endl;
449 
450  return;
451  }
452 
453  for (unsigned int iB = 0; iB < numberBstBlocks; iB += dataBlocksPerLine) {
454  myCout << "\n" << std::hex << " hex: ";
455 
456  for (unsigned int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
457  if (jB >= numberBstBlocks) {
458  break;
459  }
460 
461  myCout << std::setw(2) << std::setfill('0') << m_bst[jB] << " " << std::setfill(' ');
462  }
463 
464  myCout << "\n" << std::dec << " dec: ";
465 
466  for (unsigned int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
467  if (jB >= numberBstBlocks) {
468  break;
469  }
470 
471  myCout << std::setw(3) << std::setfill('0') << m_bst[jB] << " " << std::setfill(' ');
472  }
473 
474  myCout << std::endl;
475  }
476 
477  myCout << "\n BST source [hex]: " << std::hex << std::setw(4) << std::setfill('0') << m_bstSource
478  << std::setfill(' ') << std::dec << std::endl;
479 }
480 
481 void L1GtfeExtWord::unpack(const unsigned char* gtfePtr) {
482  LogDebug("L1GtfeExtWord") << "\nUnpacking GTFE block.\n" << std::endl;
483 
484  L1GtfeWord::unpack(gtfePtr);
485 
486  // TODO make BlockSize protected & use friends instead of creating L1GtfeWord?
487  L1GtfeWord gtfeWord;
488  const unsigned char* gtfeExtPtr = gtfePtr + gtfeWord.getSize();
489 
490  const cms_uint64_t* payload = reinterpret_cast<cms_uint64_t const*>(gtfeExtPtr);
491 
492  int BlockSizeExt = this->getSize() / 8;
493  int NumberBstBlocks = m_bst.size();
494 
495  if (edm::isDebugEnabled()) {
496  for (int iWord = BstFirstWord; iWord < BlockSizeExt; ++iWord) {
497  int jWord = iWord - BstFirstWord;
498  LogTrace("L1GtfeExtWord") << std::setw(4) << iWord << " " << std::hex << std::setfill('0') << std::setw(16)
499  << payload[jWord] << std::dec << std::setfill(' ') << std::endl;
500  }
501  }
502 
503  int blocksPerWord = sizeof(cms_uint64_t) * 8 / BstBitSize;
504 
505  for (int iB = 0; iB < NumberBstBlocks; ++iB) {
506  // keep capitalization for similarity with other functions
507  int BstWord = iB / blocksPerWord;
508 
509  setBst(payload[BstWord], iB);
510  }
511 }
512 
513 // static class members
514 
515 // block description in the raw GT record
516 
517 // index of first word for BST blocks
518 const int L1GtfeExtWord::BstFirstWord = 2;
519 
520 // size in bits for a BST block
521 const int L1GtfeExtWord::BstBitSize = 8;
522 
523 // BST block mask, correlated with the number of bits of a block
524 // 8 bit = 0xFF
526 
527 // BST blocks: conversion to defined quantities (LHC-BOB-ES-0001)
528 
530 const int L1GtfeExtWord::GpsTimeLastBlock = 7;
531 
534 
537 
540 
541 const int L1GtfeExtWord::BeamModeFirstBlock = 26;
542 const int L1GtfeExtWord::BeamModeLastBlock = 27;
543 
546 
549 
552 
555 
558 
559 // BST
560 const cms_uint64_t L1GtfeExtWord::BstSourceMask = 0xFFFF000000000000ULL;
561 const int L1GtfeExtWord::BstSourceShift = 48;
#define LogDebug(id)
bool isDebugEnabled()
static const int BstMasterStatusLastBlock
const unsigned int getSize() const
get the size of the GTFE block in GT DAQ record (in multiple of 8 bits)
Definition: L1GtfeWord.h:160
void setBstSource(const cms_uint16_t bstSourceVal)
Definition: L1GtfeExtWord.h:98
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeWord
Definition: L1GtfeWord.cc:253
static const int TotalIntensityBeam1FirstBlock
static const int ParticleTypeBeam1FirstBlock
static const int GpsTimeLastBlock
static const cms_uint64_t BstBlockMask
static const int ParticleTypeBeam2LastBlock
static const int TotalIntensityBeam1LastBlock
void print(std::ostream &myCout) const override
pretty print the content of a L1GtfeExtWord
const cms_uint64_t gpsTime() const
LHC-BOB-ES-0001 (EDMS 638899)
void setBst(const cms_uint16_t bstVal, const int iB)
static const int TurnCountNumberLastBlock
L1GtfeExtWord()
constructors
static const int ParticleTypeBeam1LastBlock
bool operator==(const L1GtfeExtWord &) const
equal operator
static const int TotalIntensityBeam2LastBlock
const cms_uint16_t bstMasterStatus() const
void setBstWord64(cms_uint64_t &word64, int iB, const int iWord)
const unsigned int getSize() const
get the size of the GTFE block in GT EVM record (in multiple of 8 bits)
const cms_uint16_t beamMomentum() const
const std::vector< cms_uint16_t > & bst() const
get the full BST block
Definition: L1GtfeExtWord.h:62
static const int ParticleTypeBeam2FirstBlock
virtual void reset()
reset the content of a L1GtfeWord
Definition: L1GtfeWord.cc:240
bool operator!=(const L1GtfeExtWord &) const
unequal operator
static const int BeamMomentumFirstBlock
static const cms_uint64_t BstSourceMask
static const int GpsTimeFirstBlock
BST blocks: conversion to defined quantities (LHC-BOB-ES-0001)
unsigned short cms_uint16_t
Definition: typedefs.h:13
static const int TurnCountNumberFirstBlock
static const int BstFirstWord
block description in the raw GT record
unsigned int cms_uint32_t
Definition: typedefs.h:15
#define LogTrace(id)
static const int TotalIntensityBeam2FirstBlock
void setBstSourceWord64(cms_uint64_t &word64, const int iWord)
const cms_uint32_t totalIntensityBeam2() const
const cms_uint32_t totalIntensityBeam1() const
void resize(int bstSizeBytes)
resize the BST vector to get the right size of the block
static const int BstSourceShift
const cms_uint32_t lhcFillNumber() const
std::vector< cms_uint16_t > m_bst
BST message - each byte is an vector element.
~L1GtfeExtWord() override
destructor
static const int BeamModeLastBlock
void setGpsTime(const cms_uint64_t)
cms_uint16_t m_bstSource
hex message indicating the source of BST message (beam or simulated)
const cms_uint16_t particleTypeBeam2() const
static const int BstBitSize
size in bits for a BST block
static const int BstMasterStatusFirstBlock
static const int LhcFillNumberLastBlock
unsigned long long cms_uint64_t
Definition: typedefs.h:17
const cms_uint32_t turnCountNumber() const
static const int BeamMomentumLastBlock
void reset() override
reset the content of a L1GtfeExtWord
const cms_uint16_t beamMode() const
static const int BeamModeFirstBlock
void unpack(const unsigned char *gtfePtr) override
virtual void unpack(const unsigned char *gtfePtr)
Definition: L1GtfeWord.cc:290
const cms_uint16_t particleTypeBeam1() const
static const int LhcFillNumberFirstBlock