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 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
#include "EventFilter/GctRawToDigi/src/GctFormatTranslateV38.h"

// C++ headers
#include <iostream>
#include <cassert>
#include <algorithm>
#include <cmath>

// Framework headers
#include "FWCore/MessageLogger/interface/MessageLogger.h"

// Namespace resolution
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;

// INITIALISE STATIC VARIABLES
/*** Setup BlockID to BlockLength Map ***/
const GctFormatTranslateV38::BlockLengthMap GctFormatTranslateV38::m_blockLength = {
    // Miscellaneous Blocks
    {0x000, 0},  // NULL
    // ConcJet FPGA
    {0x580, 12},  // ConcJet: Input TrigPathA (Jet Cands)
    {0x581, 2},   // ConcJet: Input TrigPathB (HF Rings)
    {0x582, 4},   // ConcJet: Input TrigPathC (MissHt)
    {0x583, 8},   // ConcJet: Jet Cands and Counts Output to GT
    {0x587, 4},   // ConcJet: BX & Orbit Info
    // ConcElec FPGA
    {0x680, 16},  // ConcElec: Input TrigPathA (EM Cands)
    {0x681, 6},   // ConcElec: Input TrigPathB (Et Sums)
    {0x682, 2},   // ConcElec: Input TrigPathC (Ht Sums)
    {0x683, 6},   // ConcElec: EM Cands and Energy Sums Output to GT
    {0x686, 2},   // ConcElec: Test (GT Serdes Loopback)
    {0x687, 4},   // ConcElec: BX & Orbit Info
    // Electron Leaf FPGAs
    {0x800, 20},  // Leaf0ElecPosEtaU1: Sort Input
    {0x803, 4},   // Leaf0ElecPosEtaU1: Sort Output
    {0x804, 15},  // Leaf0ElecPosEtaU1: Raw Input
    {0x880, 16},  // Leaf0ElecPosEtaU2: Sort Input
    {0x883, 4},   // Leaf0ElecPosEtaU2: Sort Output
    {0x884, 12},  // Leaf0ElecPosEtaU2: Raw Input
    {0xc00, 20},  // Leaf0ElecNegEtaU1: Sort Input
    {0xc03, 4},   // Leaf0ElecNegEtaU1: Sort Output
    {0xc04, 15},  // Leaf0ElecNegEtaU1: Raw Input
    {0xc80, 16},  // Leaf0ElecNegEtaU2: Sort Input
    {0xc83, 4},   // Leaf0ElecNegEtaU2: Sort Output
    {0xc84, 12},  // Leaf0ElecNegEtaU2: Raw Input
    // Wheel Pos-eta Jet FPGA
    {0x300, 27},  // WheelPosEtaJet: Input TrigPathA (Jet Sort)
    {0x301, 3},   // WheelPosEtaJet: Input TrigPathB (MissHt)
    {0x303, 6},   // WheelPosEtaJet: Output TrigPathA (Jet Sort)
    {0x305, 2},   // WheelPosEtaJet: Output TrigPathB (MissHt)
    {0x306,
     32},  // WheelPosEtaJet: Test (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x307,
     4},  // WheelPosEtaJet: Info (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Pos-eta Energy FPGA
    {0x380, 21},  // WheelPosEtaEnergy: Input TrigPathA (Et)
    {0x381, 6},   // WheelPosEtaEnergy: Input TrigPathB (Ht)
    {0x383, 7},   // WheelPosEtaEnergy: Output TrigPathA (Et)
    {0x385, 2},   // WheelPosEtaEnergy: Output TrigPathB (Ht)
    {0x386, 32},  // WheelPosEtaEnergy: Test
    {0x387,
     6},  // WheelPosEtaEnergy: BX & Orbit Info   (Potential data incompatibility between V24/V25 where block length=4, and V27.1 where block length=6)
    // Wheel Neg-eta Jet FPGA
    {0x700, 27},  // WheelNegEtaJet: Input TrigPathA (Jet Sort)
    {0x701, 3},   // WheelNegEtaJet: Input TrigPathB (MissHt)
    {0x703, 6},   // WheelNegEtaJet: Output TrigPathA (Jet Sort)
    {0x705, 2},   // WheelNegEtaJet: Output TrigPathB (MissHt)
    {0x706,
     32},  // WheelNegEtaJet: Test (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x707,
     4},  // WheelNegEtaJet: Info (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Neg-eta Energy FPGA
    {0x780, 21},  // WheelNegEtaEnergy: Input TrigPathA (Et)
    {0x781, 6},   // WheelNegEtaEnergy: Input TrigPathB (Ht)
    {0x783, 7},   // WheelNegEtaEnergy: Output TrigPathA (Et)
    {0x785, 2},   // WheelNegEtaEnergy: Output TrigPathB (Ht)
    {0x786, 32},  // WheelNegEtaEnergy: Test
    {0x787,
     6},  // WheelNegEtaEnergy: BX & Orbit Info   (Potential data incompatibility between V24/V25 where block length=4, and V27.1 where block length=6)
    // Jet Leaf FPGAs - Positive Eta
    {0x900, 13},  // Leaf1JetPosEtaU1: JF2 Input
    {0x901, 3},   // Leaf1JetPosEtaU1: JF2 Shared Received
    {0x902, 3},   // Leaf1JetPosEtaU1: JF2 Shared Sent
    {0x903, 10},  // Leaf1JetPosEtaU1: JF2 Output
    {0x904, 8},   // Leaf1JetPosEtaU1: JF2 Raw Input
    {0x908, 13},  // Leaf1JetPosEtaU1: JF3 Input
    {0x909, 3},   // Leaf1JetPosEtaU1: JF3 Shared Received
    {0x90a, 3},   // Leaf1JetPosEtaU1: JF3 Shared Sent
    {0x90b, 10},  // Leaf1JetPosEtaU1: JF3 Output
    {0x90c, 8},   // Leaf1JetPosEtaU1: JF3 Raw Input
    {0x980, 6},   // Leaf1JetPosEtaU2: Eta0 Input
    {0x984, 6},   // Leaf1JetPosEtaU2: Eta0 Raw Input
    {0x988, 13},  // Leaf1JetPosEtaU2: JF1 Input
    {0x989, 3},   // Leaf1JetPosEtaU2: JF1 Shared Received
    {0x98a, 3},   // Leaf1JetPosEtaU2: JF1 Shared Sent
    {0x98b, 10},  // Leaf1JetPosEtaU2: JF1 Output
    {0x98c, 8},   // Leaf1JetPosEtaU2: JF1 Raw Input
    {0xa00, 13},  // Leaf2JetPosEtaU1: JF2 Input
    {0xa01, 3},   // Leaf2JetPosEtaU1: JF2 Shared Received
    {0xa02, 3},   // Leaf2JetPosEtaU1: JF2 Shared Sent
    {0xa03, 10},  // Leaf2JetPosEtaU1: JF2 Output
    {0xa04, 8},   // Leaf2JetPosEtaU1: JF2 Raw Input
    {0xa08, 13},  // Leaf2JetPosEtaU1: JF3 Input
    {0xa09, 3},   // Leaf2JetPosEtaU1: JF3 Shared Received
    {0xa0a, 3},   // Leaf2JetPosEtaU1: JF3 Shared Sent
    {0xa0b, 10},  // Leaf2JetPosEtaU1: JF3 Output
    {0xa0c, 8},   // Leaf2JetPosEtaU1: JF3 Raw Input
    {0xa80, 6},   // Leaf2JetPosEtaU2: Eta0 Input
    {0xa84, 6},   // Leaf2JetPosEtaU2: Eta0 Raw Input
    {0xa88, 13},  // Leaf2JetPosEtaU2: JF1 Input
    {0xa89, 3},   // Leaf2JetPosEtaU2: JF1 Shared Received
    {0xa8a, 3},   // Leaf2JetPosEtaU2: JF1 Shared Sent
    {0xa8b, 10},  // Leaf2JetPosEtaU2: JF1 Output
    {0xa8c, 8},   // Leaf2JetPosEtaU2: JF1 Raw Input
    {0xb00, 13},  // Leaf3JetPosEtaU1: JF2 Input
    {0xb01, 3},   // Leaf3JetPosEtaU1: JF2 Shared Received
    {0xb02, 3},   // Leaf3JetPosEtaU1: JF2 Shared Sent
    {0xb03, 10},  // Leaf3JetPosEtaU1: JF2 Output
    {0xb04, 8},   // Leaf3JetPosEtaU1: JF2 Raw Input
    {0xb08, 13},  // Leaf3JetPosEtaU1: JF3 Input
    {0xb09, 3},   // Leaf3JetPosEtaU1: JF3 Shared Received
    {0xb0a, 3},   // Leaf3JetPosEtaU1: JF3 Shared Sent
    {0xb0b, 10},  // Leaf3JetPosEtaU1: JF3 Output
    {0xb0c, 8},   // Leaf3JetPosEtaU1: JF3 Raw Input
    {0xb80, 6},   // Leaf3JetPosEtaU2: Eta0 Input
    {0xb84, 6},   // Leaf3JetPosEtaU2: Eta0 Raw Input
    {0xb88, 13},  // Leaf3JetPosEtaU2: JF1 Input
    {0xb89, 3},   // Leaf3JetPosEtaU2: JF1 Shared Received
    {0xb8a, 3},   // Leaf3JetPosEtaU2: JF1 Shared Sent
    {0xb8b, 10},  // Leaf3JetPosEtaU2: JF1 Output
    {0xb8c, 8},   // Leaf3JetPosEtaU2: JF1 Raw Input
    // Jet Leaf FPGAs - Negative Eta
    {0xd00, 13},  // Leaf1JetNegEtaU1: JF2 Input
    {0xd01, 3},   // Leaf1JetNegEtaU1: JF2 Shared Received
    {0xd02, 3},   // Leaf1JetNegEtaU1: JF2 Shared Sent
    {0xd03, 10},  // Leaf1JetNegEtaU1: JF2 Output
    {0xd04, 8},   // Leaf1JetNegEtaU1: JF2 Raw Input
    {0xd08, 13},  // Leaf1JetNegEtaU1: JF3 Input
    {0xd09, 3},   // Leaf1JetNegEtaU1: JF3 Shared Received
    {0xd0a, 3},   // Leaf1JetNegEtaU1: JF3 Shared Sent
    {0xd0b, 10},  // Leaf1JetNegEtaU1: JF3 Output
    {0xd0c, 8},   // Leaf1JetNegEtaU1: JF3 Raw Input
    {0xd80, 6},   // Leaf1JetNegEtaU2: Eta0 Input
    {0xd84, 6},   // Leaf1JetNegEtaU2: Eta0 Raw Input
    {0xd88, 13},  // Leaf1JetNegEtaU2: JF1 Input
    {0xd89, 3},   // Leaf1JetNegEtaU2: JF1 Shared Received
    {0xd8a, 3},   // Leaf1JetNegEtaU2: JF1 Shared Sent
    {0xd8b, 10},  // Leaf1JetNegEtaU2: JF1 Output
    {0xd8c, 8},   // Leaf1JetNegEtaU2: JF1 Raw Input
    {0xe00, 13},  // Leaf2JetNegEtaU1: JF2 Input
    {0xe01, 3},   // Leaf2JetNegEtaU1: JF2 Shared Received
    {0xe02, 3},   // Leaf2JetNegEtaU1: JF2 Shared Sent
    {0xe03, 10},  // Leaf2JetNegEtaU1: JF2 Output
    {0xe04, 8},   // Leaf2JetNegEtaU1: JF2 Raw Input
    {0xe08, 13},  // Leaf2JetNegEtaU1: JF3 Input
    {0xe09, 3},   // Leaf2JetNegEtaU1: JF3 Shared Received
    {0xe0a, 3},   // Leaf2JetNegEtaU1: JF3 Shared Sent
    {0xe0b, 10},  // Leaf2JetNegEtaU1: JF3 Output
    {0xe0c, 8},   // Leaf2JetNegEtaU1: JF3 Raw Input
    {0xe80, 6},   // Leaf2JetNegEtaU2: Eta0 Input
    {0xe84, 6},   // Leaf2JetNegEtaU2: Eta0 Raw Input
    {0xe88, 13},  // Leaf2JetNegEtaU2: JF1 Input
    {0xe89, 3},   // Leaf2JetNegEtaU2: JF1 Shared Received
    {0xe8a, 3},   // Leaf2JetNegEtaU2: JF1 Shared Sent
    {0xe8b, 10},  // Leaf2JetNegEtaU2: JF1 Output
    {0xe8c, 8},   // Leaf2JetNegEtaU2: JF1 Raw Input
    {0xf00, 13},  // Leaf3JetNegEtaU1: JF2 Input
    {0xf01, 3},   // Leaf3JetNegEtaU1: JF2 Shared Received
    {0xf02, 3},   // Leaf3JetNegEtaU1: JF2 Shared Sent
    {0xf03, 10},  // Leaf3JetNegEtaU1: JF2 Output
    {0xf04, 8},   // Leaf3JetNegEtaU1: JF2 Raw Input
    {0xf08, 13},  // Leaf3JetNegEtaU1: JF3 Input
    {0xf09, 3},   // Leaf3JetNegEtaU1: JF3 Shared Received
    {0xf0a, 3},   // Leaf3JetNegEtaU1: JF3 Shared Sent
    {0xf0b, 10},  // Leaf3JetNegEtaU1: JF3 Output
    {0xf0c, 8},   // Leaf3JetNegEtaU1: JF3 Raw Input
    {0xf80, 6},   // Leaf3JetNegEtaU2: Eta0 Input
    {0xf84, 6},   // Leaf3JetNegEtaU2: Eta0 Raw Input
    {0xf88, 13},  // Leaf3JetNegEtaU2: JF1 Input
    {0xf89, 3},   // Leaf3JetNegEtaU2: JF1 Shared Received
    {0xf8a, 3},   // Leaf3JetNegEtaU2: JF1 Shared Sent
    {0xf8b, 10},  // Leaf3JetNegEtaU2: JF1 Output
    {0xf8c, 8}    // Leaf3JetNegEtaU2: JF1 Raw Input
};

