CMS 3D CMS Logo

CSCCFEBTimeSlice.cc
Go to the documentation of this file.
3 #include <cassert>
4 #include <iomanip>
5 #include <cstdint>
6 
7 // a Gray code is An ordering of 2n binary numbers such that
8 // only one bit changes from one entry to the next
9 // const unsigned layerGrayCode[] = {3,1,5,6,4,2};
10 const unsigned layerInverseGrayCode[] = {1, 5, 0, 4, 2, 3};
11 // const unsigned channelGrayCode[] = {0,1,3,2, 6,7,5,4, 12,13,15,14, 10,11,9,8};
12 const unsigned channelInverseGrayCode[] = {0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10};
13 
15  bzero(this, 99 * 2);
16  dummy = 0x7FFF;
17  blank_space_1 = 0x7;
18  blank_space_3 = 0x7;
19 }
20 
22 // trig_time( frame & 0xFF ),
23 // sca_blk( (frame>>8) & 0xF ),
24 // l1a_phase((frame>>12( & 0x1),
25 // lct_phase((frame>>13( & 0x1),
26 // sca_full((frame>>14) & 0x1),
27 // ts_flag(((frame>>15) & 0x1)
28 {
29  memcpy(this, &frame, 2);
30 }
31 
32 CSCCFEBDataWord *CSCCFEBTimeSlice::timeSample(int layer, int channel, bool isDCFEB) const {
35  assert(channel >= 1 && channel <= 16);
36  int layerIndex = layerInverseGrayCode[layer - 1];
37 
38  unsigned channelIndex = channelInverseGrayCode[channel - 1];
39  if (isDCFEB)
40  channelIndex = channel - 1;
41  unsigned scaBin = channelIndex * 6 + layerIndex;
42  assert(scaBin < 96U); // scaBin >= 0, since scaBin is unsigned
43  return timeSample(scaBin);
44 }
45 
47  unsigned int result = 0;
48  for (unsigned i = 0; i < 16; ++i) {
49  result |= timeSample(i * 6 + layer - 1)->controllerData << i;
50  }
52 }
53 
56  for (int channel = 1; channel <= 16; ++channel) {
57  const unsigned short *shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
58  timeSample(layer, channel)->controllerData = (*shortWord >> (channel - 1)) & 1;
59  }
60  }
61 }
62 
63 unsigned CSCCFEBTimeSlice::calcCRC() const {
64  unsigned CRC = 0;
65  for (uint16_t pos = 0; pos < 96; ++pos)
66  CRC = (theSamples[pos] & 0x1fff) ^ ((theSamples[pos] & 0x1fff) << 1) ^
67  (((CRC & 0x7ffc) >> 2) | ((0x0003 & CRC) << 13)) ^ ((CRC & 0x7ffc) >> 1);
68  return CRC;
69 }
70 
71 std::ostream &operator<<(std::ostream &os, const CSCCFEBTimeSlice &slice) {
72  for (int ichannel = 1; ichannel <= 16; ++ichannel) {
73  for (int ilayer = CSCDetId::minLayerId(); ilayer <= CSCDetId::maxLayerId(); ++ilayer) {
74  //unsigned index = (ilayer-1) + (ichannel-1)*6;
75  //int value = (slice.timeSample(index))->adcCounts - 560;
76  int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560;
77  os << " " << std::setw(5) << std::dec << value;
78  }
79  os << std::endl;
80  }
81  return os;
82 }
unsigned calcCRC() const
CSCCFEBDataWord * timeSample(int index) const
input from 0 to 95
const unsigned channelInverseGrayCode[]
void setControllerWord(const CSCCFEBSCAControllerWord &controllerWord)
CSCCFEBSCAControllerWord scaControllerWord(int layer) const
unpacked from the controller words for each channel in the layer
assert(be >=bs)
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
std::ostream & operator<<(std::ostream &os, const CSCCFEBTimeSlice &slice)
Definition: value.py:1
unsigned short controllerData
combined from all 16 strips to make a word
static int minLayerId()
Definition: CSCDetId.h:242
const unsigned layerInverseGrayCode[]
unsigned short theSamples[96]
static int maxLayerId()
Definition: CSCDetId.h:243