Line Code
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 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
/**
 * \class L1GTEvmDigiToRaw
 *
 *
 * Description: generate raw data from digis.
 *
 * Implementation:
 *    <TODO: enter implementation details>
 *
 * \author: Vasile Mihai Ghete - HEPHY Vienna
 *
 *
 */

// this class header
#include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GTEvmDigiToRaw.h"

// system include files
#include <vector>
#include <iostream>
#include <iomanip>

// user include files
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"

#include "DataFormats/FEDRawData/interface/FEDHeader.h"
#include "DataFormats/FEDRawData/interface/FEDTrailer.h"
#include "FWCore/Utilities/interface/CRC16.h"

#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"

#include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
#include "DataFormats/L1GlobalTrigger/interface/L1TcsWord.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/MessageLogger/interface/MessageDrop.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "CondFormats/L1TObjects/interface/L1GtFwd.h"
#include "CondFormats/L1TObjects/interface/L1GtBoard.h"

#include "CondFormats/L1TObjects/interface/L1GtBoardMaps.h"
#include "CondFormats/DataRecord/interface/L1GtBoardMapsRcd.h"

// constructor(s)
L1GTEvmDigiToRaw::L1GTEvmDigiToRaw(const edm::ParameterSet& pSet)
    : m_evmGtFedId(pSet.getUntrackedParameter<int>("EvmGtFedId", FEDNumbering::MINTriggerGTPFEDID)),
      m_evmGtInputToken(consumes<L1GlobalTriggerEvmReadoutRecord>(pSet.getParameter<edm::InputTag>("EvmGtInputTag"))),
      m_evmGtInputTag(pSet.getParameter<edm::InputTag>("EvmGtInputTag")),
      m_l1GtBMToken(esConsumes<L1GtBoardMaps, L1GtBoardMapsRcd>()),
      m_activeBoardsMaskGt(pSet.getParameter<unsigned int>("ActiveBoardsMask")),
      m_totalBxInEvent(0),
      m_minBxInEvent(0),
      m_maxBxInEvent(),
      m_verbosity(pSet.getUntrackedParameter<int>("Verbosity", 0)),
      m_isDebugEnabled(edm::isDebugEnabled())

{
  LogDebug("L1GTEvmDigiToRaw") << "\nMask for active boards (hex format): " << std::hex
                               << std::setw(sizeof(m_activeBoardsMaskGt) * 2) << std::setfill('0')
                               << m_activeBoardsMaskGt << std::dec << std::setfill(' ')
                               << "\nInput tag for EVM GT record: " << m_evmGtInputTag
                               << "\nFED Id for EVM GT record: " << m_evmGtFedId << " \n"
                               << std::endl;

  //
  produces<FEDRawDataCollection>();
}

// member functions

