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 layerInverseGrayCode[] = {1,5,0,4,2,3};
9 const unsigned channelInverseGrayCode[] = {0,1,3,2, 7,6,4,5, 15,14,12,13, 8,9,11,10};
10 
12 {
13  bzero(this, 99*2);
14  dummy = 0x7FFF;
15  blank_space_1 = 0x7;
16  blank_space_3 = 0x7;
17 }
18 
19 
21 // trig_time( frame & 0xFF ),
22 // sca_blk( (frame>>8) & 0xF ),
23 // l1a_phase((frame>>12( & 0x1),
24 // lct_phase((frame>>13( & 0x1),
25 // sca_full((frame>>14) & 0x1),
26 // ts_flag(((frame>>15) & 0x1)
27 {
28  memcpy(this, &frame, 2);
29 }
30 
31 
32 CSCCFEBDataWord * CSCCFEBTimeSlice::timeSample(int layer, int channel) const
33 {
34  assert(layer >= 1 && layer <= 6);
35  assert(channel >=1 && channel <= 16);
36  int layerIndex = layerInverseGrayCode[layer-1];
37  unsigned channelIndex = channelInverseGrayCode[channel-1];
38  unsigned scaBin = channelIndex*6 + layerIndex;
39  assert(scaBin < 96U); // scaBin >= 0, since scaBin is unsigned
40  return timeSample(scaBin);
41 }
42 
43 
45 {
46  unsigned int result=0;
47  for(unsigned i = 0; i < 16; ++i) {
48  result |= timeSample(i*6+layer-1)->controllerData << i;
49  }
50  return CSCCFEBSCAControllerWord(result);
51 }
52 
53 
55 {
56  for(int layer = 1; layer <= 6; ++layer)
57  {
58  for(int channel = 1; channel <= 16; ++channel)
59  {
60  const unsigned short * shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
61  timeSample(layer, channel)->controllerData
62  = ( *shortWord >> (channel-1)) & 1;
63  }
64  }
65 }
66 
67 
68 unsigned CSCCFEBTimeSlice::calcCRC() const
69 {
70  unsigned CRC=0;
71  for(uint16_t pos=0; pos<96; ++pos)
72  CRC=(theSamples[pos]&0x1fff)^((theSamples[pos]&0x1fff)<<1)^(((CRC&0x7ffc)>>2)|((0x0003&CRC)<<13))^((CRC&0x7ffc)>>1);
73  return CRC;
74 }
75 
76 
77 std::ostream & operator<<(std::ostream & os, const CSCCFEBTimeSlice & slice)
78 {
79  for(int ichannel = 1; ichannel <= 16; ++ichannel)
80  {
81  for(int ilayer = 1; ilayer <= 6; ++ilayer)
82  {
83  //unsigned index = (ilayer-1) + (ichannel-1)*6;
84  //int value = (slice.timeSample(index))->adcCounts - 560;
85  int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560;
86  os << " " << std::setw(5) << std::dec << value;
87  }
88  os << std::endl;
89  }
90  return os;
91 }
92 
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.