CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCCFEBTimeSlice.cc
Go to the documentation of this file.
2 #include <cassert>
3 #include <iomanip>
4 #include <stdint.h>
5 
6 // a Gray code is An ordering of 2n binary numbers such that
7 // only one bit changes from one entry to the next
8 // const unsigned layerGrayCode[] = {3,1,5,6,4,2};
9 const unsigned layerInverseGrayCode[] = {1,5,0,4,2,3};
10 // const unsigned channelGrayCode[] = {0,1,3,2, 6,7,5,4, 12,13,15,14, 10,11,9,8};
11 const unsigned channelInverseGrayCode[] = {0,1,3,2, 7,6,4,5, 15,14,12,13, 8,9,11,10};
12 
14 {
15  bzero(this, 99*2);
16  dummy = 0x7FFF;
17  blank_space_1 = 0x7;
18  blank_space_3 = 0x7;
19 }
20 
21 
23 // trig_time( frame & 0xFF ),
24 // sca_blk( (frame>>8) & 0xF ),
25 // l1a_phase((frame>>12( & 0x1),
26 // lct_phase((frame>>13( & 0x1),
27 // sca_full((frame>>14) & 0x1),
28 // ts_flag(((frame>>15) & 0x1)
29 {
30  memcpy(this, &frame, 2);
31 }
32 
33 
34 CSCCFEBDataWord * CSCCFEBTimeSlice::timeSample(int layer, int channel, bool isDCFEB) const
35 {
36  assert(layer >= 1 && layer <= 6);
37  assert(channel >=1 && channel <= 16);
38  int layerIndex = layerInverseGrayCode[layer-1];
39 
40  unsigned channelIndex = channelInverseGrayCode[channel-1];
41  if (isDCFEB) channelIndex = channel-1;
42  unsigned scaBin = channelIndex*6 + layerIndex;
43  assert(scaBin < 96U); // scaBin >= 0, since scaBin is unsigned
44  return timeSample(scaBin);
45 }
46 
47 
49 {
50  unsigned int result=0;
51  for(unsigned i = 0; i < 16; ++i) {
52  result |= timeSample(i*6+layer-1)->controllerData << i;
53  }
54  return CSCCFEBSCAControllerWord(result);
55 }
56 
57 
59 {
60  for(int layer = 1; layer <= 6; ++layer)
61  {
62  for(int channel = 1; channel <= 16; ++channel)
63  {
64  const unsigned short * shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
65  timeSample(layer, channel)->controllerData
66  = ( *shortWord >> (channel-1)) & 1;
67  }
68  }
69 }
70 
71 
72 unsigned CSCCFEBTimeSlice::calcCRC() const
73 {
74  unsigned CRC=0;
75  for(uint16_t pos=0; pos<96; ++pos)
76  CRC=(theSamples[pos]&0x1fff)^((theSamples[pos]&0x1fff)<<1)^(((CRC&0x7ffc)>>2)|((0x0003&CRC)<<13))^((CRC&0x7ffc)>>1);
77  return CRC;
78 }
79 
80 
81 std::ostream & operator<<(std::ostream & os, const CSCCFEBTimeSlice & slice)
82 {
83  for(int ichannel = 1; ichannel <= 16; ++ichannel)
84  {
85  for(int ilayer = 1; ilayer <= 6; ++ilayer)
86  {
87  //unsigned index = (ilayer-1) + (ichannel-1)*6;
88  //int value = (slice.timeSample(index))->adcCounts - 560;
89  int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560;
90  os << " " << std::setw(5) << std::dec << value;
91  }
92  os << std::endl;
93  }
94  return os;
95 }
96 
int i
Definition: DBlmapReader.cc:9
unsigned calcCRC() const
const unsigned channelInverseGrayCode[]
void setControllerWord(const CSCCFEBSCAControllerWord &controllerWord)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
CSCCFEBSCAControllerWord scaControllerWord(int layer) const
unpacked from the controller words for each channel in the layer
tuple result
Definition: query.py:137
CSCCFEBDataWord * timeSample(int index) const
input from 0 to 95
unsigned short controllerData
combined from all 16 strips to make a word
const unsigned layerInverseGrayCode[]
unsigned short theSamples[96]
unsigned dummy
WORD 100.