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  int nBX = int(ceil(block.header().getSize() / 6.)); // FOR GT Not sure what we have here...put at 6 because of 6 frames Since there are 12 EGamma objects reported per event (see CMS IN-2013/005)
27 
28  // Find the central, first and last BXs
29  int firstBX = -(ceil((double)nBX/2.)-1);
30  int lastBX;
31  if (nBX % 2 == 0) {
32  lastBX = ceil((double)nBX/2.);
33  } else {
34  lastBX = ceil((double)nBX/2.)-1;
35  }
36 
37  auto res_ = static_cast<GTCollections*>(coll)->getAlgs();
38  res_->setBXRange(firstBX, lastBX);
39 
40  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
41 
42  // Loop over multiple BX and then number of EG cands filling collection
43  for (int bx=firstBX; bx<=lastBX; bx++){
44 
45  // If this is the first block, instantiate GlobalAlg so it is there to fill from mult. blocks
46  if(block.header().getID()==1) {
47 
48  LogDebug("L1T") << "Creating GT Algorithm Block for BX =" << bx;
49  GlobalAlgBlk talg = GlobalAlgBlk();
50  res_->push_back(bx,talg);
51 
52  }
53 
54  //fetch
55  GlobalAlgBlk alg = res_->at(bx,0);
56 
57  //Determine offset of algorithm bits based on block.ID
58  // ID=0 offset = 0; ID=3 offset=192; ID=5 offset=384=2*192;
59  int algOffset = (block.header().getID()/2)*192;
60 
61  for(unsigned int wd=0; wd<block.header().getSize(); wd++) {
62  uint32_t raw_data = block.payload()[wd];
63  LogDebug("L1T") << " payload word " << wd << " 0x" << hex << raw_data << " offset=" << algOffset;
64 
65  //parse these 32 bits into algorithm bits (perhaps needs a more efficient way of doing this?
66  if(block.header().getID()!=5 || wd<4) {
67  for(unsigned int bt=0; bt<32; bt++) {
68  int val = ((raw_data >> bt) & 0x1);
69  if(val==1) alg.setAlgoDecisionFinal(bt+wd*32+algOffset,true);
70  }
71  } else if(block.header().getID()==5 && wd==4) {
72  //This is the FINOR
73  alg.setFinalOR(raw_data);
74  LogDebug("L1T") << " Packing the FinalOR " << wd << " 0x" << hex << raw_data;
75  }
76  }
77 
78  // Put the object back into place (Must be better way)
79  res_->set(bx,0,alg);
80 
81  //alg.print(std::cout);
82 
83  }
84 
85  return true;
86  }
87 }
88 }
89 
#define LogDebug(id)
void setFinalOR(int fOR)
Definition: GlobalAlgBlk.h:57
unsigned int getID() const
Definition: Block.h:22
BlockHeader header() const
Definition: Block.h:56
std::vector< uint32_t > payload() const
Definition: Block.h:57
#define DEFINE_L1T_UNPACKER(type)
Definition: Unpacker.h:31
JetCorrectorParametersCollection coll
Definition: classes.h:10
unsigned int getSize() const
Definition: Block.h:23
void setAlgoDecisionFinal(int bit, bool val)
Definition: GlobalAlgBlk.cc:98
virtual bool unpack(const Block &block, UnpackerCollections *coll) override