/*** Setup BlockID to BlockName Map ***/
const GctFormatTranslateV38::BlockNameMap GctFormatTranslateV38::m_blockName = {
    // Miscellaneous Blocks
    {0x000, "NULL"},
    // ConcJet FPGA
    {0x580, "ConcJet: Input TrigPathA (Jet Cands)"},
    {0x581, "ConcJet: Input TrigPathB (HF Rings)"},
    {0x582, "ConcJet: Input TrigPathC (MissHt)"},
    {0x583, "ConcJet: Jet Cands and Counts Output to GT"},
    {0x587, "ConcJet: BX & Orbit Info"},
    // ConcElec FPGA
    {0x680, "ConcElec: Input TrigPathA (EM Cands)"},
    {0x681, "ConcElec: Input TrigPathB (Et Sums)"},
    {0x682, "ConcElec: Input TrigPathC (Ht Sums)"},
    {0x683, "ConcElec: EM Cands and Energy Sums Output to GT"},
    {0x686, "ConcElec: Test (GT Serdes Loopback)"},
    {0x687, "ConcElec: BX & Orbit Info"},
    // Electron Leaf FPGAs
    {0x800, "Leaf0ElecPosEtaU1: Sort Input"},
    {0x803, "Leaf0ElecPosEtaU1: Sort Output"},
    {0x804, "Leaf0ElecPosEtaU1: Raw Input"},
    {0x880, "Leaf0ElecPosEtaU2: Sort Input"},
    {0x883, "Leaf0ElecPosEtaU2: Sort Output"},
    {0x884, "Leaf0ElecPosEtaU2: Raw Input"},
    {0xc00, "Leaf0ElecNegEtaU1: Sort Input"},
    {0xc03, "Leaf0ElecNegEtaU1: Sort Output"},
    {0xc04, "Leaf0ElecNegEtaU1: Raw Input"},
    {0xc80, "Leaf0ElecNegEtaU2: Sort Input"},
    {0xc83, "Leaf0ElecNegEtaU2: Sort Output"},
    {0xc84, "Leaf0ElecNegEtaU2: Raw Input"},
    // Wheel Pos-eta Jet FPGA
    {0x300, "WheelPosEtaJet: Input TrigPathA (Jet Sort)"},
    {0x301, "WheelPosEtaJet: Input TrigPathB (MissHt)"},
    {0x303, "WheelPosEtaJet: Output TrigPathA (Jet Sort)"},
    {0x305, "WheelPosEtaJet: Output TrigPathB (MissHt)"},
    {0x306,
     "WheelPosEtaJet: Test (deprecated)"},  // (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x307,
     "WheelPosEtaJet: Info (deprecated)"},  // (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Pos-eta Energy FPGA
    {0x380, "WheelPosEtaEnergy: Input TrigPathA (Et)"},
    {0x381, "WheelPosEtaEnergy: Input TrigPathB (Ht)"},
    {0x383, "WheelPosEtaEnergy: Output TrigPathA (Et)"},
    {0x385, "WheelPosEtaEnergy: Output TrigPathB (Ht)"},
    {0x386, "WheelPosEtaEnergy: Test"},
    {0x387, "WheelPosEtaEnergy: BX & Orbit Info"},
    // Wheel Neg-eta Jet FPGA
    {0x700, "WheelNegEtaJet: Input TrigPathA (Jet Sort)"},
    {0x701, "WheelNegEtaJet: Input TrigPathB (MissHt)"},
    {0x703, "WheelNegEtaJet: Output TrigPathA (Jet Sort)"},
    {0x705, "WheelNegEtaJet: Output TrigPathB (MissHt)"},
    {0x706,
     "WheelNegEtaJet: Test (deprecated)"},  // (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x707,
     "WheelNegEtaJet: Info (deprecated)"},  // (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Neg-eta Energy FPGA
    {0x780, "WheelNegEtaEnergy: Input TrigPathA (Et)"},
    {0x781, "WheelNegEtaEnergy: Input TrigPathB (Ht)"},
    {0x783, "WheelNegEtaEnergy: Output TrigPathA (Et)"},
    {0x785, "WheelNegEtaEnergy: Output TrigPathB (Ht)"},
    {0x786, "WheelNegEtaEnergy: Test"},
    {0x787, "WheelNegEtaEnergy: BX & Orbit Info"},
    // Jet Leaf FPGAs - Positive Eta
    {0x900, "Leaf1JetPosEtaU1: JF2 Input"},
    {0x901, "Leaf1JetPosEtaU1: JF2 Shared Received"},
    {0x902, "Leaf1JetPosEtaU1: JF2 Shared Sent"},
    {0x903, "Leaf1JetPosEtaU1: JF2 Output"},
    {0x904, "Leaf1JetPosEtaU1: JF2 Raw Input"},
    {0x908, "Leaf1JetPosEtaU1: JF3 Input"},
    {0x909, "Leaf1JetPosEtaU1: JF3 Shared Received"},
    {0x90a, "Leaf1JetPosEtaU1: JF3 Shared Sent"},
    {0x90b, "Leaf1JetPosEtaU1: JF3 Output"},
    {0x90c, "Leaf1JetPosEtaU1: JF3 Raw Input"},
    {0x980, "Leaf1JetPosEtaU2: Eta0 Input"},  // Next Leaf Start
    {0x984, "Leaf1JetPosEtaU2: Eta0 Raw Input"},
    {0x988, "Leaf1JetPosEtaU2: JF1 Input"},
    {0x989, "Leaf1JetPosEtaU2: JF1 Shared Received"},
    {0x98a, "Leaf1JetPosEtaU2: JF1 Shared Sent"},
    {0x98b, "Leaf1JetPosEtaU2: JF1 Output"},
    {0x98c, "Leaf1JetPosEtaU2: JF1 Raw Input"},
    {0xa00, "Leaf2JetPosEtaU1: JF2 Input"},  // Next Leaf Start
    {0xa01, "Leaf2JetPosEtaU1: JF2 Shared Received"},
    {0xa02, "Leaf2JetPosEtaU1: JF2 Shared Sent"},
    {0xa03, "Leaf2JetPosEtaU1: JF2 Output"},
    {0xa04, "Leaf2JetPosEtaU1: JF2 Raw Input"},
    {0xa08, "Leaf2JetPosEtaU1: JF3 Input"},
    {0xa09, "Leaf2JetPosEtaU1: JF3 Shared Received"},
    {0xa0a, "Leaf2JetPosEtaU1: JF3 Shared Sent"},
    {0xa0b, "Leaf2JetPosEtaU1: JF3 Output"},
    {0xa0c, "Leaf2JetPosEtaU1: JF3 Raw Input"},
    {0xa80, "Leaf2JetPosEtaU2: Eta0 Input"},  // Next Leaf Start
    {0xa84, "Leaf2JetPosEtaU2: Eta0 Raw Input"},
    {0xa88, "Leaf2JetPosEtaU2: JF1 Input"},
    {0xa89, "Leaf2JetPosEtaU2: JF1 Shared Received"},
    {0xa8a, "Leaf2JetPosEtaU2: JF1 Shared Sent"},
    {0xa8b, "Leaf2JetPosEtaU2: JF1 Output"},
    {0xa8c, "Leaf2JetPosEtaU2: JF1 Raw Input"},
    {0xb00, "Leaf3JetPosEtaU1: JF2 Input"},  // Next Leaf Start
    {0xb01, "Leaf3JetPosEtaU1: JF2 Shared Received"},
    {0xb02, "Leaf3JetPosEtaU1: JF2 Shared Sent"},
    {0xb03, "Leaf3JetPosEtaU1: JF2 Output"},
    {0xb04, "Leaf3JetPosEtaU1: JF2 Raw Input"},
    {0xb08, "Leaf3JetPosEtaU1: JF3 Input"},
    {0xb09, "Leaf3JetPosEtaU1: JF3 Shared Received"},
    {0xb0a, "Leaf3JetPosEtaU1: JF3 Shared Sent"},
    {0xb0b, "Leaf3JetPosEtaU1: JF3 Output"},
    {0xb0c, "Leaf3JetPosEtaU1: JF3 Raw Input"},
    {0xb80, "Leaf3JetPosEtaU2: Eta0 Input"},  // Next Leaf Start
    {0xb84, "Leaf3JetPosEtaU2: Eta0 Raw Input"},
    {0xb88, "Leaf3JetPosEtaU2: JF1 Input"},
    {0xb89, "Leaf3JetPosEtaU2: JF1 Shared Received"},
    {0xb8a, "Leaf3JetPosEtaU2: JF1 Shared Sent"},
    {0xb8b, "Leaf3JetPosEtaU2: JF1 Output"},
    {0xb8c, "Leaf3JetPosEtaU2: JF1 Raw Input"},
    // Jet Leaf FPGAs - Negative Eta
    {0xd00, "Leaf1JetNegEtaU1: JF2 Input"},  // START OF NEG ETA JET LEAVES
    {0xd01, "Leaf1JetNegEtaU1: JF2 Shared Received"},
    {0xd02, "Leaf1JetNegEtaU1: JF2 Shared Sent"},
    {0xd03, "Leaf1JetNegEtaU1: JF2 Output"},
    {0xd04, "Leaf1JetNegEtaU1: JF2 Raw Input"},
    {0xd08, "Leaf1JetNegEtaU1: JF3 Input"},
    {0xd09, "Leaf1JetNegEtaU1: JF3 Shared Received"},
    {0xd0a, "Leaf1JetNegEtaU1: JF3 Shared Sent"},
    {0xd0b, "Leaf1JetNegEtaU1: JF3 Output"},
    {0xd0c, "Leaf1JetNegEtaU1: JF3 Raw Input"},
    {0xd80, "Leaf1JetNegEtaU2: Eta0 Input"},  // Next Leaf Start
    {0xd84, "Leaf1JetNegEtaU2: Eta0 Raw Input"},
    {0xd88, "Leaf1JetNegEtaU2: JF1 Input"},
    {0xd89, "Leaf1JetNegEtaU2: JF1 Shared Received"},
    {0xd8a, "Leaf1JetNegEtaU2: JF1 Shared Sent"},
    {0xd8b, "Leaf1JetNegEtaU2: JF1 Output"},
    {0xd8c, "Leaf1JetNegEtaU2: JF1 Raw Input"},
    {0xe00, "Leaf2JetNegEtaU1: JF2 Input"},  // Next Leaf Start
    {0xe01, "Leaf2JetNegEtaU1: JF2 Shared Received"},
    {0xe02, "Leaf2JetNegEtaU1: JF2 Shared Sent"},
    {0xe03, "Leaf2JetNegEtaU1: JF2 Output"},
    {0xe04, "Leaf2JetNegEtaU1: JF2 Raw Input"},
    {0xe08, "Leaf2JetNegEtaU1: JF3 Input"},
    {0xe09, "Leaf2JetNegEtaU1: JF3 Shared Received"},
    {0xe0a, "Leaf2JetNegEtaU1: JF3 Shared Sent"},
    {0xe0b, "Leaf2JetNegEtaU1: JF3 Output"},
    {0xe0c, "Leaf2JetNegEtaU1: JF3 Raw Input"},
    {0xe80, "Leaf2JetNegEtaU2: Eta0 Input"},  // Next Leaf Start
    {0xe84, "Leaf2JetNegEtaU2: Eta0 Raw Input"},
    {0xe88, "Leaf2JetNegEtaU2: JF1 Input"},
    {0xe89, "Leaf2JetNegEtaU2: JF1 Shared Received"},
    {0xe8a, "Leaf2JetNegEtaU2: JF1 Shared Sent"},
    {0xe8b, "Leaf2JetNegEtaU2: JF1 Output"},
    {0xe8c, "Leaf2JetNegEtaU2: JF1 Raw Input"},
    {0xf00, "Leaf3JetNegEtaU1: JF2 Input"},  // Next Leaf Start
    {0xf01, "Leaf3JetNegEtaU1: JF2 Shared Received"},
    {0xf02, "Leaf3JetNegEtaU1: JF2 Shared Sent"},
    {0xf03, "Leaf3JetNegEtaU1: JF2 Output"},
    {0xf04, "Leaf3JetNegEtaU1: JF2 Raw Input"},
    {0xf08, "Leaf3JetNegEtaU1: JF3 Input"},
    {0xf09, "Leaf3JetNegEtaU1: JF3 Shared Received"},
    {0xf0a, "Leaf3JetNegEtaU1: JF3 Shared Sent"},
    {0xf0b, "Leaf3JetNegEtaU1: JF3 Output"},
    {0xf0c, "Leaf3JetNegEtaU1: JF3 Raw Input"},
    {0xf80, "Leaf3JetNegEtaU2: Eta0 Input"},  // Next Leaf Start
    {0xf84, "Leaf3JetNegEtaU2: Eta0 Raw Input"},
    {0xf88, "Leaf3JetNegEtaU2: JF1 Input"},
    {0xf89, "Leaf3JetNegEtaU2: JF1 Shared Received"},
    {0xf8a, "Leaf3JetNegEtaU2: JF1 Shared Sent"},
    {0xf8b, "Leaf3JetNegEtaU2: JF1 Output"},
    {0xf8c, "Leaf3JetNegEtaU2: JF1 Raw Input"}};

