00001 #include "EventFilter/GctRawToDigi/src/GctFormatTranslateMCLegacy.h"
00002
00003
00004 #include <iostream>
00005 #include <cassert>
00006
00007
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010
00011 using std::cout;
00012 using std::endl;
00013 using std::pair;
00014 using std::make_pair;
00015 using std::vector;
00016
00017
00018 GctFormatTranslateMCLegacy::BlockLengthMap GctFormatTranslateMCLegacy::m_blockLength = GctFormatTranslateMCLegacy::BlockLengthMap();
00019 GctFormatTranslateMCLegacy::BlockNameMap GctFormatTranslateMCLegacy::m_blockName = GctFormatTranslateMCLegacy::BlockNameMap();
00020 GctFormatTranslateMCLegacy::BlockIdToUnpackFnMap GctFormatTranslateMCLegacy::m_blockUnpackFn = GctFormatTranslateMCLegacy::BlockIdToUnpackFnMap();
00021 GctFormatTranslateMCLegacy::BlkToRctCrateMap GctFormatTranslateMCLegacy::m_rctEmCrate = GctFormatTranslateMCLegacy::BlkToRctCrateMap();
00022 GctFormatTranslateMCLegacy::BlkToRctCrateMap GctFormatTranslateMCLegacy::m_rctJetCrate = GctFormatTranslateMCLegacy::BlkToRctCrateMap();
00023 GctFormatTranslateMCLegacy::BlockIdToEmCandIsoBoundMap GctFormatTranslateMCLegacy::m_internEmIsoBounds = GctFormatTranslateMCLegacy::BlockIdToEmCandIsoBoundMap();
00024
00025
00026
00027
00028 GctFormatTranslateMCLegacy::GctFormatTranslateMCLegacy(bool hltMode, bool unpackSharedRegions):
00029 GctFormatTranslateBase(hltMode, unpackSharedRegions)
00030 {
00031 static bool initClass = true;
00032
00033 if(initClass)
00034 {
00035 initClass = false;
00036
00037
00038
00039 m_blockLength.insert(make_pair(0x000,0));
00040 m_blockLength.insert(make_pair(0x0ff,198));
00041
00042 m_blockLength.insert(make_pair(0x583,8));
00043
00044 m_blockLength.insert(make_pair(0x683,6));
00045
00046 m_blockLength.insert(make_pair(0x804,15));
00047 m_blockLength.insert(make_pair(0x884,12));
00048 m_blockLength.insert(make_pair(0xc04,15));
00049 m_blockLength.insert(make_pair(0xc84,12));
00050
00051
00052
00053
00054 m_blockName.insert(make_pair(0x000,"NULL"));
00055 m_blockName.insert(make_pair(0x0ff,"All RCT Calo Regions"));
00056
00057 m_blockName.insert(make_pair(0x583,"ConcJet: Jet Cands and Counts Output to GT"));
00058
00059 m_blockName.insert(make_pair(0x683,"ConcElec: EM Cands and Energy Sums Output to GT"));
00060
00061 m_blockName.insert(make_pair(0x804,"Leaf0ElecPosEtaU1: Raw Input"));
00062 m_blockName.insert(make_pair(0x884,"Leaf0ElecPosEtaU2: Raw Input"));
00063 m_blockName.insert(make_pair(0xc04,"Leaf0ElecNegEtaU1: Raw Input"));
00064 m_blockName.insert(make_pair(0xc84,"Leaf0ElecNegEtaU2: Raw Input"));
00065
00066
00067
00068
00069 m_blockUnpackFn[0x000] = &GctFormatTranslateMCLegacy::blockDoNothing;
00070 m_blockUnpackFn[0x0ff] = &GctFormatTranslateMCLegacy::blockToAllRctCaloRegions;
00071
00072 m_blockUnpackFn[0x583] = &GctFormatTranslateMCLegacy::blockToGctJetCandsAndCounts;
00073
00074 m_blockUnpackFn[0x683] = &GctFormatTranslateMCLegacy::blockToGctEmCandsAndEnergySums;
00075
00076 m_blockUnpackFn[0x804] = &GctFormatTranslateMCLegacy::blockToFibresAndToRctEmCand;
00077 m_blockUnpackFn[0x884] = &GctFormatTranslateMCLegacy::blockToFibresAndToRctEmCand;
00078 m_blockUnpackFn[0xc04] = &GctFormatTranslateMCLegacy::blockToFibresAndToRctEmCand;
00079 m_blockUnpackFn[0xc84] = &GctFormatTranslateMCLegacy::blockToFibresAndToRctEmCand;
00080
00081
00082
00083 m_rctEmCrate[0x804] = 13;
00084 m_rctEmCrate[0x884] = 9;
00085 m_rctEmCrate[0xc04] = 4;
00086 m_rctEmCrate[0xc84] = 0;
00087
00088
00089
00090
00091
00092
00093
00094
00095 }
00096 }
00097
00098 GctFormatTranslateMCLegacy::~GctFormatTranslateMCLegacy()
00099 {
00100 }
00101
00102 GctBlockHeader GctFormatTranslateMCLegacy::generateBlockHeader(const unsigned char * data) const
00103 {
00104
00105 uint32_t hdr = data[0] + (data[1]<<8) + (data[2]<<16) + (data[3]<<24);
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 uint32_t blockId = hdr & 0xfff;
00118 uint32_t blockLength = 0;
00119 uint32_t nSamples = (hdr>>16) & 0xf;
00120 uint32_t bxId = (hdr>>20) & 0xfff;
00121 uint32_t eventId = (hdr>>12) & 0xf;
00122 bool valid = (blockLengthMap().find(blockId) != blockLengthMap().end());
00123
00124 if(valid) { blockLength = blockLengthMap().find(blockId)->second; }
00125
00126 return GctBlockHeader(blockId, blockLength, nSamples, bxId, eventId, valid);
00127 }
00128
00129
00130 bool GctFormatTranslateMCLegacy::convertBlock(const unsigned char * data, const GctBlockHeader& hdr)
00131 {
00132
00133 if ( hdr.nSamples() < 1 ) { return true; }
00134
00135 if(!checkBlock(hdr)) { return false; }
00136
00137
00138
00139
00140 (this->*m_blockUnpackFn.find(hdr.blockId())->second)(data, hdr);
00141
00142 return true;
00143 }
00144
00145
00146 void GctFormatTranslateMCLegacy::writeGctOutEmAndEnergyBlock(unsigned char * d,
00147 const L1GctEmCandCollection* iso,
00148 const L1GctEmCandCollection* nonIso,
00149 const L1GctEtTotalCollection* etTotal,
00150 const L1GctEtHadCollection* etHad,
00151 const L1GctEtMissCollection* etMiss)
00152 {
00153
00154 vector<const L1GctEmCandCollection*> emCands(NUM_EM_CAND_CATEGORIES);
00155 emCands.at(NON_ISO_EM_CANDS)=nonIso;
00156 emCands.at(ISO_EM_CANDS)=iso;
00157
00158
00159
00160
00161 vector<unsigned> bx0EmCandOffsets(NUM_EM_CAND_CATEGORIES);
00162
00163
00164 for(unsigned int iCat = 0 ; iCat < NUM_EM_CAND_CATEGORIES ; ++iCat)
00165 {
00166 const L1GctEmCandCollection * cands = emCands.at(iCat);
00167 unsigned& offset = bx0EmCandOffsets.at(iCat);
00168 if(!findBx0OffsetInCollection(offset, cands)) { LogDebug("GCT") << "No EM candidates with bx=0!\nAborting packing of GCT EM Cand and Energy Sum Output!"; return; }
00169 if((cands->size()-offset) < 4) { LogDebug("GCT") << "Insufficient EM candidates with bx=0!\nAborting packing of GCT EM Cand and Energy Sum Output!"; return; }
00170 }
00171
00172 unsigned bx0EtTotalOffset, bx0EtHadOffset, bx0EtMissOffset;
00173 if(!findBx0OffsetInCollection(bx0EtTotalOffset, etTotal)) { LogDebug("GCT") << "No Et Total value for bx=0!\nAborting packing of GCT EM Cand and Energy Sum Output!"; return; }
00174 if(!findBx0OffsetInCollection(bx0EtHadOffset, etHad)) { LogDebug("GCT") << "No Et Hadronic value for bx=0!\nAborting packing of GCT EM Cand and Energy Sum Output!"; return; }
00175 if(!findBx0OffsetInCollection(bx0EtMissOffset, etMiss)) { LogDebug("GCT") << "No Et Miss value for bx=0!\nAborting packing of GCT EM Cand and Energy Sum Output!"; return; }
00176
00177
00178
00179 unsigned nSamples = 1;
00180
00181
00182 writeRawHeader(d, 0x683, nSamples);
00183
00184 d=d+4;
00185
00186
00187
00188
00189 uint16_t * p16 = reinterpret_cast<uint16_t *>(d);
00190
00191 for (unsigned iCat=0; iCat < NUM_EM_CAND_CATEGORIES; ++iCat)
00192 {
00193 const L1GctEmCandCollection * em = emCands.at(iCat);
00194 const unsigned bx0Offset = bx0EmCandOffsets.at(iCat);
00195
00196 uint16_t * cand = p16 + (iCat*4);
00197
00198 *cand = em->at(bx0Offset).raw();
00199 cand++;
00200 *cand = em->at(bx0Offset + 2).raw();
00201 cand += nSamples;
00202 *cand = em->at(bx0Offset + 1).raw();
00203 cand++;
00204 *cand = em->at(bx0Offset + 3).raw();
00205 }
00206
00207
00208
00209 p16+=8;
00210 *p16 = etTotal->at(bx0EtTotalOffset).raw();
00211 p16++;
00212 *p16 = etHad->at(bx0EtHadOffset).raw();
00213 p16++;
00214 uint32_t * p32 = reinterpret_cast<uint32_t *>(p16);
00215 *p32 = etMiss->at(bx0EtMissOffset).raw();
00216 }
00217
00218 void GctFormatTranslateMCLegacy::writeGctOutJetBlock(unsigned char * d,
00219 const L1GctJetCandCollection* cenJets,
00220 const L1GctJetCandCollection* forJets,
00221 const L1GctJetCandCollection* tauJets,
00222 const L1GctHFRingEtSumsCollection* hfRingSums,
00223 const L1GctHFBitCountsCollection* hfBitCounts,
00224 const L1GctHtMissCollection* htMiss)
00225 {
00226
00227 vector<const L1GctJetCandCollection*> jets(NUM_JET_CATEGORIES);
00228 jets.at(CENTRAL_JETS)=cenJets;
00229 jets.at(FORWARD_JETS)=forJets;
00230 jets.at(TAU_JETS)=tauJets;
00231
00232
00233
00234
00235 vector<unsigned> bx0JetCandOffsets(NUM_JET_CATEGORIES);
00236
00237
00238 for(unsigned int iCat = 0 ; iCat < NUM_JET_CATEGORIES ; ++iCat)
00239 {
00240 const L1GctJetCandCollection * jetCands = jets.at(iCat);
00241 unsigned& offset = bx0JetCandOffsets.at(iCat);
00242 if(!findBx0OffsetInCollection(offset, jetCands)) { LogDebug("GCT") << "No jet candidates with bx=0!\nAborting packing of GCT Jet Output!"; return; }
00243 if((jetCands->size()-offset) < 4) { LogDebug("GCT") << "Insufficient jet candidates with bx=0!\nAborting packing of GCT Jet Output!"; return; }
00244 }
00245
00246
00247 unsigned bx0HfRingSumsOffset, bx0HfBitCountsOffset, bx0HtMissOffset;
00248 if(!findBx0OffsetInCollection(bx0HfRingSumsOffset, hfRingSums)) { LogDebug("GCT") << "No ring sums with bx=0!\nAborting packing of GCT Jet Output!"; return; }
00249 if(!findBx0OffsetInCollection(bx0HfBitCountsOffset, hfBitCounts)) { LogDebug("GCT") << "No bit counts with bx=0!\nAborting packing of GCT Jet Output!"; return; }
00250 if(!findBx0OffsetInCollection(bx0HtMissOffset, htMiss)) { LogDebug("GCT") << "No missing Ht with bx=0!\nAborting packing of GCT Jet Output!"; return; }
00251
00252
00253 writeRawHeader(d, 0x583, 1);
00254
00255 d=d+4;
00256
00257
00258
00259 uint16_t * p16 = reinterpret_cast<uint16_t *>(d);
00260
00261 const unsigned categoryOffset = 4;
00262 const unsigned nextCandPairOffset = 2;
00263
00264
00265 for(unsigned iCat = 0 ; iCat < NUM_JET_CATEGORIES ; ++iCat)
00266 {
00267 const L1GctJetCandCollection * jetCands = jets.at(iCat);
00268 const unsigned cand0Offset = iCat*categoryOffset;
00269 const unsigned bx0Offset = bx0JetCandOffsets.at(iCat);
00270
00271 p16[cand0Offset] = jetCands->at(bx0Offset).raw();
00272 p16[cand0Offset + nextCandPairOffset] = jetCands->at(bx0Offset + 1).raw();
00273 p16[cand0Offset + 1] = jetCands->at(bx0Offset + 2).raw();
00274 p16[cand0Offset + nextCandPairOffset + 1] = jetCands->at(bx0Offset + 3).raw();
00275 }
00276
00277
00278 d=d+24;
00279
00280
00281 uint32_t * p32 = reinterpret_cast<uint32_t *>(d);
00282
00283 uint32_t tmp = hfBitCounts->at(bx0HfBitCountsOffset).raw() & 0xfff;
00284 tmp |= hfRingSums->at(bx0HfRingSumsOffset).etSum(0)<<12;
00285 tmp |= hfRingSums->at(bx0HfRingSumsOffset).etSum(1)<<16;
00286 tmp |= hfRingSums->at(bx0HfRingSumsOffset).etSum(2)<<19;
00287 tmp |= hfRingSums->at(bx0HfRingSumsOffset).etSum(3)<<22;
00288 p32[0] = tmp;
00289
00290 const L1GctHtMiss& bx0HtMiss = htMiss->at(bx0HtMissOffset);
00291 uint32_t htMissRaw = 0x5555c000 |
00292 (bx0HtMiss.overFlow() ? 0x1000 : 0x0000) |
00293 ((bx0HtMiss.et() & 0x7f) << 5) |
00294 ((bx0HtMiss.phi() & 0x1f));
00295
00296 p32[1] = htMissRaw;
00297 }
00298
00299 void GctFormatTranslateMCLegacy::writeRctEmCandBlocks(unsigned char * d, const L1CaloEmCollection * rctEm)
00300 {
00301
00302
00303 if(rctEm->size() == 0 || rctEm->size()%144 != 0)
00304 {
00305 LogDebug("GCT") << "Block pack error: bad L1CaloEmCollection size detected!\n"
00306 << "Aborting packing of RCT EM Cand data!";
00307 return;
00308 }
00309
00310
00311 SourceCardRouting::EmuToSfpData emuToSfpData[18];
00312
00313
00314 for(unsigned i=0, size=rctEm->size(); i < size ; ++i)
00315 {
00316 const L1CaloEmCand &cand = rctEm->at(i);
00317 if(cand.bx() != 0) { continue; }
00318 unsigned crateNum = cand.rctCrate();
00319 unsigned index = cand.index();
00320
00321
00322 assert(crateNum < 18);
00323 assert(index < 4);
00324
00325 if(cand.isolated())
00326 {
00327 emuToSfpData[crateNum].eIsoRank[index] = cand.rank();
00328 emuToSfpData[crateNum].eIsoCardId[index] = cand.rctCard();
00329 emuToSfpData[crateNum].eIsoRegionId[index] = cand.rctRegion();
00330 }
00331 else
00332 {
00333 emuToSfpData[crateNum].eNonIsoRank[index] = cand.rank();
00334 emuToSfpData[crateNum].eNonIsoCardId[index] = cand.rctCard();
00335 emuToSfpData[crateNum].eNonIsoRegionId[index] = cand.rctRegion();
00336 }
00337
00338
00339
00340
00341 }
00342
00343
00344 for(unsigned c = 0 ; c < 18 ; ++c)
00345 {
00346 srcCardRouting().EMUtoSFP(emuToSfpData[c].eIsoRank, emuToSfpData[c].eIsoCardId, emuToSfpData[c].eIsoRegionId,
00347 emuToSfpData[c].eNonIsoRank, emuToSfpData[c].eNonIsoCardId, emuToSfpData[c].eNonIsoRegionId,
00348 emuToSfpData[c].mipBits, emuToSfpData[c].qBits, emuToSfpData[c].sfp);
00349 }
00350
00351
00352 BlkToRctCrateMap::iterator blockStartCrateIter;
00353 for(blockStartCrateIter = rctEmCrateMap().begin() ; blockStartCrateIter != rctEmCrateMap().end() ; ++blockStartCrateIter)
00354 {
00355 unsigned blockId = blockStartCrateIter->first;
00356 unsigned startCrate = blockStartCrateIter->second;
00357 unsigned blockLength_32bit = blockLengthMap()[blockId];
00358
00359 writeRawHeader(d, blockId, 1);
00360 d+=4;
00361
00362
00363 uint16_t * p16 = reinterpret_cast<uint16_t *>(const_cast<unsigned char *>(d));
00364
00365 for(unsigned iCrate=startCrate, end=startCrate + blockLength_32bit/3 ; iCrate < end ; ++iCrate)
00366 {
00367 for(unsigned iOutput = 1 ; iOutput < 4 ; ++iOutput)
00368 {
00369 for(unsigned iCycle = 0 ; iCycle < 2 ; ++iCycle)
00370 {
00371 *p16 = emuToSfpData[iCrate].sfp[iCycle][iOutput];
00372 ++p16;
00373 }
00374 }
00375 }
00376
00377
00378 d+=(blockLength_32bit*4);
00379 }
00380 }
00381
00382 void GctFormatTranslateMCLegacy::writeAllRctCaloRegionBlock(unsigned char * d, const L1CaloRegionCollection * rctCalo)
00383 {
00384
00385
00386 if(rctCalo->size() == 0 || rctCalo->size()%396 != 0)
00387 {
00388 LogDebug("GCT") << "Block pack error: bad L1CaloRegionCollection size detected!\n"
00389 << "Aborting packing of RCT Calo Region data!";
00390 return;
00391 }
00392
00393 writeRawHeader(d, 0x0ff, 1);
00394 d+=4;
00395
00396
00397 uint16_t * p16 = reinterpret_cast<uint16_t *>(const_cast<unsigned char *>(d));
00398
00399 for(unsigned i=0, size=rctCalo->size(); i < size ; ++i)
00400 {
00401 const L1CaloRegion ® = rctCalo->at(i);
00402 if(reg.bx() != 0) { continue; }
00403 const unsigned crateNum = reg.rctCrate();
00404 const unsigned regionIndex = reg.rctRegionIndex();
00405 assert(crateNum < 18);
00406
00407
00408 const uint16_t raw = reg.et() |
00409 (reg.overFlow() ? 0x400 : 0x0) |
00410 (reg.fineGrain() ? 0x800 : 0x0) |
00411 (reg.mip() ? 0x1000 : 0x0) |
00412 (reg.quiet() ? 0x2000 : 0x0);
00413
00414 unsigned offset = 0;
00415 if(reg.isHbHe())
00416 {
00417 const unsigned cardNum = reg.rctCard();
00418 assert(cardNum < 7);
00419 assert(regionIndex < 2);
00420
00421
00422 offset = crateNum*22 + cardNum*2 + regionIndex;
00423 }
00424 else
00425 {
00426 assert(regionIndex < 8);
00427 offset = crateNum*22 + 14 + regionIndex;
00428 }
00429 p16[offset] = raw;
00430 }
00431 }
00432
00433
00434
00435
00436 uint32_t GctFormatTranslateMCLegacy::generateRawHeader(const uint32_t blockId,
00437 const uint32_t nSamples,
00438 const uint32_t bxId,
00439 const uint32_t eventId) const
00440 {
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 return ((bxId & 0xfff) << 20) | ((nSamples & 0xf) << 16) | ((eventId & 0xf) << 12) | (blockId & 0xfff);
00452 }
00453
00454
00455
00456
00457
00458 void GctFormatTranslateMCLegacy::blockToGctEmCandsAndEnergySums(const unsigned char * d, const GctBlockHeader& hdr)
00459 {
00460 const unsigned int id = hdr.blockId();
00461 const unsigned int nSamples = hdr.nSamples();
00462
00463
00464
00465 const uint16_t * p16 = reinterpret_cast<const uint16_t *>(d);
00466
00467
00468
00469 const unsigned int emCandCategoryOffset = nSamples * 4;
00470 const unsigned int timeSampleOffset = nSamples * 2;
00471
00472 unsigned int samplesToUnpack = 1;
00473 if(!hltMode()) { samplesToUnpack = nSamples; }
00474
00475 for (unsigned int iso=0; iso<2; ++iso)
00476 {
00477 bool isoFlag = (iso==1);
00478
00479
00480 L1GctEmCandCollection* em;
00481 if (isoFlag) { em = colls()->gctIsoEm(); }
00482 else { em = colls()->gctNonIsoEm(); }
00483
00484 for (unsigned int bx=0; bx<samplesToUnpack; ++bx)
00485 {
00486
00487
00488 const unsigned int cand0Offset = iso*emCandCategoryOffset + bx*2;
00489
00490 em->push_back(L1GctEmCand(p16[cand0Offset], isoFlag, id, 0, bx));
00491 em->push_back(L1GctEmCand(p16[cand0Offset + timeSampleOffset], isoFlag, id, 1, bx));
00492 em->push_back(L1GctEmCand(p16[cand0Offset + 1], isoFlag, id, 2, bx));
00493 em->push_back(L1GctEmCand(p16[cand0Offset + timeSampleOffset + 1], isoFlag, id, 3, bx));
00494 }
00495 }
00496
00497 p16 += emCandCategoryOffset * 2;
00498
00499
00500
00501
00502 colls()->gctEtTot()->push_back(L1GctEtTotal(p16[0]));
00503 colls()->gctEtHad()->push_back(L1GctEtHad(p16[1]));
00504
00505
00506 const uint32_t * p32 = reinterpret_cast<const uint32_t *>(p16);
00507
00508 colls()->gctEtMiss()->push_back(L1GctEtMiss(p32[nSamples]));
00509 }
00510
00511 void GctFormatTranslateMCLegacy::blockToGctJetCandsAndCounts(const unsigned char * d, const GctBlockHeader& hdr)
00512 {
00513 const unsigned int id = hdr.blockId();
00514 const unsigned int nSamples = hdr.nSamples();
00515
00516
00517
00518 const uint16_t * p16 = reinterpret_cast<const uint16_t *>(d);
00519
00520
00521
00522 const unsigned int jetCandCategoryOffset = nSamples * 4;
00523 const unsigned int timeSampleOffset = nSamples * 2;
00524
00525 unsigned int samplesToUnpack = 1;
00526 if(!hltMode()) { samplesToUnpack = nSamples; }
00527
00528
00529 for(unsigned int iCat = 0 ; iCat < NUM_JET_CATEGORIES ; ++iCat)
00530 {
00531 L1GctJetCandCollection * const jets = gctJets(iCat);
00532 assert(jets->empty());
00533
00534 bool tauflag = (iCat == TAU_JETS);
00535 bool forwardFlag = (iCat == FORWARD_JETS);
00536
00537
00538 for(unsigned int bx = 0 ; bx < samplesToUnpack ; ++bx)
00539 {
00540
00541 const unsigned int cand0Offset = iCat*jetCandCategoryOffset + bx*2;
00542
00543
00544 jets->push_back(L1GctJetCand(p16[cand0Offset], tauflag, forwardFlag, id, 0, bx));
00545
00546 jets->push_back(L1GctJetCand(p16[cand0Offset + timeSampleOffset], tauflag, forwardFlag, id, 1, bx));
00547
00548 jets->push_back(L1GctJetCand(p16[cand0Offset + 1], tauflag, forwardFlag, id, 2, bx));
00549
00550 jets->push_back(L1GctJetCand(p16[cand0Offset + timeSampleOffset + 1], tauflag, forwardFlag, id, 3, bx));
00551 }
00552 }
00553
00554 p16 += NUM_JET_CATEGORIES * jetCandCategoryOffset;
00555
00556
00557
00558
00559
00560 const uint32_t * p32 = reinterpret_cast<const uint32_t *>(p16);
00561
00562
00563 colls()->gctHfBitCounts()->push_back(L1GctHFBitCounts::fromConcHFBitCounts(id,6,0,p32[0]));
00564 colls()->gctHfRingEtSums()->push_back(L1GctHFRingEtSums::fromConcRingSums(id,6,0,p32[0]));
00565
00566
00567 colls()->gctHtMiss()->push_back(L1GctHtMiss(p32[nSamples], 0));
00568 }
00569
00570
00571
00572 void GctFormatTranslateMCLegacy::blockToRctEmCand(const unsigned char * d, const GctBlockHeader& hdr)
00573 {
00574
00575 if(hltMode()) { LogDebug("GCT") << "HLT mode - skipping unpack of RCT EM Cands"; return; }
00576
00577 unsigned int id = hdr.blockId();
00578 unsigned int nSamples = hdr.nSamples();
00579 unsigned int length = hdr.blockLength();
00580
00581
00582 uint16_t * p = reinterpret_cast<uint16_t *>(const_cast<unsigned char *>(d));
00583
00584
00585 uint16_t sfp[2][4];
00586 uint16_t eIsoRank[4];
00587 uint16_t eIsoCard[4];
00588 uint16_t eIsoRgn[4];
00589 uint16_t eNonIsoRank[4];
00590 uint16_t eNonIsoCard[4];
00591 uint16_t eNonIsoRgn[4];
00592 uint16_t MIPbits[7][2];
00593 uint16_t QBits[7][2];
00594
00595 unsigned int bx = 0;
00596
00597
00598 for (unsigned int crate=rctEmCrateMap()[id]; crate<rctEmCrateMap()[id]+length/3; ++crate) {
00599
00600
00601 for (unsigned short iSfp=0 ; iSfp<4 ; ++iSfp) {
00602 for (unsigned short cyc=0 ; cyc<2 ; ++cyc) {
00603 if (iSfp==0) { sfp[cyc][iSfp] = 0; }
00604 else {
00605 sfp[cyc][iSfp] = *p;
00606 ++p;
00607 }
00608 }
00609 p = p + 2*(nSamples-1);
00610 }
00611
00612
00613 srcCardRouting().SFPtoEMU(eIsoRank, eIsoCard, eIsoRgn, eNonIsoRank, eNonIsoCard, eNonIsoRgn, MIPbits, QBits, sfp);
00614
00615
00616 for (unsigned short int i=0; i<4; ++i) {
00617 colls()->rctEm()->push_back( L1CaloEmCand( eIsoRank[i], eIsoRgn[i], eIsoCard[i], crate, true, i, bx) );
00618 }
00619 for (unsigned short int i=0; i<4; ++i) {
00620 colls()->rctEm()->push_back( L1CaloEmCand( eNonIsoRank[i], eNonIsoRgn[i], eNonIsoCard[i], crate, false, i, bx) );
00621 }
00622 }
00623 }
00624
00625
00626 void GctFormatTranslateMCLegacy::blockToFibres(const unsigned char * d, const GctBlockHeader& hdr)
00627 {
00628
00629 if(hltMode()) { LogDebug("GCT") << "HLT mode - skipping unpack of GCT Fibres"; return; }
00630
00631 unsigned int id = hdr.blockId();
00632 unsigned int nSamples = hdr.nSamples();
00633 unsigned int length = hdr.blockLength();
00634
00635
00636 uint32_t * p = reinterpret_cast<uint32_t *>(const_cast<unsigned char *>(d));
00637
00638 for (unsigned int i=0; i<length; ++i) {
00639 for (unsigned int bx=0; bx<nSamples; ++bx) {
00640 colls()->gctFibres()->push_back( L1GctFibreWord(*p, id, i, bx) );
00641 ++p;
00642 }
00643 }
00644 }
00645
00646 void GctFormatTranslateMCLegacy::blockToFibresAndToRctEmCand(const unsigned char * d, const GctBlockHeader& hdr)
00647 {
00648 this->blockToRctEmCand(d, hdr);
00649 this->blockToFibres(d, hdr);
00650 }
00651
00652 void GctFormatTranslateMCLegacy::blockToAllRctCaloRegions(const unsigned char * d, const GctBlockHeader& hdr)
00653 {
00654
00655 if(hltMode()) { LogDebug("GCT") << "HLT mode - skipping unpack of RCT Calo Regions"; return; }
00656
00657
00658
00659
00660 const int nSamples = hdr.nSamples();
00661
00662
00663 const uint16_t * p16 = reinterpret_cast<const uint16_t *>(d);
00664
00665 for(unsigned iCrate = 0 ; iCrate < 18 ; ++iCrate)
00666 {
00667
00668 for(unsigned iCard = 0 ; iCard < 7 ; ++iCard)
00669 {
00670
00671 for(int16_t iSample = 0 ; iSample < nSamples ; ++iSample)
00672 {
00673
00674 for(unsigned iRegion = 0 ; iRegion < 2 ; ++iRegion)
00675 {
00676 L1CaloRegionDetId id(iCrate, iCard, iRegion);
00677 colls()->rctCalo()->push_back(L1CaloRegion(*p16, id.ieta(), id.iphi(), iSample));
00678 ++p16;
00679 }
00680 }
00681 }
00682
00683 for(unsigned iRegionPairNum = 0 ; iRegionPairNum < 4 ; ++iRegionPairNum)
00684 {
00685
00686 for(int16_t iSample = 0 ; iSample < nSamples ; ++iSample)
00687 {
00688
00689 for(unsigned iPair = 0 ; iPair < 2 ; ++iPair)
00690 {
00691
00692 L1CaloRegionDetId id(iCrate, 999, iRegionPairNum*2 + iPair);
00693 colls()->rctCalo()->push_back(L1CaloRegion(*p16, id.ieta(), id.iphi(), iSample));
00694 ++p16;
00695 }
00696 }
00697 }
00698 }
00699 }
00700
00701 template <typename Collection>
00702 bool GctFormatTranslateMCLegacy::findBx0OffsetInCollection(unsigned& bx0Offset, const Collection* coll)
00703 {
00704 bool foundBx0 = false;
00705 unsigned size = coll->size();
00706 for(bx0Offset = 0 ; bx0Offset < size ; ++bx0Offset)
00707 {
00708 if(coll->at(bx0Offset).bx() == 0) { foundBx0 = true; break; }
00709 }
00710 return foundBx0;
00711 }