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