/*** Setup BlockID to Unpack-Function Map ***/
const GctFormatTranslateV38::BlockIdToUnpackFnMap GctFormatTranslateV38::m_blockUnpackFn = {
    // Miscellaneous Blocks
    {0x000, &GctFormatTranslateV38::blockDoNothing},  // NULL
    // ConcJet FPGA
    {0x580, &GctFormatTranslateV38::blockToGctTrigObjects},            // ConcJet: Input TrigPathA (Jet Cands)
    {0x581, &GctFormatTranslateV38::blockToGctInternRingSums},         // ConcJet: Input TrigPathB (HF Rings)
    {0x582, &GctFormatTranslateV38::blockToGctInternHtMissPostWheel},  // ConcJet: Input TrigPathC (MissHt)
    {0x583, &GctFormatTranslateV38::blockToGctJetCandsAndCounts},      // ConcJet: Jet Cands and Counts Output to GT
    {0x587, &GctFormatTranslateV38::blockDoNothing},                   // ConcJet: BX & Orbit Info
    // ConcElec FPGA
    {0x680, &GctFormatTranslateV38::blockToGctInternEmCand},          // ConcElec: Input TrigPathA (EM Cands)
    {0x681, &GctFormatTranslateV38::blockToGctInternEtSums},          // ConcElec: Input TrigPathB (Et Sums)
    {0x682, &GctFormatTranslateV38::blockToGctInternEtSums},          // ConcElec: Input TrigPathC (Ht Sums)
    {0x683, &GctFormatTranslateV38::blockToGctEmCandsAndEnergySums},  // ConcElec: EM Cands and Energy Sums Output to GT
    {0x686, &GctFormatTranslateV38::blockDoNothing},                  // ConcElec: Test (GT Serdes Loopback)
    {0x687, &GctFormatTranslateV38::blockDoNothing},                  // ConcElec: BX & Orbit Info
    // Electron Leaf FPGAs
    {0x800, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecPosEtaU1: Sort Input
    {0x803, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecPosEtaU1: Sort Output
    {0x804, &GctFormatTranslateV38::blockToFibresAndToRctEmCand},  // Leaf0ElecPosEtaU1: Raw Input
    {0x880, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecPosEtaU2: Sort Input
    {0x883, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecPosEtaU2: Sort Output
    {0x884, &GctFormatTranslateV38::blockToFibresAndToRctEmCand},  // Leaf0ElecPosEtaU2: Raw Input
    {0xc00, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecNegEtaU1: Sort Input
    {0xc03, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecNegEtaU1: Sort Output
    {0xc04, &GctFormatTranslateV38::blockToFibresAndToRctEmCand},  // Leaf0ElecNegEtaU1: Raw Input
    {0xc80, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecNegEtaU2: Sort Input
    {0xc83, &GctFormatTranslateV38::blockToGctInternEmCand},       // Leaf0ElecNegEtaU2: Sort Output
    {0xc84, &GctFormatTranslateV38::blockToFibresAndToRctEmCand},  // Leaf0ElecNegEtaU2: Raw Input
    // Wheel Pos-eta Jet FPGA
    {0x300, &GctFormatTranslateV38::blockToGctJetClusterMinimal},      // WheelPosEtaJet: Input TrigPathA (Jet Sort)
    {0x301, &GctFormatTranslateV38::blockToGctInternHtMissPreWheel},   // WheelPosEtaJet: Input TrigPathB (MissHt)
    {0x303, &GctFormatTranslateV38::blockToGctTrigObjects},            // WheelPosEtaJet: Output TrigPathA (Jet Sort)
    {0x305, &GctFormatTranslateV38::blockToGctInternHtMissPostWheel},  // WheelPosEtaJet: Output TrigPathB (MissHt)
    {0x306,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelPosEtaJet: Test (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x307,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelPosEtaJet: Info (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Pos-eta Energy FPGA
    {0x380,
     &GctFormatTranslateV38::blockToGctWheelInputInternEtAndRingSums},  // WheelPosEtaEnergy: Input TrigPathA (Et)
    {0x381, &GctFormatTranslateV38::blockToGctInternEtSums},            // WheelPosEtaEnergy: Input TrigPathB (Ht)
    {0x383,
     &GctFormatTranslateV38::blockToGctWheelOutputInternEtAndRingSums},  // WheelPosEtaEnergy: Output TrigPathA (Et)
    {0x385, &GctFormatTranslateV38::blockToGctInternEtSums},             // WheelPosEtaEnergy: Output TrigPathB (Ht)
    {0x386, &GctFormatTranslateV38::blockDoNothing},                     // WheelPosEtaEnergy: Test
    {0x387,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelPosEtaEnergy: BX & Orbit Info   (Potential data incompatibility between V24/V25 where block length=4, and V27.1 where block length=6)
    // Wheel Neg-eta Jet FPGA
    {0x700, &GctFormatTranslateV38::blockToGctJetClusterMinimal},      // WheelNegEtaJet: Input TrigPathA (Jet Sort)
    {0x701, &GctFormatTranslateV38::blockToGctInternHtMissPreWheel},   // WheelNegEtaJet: Input TrigPathB (MissHt)
    {0x703, &GctFormatTranslateV38::blockToGctTrigObjects},            // WheelNegEtaJet: Output TrigPathA (Jet Sort)
    {0x705, &GctFormatTranslateV38::blockToGctInternHtMissPostWheel},  // WheelNegEtaJet: Output TrigPathB (MissHt)
    {0x706,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelNegEtaJet: Test (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    {0x707,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelNegEtaJet: Info (deprecated)  (Doesn't exist in V27.1 format, but does in V24 & V25, so keep for CRUZET2 data compatibility reasons)
    // Wheel Neg-eta Energy FPGA
    {0x780,
     &GctFormatTranslateV38::blockToGctWheelInputInternEtAndRingSums},  // WheelNegEtaEnergy: Input TrigPathA (Et)
    {0x781, &GctFormatTranslateV38::blockToGctInternEtSums},            // WheelNegEtaEnergy: Input TrigPathB (Ht)
    {0x783,
     &GctFormatTranslateV38::blockToGctWheelOutputInternEtAndRingSums},  // WheelNegEtaEnergy: Output TrigPathA (Et)
    {0x785, &GctFormatTranslateV38::blockToGctInternEtSums},             // WheelNegEtaEnergy: Output TrigPathB (Ht)
    {0x786, &GctFormatTranslateV38::blockDoNothing},                     // WheelNegEtaEnergy: Test
    {0x787,
     &GctFormatTranslateV38::
         blockDoNothing},  // WheelNegEtaEnergy: BX & Orbit Info   (Potential data incompatibility between V24/V25 where block length=4, and V27.1 where block length=6)
    // Jet Leaf FPGAs - Positive Eta
    {0x900, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetPosEtaU1: JF2 Input
    {0x901, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU1: JF2 Shared Received
    {0x902, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU1: JF2 Shared Sent
    {0x903, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetPosEtaU1: JF2 Output
    {0x904, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetPosEtaU1: JF2 Raw Input
    {0x908, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetPosEtaU1: JF3 Input
    {0x909, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU1: JF3 Shared Received
    {0x90a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU1: JF3 Shared Sent
    {0x90b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetPosEtaU1: JF3 Output
    {0x90c, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetPosEtaU1: JF3 Raw Input
    {0x980, &GctFormatTranslateV38::blockDoNothing},                       // Leaf1JetPosEtaU2: Eta0 Input
    {0x984, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetPosEtaU2: Eta0 Raw Input
    {0x988, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetPosEtaU2: JF1 Input
    {0x989, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU2: JF1 Shared Received
    {0x98a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetPosEtaU2: JF1 Shared Sent
    {0x98b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetPosEtaU2: JF1 Output
    {0x98c, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetPosEtaU2: JF1 Raw Input
    {0xa00, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetPosEtaU1: JF2 Input
    {0xa01, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU1: JF2 Shared Received
    {0xa02, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU1: JF2 Shared Sent
    {0xa03, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetPosEtaU1: JF2 Output
    {0xa04, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetPosEtaU1: JF2 Raw Input
    {0xa08, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetPosEtaU1: JF3 Input
    {0xa09, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU1: JF3 Shared Received
    {0xa0a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU1: JF3 Shared Sent
    {0xa0b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetPosEtaU1: JF3 Output
    {0xa0c, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetPosEtaU1: JF3 Raw Input
    {0xa80, &GctFormatTranslateV38::blockDoNothing},                       // Leaf2JetPosEtaU2: Eta0 Input
    {0xa84, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetPosEtaU2: Eta0 Raw Input
    {0xa88, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetPosEtaU2: JF1 Input
    {0xa89, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU2: JF1 Shared Received
    {0xa8a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetPosEtaU2: JF1 Shared Sent
    {0xa8b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetPosEtaU2: JF1 Output
    {0xa8c, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetPosEtaU2: JF1 Raw Input
    {0xb00, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetPosEtaU1: JF2 Input
    {0xb01, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU1: JF2 Shared Received
    {0xb02, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU1: JF2 Shared Sent
    {0xb03, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetPosEtaU1: JF2 Output
    {0xb04, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetPosEtaU1: JF2 Raw Input
    {0xb08, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetPosEtaU1: JF3 Input
    {0xb09, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU1: JF3 Shared Received
    {0xb0a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU1: JF3 Shared Sent
    {0xb0b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetPosEtaU1: JF3 Output
    {0xb0c, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetPosEtaU1: JF3 Raw Input
    {0xb80, &GctFormatTranslateV38::blockDoNothing},                       // Leaf3JetPosEtaU2: Eta0 Input
    {0xb84, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetPosEtaU2: Eta0 Raw Input
    {0xb88, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetPosEtaU2: JF1 Input
    {0xb89, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU2: JF1 Shared Received
    {0xb8a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetPosEtaU2: JF1 Shared Sent
    {0xb8b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetPosEtaU2: JF1 Output
    {0xb8c, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetPosEtaU2: JF1 Raw Input
    // Jet Leaf FPGAs - Negative Eta
    {0xd00, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetNegEtaU1: JF2 Input
    {0xd01, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU1: JF2 Shared Received
    {0xd02, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU1: JF2 Shared Sent
    {0xd03, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetNegEtaU1: JF2 Output
    {0xd04, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetNegEtaU1: JF2 Raw Input
    {0xd08, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetNegEtaU1: JF3 Input
    {0xd09, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU1: JF3 Shared Received
    {0xd0a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU1: JF3 Shared Sent
    {0xd0b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetNegEtaU1: JF3 Output
    {0xd0c, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetNegEtaU1: JF3 Raw Input
    {0xd80, &GctFormatTranslateV38::blockDoNothing},                       // Leaf1JetNegEtaU2: Eta0 Input
    {0xd84, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetNegEtaU2: Eta0 Raw Input
    {0xd88, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf1JetNegEtaU2: JF1 Input
    {0xd89, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU2: JF1 Shared Received
    {0xd8a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf1JetNegEtaU2: JF1 Shared Sent
    {0xd8b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf1JetNegEtaU2: JF1 Output
    {0xd8c, &GctFormatTranslateV38::blockToFibres},                        // Leaf1JetNegEtaU2: JF1 Raw Input
    {0xe00, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetNegEtaU1: JF2 Input
    {0xe01, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU1: JF2 Shared Received
    {0xe02, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU1: JF2 Shared Sent
    {0xe03, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetNegEtaU1: JF2 Output
    {0xe04, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetNegEtaU1: JF2 Raw Input
    {0xe08, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetNegEtaU1: JF3 Input
    {0xe09, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU1: JF3 Shared Received
    {0xe0a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU1: JF3 Shared Sent
    {0xe0b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetNegEtaU1: JF3 Output
    {0xe0c, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetNegEtaU1: JF3 Raw Input
    {0xe80, &GctFormatTranslateV38::blockDoNothing},                       // Leaf2JetNegEtaU2: Eta0 Input
    {0xe84, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetNegEtaU2: Eta0 Raw Input
    {0xe88, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf2JetNegEtaU2: JF1 Input
    {0xe89, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU2: JF1 Shared Received
    {0xe8a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf2JetNegEtaU2: JF1 Shared Sent
    {0xe8b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf2JetNegEtaU2: JF1 Output
    {0xe8c, &GctFormatTranslateV38::blockToFibres},                        // Leaf2JetNegEtaU2: JF1 Raw Input
    {0xf00, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetNegEtaU1: JF2 Input
    {0xf01, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU1: JF2 Shared Received
    {0xf02, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU1: JF2 Shared Sent
    {0xf03, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetNegEtaU1: JF2 Output
    {0xf04, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetNegEtaU1: JF2 Raw Input
    {0xf08, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetNegEtaU1: JF3 Input
    {0xf09, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU1: JF3 Shared Received
    {0xf0a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU1: JF3 Shared Sent
    {0xf0b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetNegEtaU1: JF3 Output
    {0xf0c, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetNegEtaU1: JF3 Raw Input
    {0xf80, &GctFormatTranslateV38::blockDoNothing},                       // Leaf3JetNegEtaU2: Eta0 Input
    {0xf84, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetNegEtaU2: Eta0 Raw Input
    {0xf88, &GctFormatTranslateV38::blockToRctCaloRegions},                // Leaf3JetNegEtaU2: JF1 Input
    {0xf89, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU2: JF1 Shared Received
    {0xf8a, &GctFormatTranslateV38::blockToGctJetPreCluster},              // Leaf3JetNegEtaU2: JF1 Shared Sent
    {0xf8b, &GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster},  // Leaf3JetNegEtaU2: JF1 Output
    {0xf8c, &GctFormatTranslateV38::blockToFibres},                        // Leaf3JetNegEtaU2: JF1 Raw Input
};

/*** Setup RCT Em Crate Map ***/
const GctFormatTranslateV38::BlkToRctCrateMap GctFormatTranslateV38::m_rctEmCrate = {
    {0x804, 13}, {0x884, 9}, {0xc04, 4}, {0xc84, 0}};

/*** Setup RCT jet crate map. ***/
const GctFormatTranslateV38::BlkToRctCrateMap GctFormatTranslateV38::m_rctJetCrate = {
    {0x900, 9},   // PosEta Leaf 1 JF2
    {0x908, 10},  // PosEta Leaf 1 JF3
    {0x988, 17},  // PosEta Leaf 1 JF1
    {0xa00, 12},  // PosEta Leaf 2 JF2
    {0xa08, 13},  // PosEta Leaf 2 JF3
    {0xa88, 11},  // PosEta Leaf 2 JF1
    {0xb00, 15},  // PosEta Leaf 3 JF2
    {0xb08, 16},  // PosEta Leaf 3 JF3
    {0xb88, 14},  // PosEta Leaf 3 JF1
    {0xd00, 0},   // NegEta Leaf 1 JF2
    {0xd08, 1},   // NegEta Leaf 1 JF3
    {0xd88, 8},   // NegEta Leaf 1 JF1
    {0xe00, 3},   // NegEta Leaf 2 JF2
    {0xe08, 4},   // NegEta Leaf 2 JF3
    {0xe88, 2},   // NegEta Leaf 2 JF1
    {0xf00, 6},   // NegEta Leaf 3 JF2
    {0xf08, 7},   // NegEta Leaf 3 JF3
    {0xf88, 5}    // NegEta Leaf 3 JF1
};

/*** Setup Block ID map for pipeline payload positions of isolated Internal EM Cands. ***/
const GctFormatTranslateV38::BlockIdToEmCandIsoBoundMap GctFormatTranslateV38::m_internEmIsoBounds = {
    {0x680, IsoBoundaryPair(8, 15)},
    {0x800, IsoBoundaryPair(0, 9)},
    {0x803, IsoBoundaryPair(0, 1)},
    {0x880, IsoBoundaryPair(0, 7)},
    {0x883, IsoBoundaryPair(0, 1)},
    {0xc00, IsoBoundaryPair(0, 9)},
    {0xc03, IsoBoundaryPair(0, 1)},
    {0xc80, IsoBoundaryPair(0, 7)},
    {0xc83, IsoBoundaryPair(0, 1)}};

// PUBLIC METHODS

GctFormatTranslateV38::GctFormatTranslateV38(bool hltMode,
                                             bool unpackSharedRegions,
                                             unsigned numberOfGctSamplesToUnpack,
                                             unsigned numberOfRctSamplesToUnpack)
    : GctFormatTranslateBase(hltMode, unpackSharedRegions),
      m_numberOfGctSamplesToUnpack(numberOfGctSamplesToUnpack),
      m_numberOfRctSamplesToUnpack(numberOfRctSamplesToUnpack) {}

GctFormatTranslateV38::~GctFormatTranslateV38() {}

GctBlockHeader GctFormatTranslateV38::generateBlockHeader(const unsigned char* data) const {
  // Turn the four 8-bit header words into the full 32-bit header.
  uint32_t hdr = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);

  //  Bit mapping of V35 header:
  //  --------------------------
  //  11:0   => block_id  Unique pipeline identifier.
  //   - 3:0    =>> pipe_id There can be up to 16 different pipelines per FPGA.
  //   - 6:4    =>> reserved  Do not use yet. Set to zero.
  //   - 11:7   =>> fpga geograpical add  The VME geographical address of the FPGA.
  //  15:12  => event_id  Determined locally.  Not reset by Resync.
  //  19:16  => number_of_time_samples  If time samples 15 or more then value = 15.
  //  31:20  => event_bcid  The bunch crossing the data was recorded.

  unsigned blockId = hdr & 0xfff;
  unsigned blockLength = 0;  // Set to zero until we know it's a valid block
  unsigned nSamples = (hdr >> 16) & 0xf;
  unsigned bxId = (hdr >> 20) & 0xfff;
  unsigned eventId = (hdr >> 12) & 0xf;
  bool valid = (blockLengthMap().find(blockId) != blockLengthMap().end());

  if (valid) {
    blockLength = blockLengthMap().find(blockId)->second;
  }

  return GctBlockHeader(blockId, blockLength, nSamples, bxId, eventId, valid);
}

// conversion
bool GctFormatTranslateV38::convertBlock(const unsigned char* data, const GctBlockHeader& hdr) {
  // if the block has no time samples, don't bother with it.
  if (hdr.nSamples() < 1) {
    return true;
  }

  if (!checkBlock(hdr)) {
    return false;
  }  // Check the block to see if it's possible to unpack.

  // The header validity check above will protect against
  // the map::find() method returning the end of the map,
  // assuming the block header definitions are up-to-date.
  (this->*m_blockUnpackFn.find(hdr.blockId())->second)(data,
                                                       hdr);  // Calls the correct unpack function, based on block ID.

  return true;
}

// PROTECTED METHODS

uint32_t GctFormatTranslateV38::generateRawHeader(const uint32_t blockId,
                                                  const uint32_t nSamples,
                                                  const uint32_t bxId,
                                                  const uint32_t eventId) const {
  //  Bit mapping of V35 header:
  //  --------------------------
  //  11:0   => block_id  Unique pipeline identifier.
  //   - 3:0    =>> pipe_id There can be up to 16 different pipelines per FPGA.
  //   - 6:4    =>> reserved  Do not use yet. Set to zero.
  //   - 11:7   =>> fpga geograpical add  The VME geographical address of the FPGA.
  //  15:12  => event_id  Determined locally.  Not reset by Resync.
  //  19:16  => number_of_time_samples  If time samples 15 or more then value = 15.
  //  31:20  => event_bxId  The bunch crossing the data was recorded.

  return ((bxId & 0xfff) << 20) | ((nSamples & 0xf) << 16) | ((eventId & 0xf) << 12) | (blockId & 0xfff);
}

// PRIVATE METHODS

// Throughout the code, bx refers to the hardware definition of time-samples
// ie. if 5 time samples are unpacked, they are bx=0, 1, 2, 3, 4 in order
// what is written to digi would be -2, -1, 0, +1, +2

// Output EM Candidates unpacking
void GctFormatTranslateV38::blockToGctEmCandsAndEnergySums(const unsigned char* d, const GctBlockHeader& hdr) {
  const unsigned int id = hdr.blockId();
  const unsigned int nSamples = hdr.nSamples();

  // Re-interpret pointer.  p16 will be pointing at the 16 bit word that
  // contains the rank0 non-isolated electron of the zeroth time-sample.
  const uint16_t* p16 = reinterpret_cast<const uint16_t*>(d);

  // UNPACK EM CANDS

  const unsigned int emCandCategoryOffset =
      nSamples * 4;  // Offset to jump from the non-iso electrons to the isolated ones.
  const unsigned int timeSampleOffset = nSamples * 2;  // Offset to jump to next candidate pair in the same time-sample.

  unsigned int samplesToUnpack =
      std::min(nSamples, m_numberOfGctSamplesToUnpack);  // Unpack as many as asked for if they are in the raw data
  unsigned int centralSample =
      (unsigned)std::ceil((double)nSamples / 2.) - 1;  // think this works when nSamples is even, need to check!!!
  unsigned int firstSample = centralSample - (unsigned)std::ceil((double)samplesToUnpack / 2.) + 1;
  unsigned int lastSample = centralSample + (unsigned)(samplesToUnpack / 2);

  LogDebug("GCT") << "Unpacking output EM.  Central sample=" << centralSample << " first=" << firstSample
                  << " last=" << lastSample;

  for (unsigned int iso = 0; iso < 2; ++iso)  // loop over non-iso/iso candidate pairs
  {
    bool isoFlag = (iso == 1);

    // Get the correct collection to put them in.
    L1GctEmCandCollection* em;
    if (isoFlag) {
      em = colls()->gctIsoEm();
    } else {
      em = colls()->gctNonIsoEm();
    }

    for (unsigned int bx = firstSample; bx <= lastSample; ++bx)  // loop over samples to be unpacked
    {
      // cand0Offset will give the offset on p16 to get the rank 0 candidate
      // of the correct category and timesample.
      const unsigned int cand0Offset = iso * emCandCategoryOffset + bx * 2;

      em->push_back(L1GctEmCand(p16[cand0Offset], isoFlag, id, 0, (int)bx - (int)centralSample));  // rank0 electron
      em->push_back(L1GctEmCand(
          p16[cand0Offset + timeSampleOffset], isoFlag, id, 1, (int)bx - (int)centralSample));         // rank1 electron
      em->push_back(L1GctEmCand(p16[cand0Offset + 1], isoFlag, id, 2, (int)bx - (int)centralSample));  // rank2 electron
      em->push_back(L1GctEmCand(
          p16[cand0Offset + timeSampleOffset + 1], isoFlag, id, 3, (int)bx - (int)centralSample));  // rank3 electron

      LogDebug("GCT") << "Unpacked a bunch of EG.  iso=" << iso << " bx=" << bx << std::endl;
    }
  }

  p16 += emCandCategoryOffset * 2;  // Move the pointer over the data we've already unpacked.

  // UNPACK ENERGY SUMS

  for (unsigned int bx = firstSample; bx <= lastSample; ++bx)  // loop over all time samples
  {
    const unsigned int offset = bx * 2;
    colls()->gctEtTot()->push_back(L1GctEtTotal(p16[offset], (int)bx - (int)centralSample));    // Et total
    colls()->gctEtHad()->push_back(L1GctEtHad(p16[offset + 1], (int)bx - (int)centralSample));  // Et hadronic
  }

  p16 += nSamples * 2;

  // 32-bit pointer for getting Missing Et.
  const uint32_t* p32 = reinterpret_cast<const uint32_t*>(p16);

  for (unsigned int bx = firstSample; bx <= lastSample; ++bx) {
    colls()->gctEtMiss()->push_back(L1GctEtMiss(p32[bx], (int)bx - (int)centralSample));  // Et Miss
    LogDebug("GCT") << "Unpacked energy sums bx=" << bx << std::endl;
  }
}

void GctFormatTranslateV38::blockToGctJetCandsAndCounts(const unsigned char* d, const GctBlockHeader& hdr) {
  const unsigned int id = hdr.blockId();         // Capture block ID.
  const unsigned int nSamples = hdr.nSamples();  // Number of time-samples.

  // Re-interpret block payload pointer to 16 bits so it sees one candidate at a time.
  // p16 points to the start of the block payload, at the rank0 tau jet candidate.
  const uint16_t* p16 = reinterpret_cast<const uint16_t*>(d);

  // UNPACK JET CANDS

  const unsigned int jetCandCategoryOffset = nSamples * 4;  // Offset to jump from one jet category to the next.
  const unsigned int timeSampleOffset = nSamples * 2;  // Offset to jump to next candidate pair in the same time-sample.

  unsigned int samplesToUnpack =
      std::min(nSamples, m_numberOfGctSamplesToUnpack);  // Unpack as many as asked for if they are in the raw data
  unsigned int centralSample =
      (unsigned)std::ceil((double)nSamples / 2.) - 1;  // think this works when nSamples is even, need to check!!!
  unsigned int firstSample = centralSample - (unsigned)std::ceil((double)samplesToUnpack / 2.) + 1;
  unsigned int lastSample = centralSample + (unsigned)(samplesToUnpack / 2);

  LogDebug("GCT") << "Unpacking output Jets. Samples to unpack=" << samplesToUnpack << " central=" << centralSample
                  << " first=" << firstSample << " last=" << lastSample;

  // Loop over the different catagories of jets
  for (unsigned int iCat = 0; iCat < NUM_JET_CATEGORIES; ++iCat) {
    L1GctJetCandCollection* const jets = gctJets(iCat);
    assert(jets->empty());  // The supplied vector should be empty.

    bool tauflag = (iCat == TAU_JETS);
    bool forwardFlag = (iCat == FORWARD_JETS);

    // Loop over the different timesamples (bunch crossings).
    for (unsigned int bx = firstSample; bx <= lastSample; ++bx) {
      // cand0Offset will give the offset on p16 to get the rank 0 Jet Cand of the correct category and timesample.
      const unsigned int cand0Offset = iCat * jetCandCategoryOffset + bx * 2;

      // Rank 0 Jet.
      jets->push_back(L1GctJetCand(p16[cand0Offset], tauflag, forwardFlag, id, 0, (int)bx - (int)centralSample));
      // Rank 1 Jet.
      jets->push_back(
          L1GctJetCand(p16[cand0Offset + timeSampleOffset], tauflag, forwardFlag, id, 1, (int)bx - (int)centralSample));
      // Rank 2 Jet.
      jets->push_back(L1GctJetCand(p16[cand0Offset + 1], tauflag, forwardFlag, id, 2, (int)bx - (int)centralSample));
      // Rank 3 Jet.
      jets->push_back(L1GctJetCand(
          p16[cand0Offset + timeSampleOffset + 1], tauflag, forwardFlag, id, 3, (int)bx - (int)centralSample));
    }
  }

  p16 += NUM_JET_CATEGORIES * jetCandCategoryOffset;  // Move the pointer over the data we've already unpacked.

  // NOW UNPACK: HFBitCounts, HFRingEtSums and Missing Ht

  // Re-interpret block payload pointer to 32 bits so it sees six jet counts at a time.
  const uint32_t* p32 = reinterpret_cast<const uint32_t*>(p16);

  for (unsigned int bx = firstSample; bx <= lastSample; ++bx)  // loop over all time samples
  {
    // Channel 0 carries both HF counts and sums
    colls()->gctHfBitCounts()->push_back(
        L1GctHFBitCounts::fromConcHFBitCounts(id, 6, (int)bx - (int)centralSample, p32[bx]));
    colls()->gctHfRingEtSums()->push_back(
        L1GctHFRingEtSums::fromConcRingSums(id, 6, (int)bx - (int)centralSample, p32[bx]));

    // Channel 1 carries Missing HT.
    colls()->gctHtMiss()->push_back(L1GctHtMiss(p32[bx + nSamples], (int)bx - (int)centralSample));
  }
}

// Internal EM Candidates unpacking
void GctFormatTranslateV38::blockToGctInternEmCand(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal EM Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int numCandPairs = hdr.blockLength();

  // Debug assertion to prevent problems if definitions not up to date.
  auto found = internEmIsoBounds().find(id);
  assert(found != internEmIsoBounds().end());

  unsigned int lowerIsoPairBound = found->second.first;
  unsigned int upperIsoPairBound = found->second.second;

  // Re-interpret pointer to 16 bits so it sees one candidate at a time.
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  // Loop over timesamples (i.e. bunch crossings)
  for (unsigned int bx = 0; bx < nSamples; ++bx) {
    // Loop over candidate pairs (i.e. each iteration unpacks a pair of candidates)
    for (unsigned int candPair = 0; candPair < numCandPairs; ++candPair) {
      // Is the candidate electron pair an isolated pair or not?
      bool iso = ((candPair >= lowerIsoPairBound) && (candPair <= upperIsoPairBound));

      // Loop over the two electron candidates in each pair
      for (unsigned int i = 0; i < 2; ++i) {
        unsigned offset = 2 * (bx + candPair * nSamples) + i;
        uint16_t candRaw = p[offset];
        colls()->gctInternEm()->push_back(L1GctInternEmCand(candRaw, iso, id, candPair * 2 + i, bx));
      }
    }
  }
}

// Input EM Candidates unpacking
// this is the last time I deal the RCT bit assignment travesty!!!
void GctFormatTranslateV38::blockToRctEmCand(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of RCT EM Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // re-interpret pointer
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  // arrays of source card data
  uint16_t sfp[2][4];  // [ cycle ] [ SFP ]
  uint16_t eIsoRank[4];
  uint16_t eIsoCard[4];
  uint16_t eIsoRgn[4];
  uint16_t eNonIsoRank[4];
  uint16_t eNonIsoCard[4];
  uint16_t eNonIsoRgn[4];
  uint16_t MIPbits[7][2];
  uint16_t QBits[7][2];

  unsigned int bx = 0;

  auto found = rctEmCrateMap().find(id);
  assert(found != rctEmCrateMap().end());
  // loop over crates
  for (unsigned int crate = found->second; crate < found->second + length / 3; ++crate) {
    // read SC SFP words
    for (unsigned short iSfp = 0; iSfp < 4; ++iSfp) {
      for (unsigned short cyc = 0; cyc < 2; ++cyc) {
        if (iSfp == 0) {
          sfp[cyc][iSfp] = 0;
        }  // muon bits
        else {  // EM candidate
          sfp[cyc][iSfp] = *p;
          ++p;
        }
      }
      p = p + 2 * (nSamples - 1);
    }

    // fill SC arrays
    srcCardRouting().SFPtoEMU(eIsoRank, eIsoCard, eIsoRgn, eNonIsoRank, eNonIsoCard, eNonIsoRgn, MIPbits, QBits, sfp);

    // create EM cands
    for (unsigned short int i = 0; i < 4; ++i) {
      colls()->rctEm()->push_back(L1CaloEmCand(eIsoRank[i], eIsoRgn[i], eIsoCard[i], crate, true, i, bx));
    }
    for (unsigned short int i = 0; i < 4; ++i) {
      colls()->rctEm()->push_back(L1CaloEmCand(eNonIsoRank[i], eNonIsoRgn[i], eNonIsoCard[i], crate, false, i, bx));
    }
  }
}

// Input RCT region unpacking
void GctFormatTranslateV38::blockToRctCaloRegions(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of RCT Regions";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Debug assertion to prevent problems if definitions not up to date.
  auto found = rctJetCrateMap().find(id);
  assert(found != rctJetCrateMap().end());

  // get crate (need this to get ieta and iphi)
  unsigned int crate = found->second;

  // re-interpret pointer
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  // eta and phi
  unsigned int ieta;
  unsigned int iphi;

  for (unsigned int i = 0; i < length; ++i) {
    for (uint16_t bx = 0; bx < nSamples; ++bx) {
      // First figure out eta and phi
      if (crate < 9) {  // negative eta
        ieta = 12 - i;
        iphi = 2 * ((11 - crate) % 9);
      } else {  // positive eta
        ieta = 9 + i;
        iphi = 2 * ((20 - crate) % 9);
      }

      // Skip the first four regions (i.e. where i<2) which are duplicates (shared data).
      if (i > 1) {
        // First region is phi=0
        colls()->rctCalo()->push_back(L1CaloRegion::makeRegionFromUnpacker(*p, ieta, iphi, id, i, bx));
        ++p;
        // Second region is phi=1
        if (iphi > 0) {
          iphi -= 1;
        } else {
          iphi = 17;
        }
        colls()->rctCalo()->push_back(L1CaloRegion::makeRegionFromUnpacker(*p, ieta, iphi, id, i, bx));
        ++p;
      }
      // Unpack the shared data if asked for debugging
      else if (unpackSharedRegions()) {
        // First region is phi=0
        colls()->rctCalo()->push_back(L1CaloRegion::makeRegionFromUnpacker(*p, ieta, iphi, id, i, bx));
        ++p;
        // Second region is phi=1
        if (iphi > 0) {
          iphi -= 1;
        } else {
          iphi = 17;
        }
        colls()->rctCalo()->push_back(L1CaloRegion::makeRegionFromUnpacker(*p, ieta, iphi, id, i, bx));
        ++p;

      } else {  // Skip the shared data
        ++p;
        ++p;
      }
    }
  }
}

// Fibre unpacking
void GctFormatTranslateV38::blockToFibres(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of GCT Fibres";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // re-interpret pointer
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctFibres()->push_back(L1GctFibreWord(*p, id, i, bx));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToFibresAndToRctEmCand(const unsigned char* d, const GctBlockHeader& hdr) {
  this->blockToRctEmCand(d, hdr);
  this->blockToFibres(d, hdr);
}

void GctFormatTranslateV38::blockToGctInternEtSums(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!

  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal Et Sums";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromTotalEtOrHt(id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctInternEtSumsAndJetCluster(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal Jet Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      if (i < 2)
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromJetMissEt(id, i, bx, *p));
      if (i == 3) {
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromJetTotEt(id, i, bx, *p));
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromJetTotHt(id, i, bx, *p));
      }
      if (i > 4)
        colls()->gctInternJets()->push_back(L1GctInternJetData::fromJetCluster(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctTrigObjects(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal Jet Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 16 bits so it sees one candidate at a time.
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromGctTrigObject(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromGctTrigObject(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctJetClusterMinimal(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal Jet Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 16 bits so it sees one candidate at a time.
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromJetClusterMinimal(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromJetClusterMinimal(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctJetPreCluster(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal Jet Cands";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 16 bits so it sees one candidate at a time.
  const uint16_t* p = reinterpret_cast<const uint16_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromJetPreCluster(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
      colls()->gctInternJets()->push_back(
          L1GctInternJetData::fromJetPreCluster(L1CaloRegionDetId(0, 0), id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctInternRingSums(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of internal HF ring data";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length / 2; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternHFData()->push_back(L1GctInternHFData::fromConcRingSums(id, i, bx, *p));
      ++p;
    }
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternHFData()->push_back(L1GctInternHFData::fromConcBitCounts(id, i, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctWheelInputInternEtAndRingSums(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of wheel input internal Et sums and HF ring data";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      if (i < 3) {
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromTotalEtOrHt(id, i, bx, *p));
      } else if (i > 2 && i < 9) {
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromMissEtxOrEty(id, i, bx, *p));
      } else if (i > 8 && i < 15) {
        colls()->gctInternHFData()->push_back(L1GctInternHFData::fromWheelRingSums(id, i, bx, *p));
      } else if (i > 14) {
        colls()->gctInternHFData()->push_back(L1GctInternHFData::fromWheelBitCounts(id, i, bx, *p));
      }
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctWheelOutputInternEtAndRingSums(const unsigned char* d,
                                                                     const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of wheel output internal Et sums and HF ring data";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int i = 0; i < length; ++i) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      if (i < 1) {
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromTotalEtOrHt(id, i, bx, *p));
      } else if (i > 0 && i < 3) {
        colls()->gctInternEtSums()->push_back(L1GctInternEtSum::fromMissEtxOrEty(id, i, bx, *p));
      } else if (i > 2 && i < 5) {
        colls()->gctInternHFData()->push_back(L1GctInternHFData::fromWheelRingSums(id, i, bx, *p));
      } else if (i > 4) {
        colls()->gctInternHFData()->push_back(L1GctInternHFData::fromWheelBitCounts(id, i, bx, *p));
      }
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctInternHtMissPreWheel(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of pre-wheel internal Missing Ht data";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int iLength = 0; iLength < length; ++iLength) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      colls()->gctInternHtMiss()->push_back(L1GctInternHtMiss::unpackerMissHtxHty(id, iLength, bx, *p));
      ++p;
    }
  }
}

void GctFormatTranslateV38::blockToGctInternHtMissPostWheel(const unsigned char* d, const GctBlockHeader& hdr) {
  // Don't want to do this in HLT optimisation mode!
  if (hltMode()) {
    LogDebug("GCT") << "HLT mode - skipping unpack of post-wheel internal Missing Ht data";
    return;
  }

  unsigned int id = hdr.blockId();
  unsigned int nSamples = hdr.nSamples();
  unsigned int length = hdr.blockLength();

  // Re-interpret pointer to 32 bits
  const uint32_t* p = reinterpret_cast<const uint32_t*>(d);

  for (unsigned int iLength = 0; iLength < length; ++iLength) {
    // Loop over timesamples (i.e. bunch crossings)
    for (unsigned int bx = 0; bx < nSamples; ++bx) {
      if (iLength % 2) {
        colls()->gctInternHtMiss()->push_back(L1GctInternHtMiss::unpackerMissHty(id, iLength, bx, *p));
      }  // Hty on odd numbers
      else {
        colls()->gctInternHtMiss()->push_back(L1GctInternHtMiss::unpackerMissHtx(id, iLength, bx, *p));
      }  // Htx on even numbers
      ++p;
    }
  }
}

//  LocalWords:  rctJetCrate