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