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  //If this is not the first block, but the vector is empty, something has gone wrong (corrupted data)
50  else if (res_->isEmpty(bx))
51  throw cms::Exception("InvalidGlobalAlgBlkBxCollection")
52  << "The GlobalAlgBlk unpacker result vector is empty, but is not receiving the first expected header "
53  "ID! This may be due to corrupted, or poorly formatted events.\n"
54  << "uGTBoard: " << uGTBoard << "\nBX: " << bx << "\nFirst expected block: " << initialBlkID
55  << "\nReceived block: " << block.header().getID();
56 
57  //fetch
58  GlobalAlgBlk alg = res_->at(bx, 0);
59 
60  //Determine offset of algorithm bits based on block.ID
61  // ID=initialBlkID offset = 0; ID=initialBlkID+2 offset=192; ID=initialBlkID+4 offset=384=2*192; (before prescale)
62  // ID=intermBlkID offset = 0; ID=intermBlkID+2 offset=192; ID=intermBlkID+4 offset=384=2*192; (after prescale)
63  // ID=finalBlkID offset = 0; ID=finalBlkID+2 offset=192; ID=finalBlkID+4 offset=384=2*192; (after mask (Final))
64  int algOffset = (block.header().getID() - initialBlkID + 1) / 2;
65  algOffset = (algOffset % 3) * 192;
66 
67  for (unsigned int wd = 0; wd < wdPerBX; wd++) {
68  uint32_t raw_data = block.payload()[wd + numBX * wdPerBX];
69  LogDebug("L1T") << "BX " << bx << " payload word " << wd << " 0x" << hex << raw_data << " offset=" << dec
70  << algOffset << std::endl;
71 
72  //parse these 32 bits into algorithm bits (perhaps needs a more efficient way of doing this?
73  if ((block.header().getID() != initialBlkID + 4 && block.header().getID() != intermBlkID + 4 &&
74  block.header().getID() != finalBlkID + 4) ||
75  wd < 4) {
76  for (unsigned int bt = 0; bt < 32; bt++) {
77  int val = ((raw_data >> bt) & 0x1);
78  unsigned int algBit = bt + wd * 32 + algOffset;
79 
80  if (val == 1 && algBit < alg.maxPhysicsTriggers) {
81  LogDebug("L1T") << "Found valid alg bit (" << algBit << ") on bit (" << bt << ") word (" << wd
82  << ") algOffset (" << algOffset << ") block ID (" << block.header().getID() << ")"
83  << " Board# " << uGTBoard << std::endl;
84  if (block.header().getID() < initialBlkID + 5) {
85  alg.setAlgoDecisionInitial(algBit, true);
86  } else if (block.header().getID() < intermBlkID + 5) {
87  alg.setAlgoDecisionInterm(algBit, true);
88  } else {
89  alg.setAlgoDecisionFinal(algBit, true);
90  }
91  } else if (val == 1) {
92  LogDebug("L1T") << "Found invalid alg bit (" << algBit << ") out of range on bit (" << bt << ") word ("
93  << wd << ") algOffset (" << algOffset << ") block ID (" << block.header().getID() << ")"
94  << std::endl;
95  }
96  }
97 
98  } else if (block.header().getID() == initialBlkID + 4 && (wd == 4 || wd == 5)) {
99  //This is the 32bit hash of menu name
100  if (wd == 4)
101  alg.setL1MenuUUID(raw_data);
102  //This is the 32bit hash of menu firmware uuid
103  if (wd == 5)
104  alg.setL1FirmwareUUID(raw_data);
105 
106  } else if (block.header().getID() == finalBlkID + 4 && wd == 4) {
107  //Get the local FINORs and Veto...Global FINOR calculated below
108  if ((raw_data & 0x100) >> 8)
109  alg.setFinalORVeto(true);
110  if ((raw_data & 0x1) >> 0)
111  alg.setFinalORPreVeto(true);
112  LogDebug("L1T") << " Packing the FinalOR " << wd << " 0x" << hex << raw_data << endl;
113  } else if (block.header().getID() == finalBlkID + 4 && wd == 5) {
114  //This is the Prescale Column
115  alg.setPreScColumn(raw_data & 0xFF);
116  LogDebug("L1T") << " Packing the Prescale Column " << wd << " 0x" << hex << raw_data << endl;
117  }
118  }
119 
120  //Redetermine Final (multiboard) FINOR
121  //be explicit and must set to false if we find a board with veto set.
122  alg.setFinalOR(alg.getFinalORPreVeto() && !alg.getFinalORVeto());
123 
124  // Put the object back into place (Must be better way)
125  res_->set(bx, 0, alg);
126 
127  //alg.print(std::cout);
128 
129  //increment counter of which BX we are processing
130  numBX++;
131  }
132 
133  return true;
134  }
135  } // namespace stage2
136 } // namespace l1t
137 
constexpr int32_t ceil(float num)
void setL1MenuUUID(int uuid)
set simple members
Definition: GlobalAlgBlk.h:55
void setFinalORPreVeto(bool fOR)
Definition: GlobalAlgBlk.h:59
void setAlgoDecisionInitial(unsigned int bit, bool val)
Set decision bits.
Definition: GlobalAlgBlk.cc:73
const bool getFinalORPreVeto() const
Definition: GlobalAlgBlk.h:68
static const unsigned int numBX
Definition: LumiConstants.h:8
delete x;
Definition: CaloConfig.h:22
const bool getFinalORVeto() const
Definition: GlobalAlgBlk.h:69
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
void setL1FirmwareUUID(int fuuid)
Definition: GlobalAlgBlk.h:56
#define DEFINE_L1T_UNPACKER(type)
static constexpr unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
void setPreScColumn(int psC)
Definition: GlobalAlgBlk.h:61
bool unpack(const Block &block, UnpackerCollections *coll) override
void setAlgoDecisionFinal(unsigned int bit, bool val)
Definition: GlobalAlgBlk.cc:94
#define LogDebug(id)