CMS 3D CMS Logo

CamacTBDataFormatter.cc

Go to the documentation of this file.
00001 /*  
00002  *
00003  *  \author G. Franzoni
00004  *
00005  */
00006 
00007 #include "CamacTBDataFormatter.h"
00008 
00009 #include <iostream>
00010 
00011 
00012 // pro-memo:
00013 // "ff" = 1 Byte
00014 // 64 bits = 8 Bytes = 16 hex carachters
00015 // for now: event is  ( 114 words x 32 bits ) = 448 Bytes
00016 // size of ulong = 4 Bytes. Thus, 1 (32 bit) word = 1 (ulong) 
00017 
00018 struct hodo_fibre_index 
00019 {
00020   int nfiber;
00021   int ndet;
00022 };
00023 
00024 // nHodoscopes = 2; nFibres = 64 
00025 const static struct hodo_fibre_index hodoFiberMap[2][64] = {
00026   { // Hodo 0
00027     // unit 1A
00028     {23,44}, {29,47}, {31,48}, {21,43},
00029     { 5,35}, {15,40}, { 7,36}, {13,39},
00030     { 1,33}, {11,38}, { 3,34}, { 9,37},
00031     { 6, 3}, {16, 8}, { 8, 4}, {14, 7},
00032     // unit 1C
00033     {17,41}, {19,42}, {27,46}, {25,45},
00034     {32,16}, {22,11}, {24,12}, {30,15},
00035     {12, 6}, { 2, 1}, { 4, 2}, {10, 5},
00036     {28,14}, {18, 9}, {20,10}, {26,13},
00037     // unit 2A
00038     {54,27}, {56,28}, {64,32}, {62,31},
00039     {49,57}, {59,62}, {51,58}, {57,61},
00040     {53,59}, {63,64}, {55,60}, {61,63},
00041     {45,55}, {39,52}, {37,51}, {47,56},
00042     // unit 2C
00043     {34,17}, {42,21}, {44,22}, {36,18},
00044     {50,25}, {60,30}, {58,29}, {52,26},
00045     {38,19}, {40,20}, {48,24}, {46,23},
00046     {41,53}, {35,50}, {33,49}, {43,54}
00047   },
00048   { // Hodo 1
00049     // unit 1A
00050     {31,48}, {29,47}, {23,44}, {21,43},
00051     { 5,35}, { 7,36}, {15,40}, {13,39},
00052     { 1,33}, { 3,34}, {11,38}, { 9,37},
00053     { 6, 3}, { 8, 4}, {16, 8}, {14, 7},
00054     // unit 1C
00055     {17,41}, {27,46}, {19,42}, {25,45},
00056     {24,12}, {22,11}, {32,16}, {30,15},
00057     { 4, 2}, { 2, 1}, {12, 6}, {10, 5},
00058     {20,10}, {18, 9}, {28,14}, {26,13},
00059     // unit 2A
00060     {54,27}, {64,32}, {56,28}, {62,31},
00061     {49,57}, {51,58}, {59,62}, {57,61},
00062     {53,59}, {55,60}, {63,64}, {61,63},
00063     {45,55}, {47,56}, {37,51}, {39,52},
00064     // unit 2C
00065     {34,17}, {42,21}, {36,18}, {44,22},
00066     {50,25}, {52,26}, {58,29}, {60,30},
00067     {38,19}, {48,24}, {40,20}, {46,23},
00068     {41,53}, {43,54}, {33,49}, {35,50}
00069   }
00070 };
00071 
00072 
00073 
00074 CamacTBDataFormatter::CamacTBDataFormatter () {
00075   nWordsPerEvent = 148;
00076 }
00077 
00078 
00079 
00080 void CamacTBDataFormatter::interpretRawData( const FEDRawData & fedData, 
00081                                              EcalTBEventHeader& tbEventHeader,
00082                                              EcalTBHodoscopeRawInfo& hodoRaw,
00083                                              EcalTBTDCRawInfo& tdcRawInfo )
00084 {
00085   
00086 
00087   const ulong * buffer = ( reinterpret_cast<ulong*>(const_cast<unsigned char*> ( fedData.data())));
00088   int fedLenght                        = fedData.size(); // in Bytes
00089   
00090   // check ultimate fed size and strip off fed-header and -trailer
00091   if (fedLenght != (nWordsPerEvent *4) )
00092     {
00093       edm::LogError("CamacTBDataFormatter") << "CamacTBData has size "  <<  fedLenght
00094                                        <<" Bytes as opposed to expected " 
00095                                        << (nWordsPerEvent *4)
00096                                        << ". Returning.";
00097       return;
00098     }
00099 
00100   
00101   
00102   ulong a=1; // used to extract an 8 Bytes word from fed 
00103   ulong b=1; // used to manipulate the 8 Bytes word and get what needed
00104 
00105   // initializing array of statuses
00106   for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
00107     { statusWords[wordNumber ] = true;}
00108 
00109   //  for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
00110   //    { checkStatus( buffer[wordNumber],  wordNumber);}
00111   
00112   //   for (int wordNumber=0; wordNumber<nWordsPerEvent; wordNumber++)
00113   //     {
00114   //       if (! statusWords[wordNumber])
00115   //    {
00116   //      edm::LogError("CamacTBDataFormatter") << "bad status in some of the event words; returning;";   
00117   //    }
00118   //     }
00119   
00120   
00121 
00122   int wordCounter =0;
00123   wordCounter +=4;
00124 
00125 
00126   // read first word
00127   a = buffer[wordCounter];wordCounter++;
00128   LogDebug("CamacTBDataFormatter") << "\n\nword:\t" << a;
00129   
00130   b = (a& 0xff000000);
00131   b = b >> 24;
00132   LogDebug("CamacTBDataFormatter") << "format  ver:\t" << b;
00133 
00134   b = (a& 0xff0000);
00135   b = b >> 16;
00136   LogDebug("CamacTBDataFormatter") << "major:\t" << b;
00137 
00138   b = (a& 0xff00);
00139   b = b >> 8;
00140   LogDebug("CamacTBDataFormatter") << "minor:\t" << b;
00141 
00142   a = buffer[wordCounter];wordCounter++;
00143   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00144   LogDebug("CamacTBDataFormatter") << "time stamp secs: "<<a;
00145 
00146   a = buffer[wordCounter];wordCounter++;
00147   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00148   LogDebug("CamacTBDataFormatter") << "time stamp musecs: " <<a;
00149 
00150 
00151   a = buffer[wordCounter];wordCounter++;
00152   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00153   b = (a& 0xffffff);
00154   LogDebug("CamacTBDataFormatter") << "LV1A: "<< b;
00155   int lv1 = b;
00156 
00157   a = buffer[wordCounter];wordCounter++;
00158   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00159   b = (a& 0xffff0000);
00160   b = b >> 16;
00161   LogDebug("CamacTBDataFormatter") << "run number: "<< b;
00162   int run = b;
00163   b = (a& 0xffff);
00164   LogDebug("CamacTBDataFormatter") << "spill number: "<< b;
00165   int spill = b;
00166 
00167   a = buffer[wordCounter];wordCounter++;
00168   b = (a& 0xffff);
00169   LogDebug("CamacTBDataFormatter") << "event number in spill: "<< b;
00170 
00171   a = buffer[wordCounter];wordCounter++;
00172   b = (a& 0xffffff);
00173   LogDebug("CamacTBDataFormatter") << "internal event number: "<< b;
00174 
00175   a = buffer[wordCounter];wordCounter++;
00176   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00177   b = (a& 0xffff0000);
00178   b = b >> 16;
00179   LogDebug("CamacTBDataFormatter") << "vme errors: "<< b;
00180   b = (a& 0xffff);
00181   LogDebug("CamacTBDataFormatter") << "camac errors: "<< b;
00182 
00183   a = buffer[wordCounter];wordCounter++;
00184   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00185   b = a;
00186   LogDebug("CamacTBDataFormatter") << "extended (32 bits) run number: "<< b;
00187 
00188   // skip 1 reserved words
00189   wordCounter +=1;
00190 
00191   /**********************************
00192   // acessing the hodoscope block
00193   **********************************/
00194 
00195   // getting 16 words buffer and checking words statuses
00196   ulong bufferHodo[16]; 
00197   bool hodoAreGood = true;
00198   for (int hodo=0; hodo<16; hodo++)
00199     {
00200       hodoAreGood = hodoAreGood && checkStatus(buffer[wordCounter], wordCounter);
00201 
00202       a                 = buffer[wordCounter];
00203       bufferHodo[hodo]  = buffer[wordCounter];
00204       wordCounter++;
00205             
00206       b = (a& 0xffffff);
00207       LogDebug("CamacTBDataFormatter") << "hodo: " << hodo << "\t: " << b;
00208     }
00209 
00210   hodoRaw.setPlanes(0);
00211   // unpacking the hodo data
00212   if (hodoAreGood){
00213   for (int iplane=0; iplane<nHodoPlanes; iplane++) 
00214     {         
00215       int detType = 1;       // new mapping for electronics channels  
00216                
00217       for (int fiber=0; fiber<nHodoFibers; fiber++) { hodoHits[iplane][fiber] = 0; }            
00218                
00219       int ch=0;
00220       
00221       // loop on [4-24bits words] = 1 plane 
00222       for(int j=0; j<hodoRawLen; j++) 
00223         {
00224           int word=  bufferHodo[  j+iplane*hodoRawLen  ]  &0xffff;
00225           for(int i=1; i<0x10000; i<<=1) 
00226             {
00227               if ( word & i ) 
00228                 {
00229                   // map electronics channel to No of fibre
00230                   hodoHits[iplane][ hodoFiberMap[detType][ch].nfiber - 1]++;
00231                 }
00232               ch ++;
00233             }
00234         } 
00235     }
00236 
00237   
00238   // building the hodo infos (returning decoded hodoscope hits information)
00239   hodoRaw.setPlanes((unsigned int)nHodoPlanes);
00240   for (int ipl = 0; ipl < nHodoPlanes; ipl++) 
00241     {             
00242       EcalTBHodoscopePlaneRawHits theHodoPlane;
00243       theHodoPlane.setChannels((unsigned int)nHodoFibers);
00244       for (int fib = 0; fib < nHodoFibers; fib++){ theHodoPlane.setHit((unsigned int)fib, (bool)hodoHits[ipl][fib]); }
00245       hodoRaw.setPlane((unsigned int)ipl, theHodoPlane);
00246     }
00247   }
00248   else
00249     {
00250       edm::LogWarning("CamacTBDataFormatter") << "hodoscope block has hardware problems or is partly unused at LV1: "
00251                                          << lv1 << " spill: " << spill 
00252                                          << "run: " << run 
00253                                          << ". Skipping digi.";
00254     }
00255   
00256   
00257 
00258 
00259 
00260   /**********************************
00261   // acessing the scalers block
00262   **********************************/
00263 
00264   // getting 72 words buffer and checking words statuses
00265 
00266   scalers_.clear();
00267   scalers_.reserve(36);
00268   
00269   bool scalersAreGood = true;
00270   for (int scaler=0; scaler<72; scaler++)
00271     {
00272       scalersAreGood = scalersAreGood && checkStatus(buffer[wordCounter], wordCounter);
00273 
00274       a = buffer[wordCounter];      wordCounter++;
00275       b = (a& 0xffffff);
00276       LogDebug("CamacTBDataFormatter") << "scaler: " << scaler << "\t: " << b;
00277 
00278       // filling vector container with scalers words
00279       if ( (scaler%2)==0 ) scalers_.push_back(b);
00280     }
00281   if (scalersAreGood){
00282     tbEventHeader.setScalers (scalers_);  
00283   }
00284   else
00285     {
00286       edm::LogWarning("CamacTBDataFormatter") << "scalers block has hardware problems  or is partly unused at LV1: "
00287                                          << lv1 << " spill: " << spill 
00288                                          << "run: " << run;
00289     }
00290   
00291 
00292 
00293 
00294 
00295   /**********************************
00296   // acessing the fingers block
00297   **********************************/
00298 
00299   LogDebug("CamacTBDataFormatter") <<"\n";
00300   bool fingersAreGood = true;
00301   for (int finger=0; finger<2; finger++)
00302     {
00303       fingersAreGood = fingersAreGood && checkStatus(buffer[wordCounter], wordCounter);
00304 
00305       a = buffer[wordCounter];      wordCounter++;
00306       b = (a& 0xffffff);
00307       LogDebug("CamacTBDataFormatter") << "finger: " << finger << "\t: " << b;
00308     }
00309   if (fingersAreGood){
00310     ;  }
00311   else
00312     {
00313       edm::LogWarning("CamacTBDataFormatter") << "fingers block has hardware problems  or is partly unused at LV1: "
00314                                          << lv1 << " spill: " << spill 
00315                                          << "run: " << run;
00316     }
00317   
00318 
00319 
00320 
00321   /**********************************
00322   // acessing the multi stop TDC block
00323   **********************************/
00324 
00325   a = buffer[wordCounter];      wordCounter++;
00326   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00327   b = (a& 0x000000ff);
00328   LogDebug("CamacTBDataFormatter") << "number of words used in multi stop TDC words: "<< b;
00329   
00330   int numberTDCwords = b;
00331   numberTDCwords = 16;
00332   bool multiStopTDCIsGood = true;
00333   for (int tdc=0; tdc< numberTDCwords ; tdc++)
00334     {
00335       multiStopTDCIsGood =  multiStopTDCIsGood && checkStatus(buffer[wordCounter], wordCounter);
00336 
00337       a = buffer[wordCounter];      wordCounter++;
00338       b =a;
00339       LogDebug("CamacTBDataFormatter") << "tdc: " << tdc << "\t: " << b;
00340     }
00341   if ( multiStopTDCIsGood ){
00342     ;  }
00343   else
00344     {
00345       edm::LogWarning("CamacTBDataFormatter") << "multi stop TDC block has hardware problems or is partly unused at LV1: "
00346                                          << lv1 << " spill: " << spill 
00347                                          << "run: " << run;
00348     }
00349   
00350   // skip the unused words in multi stop TDC block
00351   wordCounter += (16 - numberTDCwords);
00352 
00353   
00354 
00355   
00356   /**********************************
00357   // acessing table in position bit
00358   **********************************/
00359   a = buffer[wordCounter];      wordCounter++;
00360   b = (a & 0x00000001);  //1= table is in position; 0=table is moving
00361   bool tableIsMoving;
00362   if ( b ){
00363     LogDebug("CamacTBDataFormatter") << " table is in position.";
00364     tableIsMoving = false;
00365   }
00366   else
00367     {
00368     LogDebug("CamacTBDataFormatter") << " table is moving.";
00369     tableIsMoving = true;
00370     }
00371   tbEventHeader.setTableIsMoving( tableIsMoving );
00372 
00373 
00374   wordCounter += 3;
00375 
00376   
00377   
00378   /**********************************
00379    // acessing ADC block
00380    **********************************/
00381   // skip 10 reserved words
00382   wordCounter += 10;
00383   bool ADCIsGood = true;
00384 //  ADCIsGood =  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
00385   ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
00386   a = buffer[wordCounter];      wordCounter++;  // NOT read out
00387   b = (a&0x00ffffff);
00388   LogDebug("CamacTBDataFormatter") << "ADC word1: " << a << "\t ADC2: " << b << " word is: " << (wordCounter-1);
00389 //  ADCIsGood = true;
00390 //  ADCIsGood = ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
00391   ADCIsGood = checkStatus(buffer[wordCounter], wordCounter);
00392   a = buffer[wordCounter];      wordCounter++;  // read out
00393   b = (a&0xffffff);
00394   LogDebug("CamacTBDataFormatter") << "ADC word2, adc channel 11, ampli S6: " << a << "\t ADC2: " << b;
00395   if (ADCIsGood) tbEventHeader.setS6ADC ( b ) ;
00396   else tbEventHeader.setS6ADC ( -1 ) ;
00397 
00398   
00399   /**********************************
00400    // acessing TDC block
00401    **********************************/
00402   // skip 6 reserved words
00403   wordCounter += 6;
00404   bool TDCIsGood = true;
00405   TDCIsGood =  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
00406   a = buffer[wordCounter];      wordCounter++;
00407   b = (a & 0xfffff);
00408   LogDebug("CamacTBDataFormatter") << "TDC word1: " << a << "\t TDC2: " << b;
00409   TDCIsGood =  ADCIsGood && checkStatus(buffer[wordCounter], wordCounter);
00410   a = buffer[wordCounter];      wordCounter++;
00411   b = (a & 0xfffff);
00412   LogDebug("CamacTBDataFormatter") << "TDC word2: (ext_val_trig - LHC_clock) " 
00413                                    << a << "\t (ext_val_trig - LHC_clock): "
00414                                    << b;
00415   
00416   tdcRawInfo.setSize(1);
00417   int sampleNumber =1;
00418   EcalTBTDCSample theTdc(sampleNumber, b);
00419   tdcRawInfo.setSample(0, theTdc);
00420 
00421 
00422   a = buffer[wordCounter];      wordCounter++;
00423   LogDebug("CamacTBDataFormatter") << "\n\n word:\t" << a;
00424   b = a;
00425   LogDebug("CamacTBDataFormatter") << "last word of event: "<< b;
00426 
00427 
00428 }
00429 
00430 
00431 
00432 
00433 
00434 
00435 
00436 
00437 // given a data word with 8 msb as status, checks status
00438 
00439 bool CamacTBDataFormatter::checkStatus(ulong word, int wordNumber){
00440   
00441 
00442   if ( wordNumber < 1 || wordNumber > nWordsPerEvent)
00443     { 
00444       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "checking word number: "
00445                                                     <<  wordNumber << " which is out of allowed range (" 
00446                                                     << nWordsPerEvent << ")";
00447       return false;
00448     }
00449 
00450   bool isOk = true;
00451 
00452   if  (word & 0x80000000) // daq item not used
00453     { 
00454       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "daq item not used at word: "<<  wordNumber;
00455       statusWords[wordNumber -1] = false;      
00456       isOk = false;
00457     }
00458   
00459   if (word & 0x40000000) // vme error on data
00460     { 
00461       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme error on word: "<<  wordNumber;
00462       statusWords[wordNumber -1] = false;      
00463       isOk = false;
00464     }
00465     
00466   if (word & 0x20000000) // vme error on status
00467     { 
00468       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "vme status error at word: "<<  wordNumber;
00469       statusWords[wordNumber -1] = false;      
00470       isOk = false;
00471     }
00472     
00473   if (word & 0x10000000) // camac error (no X)
00474     { 
00475       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no X) at word: "<<  wordNumber;
00476       statusWords[wordNumber -1] = false;      
00477       isOk = false;
00478     }
00479     
00480   if (word & 0x08000000) // camac error (no Q)
00481     { 
00482       edm::LogWarning("CamacTBDataFormatter::checkStatus") << "camac error (no Q) at word: "<<  wordNumber;
00483       statusWords[wordNumber -1] = false;      
00484       isOk = false;
00485     }
00486   
00487   // camac error check not done on purpose from Aug 8, to speed up Camac communication. This bit status is now ignored.
00488   //  if (word & 0x04000000) // no camac check error
00489   //    { 
00490   //edm::LogWarning("CamacTBDataFormatter::checkStatus") << "no camac check error at word: "<<  wordNumber;
00491   //statusWords[wordNumber -1] = false;      
00492   //isOk = false;
00493   //    }
00494   
00495   return isOk;
00496 
00497 }

Generated on Tue Jun 9 17:34:37 2009 for CMSSW by  doxygen 1.5.4