CMS 3D CMS Logo

GlobalAlgBlkUnpacker.cc
Go to the documentation of this file.
3 
4 #include "GTCollections.h"
5 #include "GlobalAlgBlkUnpacker.h"
6 
7 namespace l1t {
8  namespace stage2 {
10  LogDebug("L1T") << "AMCNo " << block.amc().getAMCNumber() << " Block ID = " << block.header().getID()
11  << " size = " << block.header().getSize();
12 
13  // ================================================================================
14  //Should this be configured someplace?
15  unsigned int wdPerBX = 6;
16  unsigned int initialBlkID = 33; //first block of inital alg bits
17  unsigned int intermBlkID = 39; //first block of alg bits after intermediate step
18  unsigned int finalBlkID = 45; //first block of final alg bits
19  // ================================================================================
20 
21  unsigned int uGTBoard = block.amc().getAMCNumber() - 1;
22 
23  int nBX =
24  int(ceil(block.header().getSize() / 6.)); // FOR GT Not sure what we have here...put at 6 because of 6 frames
25 
26  // Find the central, first and last BXs
27  int firstBX = -(ceil((double)nBX / 2.) - 1);
28  int lastBX;
29  if (nBX % 2 == 0) {
30  lastBX = ceil((double)nBX / 2.);
31  } else {
32  lastBX = ceil((double)nBX / 2.) - 1;
33  }
34 
35  auto res_ = static_cast<GTCollections*>(coll)->getAlgs();
36  res_->setBXRange(firstBX, lastBX);
37 
38  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX << endl;
39 
40  // Loop over multiple BX and then number of EG cands filling collection
41  int numBX = 0; //positive int to count BX
42  for (int bx = firstBX; bx <= lastBX; bx++) {
43  // If this is the first block on first board, instantiate GlobalAlg so it is there to fill from mult. blocks
44  if (block.header().getID() == initialBlkID && uGTBoard == 0) {
45  LogDebug("L1T") << "Creating GT Algorithm Block for BX =" << bx << std::endl;
46  GlobalAlgBlk talg = GlobalAlgBlk();
47  res_->push_back(bx, talg);
48  }
49 
50  //fetch
51  GlobalAlgBlk alg = res_->at(bx, 0);
52 
53  //Determine offset of algorithm bits based on block.ID
54  // ID=initialBlkID offset = 0; ID=initialBlkID+2 offset=192; ID=initialBlkID+4 offset=384=2*192; (before prescale)
55  // ID=intermBlkID offset = 0; ID=intermBlkID+2 offset=192; ID=intermBlkID+4 offset=384=2*192; (after prescale)
56  // ID=finalBlkID offset = 0; ID=finalBlkID+2 offset=192; ID=finalBlkID+4 offset=384=2*192; (after mask (Final))
57  int algOffset = (block.header().getID() - initialBlkID + 1) / 2;
58  algOffset = (algOffset % 3) * 192;
59 
60  for (unsigned int wd = 0; wd < wdPerBX; wd++) {
61  uint32_t raw_data = block.payload()[wd + numBX * wdPerBX];
62  LogDebug("L1T") << "BX " << bx << " payload word " << wd << " 0x" << hex << raw_data << " offset=" << dec
63  << algOffset << std::endl;
64 
65  //parse these 32 bits into algorithm bits (perhaps needs a more efficient way of doing this?
66  if ((block.header().getID() != initialBlkID + 4 && block.header().getID() != intermBlkID + 4 &&
67  block.header().getID() != finalBlkID + 4) ||
68  wd < 4) {
69  for (unsigned int bt = 0; bt < 32; bt++) {
70  int val = ((raw_data >> bt) & 0x1);
71  unsigned int algBit = bt + wd * 32 + algOffset;
72 
73  if (val == 1 && algBit < alg.maxPhysicsTriggers) {
74  LogDebug("L1T") << "Found valid alg bit (" << algBit << ") on bit (" << bt << ") word (" << wd
75  << ") algOffset (" << algOffset << ") block ID (" << block.header().getID() << ")"
76  << " Board# " << uGTBoard << std::endl;
77  if (block.header().getID() < initialBlkID + 5) {
78  alg.setAlgoDecisionInitial(algBit, true);
79  } else if (block.header().getID() < intermBlkID + 5) {
80  alg.setAlgoDecisionInterm(algBit, true);
81  } else {
82  alg.setAlgoDecisionFinal(algBit, true);
83  }
84  } else if (val == 1) {
85  LogDebug("L1T") << "Found invalid alg bit (" << algBit << ") out of range on bit (" << bt << ") word ("
86  << wd << ") algOffset (" << algOffset << ") block ID (" << block.header().getID() << ")"
87  << std::endl;
88  }
89  }
90 
91  } else if (block.header().getID() == initialBlkID + 4 && (wd == 4 || wd == 5)) {
92  //This is the 32bit hash of menu name
93  if (wd == 4)
94  alg.setL1MenuUUID(raw_data);
95  //This is the 32bit hash of menu firmware uuid
96  if (wd == 5)
97  alg.setL1FirmwareUUID(raw_data);
98 
99  } else if (block.header().getID() == finalBlkID + 4 && wd == 4) {
100  //Get the local FINORs and Veto...Global FINOR calculated below
101  if ((raw_data & 0x100) >> 8)
102  alg.setFinalORVeto(true);
103  if ((raw_data & 0x1) >> 0)
104  alg.setFinalORPreVeto(true);
105  LogDebug("L1T") << " Packing the FinalOR " << wd << " 0x" << hex << raw_data << endl;
106  } else if (block.header().getID() == finalBlkID + 4 && wd == 5) {
107  //This is the Prescale Column
108  alg.setPreScColumn(raw_data & 0xFF);
109  LogDebug("L1T") << " Packing the Prescale Column " << wd << " 0x" << hex << raw_data << endl;
110  }
111  }
112 
113  //Redetermine Final (multiboard) FINOR
114  if (alg.getFinalORPreVeto() & !alg.getFinalORVeto()) {
115  alg.setFinalOR(true);
116  } else {
117  alg.setFinalOR(false); //be explicit and must set to false if we find a board with veto set.
118  }
119 
120  // Put the object back into place (Must be better way)
121  res_->set(bx, 0, alg);
122 
123  //alg.print(std::cout);
124 
125  //increment counter of which BX we are processing
126  numBX++;
127  }
128 
129  return true;
130  }
131  } // namespace stage2
132 } // namespace l1t
133 
#define LogDebug(id)
void setL1MenuUUID(int uuid)
set simple members
Definition: GlobalAlgBlk.h:55
const std::vector< uint32_t > & payload() const
Definition: Block.h:70
unsigned int getID() const
Definition: Block.h:27
void setFinalORPreVeto(bool fOR)
Definition: GlobalAlgBlk.h:59
void setAlgoDecisionInitial(unsigned int bit, bool val)
Set decision bits.
Definition: GlobalAlgBlk.cc:73
BlockHeader header() const
Definition: Block.h:69
static const unsigned int numBX
Definition: LumiConstants.h:8
delete x;
Definition: CaloConfig.h:22
const bool getFinalORVeto() const
Definition: GlobalAlgBlk.h:69
const bool getFinalORPreVeto() const
Definition: GlobalAlgBlk.h:68
constexpr int32_t ceil(float num)
void setAlgoDecisionInterm(unsigned int bit, bool val)
Definition: GlobalAlgBlk.cc:84
void setFinalOR(bool fOR)
Definition: GlobalAlgBlk.h:60
void setFinalORVeto(bool fOR)
Definition: GlobalAlgBlk.h:58
JetCorrectorParametersCollection coll
Definition: classes.h:10
static unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
void setL1FirmwareUUID(int fuuid)
Definition: GlobalAlgBlk.h:56
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:28
void setPreScColumn(int psC)
Definition: GlobalAlgBlk.h:61
void amc(const amc::Header &h)
Definition: Block.h:72
bool unpack(const Block &block, UnpackerCollections *coll) override
void setAlgoDecisionFinal(unsigned int bit, bool val)
Definition: GlobalAlgBlk.cc:94