CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/EventFilter/CSCRawToDigi/src/CSCCFEBTimeSlice.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBTimeSlice.h"
00002 #include <cassert>
00003 #include <iomanip>
00004 #include <stdint.h>
00005 
00006 // a Gray code is An ordering of 2n binary numbers such that
00007 // only one bit changes from one entry to the next
00008 unsigned layerGrayCode[] = {3,1,5,6,4,2};
00009 unsigned layerInverseGrayCode[] = {1,5,0,4,2,3};
00010 unsigned channelGrayCode[] = {0,1,3,2, 6,7,5,4, 12,13,15,14, 10,11,9,8};
00011 unsigned channelInverseGrayCode[] = {0,1,3,2, 7,6,4,5, 15,14,12,13, 8,9,11,10};
00012 
00013 CSCCFEBTimeSlice::CSCCFEBTimeSlice() 
00014 {
00015     bzero(this, 99*2);
00016   dummy = 0x7FFF;
00017   blank_space_1 = 0x7;
00018   blank_space_3 = 0x7;
00019 }
00020 
00021 
00022 CSCCFEBSCAControllerWord::CSCCFEBSCAControllerWord(unsigned short frame)
00023 // trig_time( frame & 0xFF ),
00024 // sca_blk( (frame>>8) & 0xF ),
00025 // l1a_phase((frame>>12( & 0x1),
00026 // lct_phase((frame>>13( & 0x1),
00027 // sca_full((frame>>14) & 0x1),
00028 // ts_flag(((frame>>15) & 0x1)
00029 {
00030   memcpy(this, &frame, 2);
00031 }
00032 
00033 
00034 CSCCFEBDataWord * CSCCFEBTimeSlice::timeSample(int layer, int channel) const 
00035 {
00036   assert(layer >= 1 && layer <= 6);
00037   assert(channel >=1 && channel <= 16);
00038   int layerIndex = layerInverseGrayCode[layer-1];
00039   unsigned channelIndex = channelInverseGrayCode[channel-1];
00040   unsigned scaBin = channelIndex*6 + layerIndex;
00041   assert(scaBin < 96U); // scaBin >= 0, since scaBin is unsigned
00042   return timeSample(scaBin);
00043 }
00044 
00045 
00046 CSCCFEBSCAControllerWord CSCCFEBTimeSlice::scaControllerWord(int layer) const 
00047 {
00048   unsigned int result=0;
00049   for(unsigned i = 0; i < 16; ++i) {
00050      result |= timeSample(i*6+layer-1)->controllerData << i;
00051   }
00052   return CSCCFEBSCAControllerWord(result);
00053 }
00054 
00055 
00056 void CSCCFEBTimeSlice::setControllerWord(const CSCCFEBSCAControllerWord & controllerWord) 
00057 {
00058   for(int layer = 1; layer <= 6; ++layer)
00059     {
00060       for(int channel = 1; channel <= 16; ++channel)
00061         {
00062           const unsigned short * shortWord = reinterpret_cast<const unsigned short *>(&controllerWord);
00063           timeSample(layer, channel)->controllerData
00064             = ( *shortWord >> (channel-1)) & 1;
00065         }
00066     }
00067 }
00068 
00069 
00070 unsigned CSCCFEBTimeSlice::calcCRC() const
00071 {
00072         unsigned CRC=0;
00073         for(uint16_t pos=0; pos<96; ++pos)
00074         CRC=(theSamples[pos]&0x1fff)^((theSamples[pos]&0x1fff)<<1)^(((CRC&0x7ffc)>>2)|((0x0003&CRC)<<13))^((CRC&0x7ffc)>>1);
00075         return CRC;
00076 }
00077 
00078 
00079 std::ostream & operator<<(std::ostream & os, const CSCCFEBTimeSlice & slice) 
00080 {
00081   for(int ichannel = 1; ichannel <= 16; ++ichannel) 
00082     {
00083       for(int ilayer = 1; ilayer <= 6; ++ilayer)
00084         {
00085           //unsigned index = (ilayer-1) + (ichannel-1)*6;
00086           //int value = (slice.timeSample(index))->adcCounts - 560;
00087           int value = (slice.timeSample(ilayer, ichannel))->adcCounts - 560; 
00088           os << " " << std::setw(5) << std::dec << value;
00089         }
00090       os << std::endl;
00091     }
00092   return os;
00093 }
00094