test
CMS 3D CMS Logo

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