// method called to produce the data
void L1GTEvmDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
  // define new FEDRawDataCollection
  // it contains ALL FEDs in an event
  std::unique_ptr<FEDRawDataCollection> allFedRawData(new FEDRawDataCollection);

  FEDRawData& gtRawData = allFedRawData->FEDData(m_evmGtFedId);

  // get records from EventSetup

  //  board maps
  edm::ESHandle<L1GtBoardMaps> l1GtBM = evSetup.getHandle(m_l1GtBMToken);

  const std::vector<L1GtBoard> boardMaps = l1GtBM->gtBoardMaps();
  int boardMapsSize = boardMaps.size();

  typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;

  // create an ordered vector for the GT EVM record
  // header (pos 0 in record) and trailer (last position in record)
  // not included, as they are not in board list
  std::vector<L1GtBoard> gtRecordMap;
  gtRecordMap.reserve(boardMapsSize);

  for (int iPos = 0; iPos < boardMapsSize; ++iPos) {
    for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
      if (itBoard->gtPositionEvmRecord() == iPos) {
        gtRecordMap.push_back(*itBoard);
        break;
      }
    }
  }

  // get L1GlobalTriggerEvmReadoutRecord
  edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtReadoutRecord;
  iEvent.getByToken(m_evmGtInputToken, gtReadoutRecord);

  if (!gtReadoutRecord.isValid()) {
    edm::LogWarning("L1GTEvmDigiToRaw") << "\nWarning: L1GlobalTriggerEvmReadoutRecord with input tag "
                                        << m_evmGtInputTag
                                        << "\nrequested in configuration, but not found in the event."
                                        << "\nQuit packing this event" << std::endl;

    // put the raw data in the event
    iEvent.put(std::move(allFedRawData));

    return;
  }

  if (m_verbosity && m_isDebugEnabled) {
    std::ostringstream myCoutStream;
    gtReadoutRecord->print(myCoutStream);
    LogTrace("L1GTEvmDigiToRaw") << "\n The following L1 GT EVM readout record will be packed.\n"
                                 << " Some boards could be disabled before packing,"
                                 << " see detailed board packing.\n"
                                 << myCoutStream.str() << "\n"
                                 << std::endl;
  }

  // get GTFE block
  L1GtfeExtWord gtfeBlock = gtReadoutRecord->gtfeWord();

  // get the number of Bx in the event for alternative 0 and alternative 1
  cms_uint16_t recordLength0 = gtfeBlock.recordLength();
  cms_uint16_t recordLength1 = gtfeBlock.recordLength1();

  // length of BST record (in bytes)
  m_bstLengthBytes = static_cast<int>(gtfeBlock.bstLengthBytes());

  // get list of active blocks from the GTFE block
  // and mask some blocks, if required
  // blocks not active are not written to the record

  cms_uint16_t activeBoardsGtInitial = gtfeBlock.activeBoards();
  cms_uint16_t altNrBxBoardInitial = gtfeBlock.altNrBxBoard();

  // mask some boards, if needed

  cms_uint16_t activeBoardsGt = activeBoardsGtInitial & m_activeBoardsMaskGt;

  if (m_verbosity && m_isDebugEnabled) {
    LogDebug("L1GTEvmDigiToRaw") << "\nActive boards before masking(hex format): " << std::hex
                                 << std::setw(sizeof(activeBoardsGtInitial) * 2) << std::setfill('0')
                                 << activeBoardsGtInitial << std::dec << std::setfill(' ')
                                 << "\nActive boards after masking(hex format):  " << std::hex
                                 << std::setw(sizeof(activeBoardsGt) * 2) << std::setfill('0') << activeBoardsGt
                                 << std::dec << std::setfill(' ') << " \n"
                                 << std::endl;
  }

  // get the size of the record

  unsigned int gtDataSize = 0;

  unsigned int headerSize = 8;
  gtDataSize += headerSize;

  for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
    if (itBoard->gtBoardType() == GTFE) {
      gtDataSize += gtfeBlock.getSize();
      continue;
    }

    int iActiveBit = itBoard->gtBitEvmActiveBoards();
    bool activeBoardToPack = false;

    int altNrBxBoardVal = -1;

    if (iActiveBit >= 0) {
      activeBoardToPack = activeBoardsGt & (1 << iActiveBit);

      altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;

      if (altNrBxBoardVal == 1) {
        m_totalBxInEvent = recordLength1;
      } else if (altNrBxBoardVal == 0) {
        m_totalBxInEvent = recordLength0;
      } else {
        if (m_verbosity) {
          edm::LogWarning("L1GTEvmDigiToRaw")
              << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal << " for board " << std::hex
              << (itBoard->gtBoardId()) << std::dec << "\n  iActiveBit =            " << iActiveBit
              << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
              << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt << std::dec
              << "\n  activeBoardToPack =   " << activeBoardToPack << "\n Set altNrBxBoardVal tentatively to "
              << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
              << std::endl;
        }

        m_totalBxInEvent = recordLength0;
      }
    } else {
      // board not in the ActiveBoards for the record
      continue;
    }

    if (activeBoardToPack) {
      switch (itBoard->gtBoardType()) {
        case GTFE: {
          // size already added;
        }

        break;
        case FDL: {
          L1GtFdlWord fdlBlock;
          gtDataSize += m_totalBxInEvent * fdlBlock.getSize();
        }

        break;
        case TCS: {
          L1TcsWord tcsBlock;
          gtDataSize += tcsBlock.getSize();
        }

        break;
        case TIM: {
          // not considered
        }

        break;
        default: {
          // do nothing, all blocks are given in GtBoardType enum
        }

        break;
      }
    }
  }

  unsigned int trailerSize = 8;
  gtDataSize += trailerSize;

  // resize, GT raw data record has variable length,
  // depending on active boards (read in GTFE)
  gtRawData.resize(gtDataSize);

  // ptrGt: pointer to the beginning of GT record in the raw data

  unsigned char* ptrGt = gtRawData.data();
  unsigned char* ptrGtBegin = gtRawData.data();

  if (m_verbosity && m_isDebugEnabled) {
    LogDebug("L1GTEvmDigiToRaw") << "\n Size of raw data: " << gtRawData.size() << "\n" << std::endl;
  }

  // ------- pack boards -------

  // pack header
  packHeader(ptrGt, iEvent);
  ptrGt += headerSize;  // advance with header size

  // loop over other blocks in the raw record, if they are active

  for (CItBoardMaps itBoard = gtRecordMap.begin(); itBoard != gtRecordMap.end(); ++itBoard) {
    if (itBoard->gtBoardType() == GTFE) {
      packGTFE(evSetup, ptrGt, gtfeBlock, activeBoardsGt);

      if (m_verbosity && m_isDebugEnabled) {
        std::ostringstream myCoutStream;
        gtfeBlock.print(myCoutStream);
        LogTrace("L1GTEvmDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
      }

      ptrGt += gtfeBlock.getSize();  // advance with GTFE block size

      continue;
    }

    // pack modules other than GTFE if they are active

    int iActiveBit = itBoard->gtBitEvmActiveBoards();
    bool activeBoardToPack = false;

    int altNrBxBoardVal = -1;

    if (iActiveBit >= 0) {
      activeBoardToPack = activeBoardsGt & (1 << iActiveBit);

      altNrBxBoardVal = (altNrBxBoardInitial & (1 << iActiveBit)) >> iActiveBit;

      if (altNrBxBoardVal == 1) {
        m_totalBxInEvent = recordLength1;
      } else if (altNrBxBoardVal == 0) {
        m_totalBxInEvent = recordLength0;
      } else {
        if (m_verbosity) {
          edm::LogWarning("L1GTEvmDigiToRaw")
              << "\n\nWARNING: Wrong value altNrBxBoardVal = " << altNrBxBoardVal << " for board " << std::hex
              << (itBoard->gtBoardId()) << std::dec << "\n  iActiveBit =            " << iActiveBit
              << "\n  altNrBxBoardInitial = 0x" << std::hex << altNrBxBoardInitial << std::dec
              << "\n  activeBoardsGt =      0x" << std::hex << activeBoardsGt << std::dec
              << "\n  activeBoardToPack =   " << activeBoardToPack << "\n Set altNrBxBoardVal tentatively to "
              << recordLength0 << "\n Job may crash or produce wrong results!\n\n"
              << std::endl;
        }

        m_totalBxInEvent = recordLength0;
      }

      m_minBxInEvent = (m_totalBxInEvent + 1) / 2 - m_totalBxInEvent;
      m_maxBxInEvent = (m_totalBxInEvent + 1) / 2 - 1;

    } else {
      // board not in the ActiveBoards for the record
      continue;
    }

    if (activeBoardToPack) {
      if (m_verbosity && m_isDebugEnabled) {
        LogDebug("L1GTEvmDigiToRaw") << "\nBoard " << std::hex << "0x" << (itBoard->gtBoardId()) << std::dec
                                     << "\n  Number of bunch crosses in the record: " << m_totalBxInEvent << " = "
                                     << "[" << m_minBxInEvent << ", " << m_maxBxInEvent << "] BX\n"
                                     << std::endl;
      }

      // active board, pack it
      switch (itBoard->gtBoardType()) {
        case TCS: {
          L1TcsWord tcsBlock = gtReadoutRecord->tcsWord();
          packTCS(evSetup, ptrGt, tcsBlock);

          if (m_verbosity && m_isDebugEnabled) {
            std::ostringstream myCoutStream;
            tcsBlock.print(myCoutStream);
            LogTrace("L1GTEvmDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
          }

          ptrGt += tcsBlock.getSize();  // advance with TCS block size

        } break;
        case FDL: {
          for (int iBxInEvent = m_minBxInEvent; iBxInEvent <= m_maxBxInEvent; ++iBxInEvent) {
            L1GtFdlWord fdlBlock = gtReadoutRecord->gtFdlWord(iBxInEvent);
            packFDL(evSetup, ptrGt, fdlBlock);

            if (m_verbosity && m_isDebugEnabled) {
              std::ostringstream myCoutStream;
              fdlBlock.print(myCoutStream);
              LogTrace("L1GTEvmDigiToRaw") << myCoutStream.str() << "\n" << std::endl;
            }

            ptrGt += fdlBlock.getSize();  // advance with FDL block size
          }

        } break;
        default: {
          // do nothing, all blocks are given in GtBoardType enum
          break;
        }
      }
    }
  }

  // pack trailer
  packTrailer(ptrGt, ptrGtBegin, gtDataSize);

  // put the raw data in the event

  iEvent.put(std::move(allFedRawData));
}

// pack header
void L1GTEvmDigiToRaw::packHeader(unsigned char* ptrGt, edm::Event& iEvent) {
  // TODO FIXME where from to get all numbers?

  // Event Trigger type identifier
  int triggerTypeVal = 0;

  // Level-1 event number generated by the TTC system
  int lvl1IdVal = iEvent.id().event();

  // The bunch crossing number
  int bxCross = iEvent.bunchCrossing();
  cms_uint16_t bxCrossHw = 0;
  if ((bxCross & 0xFFF) == bxCross) {
    bxCrossHw = static_cast<cms_uint16_t>(bxCross);
  } else {
    bxCrossHw = 0;  // Bx number too large, set to 0!
    if (m_verbosity && m_isDebugEnabled) {
      LogDebug("L1GTEvmDigiToRaw") << "\nBunch cross number [hex] = " << std::hex << bxCross
                                   << "\n  larger than 12 bits. Set to 0! \n"
                                   << std::dec << std::endl;
    }
  }
  int bxIdVal = bxCrossHw;

  // Identifier of the FED
  int sourceIdVal = m_evmGtFedId;

  // Version identifier of the FED data format
  int versionVal = 0;

  // 0 -> the current header word is the last one.
  // 1-> other header words can follow
  // (always 1 for ECAL)
  bool moreHeadersVal = false;

  FEDHeader gtFEDHeader(ptrGt);

  gtFEDHeader.set(ptrGt, triggerTypeVal, lvl1IdVal, bxIdVal, sourceIdVal, versionVal, moreHeadersVal);
}

// pack the GTFE block
void L1GTEvmDigiToRaw::packGTFE(const edm::EventSetup& evSetup,
                                unsigned char* ptrGt,
                                L1GtfeExtWord& gtfeBlock,
                                cms_uint16_t activeBoardsGtValue) {
  if (m_verbosity && m_isDebugEnabled) {
    LogDebug("L1GTEvmDigiToRaw") << "\nPacking GTFE \n" << std::endl;
  }

  int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

  // initialize the required number of word64
  int nrWord64 = gtfeBlock.getSize() / uLength;
  std::vector<cms_uint64_t> tmpWord64;
  tmpWord64.resize(nrWord64);

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    tmpWord64[iWord] = 0x0000000000000000ULL;
  }

  // fill the values in the words
  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    gtfeBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
    gtfeBlock.setRecordLength1Word64(tmpWord64[iWord], iWord);
    gtfeBlock.setRecordLengthWord64(tmpWord64[iWord], iWord);
    gtfeBlock.setBxNrWord64(tmpWord64[iWord], iWord);
    gtfeBlock.setSetupVersionWord64(tmpWord64[iWord], iWord);
    gtfeBlock.setActiveBoardsWord64(tmpWord64[iWord], iWord, activeBoardsGtValue);
    gtfeBlock.setAltNrBxBoardWord64(tmpWord64[iWord], iWord);
    gtfeBlock.setTotalTriggerNrWord64(tmpWord64[iWord], iWord);

    for (int iBst = 0; iBst < m_bstLengthBytes; ++iBst) {
      gtfeBlock.setBstWord64(tmpWord64[iWord], iBst, iWord);
    }
  }

  // put the words in the FED record

  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    *pw++ = tmpWord64[iWord];

    if (m_verbosity && m_isDebugEnabled) {
      LogTrace("L1GTEvmDigiToRaw") << std::setw(4) << iWord << "  " << std::hex << std::setfill('0') << std::setw(16)
                                   << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
    }
  }
}

