CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/CSCRawToDigi/src/CSCTMBScope.cc

Go to the documentation of this file.
00001 //_________________________________________________________
00002 //
00003 //  CSCTMBScope 9/11/03  B.Mohr                             
00004 //  Unpacks TMB Logic Analyzer and stores in CSCTMBScope.h  
00005 //_________________________________________________________
00006 //
00007 #include "EventFilter/CSCRawToDigi/interface/CSCTMBScope.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <iostream>
00010 
00011 bool CSCTMBScope::debug = false;
00012 
00013 CSCTMBScope::CSCTMBScope(unsigned short *buf,int b05Line,int e05Line) {
00014 
00015   size_ = UnpackScope(buf,b05Line,e05Line);
00016 
00017 } //CSCTMBScope
00018 
00019 
00020 int CSCTMBScope::UnpackScope(unsigned short *buf,int b05Line,int e05Line) {
00021 
00022   int pretrig_chan[4]={0,0,0,0};
00023   unsigned int tbin_strt,tbin_stop;
00024   unsigned int ibit,jbit,itbin,ich,iram,iline,iadr;
00025   unsigned int lct_bxn;
00026 
00027 
00028   if(debug) {
00029     LogTrace("CSCTMBScope|CSCRawToDigi") << " .....TMBHeader -- unpacking Logic Analyzer......";
00030   }
00031 
00032   if((e05Line-b05Line) == 1537) {
00033 
00034     if(debug) 
00035      LogTrace("CSCTMBScope|CSCRawToDigi") << "Scope data found";
00036 
00037     //load scope_ram from raw-hits format readout
00038     iline = b05Line + 1;
00039     for(iram=0;iram<6;iram++){
00040       for(iadr=0;iadr<256;iadr++) {
00041         itbin = iadr;   //ram_sel*256
00042         scope_ram[itbin][iram] = buf[iline];
00043         iline++;
00044       }
00045     }
00046 
00047     for(ich=0;ich<51;ich++) data[ich]=0;  //clear all data
00048 
00049 
00050     //----- find pretrig chan offset -----------------
00051     pretrig_chan[0] = GetPretrig(0);
00052     pretrig_chan[1] = GetPretrig(32);
00053     pretrig_chan[2] = GetPretrig(48);
00054     pretrig_chan[3] = GetPretrig(64);
00055 
00056     //----- ram 1 ------------------------------------
00057     tbin_strt = pretrig_chan[0]-7;
00058     tbin_stop = pretrig_chan[0]+24;
00059 
00060     for(ich=0;ich<=14;ich++) {
00061       iram=ich/16;
00062       jbit=0;
00063       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00064         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00065         data[ich] = (ibit << jbit) | data[ich];
00066         jbit++;
00067       }
00068     }
00069 
00070     //----- ram 2 ------------------------------------
00071     for(ich=16;ich<=30;ich++) {
00072       iram=ich/16;
00073       jbit=0;
00074       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00075         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00076         data[ich-1] = (ibit << jbit) | data[ich-1];
00077         jbit++;
00078       }
00079     }
00080 
00081     //----- ram 3 ------------------------------------
00082     tbin_strt = pretrig_chan[1]-7;
00083     tbin_stop = pretrig_chan[1]+24;
00084 
00085     for(ich=32;ich<=36;ich++) {
00086       iram=ich/16;
00087       jbit=0;
00088       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00089         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00090         data[ich-2] = (ibit << jbit) | data[ich-2];
00091         jbit++;
00092       }
00093     }
00094 
00095     tbin_strt = pretrig_chan[1]-7+120;
00096     tbin_stop = pretrig_chan[1]+24+120;
00097 
00098     for(ich=37;ich<=40;ich++) {
00099       iram=ich/16;
00100       jbit=0;
00101       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00102         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00103         data[ich-2] = (ibit << jbit) | data[ich-2];
00104         jbit++;
00105       }
00106     }
00107 
00108     tbin_strt = pretrig_chan[1]-7;
00109     tbin_stop = pretrig_chan[1]+24;
00110 
00111     for(ich=41;ich<=46;ich++) {
00112       iram=ich/16;
00113       jbit=0;
00114       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00115         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00116         data[ich-2] = (ibit << jbit) | data[ich-2];
00117         jbit++;
00118       }
00119     }
00120 
00121     //----- ram 4 ------------------------------------
00122     tbin_strt = pretrig_chan[2]-7;
00123     tbin_stop = pretrig_chan[2]+24;
00124 
00125     for(ich=48;ich<=53;ich++) {
00126       iram=ich/16;
00127       jbit=0;
00128       for(itbin=tbin_strt;itbin<=tbin_stop;itbin++) {
00129         ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00130         data[ich-3] = (ibit << jbit) | data[ich-3];
00131         jbit++;
00132       }
00133     }
00134 
00135     //----- ram 5 - bxn ------------------------------
00136     lct_bxn = 0;
00137     jbit=0;
00138 
00139     for(ich=65;ich<=76;ich++) {
00140       iram=ich/16;
00141       itbin = pretrig_chan[3];
00142       ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00143       lct_bxn = (ibit << jbit) | lct_bxn;
00144       jbit++;
00145     }
00146     data[51]=lct_bxn;
00147 
00148     if(debug) 
00149       LogTrace("CSCTMBScope|CSCRawToDigi") << "Scope bxn at LCT (seq_pretrig): " 
00150                                   << lct_bxn;
00151 
00152     //----- now read back decoded scope data ---------
00153     if(debug) {
00154       for(ich=0;ich<=50;ich++) {
00155         for(itbin=0;itbin<32;itbin++) {
00156           ibit = (data[ich] >> itbin ) & 1;
00157           if(ibit == 0) LogTrace("CSCTMBScope|CSCRawToDigi") << "_";    //display symbol for logic 0
00158           if(ibit == 1) LogTrace("CSCTMBScope|CSCRawToDigi") << "-";    //display symbol for logic 1
00159         }
00160       }
00161     }
00162 
00163   } //end if(b05-e05)
00164 
00165 
00166   //-------------- if no scope data: fill everything with 0 --------------------
00167   else {
00168     for(ich=0;ich<51;ich++) data[ich]=0;
00169     lct_bxn  = 0xff0000;    //value not possible for real data (short)
00170     data[51] = lct_bxn;
00171 
00172     if(debug) 
00173       LogTrace("CSCTMBScope|CSCRawToDigi")  << "No scope data found: wrdcnt: " 
00174                                    << (e05Line-b05Line);
00175   }
00176 
00177   if(debug) {
00178      LogTrace("CSCTMBScope|CSCRawToDigi") << " .....END -- unpacking Logic Analyzer...........";
00179   }
00180 
00181   return (e05Line - b05Line + 1);
00182 
00183 } //UnpackScope
00184 
00185 
00186 int CSCTMBScope::GetPretrig(int ich) {
00187 
00188   unsigned int ibit,itbin,iram;
00189   int value = 0;
00190 
00191   ibit=0;
00192   itbin=0;
00193   iram=ich/16;
00194   while(!ibit) {
00195     ibit = (scope_ram[itbin][iram] >> (ich%16) ) & 1;
00196     value = itbin;
00197     itbin++;
00198   }
00199 
00200   if(debug)
00201     LogTrace("CSCTMBScope|CSCRawToDigi") << "TMB SCOPE: ------- Pretrig value: " << value;
00202   return value;
00203 
00204 } //GetPretrig