00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "EcalTB07DaqFormatter.h"
00013 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00014 #include <DataFormats/EcalDetId/interface/EBDetId.h>
00015 #include <DataFormats/EcalDetId/interface/EEDetId.h>
00016 #include <DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h>
00017 #include <DataFormats/EcalDigi/interface/EBDataFrame.h>
00018 #include <DataFormats/EcalDigi/interface/EEDataFrame.h>
00019 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00020
00021 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCCHeaderRuntypeDecoder.h>
00022 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h>
00023 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h>
00024 #include <FWCore/ParameterSet/interface/FileInPath.h>
00025
00026 #include "DCCDataParser.h"
00027 #include "DCCEventBlock.h"
00028 #include "DCCTowerBlock.h"
00029 #include "DCCTCCBlock.h"
00030 #include "DCCXtalBlock.h"
00031 #include "DCCDataMapper.h"
00032
00033
00034 #include <iostream>
00035 #include <string>
00036
00037 EcalTB07DaqFormatter::EcalTB07DaqFormatter (std::string tbName,
00038 int cryIcMap[68][5][5],
00039 int tbStatusToLocation[71],
00040 int tbTowerIDToLocation[201]) {
00041
00042 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter";
00043 std::vector<uint32_t> parameters;
00044 parameters.push_back(10);
00045 parameters.push_back(1);
00046 parameters.push_back(68);
00047 parameters.push_back(68);
00048 parameters.push_back(1);
00049 parameters.push_back(1);
00050 parameters.push_back(1);
00051 parameters.push_back(2);
00052 parameters.push_back(3);
00053 parameters.push_back(4);
00054
00055 theParser_ = new DCCTBDataParser(parameters);
00056
00057 tbName_ = tbName;
00058
00059 for(int i=0; i<68; ++i)
00060 for (int j=0; j<5; ++j)
00061 for (int k=0; k<5; ++k)
00062 cryIcMap_[i][j][k] = cryIcMap[i][j][k];
00063
00064 for(int i=0; i<71; ++i)
00065 tbStatusToLocation_[i] = tbStatusToLocation[i];
00066
00067 for(int i=0; i<201; ++i)
00068 tbTowerIDToLocation_[i] = tbTowerIDToLocation[i];
00069
00070
00071 }
00072
00073 void EcalTB07DaqFormatter::interpretRawData(const FEDRawData & fedData ,
00074 EBDigiCollection& digicollection,
00075 EEDigiCollection& eeDigiCollection,
00076 EcalPnDiodeDigiCollection & pndigicollection,
00077 EcalRawDataCollection& DCCheaderCollection,
00078 EBDetIdCollection & dccsizecollection,
00079 EcalElectronicsIdCollection & ttidcollection,
00080 EcalElectronicsIdCollection & blocksizecollection,
00081 EBDetIdCollection & chidcollection , EBDetIdCollection & gaincollection,
00082 EBDetIdCollection & gainswitchcollection,
00083 EcalElectronicsIdCollection & memttidcollection,
00084 EcalElectronicsIdCollection & memblocksizecollection,
00085 EcalElectronicsIdCollection & memgaincollection,
00086 EcalElectronicsIdCollection & memchidcollection,
00087 EcalTrigPrimDigiCollection &tpcollection)
00088 {
00089
00090
00091 const unsigned char * pData = fedData.data();
00092 int length = fedData.size();
00093 bool shit=true;
00094 unsigned int tower=0;
00095 int ch=0;
00096 int strip=0;
00097
00098 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00099 << "size " << length;
00100
00101
00102
00103 digicollection.reserve(kCrystals);
00104 eeDigiCollection.reserve(kCrystals);
00105 pnAllocated = false;
00106
00107
00108 theParser_->parseBuffer( reinterpret_cast<uint32_t*>(const_cast<unsigned char*>(pData)), static_cast<uint32_t>(length), shit );
00109
00110 std::vector< DCCTBEventBlock * > & dccEventBlocks = theParser_->dccEvents();
00111
00112
00113 for( std::vector< DCCTBEventBlock * >::iterator itEventBlock = dccEventBlocks.begin();
00114 itEventBlock != dccEventBlocks.end();
00115 itEventBlock++){
00116
00117 bool _displayParserMessages = false;
00118 if( (*itEventBlock)->eventHasErrors() && _displayParserMessages)
00119 {
00120 edm::LogWarning("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00121 << "errors found from parser... ";
00122 edm::LogWarning("EcalTB07RawToDigi") << (*itEventBlock)->eventErrorString();
00123 edm::LogWarning("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00124 << "... errors from parser notified";
00125 }
00126
00127
00128 EcalDCCHeaderBlock theDCCheader;
00129
00130 theDCCheader.setId(46);
00131 int fedId = (*itEventBlock)->getDataField("FED/DCC ID");
00132 theDCCheader.setFedId( fedId );
00133
00134 theDCCheader.setRunNumber((*itEventBlock)->getDataField("RUN NUMBER"));
00135 short trigger_type = (*itEventBlock)->getDataField("TRIGGER TYPE");
00136 short zs = (*itEventBlock)->getDataField("ZS");
00137 short tzs = (*itEventBlock)->getDataField("TZS");
00138 short sr = (*itEventBlock)->getDataField("SR");
00139 bool dataIsSuppressed;
00140
00141
00142 if ( zs && !(tzs) ) dataIsSuppressed = true;
00143 else dataIsSuppressed = false;
00144
00145 if(trigger_type >0 && trigger_type <5){theDCCheader.setBasicTriggerType(trigger_type);}
00146 else{ edm::LogWarning("EcalTB07RawToDigiTriggerType") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00147 << "unrecognized TRIGGER TYPE: "<<trigger_type;}
00148 theDCCheader.setLV1((*itEventBlock)->getDataField("LV1"));
00149 theDCCheader.setOrbit((*itEventBlock)->getDataField("ORBIT COUNTER"));
00150 theDCCheader.setBX((*itEventBlock)->getDataField("BX"));
00151 theDCCheader.setErrors((*itEventBlock)->getDataField("DCC ERRORS"));
00152 theDCCheader.setSelectiveReadout( sr );
00153 theDCCheader.setZeroSuppression( zs );
00154 theDCCheader.setTestZeroSuppression( tzs );
00155 theDCCheader.setSrpStatus((*itEventBlock)->getDataField("SR_CHSTATUS"));
00156
00157
00158
00159
00160 std::vector<short> theTCCs;
00161 for(int i=0; i<MAX_TCC_SIZE; i++){
00162
00163 char TCCnum[20]; sprintf(TCCnum,"TCC_CHSTATUS#%d",i+1); std::string TCCnumS(TCCnum);
00164 theTCCs.push_back ((*itEventBlock)->getDataField(TCCnumS) );
00165 }
00166 theDCCheader.setTccStatus(theTCCs);
00167
00168
00169 std::vector< DCCTBTCCBlock * > tccBlocks = (*itEventBlock)->tccBlocks();
00170
00171 for( std::vector< DCCTBTCCBlock * >::iterator itTCCBlock = tccBlocks.begin();
00172 itTCCBlock != tccBlocks.end();
00173 itTCCBlock ++)
00174 {
00175
00176 std::vector< std::pair<int,bool> > TpSamples = (* itTCCBlock) -> triggerSamples() ;
00177
00178 std::vector<int> TpFlags = (* itTCCBlock) -> triggerFlags() ;
00179
00180
00181 if (TpSamples.size()==68 && TpFlags.size()==68)
00182 {
00183 for(int i=0; i<((int)TpSamples.size()); i++)
00184 {
00185
00186 int etaTT = (i) / kTowersInPhi +1;
00187 int phiTT = (i) % kTowersInPhi +1;
00188
00189
00190 phiTT=3-phiTT;
00191 if(phiTT<=0)phiTT=phiTT+72;
00192
00193 EcalTriggerPrimitiveSample theSample(TpSamples[i].first, TpSamples[i].second, TpFlags[i]);
00194
00195 EcalTrigTowerDetId idtt(2, EcalBarrel, etaTT, phiTT, 0);
00196 EcalTriggerPrimitiveDigi thePrimitive(idtt);
00197 thePrimitive.setSize(1);
00198 thePrimitive.setSample(0, theSample);
00199
00200 tpcollection.push_back(thePrimitive);
00201
00202 LogDebug("EcalTB07RawToDigiTpg") << "@SUBS=EcalTB07DaqFormatter::interpretRawData"
00203 << "tower: " << (i+1)
00204 << " primitive: " << TpSamples[i].first
00205 << " flag: " << TpSamples[i].second;
00206
00207 LogDebug("EcalTB07RawToDigiTpg") << "@SUBS=EcalTB07DaqFormatter::interpretRawData"<<
00208 "tower: " << (i+1) << " flag: " << TpFlags[i];
00209 }
00210
00211 }
00212 else
00213 {
00214 edm::LogWarning("EcalTB07RawToDigiTpg") << "68 elements not found for TpFlags or TpSamples, collection will be empty";
00215 }
00216 }
00217
00218
00219
00220
00221 short TowerStatus[MAX_TT_SIZE+1];
00222 char buffer[20];
00223 std::vector<short> theTTstatus;
00224 for(int i=1;i<MAX_TT_SIZE+1;i++)
00225 {
00226 sprintf(buffer, "FE_CHSTATUS#%d", i);
00227 std::string Tower(buffer);
00228 TowerStatus[i]= (*itEventBlock)->getDataField(Tower);
00229 theTTstatus.push_back(TowerStatus[i]);
00230
00231 }
00232 bool checkTowerStatus = TowerStatus[1] == 0 && TowerStatus[2] == 0 && TowerStatus[3] == 0 && TowerStatus[4] == 0;
00233 for (int i=5; i < MAX_TT_SIZE+1; ++i) checkTowerStatus = checkTowerStatus && TowerStatus[i] == 1;
00234 if (!checkTowerStatus) {
00235 for(int i=1; i<MAX_TT_SIZE+1; ++i) {
00236 std::cout << "tower " << i << " has status " << TowerStatus[i] << std::endl;
00237 }
00238 }
00239
00240 theDCCheader.setFEStatus(theTTstatus);
00241
00242 EcalDCCTBHeaderRuntypeDecoder theRuntypeDecoder;
00243 uint32_t DCCruntype = (*itEventBlock)->getDataField("RUN TYPE");
00244 theRuntypeDecoder.Decode(DCCruntype, &theDCCheader);
00245
00246 DCCheaderCollection.push_back(theDCCheader);
00247
00248
00249 EcalDCCHeaderBlock hdr = theDCCheader;
00250 hdr.setId(04);
00251 DCCheaderCollection.push_back(hdr);
00252 hdr.setId(05);
00253 DCCheaderCollection.push_back(hdr);
00254 hdr.setId(06);
00255 DCCheaderCollection.push_back(hdr);
00256
00257 std::vector< DCCTBTowerBlock * > dccTowerBlocks = (*itEventBlock)->towerBlocks();
00258 LogDebug("EcalTB07RawToDigi") << "@SUBS=EcalTB07DaqFormatter::interpretRawData"
00259 << "dccTowerBlocks size " << dccTowerBlocks.size();
00260
00261
00262
00263 _expTowersIndex=0;_numExpectedTowers=0;
00264 for (int v=0; v<71; v++){
00265 _ExpectedTowers[v]=99999;
00266 }
00267
00268
00269
00270
00271
00272
00273 for (int u=1; u< (kTriggerTowersAndMem+1); u++)
00274 {
00275
00276
00277
00278
00279
00280
00281
00282
00283 if( TowerStatus[u] ==0 || TowerStatus[u] ==9 || TowerStatus[u] ==10 )
00284 {_ExpectedTowers[_expTowersIndex]= tbStatusToLocation_[u];
00285 _expTowersIndex++;
00286 _numExpectedTowers++;
00287 }
00288 }
00289
00290 _expTowersIndex=0;
00291
00292
00293
00294 if (! (dccTowerBlocks.size() == _numExpectedTowers) )
00295 {
00296
00297 edm::LogWarning("EcalTB07RawToDigiNumTowerBlocks") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00298 << "number of TowerBlocks found (" << dccTowerBlocks.size()
00299 << ") differs from expected (" << _numExpectedTowers
00300 << ") skipping event";
00301
00302 EBDetId idsm(1, 1);
00303 dccsizecollection.push_back(idsm);
00304
00305 return;
00306
00307 }
00308
00309
00310
00311
00312
00313
00314 for( std::vector< DCCTBTowerBlock * >::iterator itTowerBlock = dccTowerBlocks.begin();
00315 itTowerBlock!= dccTowerBlocks.end();
00316 itTowerBlock++){
00317
00318 tower=(*itTowerBlock)->towerID();
00319
00320
00321
00322
00323
00324 tower = tbTowerIDToLocation_[tower];
00325
00326
00327
00328
00329
00330
00331 EcalElectronicsId idtt(46, _ExpectedTowers[_expTowersIndex], 1, 1);
00332
00333
00334 if ( !(tower == _ExpectedTowers[_expTowersIndex]) )
00335 {
00336
00337 if (_ExpectedTowers[_expTowersIndex] <= 68){
00338 edm::LogWarning("EcalTB07RawToDigiTowerId") << "@SUBS=EcalTB07DaqFormatter::interpretRawData"
00339 << "TTower id found (=" << tower
00340 << ") different from expected (=" << _ExpectedTowers[_expTowersIndex]
00341 << ") " << (_expTowersIndex+1) << "-th tower checked"
00342 << "\n Real hardware id is " << (*itTowerBlock)->towerID();
00343
00344
00345 ttidcollection.push_back(idtt);
00346 }
00347 else
00348 {
00349 edm::LogWarning("EcalTB07RawToDigiTowerId") << "@SUB=EcalTB07DaqFormatter:interpretRawData"
00350 << "DecodeMEM: tower " << tower
00351 << " is not the same as expected " << ((int)_ExpectedTowers[_expTowersIndex])
00352 << " (according to DCC header channel status)";
00353
00354
00355
00356 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], 1, 1);
00357 memttidcollection.push_back(id);
00358 }
00359
00360 ++ _expTowersIndex;
00361 continue;
00362 }
00363
00364
00365
00366
00367
00368
00369 if ( 0< (*itTowerBlock)->towerID() &&
00370 ((*itTowerBlock)->towerID() < (kTriggerTowers+1) ||
00371 (*itTowerBlock)->towerID() == 71 ||
00372 (*itTowerBlock)->towerID() == 80)
00373 )
00374 {
00375
00376 std::vector<DCCTBXtalBlock * > & xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
00377
00378
00379 if ( (!dataIsSuppressed) && (xtalDataBlocks.size() != kChannelsPerTower) )
00380 {
00381 edm::LogWarning("EcalTB07RawToDigiTowerSize") << "EcalTB07DaqFormatter::interpretRawData, no zero suppression "
00382 << "wrong tower block size is: " << xtalDataBlocks.size()
00383 << " at LV1 " << (*itEventBlock)->getDataField("LV1")
00384 << " for TT " << _ExpectedTowers[_expTowersIndex];
00385
00386 blocksizecollection.push_back(idtt);
00387
00388 ++ _expTowersIndex; continue;
00389
00390 }
00391
00392
00393 short cryInTower =0;
00394
00395 short expStripInTower;
00396 short expCryInStrip;
00397 short expCryInTower =0;
00398
00399
00400 for( std::vector< DCCTBXtalBlock * >::iterator itXtalBlock = xtalDataBlocks.begin();
00401 itXtalBlock!= xtalDataBlocks.end();
00402 itXtalBlock++){
00403
00404 strip =(*itXtalBlock)->stripID();
00405 ch =(*itXtalBlock)->xtalID();
00406 cryInTower =(strip-1)* kChannelsPerCard + (ch -1);
00407
00408 expStripInTower = expCryInTower/5 +1;
00409 expCryInStrip = expCryInTower%5 +1;
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 if (dataIsSuppressed)
00421 {
00422
00423 if ( strip < 1 || 5<strip || ch <1 || 5 < ch)
00424 {
00425 int sm = 1;
00426 for (int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
00427 for (int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
00428 int ic = cryIc(tower, StripInTower_, CryInStrip_) ;
00429 EBDetId idExp(sm, ic,1);
00430 chidcollection.push_back(idExp);
00431 }
00432 }
00433
00434 edm::LogWarning("EcalTB07RawToDigiChId") << "EcalTB07DaqFormatter::interpretRawData with zero suppression, "
00435 << " wrong channel id, since out of range: "
00436 << "\t strip: " << strip << "\t channel: " << ch
00437 << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
00438 << "\t at LV1 : " << (*itEventBlock)->getDataField("LV1");
00439
00440 expCryInTower++;
00441 continue;
00442 }
00443
00444
00445
00446 if( cryInTower >= expCryInTower ){
00447 expCryInTower = cryInTower +1;
00448 }
00449
00450
00451
00452 else
00453 {
00454 edm::LogWarning("EcalTB07RawToDigiChId") << "EcalTB07DaqFormatter::interpretRawData with zero suppression, "
00455 << " based on ch ordering within tt, wrong channel id: "
00456 << "\t strip: " << strip << "\t channel: " << ch
00457 << "\t cryInTower " << cryInTower
00458 << "\t expCryInTower: " << expCryInTower
00459 << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
00460 << "\t at LV1: " << (*itEventBlock)->getDataField("LV1");
00461
00462 int sm = 1;
00463 for (int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
00464 for (int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
00465 int ic = cryIc(tower, StripInTower_, CryInStrip_) ;
00466 EBDetId idExp(sm, ic,1);
00467 chidcollection.push_back(idExp);
00468 }
00469 }
00470
00471
00472 expCryInTower++; continue;
00473
00474 }
00475
00476 }
00477
00478
00479
00480 else {
00481
00482
00483 if( cryInTower != expCryInTower ||
00484 strip < 1 || kStripsPerTower <strip ||
00485 ch <1 || kChannelsPerStrip < ch )
00486 {
00487
00488 int ic = cryIc(tower, expStripInTower, expCryInStrip) ;
00489 int sm = 1;
00490 EBDetId idExp(sm, ic,1);
00491
00492 edm::LogWarning("EcalTB07RawToDigiChId") << "EcalTB07DaqFormatter::interpretRawData no zero suppression "
00493 << " wrong channel id for channel: " << expCryInStrip
00494 << "\t strip: " << expStripInTower
00495 << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
00496 << "\t at LV1: " << (*itEventBlock)->getDataField("LV1")
00497 << "\t (in the data, found channel: " << ch
00498 << "\t strip: " << strip << " ).";
00499
00500
00501
00502 chidcollection.push_back(idExp);
00503
00504
00505 expCryInTower++; continue;
00506
00507 }
00508
00509 expCryInTower++;
00510
00511 }
00512
00513
00514
00515
00516 int ic = cryIc(tower, strip, ch) ;
00517 int sm = 1;
00518 EBDetId id(sm, ic,1);
00519
00520
00521 int ix = getEE_ix(tower, strip, ch);
00522 int iy = getEE_iy(tower, strip, ch);
00523
00524 int iz = 1;
00525 if ( tbName_ == "h4" ) iz = -1;
00526 EEDetId eeId(ix, iy, iz);
00527
00528
00529
00530 digicollection.push_back( id );
00531 eeDigiCollection.push_back( eeId );
00532 EBDataFrame theFrame ( digicollection.back() );
00533 EEDataFrame eeFrame ( eeDigiCollection.back() );
00534
00535 std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
00536
00537
00538
00539
00540
00541 bool gainIsOk =true;
00542 unsigned gain_mask = 12288;
00543 std::vector <int> xtalGain;
00544
00545 for (unsigned short i=0; i<xtalDataSamples.size(); ++i ) {
00546
00547 theFrame.setSample (i, xtalDataSamples[i] );
00548 eeFrame .setSample (i, xtalDataSamples[i] );
00549
00550 if((xtalDataSamples[i] & gain_mask) == 0){gainIsOk =false;}
00551
00552 xtalGain.push_back(0);
00553 xtalGain[i] |= (xtalDataSamples[i] >> 12);
00554 }
00555
00556 if (! gainIsOk) {
00557
00558 edm::LogWarning("EcalTB07RawToDigiGainZero") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00559 << " gain==0 for strip: " << expStripInTower
00560 << "\t channel: " << expCryInStrip
00561 << "\t in TT: " << _ExpectedTowers[_expTowersIndex]
00562 << "\t ic: " << ic
00563 << "\t at LV1: " << (*itEventBlock)->getDataField("LV1");
00564
00565 gaincollection.push_back(id);
00566
00567
00568 digicollection.pop_back();
00569 eeDigiCollection.pop_back();
00570 continue;
00571 }
00572
00573
00574
00575
00576
00577
00578 short firstGainWrong=-1;
00579 short numGainWrong=0;
00580
00581 for (unsigned short i=0; i<xtalGain.size(); i++ ) {
00582
00583 if (i>0 && xtalGain[i-1]>xtalGain[i]) {
00584
00585 numGainWrong++;
00586
00587 if (firstGainWrong == -1) {
00588 firstGainWrong=i;
00589 edm::LogWarning("EcalTB07RawToDigiGainSwitch") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00590 << "channelHasGainSwitchProblem: crystal eta = "
00591 << id.ieta() << " phi = " << id.iphi();
00592 }
00593 edm::LogWarning("EcalTB07RawToDigiGainSwitch") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00594 << "channelHasGainSwitchProblem: sample = " << (i-1)
00595 << " gain: " << xtalGain[i-1] << " sample: "
00596 << i << " gain: " << xtalGain[i];
00597 }
00598 }
00599
00600 if (numGainWrong>0) {
00601 gainswitchcollection.push_back(id);
00602
00603 edm::LogWarning("EcalTB07RawToDigiGainSwitch") << "@SUB=EcalTB07DaqFormatter:interpretRawData"
00604 << "channelHasGainSwitchProblem: more than 1 wrong transition";
00605
00606 for (unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
00607 int countADC = 0x00000FFF;
00608 countADC &= xtalDataSamples[i1];
00609 LogDebug("EcalTB07RawToDigi") << "Sample " << i1 << " ADC " << countADC << " Gain " << xtalGain[i1];
00610 }
00611
00612
00613 digicollection.pop_back();
00614 eeDigiCollection.pop_back();
00615 continue;
00616
00617 }
00618
00619 }
00620
00621 _expTowersIndex++;
00622 }
00623
00624
00625
00626
00627
00628
00629
00630
00631 else if ( (*itTowerBlock)->towerID() == 69
00632 || (*itTowerBlock)->towerID() == 70 )
00633 {
00634
00635 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00636 << "processing mem box num: " << (*itTowerBlock)->towerID();
00637
00638
00639 if(! pnAllocated)
00640 {
00641 pndigicollection.reserve(kPns);
00642 pnAllocated = true;
00643 }
00644
00645 DecodeMEM( (*itTowerBlock), pndigicollection ,
00646 memttidcollection, memblocksizecollection,
00647 memgaincollection, memchidcollection);
00648
00649 }
00650
00651
00652
00653
00654
00655
00656 else {
00657 edm::LogWarning("EcalTB07RawToDigiTowerId") <<"@SUB=EcalTB07DaqFormatter::interpretRawData"
00658 << " processing tt with ID not existing ( "
00659 << (*itTowerBlock)->towerID() << ")";
00660 ++ _expTowersIndex;
00661 continue;
00662 }
00663
00664 }
00665
00666 }
00667 }
00668
00669
00670
00671
00672
00673
00674
00675
00676 void EcalTB07DaqFormatter::DecodeMEM( DCCTBTowerBlock * towerblock, EcalPnDiodeDigiCollection & pndigicollection ,
00677 EcalElectronicsIdCollection & memttidcollection, EcalElectronicsIdCollection & memblocksizecollection,
00678 EcalElectronicsIdCollection & memgaincollection, EcalElectronicsIdCollection & memchidcollection)
00679 {
00680
00681 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::DecodeMEM"
00682 << "in mem " << towerblock->towerID();
00683
00684 int tower_id = towerblock ->towerID() ;
00685 int mem_id = tower_id-69;
00686
00687
00688 for (int st_id=0; st_id< kStripsPerTower; st_id++){
00689 for (int ch_id=0; ch_id<kChannelsPerStrip; ch_id++){
00690 for (int sa=0; sa<11; sa++){
00691 memRawSample_[st_id][ch_id][sa] = -1;} } }
00692
00693
00694
00695 if(tower_id != 69 && tower_id != 70)
00696 {
00697 edm::LogWarning("EcalTB07RawToDigiTowerId") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00698 << "DecodeMEM: this is not a mem box tower (" << tower_id << ")";
00699 ++ _expTowersIndex;
00700 return;
00701 }
00702
00703
00704
00705
00706
00707 std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->xtalBlocks();
00708 std::vector<DCCTBXtalBlock*>::iterator itXtal;
00709
00710
00711 if (dccXtalBlocks.size() != kChannelsPerTower)
00712 {
00713 LogDebug("EcalTB07RawToDigiDccBlockSize") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00714 << " wrong dccBlock size, namely: " << dccXtalBlocks.size()
00715 << ", for mem " << _ExpectedTowers[_expTowersIndex];
00716
00717
00718
00719 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], 1, 1);
00720 memblocksizecollection.push_back(id);
00721
00722 ++ _expTowersIndex;
00723 return;
00724 }
00725
00726
00727
00728 int cryCounter = 0; int strip_id = 0; int xtal_id = 0;
00729
00730 for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
00731 strip_id = (*itXtal) ->getDataField("STRIP ID");
00732 xtal_id = (*itXtal) ->getDataField("XTAL ID");
00733 int wished_strip_id = cryCounter/ kStripsPerTower;
00734 int wished_ch_id = cryCounter% kStripsPerTower;
00735
00736 if( (wished_strip_id+1) != ((int)strip_id) ||
00737 (wished_ch_id+1) != ((int)xtal_id) )
00738 {
00739
00740 LogDebug("EcalTB07RawToDigiChId") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00741 << " in mem " << towerblock->towerID()
00742 << ", expected:\t strip"
00743 << (wished_strip_id+1) << " cry " << (wished_ch_id+1) << "\tfound: "
00744 << " strip " << strip_id << " cry " << xtal_id;
00745
00746
00747 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], wished_strip_id, wished_ch_id);
00748 memchidcollection.push_back(id);
00749 }
00750
00751
00752
00753 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField("ADC#1");
00754 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField("ADC#2");
00755 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField("ADC#3");
00756 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField("ADC#4");
00757 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField("ADC#5");
00758 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField("ADC#6");
00759 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField("ADC#7");
00760 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField("ADC#8");
00761 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField("ADC#9");
00762 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField("ADC#10");
00763
00764 cryCounter++;
00765 }
00766
00767
00768
00769 ++ _expTowersIndex;
00770
00771
00772
00773
00774
00775
00776 int tempSample=0;
00777 int memStoreIndex=0;
00778 int ipn=0;
00779 for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
00780 data_MEM[memStoreIndex]= -1; }
00781
00782
00783 for(int strip=0; strip<kStripsPerTower; strip++) {
00784 for(int channel=0; channel<kChannelsPerStrip; channel++) {
00785
00786 if(strip%2 == 0)
00787 {ipn= mem_id*5+channel;}
00788 else
00789 {ipn=mem_id*5+4-channel;}
00790
00791 for(int sample=0;sample< kSamplesPerChannel ;sample++) {
00792 tempSample= memRawSample_[strip][channel][sample+1];
00793
00794 int new_data=0;
00795 if(strip%2 == 1) {
00796
00797 for(int ib=0;ib<14;ib++)
00798 {
00799 new_data <<= 1;
00800 new_data=new_data | (tempSample&1);
00801 tempSample >>= 1;
00802 }
00803 } else {
00804 new_data=tempSample;
00805 }
00806
00807
00808
00809 new_data = (new_data ^ 0x800) & 0x3fff;
00810
00811
00812
00813
00814
00815 short sampleGain = (new_data &0x3000)/4096;
00816 if ( sampleGain==2 || sampleGain==3)
00817 {
00818 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], strip, channel);
00819 memgaincollection.push_back(id);
00820
00821 edm::LogWarning("EcalTB07RawToDigiGainZero") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00822 << "in mem " << towerblock->towerID()
00823 << " :\t strip: "
00824 << (strip +1) << " cry: " << (channel+1)
00825 << " has 14th bit non zero! Gain results: "
00826 << sampleGain << ".";
00827
00828 continue;
00829 }
00830
00831 memStoreIndex= ipn*50+strip*kSamplesPerChannel+sample;
00832
00833 data_MEM[memStoreIndex]= new_data & 0x3fff;
00834
00835 }
00836 }
00837 }
00838
00839
00840
00841
00842 for (int pnId=0; pnId<kPnPerTowerBlock; pnId++) pnIsOkInBlock[pnId]=true;
00843
00844
00845
00846 if (! (memgaincollection.size()==0 && memchidcollection.size()==0) )
00847 {
00848 for ( EcalElectronicsIdCollection::const_iterator idItr = memgaincollection.begin();
00849 idItr != memgaincollection.end();
00850 ++ idItr ) {
00851 int ch = (*idItr).channelId();
00852 ch = (ch-1)/5;
00853 pnIsOkInBlock [ch] = false;
00854 }
00855
00856 for ( EcalElectronicsIdCollection::const_iterator idItr = memchidcollection.begin();
00857 idItr != memchidcollection.end();
00858 ++ idItr ) {
00859 int ch = (*idItr).channelId();
00860 ch = (ch-1)/5;
00861 pnIsOkInBlock [ch] = false;
00862 }
00863
00864 }
00865
00866
00867
00868
00869
00870 for (int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
00871
00872
00873 if (! pnIsOkInBlock [pnId-1] ) continue;
00874
00875
00876 EcalPnDiodeDetId PnId(2, 46, pnId + kPnPerTowerBlock*mem_id);
00877 EcalPnDiodeDigi thePnDigi(PnId );
00878
00879 thePnDigi.setSize(kSamplesPerPn);
00880
00881 for (int sample =0; sample<kSamplesPerPn; sample++)
00882 {
00883 EcalFEMSample thePnSample( data_MEM[(mem_id)*250 + (pnId-1)*kSamplesPerPn + sample ] );
00884 thePnDigi.setSample(sample, thePnSample );
00885 }
00886 pndigicollection.push_back(thePnDigi);
00887 }
00888
00889
00890 }
00891
00892
00893 std::pair<int,int> EcalTB07DaqFormatter::cellIndex(int tower_id, int strip, int ch) {
00894
00895 int xtal= (strip-1)*5+ch-1;
00896
00897 std::pair<int,int> ind;
00898
00899 int eta = (tower_id - 1)/kTowersInPhi*kCardsPerTower;
00900 int phi = (tower_id - 1)%kTowersInPhi*kChannelsPerCard;
00901
00902 if (rightTower(tower_id))
00903 eta += xtal/kCardsPerTower;
00904 else
00905 eta += (kCrystalsPerTower - 1 - xtal)/kCardsPerTower;
00906
00907 if ((rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 1) ||
00908 (!rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 0))
00909
00910 phi += (kChannelsPerCard - 1 - xtal%kChannelsPerCard);
00911 else
00912 phi += xtal%kChannelsPerCard;
00913
00914
00915 ind.first =eta+1;
00916 ind.second=phi+1;
00917
00918
00919
00920 return ind;
00921
00922 }
00923
00924 int EcalTB07DaqFormatter::getEE_ix(int tower, int strip, int ch){
00925
00926 int ic = cryIc(tower, strip, ch);
00927 int ix = 0;
00928 if ( tbName_ == "h2" )
00929 ix = 95 - (ic-1)/20;
00930
00931 if ( tbName_ == "h4" )
00932 ix = 35 - (ic-1)%20;
00933
00934 return ix;
00935
00936 }
00937 int EcalTB07DaqFormatter::getEE_iy(int tower, int strip, int ch){
00938 int ic = cryIc(tower, strip, ch);
00939 int iy = 0;
00940 if ( tbName_ == "h2" )
00941 iy = 46 + (ic-1)%20;
00942
00943 if ( tbName_ == "h4" )
00944 iy = 51 + (int)((ic-1)/20);
00945
00946 return iy;
00947 }
00948
00949 int EcalTB07DaqFormatter::cryIc(int tower, int strip, int ch) {
00950
00951 if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
00952 {
00953 edm::LogWarning("EcalTB07RawToDigiChId") << "EcalTB07DaqFormatter::interpretRawData (cryIc) "
00954 << " wrong channel id, since out of range: "
00955 << "\t strip: " << strip << "\t channel: " << ch
00956 << "\t in TT: " << tower;
00957 return -1;
00958 }
00959
00960
00961 return cryIcMap_[tower-1][strip-1][ch-1];
00962
00963
00964 }
00965
00966
00967
00968 bool EcalTB07DaqFormatter::rightTower(int tower) const {
00969
00970 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
00971 (tower>44 && tower<53) || (tower>60 && tower<69))
00972 return true;
00973 else
00974 return false;
00975 }
00976
00977
00978
00979 bool EcalTB07DaqFormatter::leftTower(int tower) const
00980 {
00981 return !rightTower(tower);
00982 }
00983
00984