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