CMS 3D CMS Logo

CaloSummaryUnpacker.cc
Go to the documentation of this file.
3 
5 
6 #include "L1TObjectCollections.h"
7 
9 
10 #include "CaloSummaryUnpacker.h"
11 #include "GTSetup.h"
12 
13 #include <cmath>
14 
15 float l1t::stage2::CaloSummaryUnpacker::processBitsToScore(const unsigned int bitsArray[]) {
16  float constructedScore = 0.0;
17  //All bits have been shifted to just left of the decimal point
18  //We need to convert them to float, shift them back to their proper position
19  //And then add them into the total
20  //The proper power is 4(-(bitIndex+1) + numCICADAWords/2)
21  // i.e. shift bitIndex to max out at half the number of CICADA words (indexed at 0) then count down
22  //And we shift by 4 bits a time, hence the factor of 4
23  for (unsigned short bitIndex = 0; bitIndex < numCICADAWords; ++bitIndex) {
24  constructedScore += ((float)bitsArray[bitIndex]) * pow(2.0, 4 * ((numCICADAWords / 2) - (bitIndex + 1)));
25  }
26  return constructedScore;
27 }
28 
30  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
31 
32  //Just a few things to help us handle the number of BXs
33  //Strictly, we should generally get five BXs, starting at -2, and going to 2
34  //With the central BX at 0. The frames count up from -2
35  int nBX = int(ceil(block.header().getSize() / nFramesPerEvent));
36  int firstBX = (nBX / 2) - nBX + 1;
37  int lastBX = nBX / 2;
38  int processedBXs = 0; //This will just help us keep track of what words we are grabbing
39 
40  auto res_ = static_cast<L1TObjectCollections*>(coll)->getCICADAScore();
41  res_->setBXRange(firstBX, lastBX);
42 
43  for (int bx = firstBX; bx <= lastBX; ++bx) {
44  //convert to float and then multiply by a factor based on the index?
45  unsigned int cicadaBits[numCICADAWords] = {0, 0, 0, 0};
46 
47  for (unsigned int wordNum = 0; wordNum < numCICADAWords; ++wordNum) {
48  unsigned short wordLocation =
49  processedBXs * nFramesPerEvent +
50  wordNum; //Calculate the location of the needed CICADA word based on how many BXs we have already handled, and how many words of CICADA we have already grabbed.
51  //Frame 0 of a bx are the most significant integer bits
52  //Frame 1 of a bx are the least significant integer bits
53  //Frame 2 of a bx are the most significant decimal bits
54  //Frame 3 of a bx are the lest significant decimal bits
55  //Frames 4&5 are unused (by CICADA), they are reserved.
56  uint32_t raw_data = block.payload().at(wordLocation);
57  cicadaBits[wordNum] =
58  (cicadaBitsPattern & raw_data) >>
59  28; //The 28 shifts the extracted bits over to the start of the 32 bit result data for easier working with later
60  }
61  res_->push_back(
62  bx,
63  processBitsToScore(
64  cicadaBits)); //Now we insert CICADA into the proper BX, after a quick utility constructs a number from the 4 sets of bits.
65  ++processedBXs; //index BXs
66  }
67 
68  return true;
69 }
70 
constexpr int32_t ceil(float num)
bool unpack(const Block &block, UnpackerCollections *coll) override
float processBitsToScore(const unsigned int[])
static constexpr unsigned short numCICADAWords
#define DEFINE_L1T_UNPACKER(type)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
#define LogDebug(id)