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 unsigned layerGrayCode[] = {3,1,5,6,4,2};
9 unsigned layerInverseGrayCode[] = {1,5,0,4,2,3};
10 unsigned channelGrayCode[] = {0,1,3,2, 6,7,5,4, 12,13,15,14, 10,11,9,8};
11 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) const
35 {
36  assert(layer >= 1 && layer <= 6);
37  assert(channel >=1 && channel <= 16);
38  int layerIndex = layerInverseGrayCode[layer-1];
39  unsigned channelIndex = channelInverseGrayCode[channel-1];
40  unsigned scaBin = channelIndex*6 + layerIndex;
41  assert(scaBin < 96U); // scaBin >= 0, since scaBin is unsigned
42  return timeSample(scaBin);
43 }
44 
45 
47 {
48  unsigned int result=0;
49  for(unsigned i = 0; i < 16; ++i) {
50  result |= timeSample(i*6+layer-1)->controllerData << i;
51  }
52  return CSCCFEBSCAControllerWord(result);
53 }
54 
55 
57 {
58  for(int layer = 1; layer <= 6; ++layer)
59  {
60  for(int channel = 1; channel <= 16; ++channel)
61  {
62  const unsigned short * shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
63  timeSample(layer, channel)->controllerData
64  = ( *shortWord >> (channel-1)) & 1;
65  }
66  }
67 }
68 
69 
70 unsigned CSCCFEBTimeSlice::calcCRC() const
71 {
72  unsigned CRC=0;
73  for(uint16_t pos=0; pos<96; ++pos)
74  CRC=(theSamples[pos]&0x1fff)^((theSamples[pos]&0x1fff)<<1)^(((CRC&0x7ffc)>>2)|((0x0003&CRC)<<13))^((CRC&0x7ffc)>>1);
75  return CRC;
76 }
77 
78 
79 std::ostream & operator<<(std::ostream & os, const CSCCFEBTimeSlice & slice)
80 {
81  for(int ichannel = 1; ichannel <= 16; ++ichannel)
82  {
83  for(int ilayer = 1; ilayer <= 6; ++ilayer)
84  {
85  //unsigned index = (ilayer-1) + (ichannel-1)*6;
86  //int value = (slice.timeSample(index))->adcCounts - 560;
87  int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560;
88  os << " " << std::setw(5) << std::dec << value;
89  }
90  os << std::endl;
91  }
92  return os;
93 }
94 
int i
Definition: DBlmapReader.cc:9
unsigned calcCRC() const
void setControllerWord(const CSCCFEBSCAControllerWord &controllerWord)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
unsigned channelGrayCode[]
CSCCFEBSCAControllerWord scaControllerWord(int layer) const
unpacked from the controller words for each channel in the layer
unsigned layerGrayCode[]
tuple result
Definition: query.py:137
CSCCFEBDataWord * timeSample(int index) const
input from 0 to 95
unsigned channelInverseGrayCode[]
unsigned short controllerData
combined from all 16 strips to make a word
unsigned short theSamples[96]
unsigned dummy
WORD 100.
unsigned layerInverseGrayCode[]