CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtfeExtWord.cc
Go to the documentation of this file.
1 
17 // this class header
19 
20 // system include files
21 #include <iomanip>
22 #include <stdint.h>
23 
24 // user include files
26 
29 
32 
33 
34 // constructors
35 
36 // empty constructor, all members set to zero;
38  L1GtfeWord(), m_bstSource(0) {
39 
40  // empty
41 
42 }
43 
44 // all members set to zero, m_bst has bstSizeBytes zero elements
45 L1GtfeExtWord::L1GtfeExtWord(int bstSizeBytes) :
46  L1GtfeWord(), m_bstSource(0) {
47 
48  m_bst.resize(bstSizeBytes);
49 
50 }
51 
52 
53 // constructor from unpacked values, m_bst size taken from bstValue
55  cms_uint16_t boardIdValue, cms_uint16_t recordLength1Value,
56  cms_uint16_t recordLengthValue, cms_uint16_t bxNrValue,
57  cms_uint32_t setupVersionValue, cms_uint16_t activeBoardsValue,
58  cms_uint16_t altNrBxBoardValue, cms_uint32_t totalTriggerNrValue, // end of L1GtfeWord
59  const std::vector<cms_uint16_t>& bstValue, cms_uint16_t bstSourceValue) :
60  L1GtfeWord(
61  boardIdValue, recordLength1Value, recordLengthValue, bxNrValue, setupVersionValue,
62  activeBoardsValue, altNrBxBoardValue, totalTriggerNrValue), m_bst(bstValue),
63  m_bstSource(bstSourceValue)
64 
65 {
66 
67  // empty
68 }
69 
70 // destructor
72 
73  // empty now
74 
75 }
76 
77 // equal operator
79 {
80 
81  // base class
82 
83  const L1GtfeWord gtfeResult = result;
84  const L1GtfeWord gtfeThis = *this;
85 
86  if (gtfeThis != gtfeResult) {
87  return false;
88  }
89 
90 
91  //
92 
93  for (unsigned int iB = 0; iB < m_bst.size(); ++iB) {
94  if(m_bst[iB] != result.m_bst[iB]) {
95  return false;
96  }
97  }
98 
99  if ( m_bstSource != result.m_bstSource) {
100  return false;
101  }
102 
103  // all members identical
104  return true;
105 
106 }
107 
108 // unequal operator
110 {
111 
112  return !( result == *this);
113 
114 }
115 
116 // methods
117 
119 {
120 
121  cms_uint64_t gpst = 0ULL;
122 
123  // return 0 if BST message too small
124  int bstSize = m_bst.size();
125  if (GpsTimeLastBlock >= bstSize) {
126  return gpst;
127  }
128 
129  for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
130 
131  // keep capitalization for similarity with other functions
132  const int scaledIB = iB - GpsTimeFirstBlock;
133  const int BstShift = BstBitSize*scaledIB;
134 
135  gpst = gpst |
136  ( (static_cast<cms_uint64_t> (m_bst[iB])) << BstShift );
137 
138  }
139 
140  return gpst;
141 }
142 
143 void L1GtfeExtWord::setGpsTime(const cms_uint64_t gpsTimeValue) {
144 
145  // return if BST message too small
146  int bstSize = m_bst.size();
147  if (GpsTimeLastBlock >= bstSize) {
148 
149  edm::LogError("L1GtfeExtWord") << "Error: BST message length "
150  << bstSize << " smaller than the required GpsTimeLastBlock "
151  << GpsTimeLastBlock << "\n Cannot set GpsTime" << std::endl;
152 
153  return;
154  }
155 
156  for (int iB = GpsTimeFirstBlock; iB <= GpsTimeLastBlock; ++iB) {
157 
158  // keep capitalization for similarity with other functions
159  const int scaledIB = iB - GpsTimeFirstBlock;
160  const int BstShift = BstBitSize*scaledIB;
161  const cms_uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
162 
163  m_bst[iB] = static_cast<cms_uint16_t> ((gpsTimeValue & BstMask) >> BstShift);
164 
165  //LogTrace("L1GtfeExtWord")
166  //<< "BstShift: value [dec] = " << BstShift << "\n"
167  //<< "BstBlockMask: value [hex] = " << std::hex << BstBlockMask << "\n"
168  //<< "BstMask: value [hex] = "<< BstMask << std::dec
169  //<< std::endl;
170 
171  //LogTrace("L1GtfeExtWord")
172  //<< "BST block " << iB << ": value [hex] = " << std::hex << m_bst[iB] << std::dec
173  //<< std::endl;
174 
175  }
176 
177 }
178 
180 {
181 
182  cms_uint16_t bms = 0;
183 
184  // return 0 if BST message too small
185  int bstSize = m_bst.size();
186  if (BstMasterStatusLastBlock >= bstSize) {
187  return bms;
188  }
189 
190  for (int iB = BstMasterStatusFirstBlock; iB <= BstMasterStatusLastBlock; ++iB) {
191 
192  // keep capitalization for similarity with other functions
193  const int scaledIB = iB - BstMasterStatusFirstBlock;
194  const int BstShift = BstBitSize*scaledIB;
195 
196  bms = bms | ( m_bst[iB] << BstShift );
197 
198  }
199 
200  return bms;
201 }
202 
203 
205 {
206 
207  cms_uint32_t tcn = 0;
208 
209  // return 0 if BST message too small
210  int bstSize = m_bst.size();
211  if (TurnCountNumberLastBlock >= bstSize) {
212  return tcn;
213  }
214 
215  for (int iB = TurnCountNumberFirstBlock; iB <= TurnCountNumberLastBlock; ++iB) {
216 
217  // keep capitalization for similarity with other functions
218  const int scaledIB = iB - TurnCountNumberFirstBlock;
219  const int BstShift = BstBitSize*scaledIB;
220 
221  tcn = tcn |
222  ( (static_cast<cms_uint32_t> (m_bst[iB])) << BstShift );
223 
224  }
225 
226  return tcn;
227 }
228 
230 {
231 
232  cms_uint32_t lhcfn = 0;
233 
234  // return 0 if BST message too small
235  int bstSize = m_bst.size();
236  if (LhcFillNumberLastBlock >= bstSize) {
237  return lhcfn;
238  }
239 
240  for (int iB = LhcFillNumberFirstBlock; iB <= LhcFillNumberLastBlock; ++iB) {
241 
242  // keep capitalization for similarity with other functions
243  const int scaledIB = iB - LhcFillNumberFirstBlock;
244  const int BstShift = BstBitSize*scaledIB;
245 
246  lhcfn = lhcfn |
247  ( (static_cast<cms_uint32_t> (m_bst[iB])) << BstShift );
248 
249  }
250 
251  return lhcfn;
252 }
253 
255 {
256 
257  cms_uint16_t bm = 0;
258 
259  // return 0 if BST message too small
260  int bstSize = m_bst.size();
261  if (BeamModeLastBlock >= bstSize) {
262  return bm;
263  }
264 
265  for (int iB = BeamModeFirstBlock; iB <= BeamModeLastBlock; ++iB) {
266 
267  // keep capitalization for similarity with other functions
268  const int scaledIB = iB - BeamModeFirstBlock;
269  const int BstShift = BstBitSize*scaledIB;
270 
271  bm = bm | ( m_bst[iB] << BstShift );
272 
273  }
274 
275  return bm;
276 }
277 
279 {
280 
281  cms_uint16_t ptb = 0;
282 
283  // return 0 if BST message too small
284  int bstSize = m_bst.size();
285  if (ParticleTypeBeam1LastBlock >= bstSize) {
286  return ptb;
287  }
288 
289  for (int iB = ParticleTypeBeam1FirstBlock; iB <= ParticleTypeBeam1LastBlock; ++iB) {
290 
291  // keep capitalization for similarity with other functions
292  const int scaledIB = iB - ParticleTypeBeam1FirstBlock;
293  const int BstShift = BstBitSize*scaledIB;
294 
295  ptb = ptb | ( m_bst[iB] << BstShift );
296 
297  }
298 
299  return ptb;
300 }
301 
303 {
304 
305  cms_uint16_t ptb = 0;
306 
307  // return 0 if BST message too small
308  int bstSize = m_bst.size();
309  if (ParticleTypeBeam2LastBlock >= bstSize) {
310  return ptb;
311  }
312 
313  for (int iB = ParticleTypeBeam2FirstBlock; iB <= ParticleTypeBeam2LastBlock; ++iB) {
314 
315  // keep capitalization for similarity with other functions
316  const int scaledIB = iB - ParticleTypeBeam2FirstBlock;
317  const int BstShift = BstBitSize*scaledIB;
318 
319  ptb = ptb | ( m_bst[iB] << BstShift );
320 
321  }
322 
323  return ptb;
324 
325 }
326 
328 {
329 
330  cms_uint16_t bm = 0;
331 
332  // return 0 if BST message too small
333  int bstSize = m_bst.size();
334  if (BeamMomentumLastBlock >= bstSize) {
335  return bm;
336  }
337 
338  for (int iB = BeamMomentumFirstBlock; iB <= BeamMomentumLastBlock; ++iB) {
339 
340  // keep capitalization for similarity with other functions
341  const int scaledIB = iB - BeamMomentumFirstBlock;
342  const int BstShift = BstBitSize*scaledIB;
343 
344  bm = bm | ( m_bst[iB] << BstShift );
345 
346  }
347 
348  return bm;
349 }
350 
352 {
353 
354  cms_uint32_t tib = 0;
355 
356  // return 0 if BST message too small
357  int bstSize = m_bst.size();
358  if (TotalIntensityBeam1LastBlock >= bstSize) {
359  return tib;
360  }
361 
362  for (int iB = TotalIntensityBeam1FirstBlock; iB <= TotalIntensityBeam1LastBlock; ++iB) {
363 
364  // keep capitalization for similarity with other functions
365  const int scaledIB = iB - TotalIntensityBeam1FirstBlock;
366  const int BstShift = BstBitSize*scaledIB;
367 
368  tib = tib |
369  ( (static_cast<cms_uint32_t> (m_bst[iB])) << BstShift );
370 
371  }
372 
373  return tib;
374 }
375 
377 {
378 
379  cms_uint32_t tib = 0;
380 
381  // return 0 if BST message too small
382  int bstSize = m_bst.size();
383  if (TotalIntensityBeam2LastBlock >= bstSize) {
384  return tib;
385  }
386 
387  for (int iB = TotalIntensityBeam2FirstBlock; iB <= TotalIntensityBeam2LastBlock; ++iB) {
388 
389  // keep capitalization for similarity with other functions
390  const int scaledIB = iB - TotalIntensityBeam2FirstBlock;
391  const int BstShift = BstBitSize*scaledIB;
392 
393  tib = tib |
394  ( (static_cast<cms_uint32_t> (m_bst[iB])) << BstShift );
395 
396  }
397 
398  return tib;
399 }
400 
401 
402 // get/set BST for block iB
403 const uint16_t L1GtfeExtWord::bst(int iB) const
404 {
405 
406  int NumberBstBlocks = m_bst.size();
407 
408  if (iB < 0 || iB >= NumberBstBlocks) {
409  throw cms::Exception("BstIndexError")
410  << "\nError: index for BST array out of range. Allowed range: [0, "
411  << NumberBstBlocks << ") " << std::endl;
412 
413  } else {
414  return m_bst[iB];
415  }
416 
417 }
418 
419 void L1GtfeExtWord::setBst(const uint16_t bstVal, const int iB)
420 {
421 
422  int NumberBstBlocks = m_bst.size();
423 
424  if (iB < 0 || iB >= NumberBstBlocks) {
425  throw cms::Exception("BstIndexError")
426  << "\nError: index for BST array out of range. Allowed range: [0, "
427  << NumberBstBlocks << ") " << std::endl;
428 
429  } else {
430  m_bst[iB] = bstVal;
431  }
432 
433 }
434 
435 // set the BST block for index iB from a 64-bits word
436 void L1GtfeExtWord::setBst(const cms_uint64_t& word64, const int iB)
437 {
438 
439  // keep capitalization for similarity with other functions //FIXME check it again
440  const int scaledIB = iB%(sizeof(word64)*8/BstBitSize);
441  const int BstShift = BstBitSize*scaledIB;
442  const cms_uint64_t BstMask = 0x0000000000000000ULL | (BstBlockMask << BstShift);
443 
444  m_bst[iB] = static_cast<cms_uint16_t> ((word64 & BstMask) >> BstShift);
445 
446 }
447 
448 // set the BST block in a 64-bits word, having the index iWord
449 // in the GTFE raw record
450 void L1GtfeExtWord::setBstWord64(cms_uint64_t& word64, int iB, int iWord)
451 {
452 
453  // keep capitalization for similarity with other functions
454  const int scaledIB = iB%(sizeof(word64)*8/BstBitSize);
455  const int BstShift = BstBitSize*scaledIB;
456  const int BstWord = iB/(sizeof(word64)*8/BstBitSize) + BstFirstWord;
457 
458  if (iWord == BstWord) {
459  word64 = word64 |
460  (static_cast<cms_uint64_t> (m_bst[iB]) << BstShift);
461  }
462 
463 
464 }
465 
466 
467 // set the hex message indicating the source of BST message from a 64-bits word
469 
470  m_bstSource = (word64 & BstSourceMask) >> BstSourceShift;
471 
472 }
473 
474 // set hex message indicating the source of BST message in a 64-bits word,
475 // having the index iWord in the GTFE raw record
476 void L1GtfeExtWord::setBstSourceWord64(cms_uint64_t& word64, const int iWord) {
477 
478  // BST always in the last word of GTFE extended - size must be correct!
479  int gtfeSize = this->getSize();
480 
481  int BstSourceWord = gtfeSize/8 - 1; // counting starts at 0
482 
483  if (iWord == BstSourceWord) {
484  word64 = word64 | (static_cast<cms_uint64_t> (m_bstSource)
485  << BstSourceShift);
486  }
487 
488 }
489 
490 
491 // get the size of the GTFE block in GT EVM record (in multiple of 8 bits)
492 const unsigned int L1GtfeExtWord::getSize() const {
493 
494  L1GtfeWord gtfeWord;
495  unsigned int gtfeSize = gtfeWord.getSize();
496 
497  unsigned int gtfeExtSize;
498 
499  // 2 bytes to write if real BST message or simulated BST message
500  unsigned int bytesBstWriter = 2;
501 
502  // size of BST block, using rounded 64-bit words (8 bytes per 64-bit word)
503 
504  unsigned int bstSize = m_bst.size();
505 
506  if ( (bstSize +bytesBstWriter )%8 == 0) {
507  gtfeExtSize = gtfeSize + bstSize + bytesBstWriter;
508  }
509  else {
510  gtfeExtSize = gtfeSize + bstSize + bytesBstWriter + (8 - (bstSize + bytesBstWriter)%8 );
511  }
512 
513  return gtfeExtSize;
514 }
515 
516 
517 
518 // resize the BST vector to get the right size of the block
519 void L1GtfeExtWord::resize(int bstSizeBytes) {
520 
521  m_bst.resize(bstSizeBytes);
522 
523 }
524 
525 // reset the content of a L1GtfeExtWord
527 {
528 
530  m_bst.clear();
531 
532 }
533 
534 // pretty print the content of a L1GtfeWord
535 void L1GtfeExtWord::print(std::ostream& myCout) const {
536 
537  myCout << "\n L1GtfeExtWord::print \n" << std::endl;
538 
539  unsigned int sizeW64 = 64;
540  unsigned int dataBlocksPerLine = sizeW64 / 8; // 8x8 bits per line
541 
542  L1GtfeWord::print(myCout);
543 
544  unsigned int numberBstBlocks = m_bst.size();
545 
546  myCout << "\n BST ";
547 
548  if (numberBstBlocks == 0) {
549 
550  myCout << "\n BST source [hex]: " << std::hex << std::setw(4)
551  << std::setfill('0') << m_bstSource << std::setfill(' ')
552  << std::dec << std::endl;
553 
554  return;
555  }
556 
557  for (unsigned int iB = 0; iB < numberBstBlocks; iB += dataBlocksPerLine) {
558 
559  myCout << "\n" << std::hex << " hex: ";
560 
561  for (unsigned int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
562 
563  if (jB >= numberBstBlocks) {
564  break;
565  }
566 
567  myCout << std::setw(2) << std::setfill('0') << m_bst[jB] << " "
568  << std::setfill(' ');
569  }
570 
571  myCout << "\n" << std::dec << " dec: ";
572 
573  for (unsigned int jB = iB; jB < dataBlocksPerLine + iB; ++jB) {
574 
575  if (jB >= numberBstBlocks) {
576  break;
577  }
578 
579  myCout << std::setw(3) << std::setfill('0') << m_bst[jB] << " "
580  << std::setfill(' ');
581  }
582 
583  myCout << std::endl;
584 
585  }
586 
587  myCout << "\n BST source [hex]: " << std::hex << std::setw(4)
588  << std::setfill('0') << m_bstSource << std::setfill(' ')
589  << std::dec << std::endl;
590 
591 }
592 
593 void L1GtfeExtWord::unpack(const unsigned char* gtfePtr)
594 {
595  LogDebug("L1GtfeExtWord")
596  << "\nUnpacking GTFE block.\n"
597  << std::endl;
598 
599  L1GtfeWord::unpack(gtfePtr);
600 
601  // TODO make BlockSize protected & use friends instead of creating L1GtfeWord?
602  L1GtfeWord gtfeWord;
603  const unsigned char* gtfeExtPtr = gtfePtr + gtfeWord.getSize();
604 
605  const cms_uint64_t* payload =
606  reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(gtfeExtPtr));
607 
608  int BlockSizeExt = this->getSize()/8;
609  int NumberBstBlocks = m_bst.size();
610 
611  if (edm::isDebugEnabled() ) {
612 
613  for (int iWord = BstFirstWord; iWord < BlockSizeExt; ++iWord) {
614 
615  int jWord = iWord - BstFirstWord;
616  LogTrace("L1GtfeExtWord")
617  << std::setw(4) << iWord << " "
618  << std::hex << std::setfill('0')
619  << std::setw(16) << payload[jWord]
620  << std::dec << std::setfill(' ')
621  << std::endl;
622 
623  }
624  }
625 
626  int blocksPerWord = sizeof(cms_uint64_t)*8/BstBitSize;
627 
628  for (int iB = 0; iB < NumberBstBlocks; ++iB) {
629 
630  // keep capitalization for similarity with other functions
631  int BstWord = iB/blocksPerWord;
632 
633  setBst(payload[BstWord], iB);
634 
635  }
636 
637 }
638 
639 
640 
641 
642 // static class members
643 
644 // block description in the raw GT record
645 
646 // index of first word for BST blocks
647 const int L1GtfeExtWord::BstFirstWord = 2;
648 
649 // size in bits for a BST block
650 const int L1GtfeExtWord::BstBitSize = 8;
651 
652 // BST block mask, correlated with the number of bits of a block
653 // 8 bit = 0xFF
655 
656 // BST blocks: conversion to defined quantities (LHC-BOB-ES-0001)
657 
659 const int L1GtfeExtWord::GpsTimeLastBlock = 7;
660 
663 
666 
669 
670 const int L1GtfeExtWord::BeamModeFirstBlock = 26;
671 const int L1GtfeExtWord::BeamModeLastBlock = 27;
672 
675 
678 
681 
684 
687 
688 // BST
689 const cms_uint64_t L1GtfeExtWord::BstSourceMask = 0xFFFF000000000000ULL;
690 const int L1GtfeExtWord::BstSourceShift = 48;
691 
692 
693 
#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:231
void setBstSource(const cms_uint16_t bstSourceVal)
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeWord
Definition: L1GtfeWord.cc:323
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 reset()
reset 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:71
static const int ParticleTypeBeam2FirstBlock
virtual void reset()
reset the content of a L1GtfeWord
Definition: L1GtfeWord.cc:308
bool operator!=(const L1GtfeExtWord &) const
unequal operator
virtual void unpack(const unsigned char *gtfePtr)
static const int BeamMomentumFirstBlock
tuple result
Definition: query.py:137
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.
virtual ~L1GtfeExtWord()
destructor
static const int BeamModeLastBlock
virtual void print(std::ostream &myCout) const
pretty print the content of a L1GtfeExtWord
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
const cms_uint16_t beamMode() const
static const int BeamModeFirstBlock
virtual void unpack(const unsigned char *gtfePtr)
Definition: L1GtfeWord.cc:382
const cms_uint16_t particleTypeBeam1() const
static const int LhcFillNumberFirstBlock