// pack the TCS block
void L1GTEvmDigiToRaw::packTCS(const edm::EventSetup& evSetup, unsigned char* ptrGt, L1TcsWord& tcsBlock) {
  if (m_verbosity && m_isDebugEnabled) {
    LogDebug("L1GTEvmDigiToRaw") << "\nPacking TCS \n" << std::endl;
  }

  int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

  // initialize the required number of word64
  int nrWord64 = tcsBlock.getSize() / uLength;
  std::vector<cms_uint64_t> tmpWord64;
  tmpWord64.resize(nrWord64);

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    tmpWord64[iWord] = 0x0000000000000000ULL;
  }

  // fill the values in the words
  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    tcsBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
    tcsBlock.setBxNrWord64(tmpWord64[iWord], iWord);
    tcsBlock.setDaqNrWord64(tmpWord64[iWord], iWord);
    tcsBlock.setTriggerTypeWord64(tmpWord64[iWord], iWord);
    tcsBlock.setStatusWord64(tmpWord64[iWord], iWord);
    tcsBlock.setLuminositySegmentNrWord64(tmpWord64[iWord], iWord);

    tcsBlock.setPartRunNrWord64(tmpWord64[iWord], iWord);
    tcsBlock.setAssignedPartitionsWord64(tmpWord64[iWord], iWord);

    tcsBlock.setPartTrigNrWord64(tmpWord64[iWord], iWord);
    tcsBlock.setEventNrWord64(tmpWord64[iWord], iWord);

    tcsBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
  }

  // put the words in the FED record

  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    *pw++ = tmpWord64[iWord];

    if (m_verbosity && m_isDebugEnabled) {
      LogTrace("L1GTEvmDigiToRaw") << std::setw(4) << iWord << "  " << std::hex << std::setfill('0') << std::setw(16)
                                   << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
    }
  }
}

