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<ulong> 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, EBDetIdCollection & gainswitchstaycollection,
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<ulong*>(const_cast<unsigned char*>(pData)), static_cast<ulong>(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 ulong 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 int towerMap[kTriggerTowersAndMem+1];
00277 for (int i=0; i<kTriggerTowersAndMem; ++i ) towerMap[i] = i;
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
00601 bool wrongGainStaysTheSame=false;
00602 if (firstGainWrong!=-1 && firstGainWrong<9){
00603 short gainWrong = xtalGain[firstGainWrong];
00604
00605
00606 for (unsigned short u=firstGainWrong+1; u<xtalGain.size(); u++){
00607
00608 if( gainWrong == xtalGain[u])
00609 wrongGainStaysTheSame=true;
00610 else
00611 wrongGainStaysTheSame=false;
00612
00613 }
00614
00615 }
00616
00617
00618 if (numGainWrong>0) {
00619 gainswitchcollection.push_back(id);
00620
00621 if (numGainWrong == 1 && (wrongGainStaysTheSame)) {
00622
00623 edm::LogWarning("EcalTB07RawToDigiGainSwitch") << "@SUB=EcalTB07DaqFormatter:interpretRawData"
00624 << "channelHasGainSwitchProblem: wrong transition stays till last sample";
00625
00626 gainswitchstaycollection.push_back(id);
00627 }
00628 else if (numGainWrong>1) {
00629 edm::LogWarning("EcalTB07RawToDigiGainSwitch") << "@SUB=EcalTB07DaqFormatter:interpretRawData"
00630 << "channelHasGainSwitchProblem: more than 1 wrong transition";
00631
00632 for (unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
00633 int countADC = 0x00000FFF;
00634 countADC &= xtalDataSamples[i1];
00635 LogDebug("EcalTB07RawToDigi") << "Sample " << i1 << " ADC " << countADC << " Gain " << xtalGain[i1];
00636 }
00637
00638 }
00639
00640
00641
00642 digicollection.pop_back();
00643 eeDigiCollection.pop_back();
00644 continue;
00645
00646 }
00647
00648
00649 }
00650
00651
00652 _expTowersIndex++;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662 else if ( (*itTowerBlock)->towerID() == 69
00663 || (*itTowerBlock)->towerID() == 70 )
00664 {
00665
00666 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::interpretRawData"
00667 << "processing mem box num: " << (*itTowerBlock)->towerID();
00668
00669
00670 if(! pnAllocated)
00671 {
00672 pndigicollection.reserve(kPns);
00673 pnAllocated = true;
00674 }
00675
00676 DecodeMEM( (*itTowerBlock), pndigicollection ,
00677 memttidcollection, memblocksizecollection,
00678 memgaincollection, memchidcollection);
00679
00680 }
00681
00682
00683
00684
00685
00686
00687 else {
00688 edm::LogWarning("EcalTB07RawToDigiTowerId") <<"@SUB=EcalTB07DaqFormatter::interpretRawData"
00689 << " processing tt with ID not existing ( "
00690 << (*itTowerBlock)->towerID() << ")";
00691 ++ _expTowersIndex;
00692 continue;
00693 }
00694
00695 }
00696
00697 }
00698 }
00699
00700
00701
00702
00703
00704
00705
00706
00707 void EcalTB07DaqFormatter::DecodeMEM( DCCTBTowerBlock * towerblock, EcalPnDiodeDigiCollection & pndigicollection ,
00708 EcalElectronicsIdCollection & memttidcollection, EcalElectronicsIdCollection & memblocksizecollection,
00709 EcalElectronicsIdCollection & memgaincollection, EcalElectronicsIdCollection & memchidcollection)
00710 {
00711
00712 LogDebug("EcalTB07RawToDigi") << "@SUB=EcalTB07DaqFormatter::DecodeMEM"
00713 << "in mem " << towerblock->towerID();
00714
00715 int tower_id = towerblock ->towerID() ;
00716 int mem_id = tower_id-69;
00717
00718
00719 for (int st_id=0; st_id< kStripsPerTower; st_id++){
00720 for (int ch_id=0; ch_id<kChannelsPerStrip; ch_id++){
00721 for (int sa=0; sa<11; sa++){
00722 memRawSample_[st_id][ch_id][sa] = -1;} } }
00723
00724
00725
00726 if(tower_id != 69 && tower_id != 70)
00727 {
00728 edm::LogWarning("EcalTB07RawToDigiTowerId") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00729 << "DecodeMEM: this is not a mem box tower (" << tower_id << ")";
00730 ++ _expTowersIndex;
00731 return;
00732 }
00733
00734
00735
00736
00737
00738 std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->xtalBlocks();
00739 std::vector<DCCTBXtalBlock*>::iterator itXtal;
00740
00741
00742 if (dccXtalBlocks.size() != kChannelsPerTower)
00743 {
00744 LogDebug("EcalTB07RawToDigiDccBlockSize") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00745 << " wrong dccBlock size, namely: " << dccXtalBlocks.size()
00746 << ", for mem " << _ExpectedTowers[_expTowersIndex];
00747
00748
00749
00750 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], 1, 1);
00751 memblocksizecollection.push_back(id);
00752
00753 ++ _expTowersIndex;
00754 return;
00755 }
00756
00757
00758
00759 int cryCounter = 0; int strip_id = 0; int xtal_id = 0;
00760
00761 for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
00762 strip_id = (*itXtal) ->getDataField("STRIP ID");
00763 xtal_id = (*itXtal) ->getDataField("XTAL ID");
00764 int wished_strip_id = cryCounter/ kStripsPerTower;
00765 int wished_ch_id = cryCounter% kStripsPerTower;
00766
00767 if( (wished_strip_id+1) != ((int)strip_id) ||
00768 (wished_ch_id+1) != ((int)xtal_id) )
00769 {
00770
00771 LogDebug("EcalTB07RawToDigiChId") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00772 << " in mem " << towerblock->towerID()
00773 << ", expected:\t strip"
00774 << (wished_strip_id+1) << " cry " << (wished_ch_id+1) << "\tfound: "
00775 << " strip " << strip_id << " cry " << xtal_id;
00776
00777
00778 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], wished_strip_id, wished_ch_id);
00779 memchidcollection.push_back(id);
00780 }
00781
00782
00783
00784 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField("ADC#1");
00785 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField("ADC#2");
00786 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField("ADC#3");
00787 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField("ADC#4");
00788 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField("ADC#5");
00789 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField("ADC#6");
00790 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField("ADC#7");
00791 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField("ADC#8");
00792 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField("ADC#9");
00793 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField("ADC#10");
00794
00795 cryCounter++;
00796 }
00797
00798
00799
00800 ++ _expTowersIndex;
00801
00802
00803
00804
00805
00806
00807 int tempSample=0;
00808 int memStoreIndex=0;
00809 int ipn=0;
00810 for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
00811 data_MEM[memStoreIndex]= -1; }
00812
00813
00814 for(int strip=0; strip<kStripsPerTower; strip++) {
00815 for(int channel=0; channel<kChannelsPerStrip; channel++) {
00816
00817 if(strip%2 == 0)
00818 {ipn= mem_id*5+channel;}
00819 else
00820 {ipn=mem_id*5+4-channel;}
00821
00822 for(int sample=0;sample< kSamplesPerChannel ;sample++) {
00823 tempSample= memRawSample_[strip][channel][sample+1];
00824
00825 int new_data=0;
00826 if(strip%2 == 1) {
00827
00828 for(int ib=0;ib<14;ib++)
00829 {
00830 new_data <<= 1;
00831 new_data=new_data | (tempSample&1);
00832 tempSample >>= 1;
00833 }
00834 } else {
00835 new_data=tempSample;
00836 }
00837
00838
00839
00840 new_data = (new_data ^ 0x800) & 0x3fff;
00841
00842
00843
00844
00845
00846 short sampleGain = (new_data &0x3000)/4096;
00847 if ( sampleGain==2 || sampleGain==3)
00848 {
00849 EcalElectronicsId id(1, (int)_ExpectedTowers[_expTowersIndex], strip, channel);
00850 memgaincollection.push_back(id);
00851
00852 edm::LogWarning("EcalTB07RawToDigiGainZero") << "@SUB=EcalTB07DaqFormatter:decodeMem"
00853 << "in mem " << towerblock->towerID()
00854 << " :\t strip: "
00855 << (strip +1) << " cry: " << (channel+1)
00856 << " has 14th bit non zero! Gain results: "
00857 << sampleGain << ".";
00858
00859 continue;
00860 }
00861
00862 memStoreIndex= ipn*50+strip*kSamplesPerChannel+sample;
00863
00864 data_MEM[memStoreIndex]= new_data & 0x3fff;
00865
00866 }
00867 }
00868 }
00869
00870
00871
00872
00873 for (int pnId=0; pnId<kPnPerTowerBlock; pnId++) pnIsOkInBlock[pnId]=true;
00874
00875
00876
00877 if (! (memgaincollection.size()==0 && memchidcollection.size()==0) )
00878 {
00879 for ( EcalElectronicsIdCollection::const_iterator idItr = memgaincollection.begin();
00880 idItr != memgaincollection.end();
00881 ++ idItr ) {
00882 int ch = (*idItr).channelId();
00883 ch = (ch-1)/5;
00884 pnIsOkInBlock [ch] = false;
00885 }
00886
00887 for ( EcalElectronicsIdCollection::const_iterator idItr = memchidcollection.begin();
00888 idItr != memchidcollection.end();
00889 ++ idItr ) {
00890 int ch = (*idItr).channelId();
00891 ch = (ch-1)/5;
00892 pnIsOkInBlock [ch] = false;
00893 }
00894
00895 }
00896
00897
00898
00899
00900
00901 for (int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
00902
00903
00904 if (! pnIsOkInBlock [pnId-1] ) continue;
00905
00906
00907 EcalPnDiodeDetId PnId(2, 46, pnId + kPnPerTowerBlock*mem_id);
00908 EcalPnDiodeDigi thePnDigi(PnId );
00909
00910 thePnDigi.setSize(kSamplesPerPn);
00911
00912 for (int sample =0; sample<kSamplesPerPn; sample++)
00913 {
00914 EcalFEMSample thePnSample( data_MEM[(mem_id)*250 + (pnId-1)*kSamplesPerPn + sample ] );
00915 thePnDigi.setSample(sample, thePnSample );
00916 }
00917 pndigicollection.push_back(thePnDigi);
00918 }
00919
00920
00921 }
00922
00923
00924 std::pair<int,int> EcalTB07DaqFormatter::cellIndex(int tower_id, int strip, int ch) {
00925
00926 int xtal= (strip-1)*5+ch-1;
00927
00928 std::pair<int,int> ind;
00929
00930 int eta = (tower_id - 1)/kTowersInPhi*kCardsPerTower;
00931 int phi = (tower_id - 1)%kTowersInPhi*kChannelsPerCard;
00932
00933 if (rightTower(tower_id))
00934 eta += xtal/kCardsPerTower;
00935 else
00936 eta += (kCrystalsPerTower - 1 - xtal)/kCardsPerTower;
00937
00938 if (rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 1 ||
00939 !rightTower(tower_id) && (xtal/kCardsPerTower)%2 == 0)
00940
00941 phi += (kChannelsPerCard - 1 - xtal%kChannelsPerCard);
00942 else
00943 phi += xtal%kChannelsPerCard;
00944
00945
00946 ind.first =eta+1;
00947 ind.second=phi+1;
00948
00949
00950
00951 return ind;
00952
00953 }
00954
00955 int EcalTB07DaqFormatter::getEE_ix(int tower, int strip, int ch){
00956
00957 int ic = cryIc(tower, strip, ch);
00958 int ix = 0;
00959 if ( tbName_ == "h2" )
00960 ix = 95 - (ic-1)/20;
00961
00962 if ( tbName_ == "h4" )
00963 ix = 35 - (ic-1)%20;
00964
00965 return ix;
00966
00967 }
00968 int EcalTB07DaqFormatter::getEE_iy(int tower, int strip, int ch){
00969 int ic = cryIc(tower, strip, ch);
00970 int iy = 0;
00971 if ( tbName_ == "h2" )
00972 iy = 46 + (ic-1)%20;
00973
00974 if ( tbName_ == "h4" )
00975 iy = 51 + (int)((ic-1)/20);
00976
00977 return iy;
00978 }
00979
00980 int EcalTB07DaqFormatter::cryIc(int tower, int strip, int ch) {
00981
00982 if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
00983 {
00984 edm::LogWarning("EcalTB07RawToDigiChId") << "EcalTB07DaqFormatter::interpretRawData (cryIc) "
00985 << " wrong channel id, since out of range: "
00986 << "\t strip: " << strip << "\t channel: " << ch
00987 << "\t in TT: " << tower;
00988 return -1;
00989 }
00990
00991
00992 return cryIcMap_[tower-1][strip-1][ch-1];
00993
00994
00995 }
00996
00997
00998
00999 bool EcalTB07DaqFormatter::rightTower(int tower) const {
01000
01001 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
01002 (tower>44 && tower<53) || (tower>60 && tower<69))
01003 return true;
01004 else
01005 return false;
01006 }
01007
01008
01009
01010 bool EcalTB07DaqFormatter::leftTower(int tower) const
01011 {
01012 return !rightTower(tower);
01013 }
01014
01015