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") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
25 
26  //Should this be configured someplace?
27  unsigned int wdPerBX = 6;
28  unsigned int initialBlkID = 33; //first block of inital alg bits
29  unsigned int intermBlkID = 39; //first block of alg bits after intermediate step
30  unsigned int finalBlkID = 45; //first block of final alg bits
31 
32  int nBX = int(ceil(block.header().getSize() / 6.)); // FOR GT Not sure what we have here...put at 6 because of 6 frames
33 
34  // Find the central, first and last BXs
35  int firstBX = -(ceil((double)nBX/2.)-1);
36  int lastBX;
37  if (nBX % 2 == 0) {
38  lastBX = ceil((double)nBX/2.);
39  } else {
40  lastBX = ceil((double)nBX/2.)-1;
41  }
42 
43  auto res_ = static_cast<GTCollections*>(coll)->getAlgs();
44  res_->setBXRange(firstBX, lastBX);
45 
46  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX << endl;
47 
48  // Loop over multiple BX and then number of EG cands filling collection
49  int numBX = 0; //positive int to count BX
50  for (int bx=firstBX; bx<=lastBX; bx++){
51 
52 
53  // If this is the first block, instantiate GlobalAlg so it is there to fill from mult. blocks
54  if(block.header().getID()==initialBlkID) {
55 
56  LogDebug("L1T") << "Creating GT Algorithm Block for BX =" << bx;
57  GlobalAlgBlk talg = GlobalAlgBlk();
58  res_->push_back(bx,talg);
59 
60  }
61 
62  //fetch
63  GlobalAlgBlk alg = res_->at(bx,0);
64 
65  //Determine offset of algorithm bits based on block.ID
66  // ID=initialBlkID offset = 0; ID=initialBlkID+2 offset=192; ID=initialBlkID+4 offset=384=2*192; (before prescale)
67  // ID=intermBlkID offset = 0; ID=intermBlkID+2 offset=192; ID=intermBlkID+4 offset=384=2*192; (after prescale)
68  // ID=finalBlkID offset = 0; ID=finalBlkID+2 offset=192; ID=finalBlkID+4 offset=384=2*192; (after mask (Final))
69  int algOffset = (block.header().getID() - initialBlkID + 1)/2;
70  algOffset = (algOffset%3)*192;
71 
72  for(unsigned int wd=0; wd<wdPerBX; wd++) {
73  uint32_t raw_data = block.payload()[wd+numBX*wdPerBX];
74  LogDebug("L1T") << "BX "<<bx << " payload word " << wd << " 0x" << hex << raw_data << " offset=" << dec << algOffset << std::endl;
75 
76  //parse these 32 bits into algorithm bits (perhaps needs a more efficient way of doing this?
77  if( (block.header().getID()!=initialBlkID+4 && block.header().getID()!=intermBlkID+4 && block.header().getID()!=finalBlkID+4 ) || wd<4) {
78  for(unsigned int bt=0; bt<32; bt++) {
79  int val = ((raw_data >> bt) & 0x1);
80  unsigned int algBit = bt+wd*32+algOffset;
81  if(val==1 && algBit < alg.maxPhysicsTriggers) { //FIX ME...get dimension from object
82  LogDebug("L1T") << "Found valid alg bit ("<< algBit <<") on bit ("<<bt<<") word ("<<wd<<") algOffset ("<<algOffset<<") block ID ("<< block.header().getID() <<")" <<std::endl;
83  if(block.header().getID()<initialBlkID+5) {
84  alg.setAlgoDecisionInitial(algBit,true);
85  } else if(block.header().getID()<intermBlkID+5) {
86  alg.setAlgoDecisionInterm(algBit,true);
87  } else {
88  alg.setAlgoDecisionFinal(algBit,true);
89  }
90  } else if(val==1) {
91  LogDebug("L1T") << "Found invalid alg bit ("<< algBit <<") out of range (128) on bit ("<<bt<<") word ("<<wd<<") algOffset ("<<algOffset<<") block ID ("<< block.header().getID() <<")" <<std::endl;
92  }
93  }
94 
95  } else if(block.header().getID()==initialBlkID+4 && (wd==4 || wd==5) ) {
96  //This is the 32bit hash of menu name
97  if(wd==4) alg.setL1MenuUUID(raw_data);
98  //This is the 32bit hash of menu firmware uuid
99  if(wd==5) alg.setL1FirmwareUUID(raw_data);
100 
101  } else if(block.header().getID()==finalBlkID+4 && wd==4) {
102  //This is the FINOR
103  if ( (raw_data & 0x10000)>>16 ) alg.setFinalOR(true);
104  if ( (raw_data & 0x100)>> 8 ) alg.setFinalORVeto(true);
105  if ( (raw_data & 0x1)>> 0 ) alg.setFinalORPreVeto(true);
106  LogDebug("L1T") << " Packing the FinalOR " << wd << " 0x" << hex << raw_data << endl;
107  } else if(block.header().getID()==finalBlkID+4 && wd==5) {
108  //This is the Prescale Column
109  alg.setPreScColumn(raw_data & 0xFF );
110  LogDebug("L1T") << " Packing the Prescale Column " << wd << " 0x" << hex << raw_data << endl;
111  }
112  }
113 
114  // Put the object back into place (Must be better way)
115  res_->set(bx,0,alg);
116 
117  //alg.print(std::cout);
118 
119  //increment counter of which BX we are processing
120  numBX++;
121  }
122 
123  return true;
124  }
125 }
126 }
127 
#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
std::vector< uint32_t > payload() const
Definition: Block.h:57
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
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
void setAlgoDecisionFinal(unsigned int bit, bool val)