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