// pack the FDL block
void L1GTEvmDigiToRaw::packFDL(const edm::EventSetup& evSetup, unsigned char* ptrGt, L1GtFdlWord& fdlBlock) {
  if (m_verbosity && m_isDebugEnabled) {
    LogDebug("L1GTEvmDigiToRaw") << "\nPacking FDL \n" << std::endl;
  }

  int uLength = L1GlobalTriggerReadoutSetup::UnitLength;

  // initialize the required number of word64
  int nrWord64 = fdlBlock.getSize() / uLength;
  std::vector<cms_uint64_t> tmpWord64;
  tmpWord64.resize(nrWord64);

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    tmpWord64[iWord] = 0x0000000000000000ULL;
  }

  // fill the values in the words
  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    fdlBlock.setBoardIdWord64(tmpWord64[iWord], iWord);
    fdlBlock.setBxInEventWord64(tmpWord64[iWord], iWord);
    fdlBlock.setBxNrWord64(tmpWord64[iWord], iWord);
    fdlBlock.setEventNrWord64(tmpWord64[iWord], iWord);

    fdlBlock.setGtTechnicalTriggerWordWord64(tmpWord64[iWord], iWord);

    fdlBlock.setGtDecisionWordAWord64(tmpWord64[iWord], iWord);
    fdlBlock.setGtDecisionWordBWord64(tmpWord64[iWord], iWord);

    fdlBlock.setGtDecisionWordExtendedWord64(tmpWord64[iWord], iWord);

    fdlBlock.setPhysicsDeclaredWord64(tmpWord64[iWord], iWord);
    fdlBlock.setGtPrescaleFactorIndexTechWord64(tmpWord64[iWord], iWord);
    fdlBlock.setGtPrescaleFactorIndexAlgoWord64(tmpWord64[iWord], iWord);
    fdlBlock.setNoAlgoWord64(tmpWord64[iWord], iWord);
    fdlBlock.setFinalORWord64(tmpWord64[iWord], iWord);

    fdlBlock.setOrbitNrWord64(tmpWord64[iWord], iWord);
    fdlBlock.setLumiSegmentNrWord64(tmpWord64[iWord], iWord);
    fdlBlock.setLocalBxNrWord64(tmpWord64[iWord], iWord);
  }

  // put the words in the FED record

  cms_uint64_t* pw = reinterpret_cast<cms_uint64_t*>(const_cast<unsigned char*>(ptrGt));

  for (int iWord = 0; iWord < nrWord64; ++iWord) {
    *pw++ = tmpWord64[iWord];

    if (m_verbosity && m_isDebugEnabled) {
      LogTrace("L1GTEvmDigiToRaw") << std::setw(4) << iWord << "  " << std::hex << std::setfill('0') << std::setw(16)
                                   << tmpWord64[iWord] << std::dec << std::setfill(' ') << std::endl;
    }
  }
}

// pack trailer
void L1GTEvmDigiToRaw::packTrailer(unsigned char* ptrGt, unsigned char* ptrGtBegin, int dataSize) {
  // TODO FIXME where from to get all numbers?

  // The length of the event fragment counted in 64-bit words including header and trailer
  int lengthVal = dataSize / 8;

  // Cyclic Redundancy Code of the event fragment including header and trailer
  int crcVal = evf::compute_crc(ptrGtBegin, dataSize);

  // Event fragment status information
  int evtStatusVal = 0;

  // Current value of the Trigger Throttling System bits.
  int ttsBitsVal = 0;

  // 0 -> the current trailer word is the last one.
  // 1-> other trailer words can follow
  // (always 0 for ECAL)
  bool moreTrailersVal = false;

  FEDTrailer gtFEDTrailer(ptrGt);
  gtFEDTrailer.set(ptrGt, lengthVal, crcVal, evtStatusVal, ttsBitsVal, moreTrailersVal);
}

// static class members