Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:05

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0003 
0004 #include "GTCollections.h"
0005 #include "GlobalExtBlkUnpacker.h"
0006 
0007 namespace l1t {
0008   namespace stage2 {
0009     bool GlobalExtBlkUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0010       LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize();
0011 
0012       unsigned int wdPerBX = 6;  //should this be configured someplace else?
0013       int nBX = int(ceil(
0014           block.header().getSize() /
0015           6.));  // FOR GT Not sure what we have here...put at 6 because of 6 frames. Since there are 12 EGamma objects reported per event (see CMS IN-2013/005)
0016 
0017       // Find the central, first and last BXs
0018       int firstBX = -(ceil((double)nBX / 2.) - 1);
0019       int lastBX;
0020       if (nBX % 2 == 0) {
0021         lastBX = ceil((double)nBX / 2.);
0022       } else {
0023         lastBX = ceil((double)nBX / 2.) - 1;
0024       }
0025 
0026       auto res_ = static_cast<GTCollections*>(coll)->getExts();
0027       res_->setBXRange(firstBX, lastBX);
0028 
0029       LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0030 
0031       // Loop over multiple BX and then number of EG cands filling collection
0032       int numBX = 0;  //positive int to count BX
0033       for (int bx = firstBX; bx <= lastBX; bx++) {
0034         // If this is the first block, instantiate GlobalExt so it is there to fill from mult. blocks
0035         if (block.header().getID() == 24) {
0036           LogDebug("L1T") << "Creating GT External Block for BX =" << bx;
0037           GlobalExtBlk tExt = GlobalExtBlk();
0038           res_->push_back(bx, tExt);
0039         }
0040 
0041         //fetch from collection
0042         GlobalExtBlk ext = res_->at(bx, 0);
0043 
0044         //Determine offset of algorithm bits based on block.ID
0045         // ID=24  offset = 0;  ID=26  offset=64;  ID=28  offset=128=2*64; ID=30 offset=3*64=192
0046         int extOffset = ((block.header().getID() - 24) / 2) * 64;
0047 
0048         for (unsigned int wd = 0; wd < wdPerBX; wd++) {
0049           uint32_t raw_data = block.payload()[wd + numBX * wdPerBX];
0050           LogDebug("L1T") << " payload word " << wd << " 0x" << hex << raw_data;
0051 
0052           if (wd < 2) {
0053             for (unsigned int bt = 0; bt < 32; bt++) {
0054               int val = ((raw_data >> bt) & 0x1);
0055               int extBit = bt + wd * 32 + extOffset;
0056               if (val == 1)
0057                 ext.setExternalDecision(extBit, true);
0058             }
0059           }
0060         }
0061 
0062         // Put the object back into place (Must be better way???)
0063         res_->set(bx, 0, ext);
0064 
0065         //ext.print(std::cout);
0066         numBX++;
0067       }
0068 
0069       return true;
0070     }
0071   }  // namespace stage2
0072 }  // namespace l1t
0073 
0074 DEFINE_L1T_UNPACKER(l1t::stage2::GlobalExtBlkUnpacker);