Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:35

0001 #include "EventFilter/EcalRawToDigi/interface/DCCEETCCBlock.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
0004 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
0005 
0006 DCCEETCCBlock::DCCEETCCBlock(DCCDataUnpacker* u, EcalElectronicsMapper* m, DCCEventBlock* e, bool unpack)
0007     : DCCTCCBlock(u, m, e, unpack) {
0008   blockLength_ = 0;
0009 }
0010 
0011 void DCCEETCCBlock::updateCollectors() {
0012   tps_ = unpacker_->ecalTpsCollection();
0013   pss_ = unpacker_->ecalPSsCollection();
0014 }
0015 
0016 void DCCEETCCBlock::addTriggerPrimitivesToCollection() {
0017   //point to trigger data
0018   data_++;
0019 
0020   bool processTPG2(true);
0021   unsigned int psInputCounter(0);
0022 
0023   const uint16_t* tccP_ = reinterpret_cast<const uint16_t*>(data_);
0024 
0025   int dccFOV = event_->fov();
0026   if (!(dccFOV == dcc_FOV_0 || dccFOV == dcc_FOV_1 || dccFOV == dcc_FOV_2)) {
0027     if (!DCCDataUnpacker::silentMode_) {
0028       edm::LogWarning("IncorrectEvent") << "\n FOV value in data is: " << dccFOV << "At event: " << event_->l1A()
0029                                         << " with bx " << event_->bx() << " in fed <<" << mapper_->getActiveDCC()
0030                                         << "\n TCC id " << tccId_ << " FOV " << dccFOV
0031                                         << " which is not a foreseen value. Setting it to: " << dcc_FOV_2;
0032     }
0033     dccFOV = dcc_FOV_2;
0034   }
0035 
0036   /////////////////////////
0037   // MC raw data based on CMS NOTE 2005/021
0038   // (and raw data when FOV was unassigned, earlier than mid 2008)
0039   if (dccFOV == dcc_FOV_0) {
0040     // Unpack TPG1 pseudostrip input block
0041     if (ps_) {
0042       for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
0043         pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
0044         if (!pPS_)
0045           continue;
0046         pPS_->setSampleValue(0, *tccP_);
0047         (*pss_)->push_back(*pPS_);
0048       }
0049     }
0050 
0051     // Unpack TPG1 trigger primitive block
0052     // loop over tp_counter=i and navigate forward in raw (tccP_)
0053     for (unsigned int i = 1; i <= NUMB_TTS_TPG1; i++, tccP_++) {  //16
0054 
0055       if (i <= nTTs_) {
0056         pTP_ = mapper_->getTPPointer(tccId_, i);  // pointer to tp digi container
0057         if (pTP_)
0058           pTP_->setSample(0, *tccP_);  // fill it
0059       } else {
0060         processTPG2 = false;
0061         break;
0062       }
0063       // adding trigger primitive digi to the collection
0064       if (pTP_)
0065         (*tps_)->push_back(*pTP_);
0066       else
0067         edm::LogError("IncorrectBlock") << "trigger primitive digi was not aquired";
0068     }
0069 
0070     if (processTPG2) {
0071       // Unpack TPG2 pseudostrip input block
0072       if (ps_) {
0073         for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
0074           if (i <= NUMB_TTS_TPG2_DUPL)
0075             continue;
0076           //fill pseudostrip container
0077           pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
0078           if (!pPS_)
0079             continue;
0080           pPS_->setSampleValue(0, *tccP_);
0081           (*pss_)->push_back(*pPS_);
0082         }
0083       }
0084 
0085       // Unpack TPG2 trigger primitive block
0086       for (unsigned int i = 1; i <= NUMB_TTS_TPG2; i++, tccP_++) {  //12
0087         unsigned int tt = i + NUMB_TTS_TPG1;
0088 
0089         if (tt <= nTTs_) {
0090           pTP_ = mapper_->getTPPointer(tccId_, tt);
0091           if (pTP_)
0092             pTP_->setSample(0, *tccP_);
0093         } else
0094           break;
0095         // adding trigger primitive digi to the collection
0096         (*tps_)->push_back(*pTP_);
0097       }
0098 
0099     }  // end if(processTPG2)
0100 
0101   }  // end FOV==0
0102 
0103   ///////////////////////////
0104   // real data since ever FOV was initialized; only 2 used >= June 09
0105   else if (dccFOV == dcc_FOV_1 || dccFOV == dcc_FOV_2) {
0106     // Unpack TPG1 pseudostrip input block
0107     if (ps_) {
0108       for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
0109         pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
0110         if (!pPS_)
0111           continue;
0112         pPS_->setSampleValue(0, *tccP_);
0113         (*pss_)->push_back(*pPS_);
0114       }
0115     }
0116 
0117     int offset(0);
0118     // Unpack TPG1 trigger primitive block
0119     // loop over tp_counter=i and navigate forward in raw (tccP_)
0120     for (unsigned int i = 1; i <= NUMB_TTS_TPG1; i++, tccP_++) {  //16
0121 
0122       if (i <= nTTs_) {
0123         if (mapper_->isTCCExternal(tccId_)) {
0124           if (i > 8 && i <= 16)
0125             continue;  // skip blank tp's [9,16]
0126           if (i > 8)
0127             offset = 8;  //
0128           if (i > 24)
0129             continue;  // skip blank tp's [25, 28]
0130         }
0131 
0132         pTP_ = mapper_->getTPPointer(tccId_, i - offset);  // pointer to tp digi container
0133         if (pTP_)
0134           pTP_->setSample(0, *tccP_);  // fill it
0135 
0136       } else {
0137         processTPG2 = false;
0138         break;
0139       }
0140       // adding trigger primitive digi to the collection
0141       if (pTP_)
0142         (*tps_)->push_back(*pTP_);
0143       else
0144         edm::LogError("IncorrectBlock") << "trigger primitive digi was not aquired";
0145     }
0146 
0147     if (processTPG2) {
0148       // Unpack TPG2 pseudostrip input block
0149       if (ps_) {
0150         for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
0151           if (i <= NUMB_TTS_TPG2_DUPL)
0152             continue;
0153           //fill pseudostrip container
0154           pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
0155           if (!pPS_)
0156             continue;
0157           pPS_->setSampleValue(0, *tccP_);
0158           (*pss_)->push_back(*pPS_);
0159         }
0160       }
0161 
0162       // Unpack TPG2 trigger primitive block
0163       for (unsigned int i = 1; i <= NUMB_TTS_TPG2; i++, tccP_++) {  //12
0164         unsigned int tt = i + NUMB_TTS_TPG1;
0165 
0166         if (i <= nTTs_) {
0167           if (mapper_->isTCCExternal(tccId_)) {
0168             if (tt > 8 && tt <= 16)
0169               continue;  // skip blank tp's [9,16]
0170             if (tt > 8)
0171               offset = 8;  //
0172             if (tt > 24)
0173               continue;  // skip blank tp's [25, 28]
0174           }
0175 
0176           pTP_ = mapper_->getTPPointer(tccId_, tt - offset);
0177           if (pTP_)
0178             pTP_->setSample(0, *tccP_);
0179         } else
0180           break;
0181         // adding trigger primitive digi to the collection
0182         (*tps_)->push_back(*pTP_);
0183       }
0184     }  // end if(processTPG2)
0185   }    // end FOV==1 or 2
0186 }
0187 
0188 bool DCCEETCCBlock::checkTccIdAndNumbTTs() {
0189   bool tccFound(false);
0190   bool errorOnNumbOfTTs(false);
0191   const int activeDCC = mapper_->getActiveSM();
0192   std::vector<unsigned int>* m = mapper_->getTccs(activeDCC);
0193   std::vector<unsigned int>::iterator it;
0194   for (it = m->begin(); it != m->end(); it++) {
0195     if ((*it) == tccId_) {
0196       tccFound = true;
0197 
0198       /*
0199             expNumbTTs_= 28; //separate from inner and outer tcc 
0200             For inner TCCs you expect 28 TTs (4 in phi, 7 in eta).
0201             For outer TCCs you expect 16 TTs (4 in phi, 4 in eta).
0202             to implement : map tccid-> number of tts
0203 
0204             Pascal P.: For outer board, only 16 TPs are meaningful but 28 are sent.
0205             - [1,8] are meaningful 
0206             - [9,16] are empty ie should be skipped by unpacker 
0207             - [17, 24] are meaningful 
0208             - [25, 28] are empty ie should be skipped by unpacker 
0209           */
0210 
0211       if (nTTs_ != 28 && nTTs_ != 16) {
0212         if (!DCCDataUnpacker::silentMode_) {
0213           edm::LogWarning("IncorrectBlock")
0214               << "Error on event " << event_->l1A() << " with bx " << event_->bx() << " in fed <<"
0215               << mapper_->getActiveDCC() << "\n TCC id " << tccId_ << " has " << nTTs_
0216               << " Trigger Towers (only 28 or 16 are the expected values in EE)"
0217               << "\n => Skipping to next fed block...";
0218           errorOnNumbOfTTs = true;
0219           //todo : add to error collection
0220         }
0221       }
0222     }
0223   }
0224 
0225   if (!tccFound) {
0226     if (!DCCDataUnpacker::silentMode_) {
0227       edm::LogWarning("IncorrectBlock") << "Error on event " << event_->l1A() << " with bx " << event_->bx()
0228                                         << " in fed <<" << mapper_->getActiveDCC() << "\n TCC id " << tccId_
0229                                         << " is not valid for this dcc "
0230                                         << "\n => Skipping to next fed block...";
0231       //todo : add to error collection
0232     }
0233   }
0234 
0235   return (tccFound || errorOnNumbOfTTs);
0236 }
0237 
0238 unsigned int DCCEETCCBlock::getLength() {
0239   const uint64_t* temp = data_;
0240   temp++;
0241 
0242   ps_ = (*temp >> TCC_PS_B) & B_MASK;
0243 
0244   unsigned int numbTps = (NUMB_TTS_TPG1 + NUMB_TTS_TPG2);
0245   if (ps_) {
0246     numbTps += 2 * NUMB_PSEUDOSTRIPS;
0247   }
0248 
0249   unsigned int length = numbTps / 4 + 2;  //header and trailer
0250   if (numbTps % 4)
0251     length++;
0252 
0253   return length;
0254 }