CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/EcalBarrelMonitorTasks/src/RawDataTask.cc

Go to the documentation of this file.
00001 #include "../interface/RawDataTask.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 
00005 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00006 #include "DQM/EcalCommon/interface/FEFlags.h"
00007 
00008 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00009 
00010 namespace ecaldqm {
00011 
00012   RawDataTask::RawDataTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
00013     DQWorkerTask(_params, _paths, "RawDataTask"),
00014     hltTaskMode_(0),
00015     hltTaskFolder_(""),
00016     run_(0),
00017     l1A_(0),
00018     orbit_(0),
00019     bx_(0),
00020     triggerType_(0),
00021     feL1Offset_(0)
00022   {
00023     collectionMask_ = 
00024       (0x1 << kLumiSection) |
00025       (0x1 << kSource) |
00026       (0x1 << kEcalRawData);
00027 
00028     dependencies_.push_back(std::pair<Collections, Collections>(kEcalRawData, kSource));
00029 
00030     edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
00031 
00032     hltTaskMode_ = commonParams.getUntrackedParameter<int>("hltTaskMode");
00033     hltTaskFolder_ = commonParams.getUntrackedParameter<std::string>("hltTaskFolder");
00034 
00035     if(hltTaskMode_ != 0 && hltTaskFolder_.size() == 0)
00036         throw cms::Exception("InvalidConfiguration") << "HLTTask mode needs a folder name";
00037 
00038     if(hltTaskMode_ != 0){
00039       std::map<std::string, std::string> replacements;
00040       replacements["hlttask"] = hltTaskFolder_;
00041 
00042       MEs_[kFEDEntries]->name(replacements);
00043       MEs_[kFEDFatal]->name(replacements);
00044     }
00045   }
00046 
00047   RawDataTask::~RawDataTask()
00048   {
00049   }
00050 
00051   void
00052   RawDataTask::bookMEs()
00053   {
00054     DQWorker::bookMEs();
00055 
00056     if(hltTaskMode_ != 1){
00057       std::string eventTypes[nEventTypes];
00058       eventTypes[0] = "UNKNOWN";
00059       // From DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h; should move to reflex
00060       eventTypes[EcalDCCHeaderBlock::COSMIC + 1] = "COSMIC";
00061       eventTypes[EcalDCCHeaderBlock::BEAMH4 + 1] = "BEAMH4";
00062       eventTypes[EcalDCCHeaderBlock::BEAMH2 + 1] = "BEAMH2";
00063       eventTypes[EcalDCCHeaderBlock::MTCC + 1] = "MTCC";
00064       eventTypes[EcalDCCHeaderBlock::LASER_STD + 1] = "LASER_STD";
00065       eventTypes[EcalDCCHeaderBlock::LASER_POWER_SCAN + 1] = "LASER_POWER_SCAN";
00066       eventTypes[EcalDCCHeaderBlock::LASER_DELAY_SCAN + 1] = "LASER_DELAY_SCAN";
00067       eventTypes[EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM + 1] = "TESTPULSE_SCAN_MEM";
00068       eventTypes[EcalDCCHeaderBlock::TESTPULSE_MGPA + 1] = "TESTPULSE_MGPA";
00069       eventTypes[EcalDCCHeaderBlock::PEDESTAL_STD + 1] = "PEDESTAL_STD";
00070       eventTypes[EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN + 1] = "PEDESTAL_OFFSET_SCAN";
00071       eventTypes[EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN + 1] = "PEDESTAL_25NS_SCAN";
00072       eventTypes[EcalDCCHeaderBlock::LED_STD + 1] = "LED_STD";
00073       eventTypes[EcalDCCHeaderBlock::PHYSICS_GLOBAL + 1] = "PHYSICS_GLOBAL";
00074       eventTypes[EcalDCCHeaderBlock::COSMICS_GLOBAL + 1] = "COSMICS_GLOBAL";
00075       eventTypes[EcalDCCHeaderBlock::HALO_GLOBAL + 1] = "HALO_GLOBAL";
00076       eventTypes[EcalDCCHeaderBlock::LASER_GAP + 1] = "LASER_GAP";
00077       eventTypes[EcalDCCHeaderBlock::TESTPULSE_GAP + 1] = "TESTPULSE_GAP";
00078       eventTypes[EcalDCCHeaderBlock::PEDESTAL_GAP + 1] = "PEDESTAL_GAP";
00079       eventTypes[EcalDCCHeaderBlock::LED_GAP + 1] = "LED_GAP";
00080       eventTypes[EcalDCCHeaderBlock::PHYSICS_LOCAL + 1] = "PHYSICS_LOCAL";
00081       eventTypes[EcalDCCHeaderBlock::COSMICS_LOCAL + 1] = "COSMICS_LOCAL";
00082       eventTypes[EcalDCCHeaderBlock::HALO_LOCAL + 1] = "HALO_LOCAL";
00083       eventTypes[EcalDCCHeaderBlock::CALIB_LOCAL + 1] = "CALIB_LOCAL";
00084 
00085       std::string statuses[nFEFlags];
00086       statuses[Enabled] = "ENABLED";
00087       statuses[Disabled] = "DISABLED";
00088       statuses[Timeout] = "TIMEOUT";
00089       statuses[HeaderError] = "HEADERERROR";
00090       statuses[ChannelId] = "CHANNELID";
00091       statuses[LinkError] = "LINKERROR";
00092       statuses[BlockSize] = "BLOCKSIZE";
00093       statuses[Suppressed] = "SUPPRESSED";
00094       statuses[FIFOFull] = "FIFOFULL";
00095       statuses[L1ADesync] = "L1ADESYNC";
00096       statuses[BXDesync] = "BXDESYNC";
00097       statuses[L1ABXDesync] = "L1ABXDESYNC";
00098       statuses[FIFOFullL1ADesync] = "FIFOFULLL1ADESYNC";
00099       statuses[HParity] = "HPARITY";
00100       statuses[VParity] = "VPARITY";
00101       statuses[ForcedZS] = "FORCEDZS";
00102 
00103       for(unsigned iME(kEventTypePreCalib); iME < kFEByLumi; iME++)
00104         MEs_[iME]->book();
00105 
00106       for(int i(1); i <= nEventTypes; i++){
00107         MEs_[kEventTypePreCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
00108         MEs_[kEventTypeCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
00109         MEs_[kEventTypePostCalib]->setBinLabel(0, i, eventTypes[i - 1], 1);
00110       }
00111 
00112       for(int i(1); i <= nFEFlags; i++)
00113         MEs_[kFEStatus]->setBinLabel(-1, i, statuses[i - 1], 2);
00114     }
00115 
00116     if(hltTaskMode_ != 0){
00117       MEs_[kFEDEntries]->book();
00118       MEs_[kFEDFatal]->book();
00119     }
00120   }
00121 
00122   void
00123   RawDataTask::beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
00124   {
00125     if(MEs_[kDesyncByLumi]->isActive()) MEs_[kDesyncByLumi]->reset();
00126     if(MEs_[kFEByLumi]->isActive()) MEs_[kFEByLumi]->reset();
00127   }
00128 
00129   void
00130   RawDataTask::beginEvent(const edm::Event &_evt, const edm::EventSetup &)
00131   {
00132     run_ = _evt.run();
00133     orbit_ = _evt.orbitNumber() & 0xffffff;
00134     bx_ = _evt.bunchCrossing() & 0xfff;
00135     triggerType_ = _evt.experimentType() & 0xf;
00136     l1A_ = 0;
00137     feL1Offset_ = _evt.isRealData() ? 1 : 0;
00138   }
00139 
00140   void
00141   RawDataTask::runOnSource(const FEDRawDataCollection &_fedRaw, Collections)
00142   {
00143     // Get GT L1 info
00144     const FEDRawData &gtFED(_fedRaw.FEDData(812));
00145     if(gtFED.size() > sizeof(uint64_t)){ // FED header is one 64 bit word
00146       uint32_t *halfHeader((uint32_t *)gtFED.data());
00147       l1A_ = *(halfHeader + 1) & 0xffffff;
00148     }
00149 
00150     for(unsigned iFED(601); iFED <= 654; iFED++){
00151       const FEDRawData& fedData(_fedRaw.FEDData(iFED));
00152       unsigned length(fedData.size() / sizeof(uint64_t));
00153       if(length > 1){ // FED header is one 64 bit word
00154         if(MEs_[kFEDEntries]->isActive()) MEs_[kFEDEntries]->fill(iFED - 600);
00155 
00156         const uint64_t* pData(reinterpret_cast<const uint64_t*>(fedData.data()));
00157         bool crcError((pData[length - 1] >> 2) & 0x1);
00158 
00159         if(crcError && MEs_[kFEDFatal]->isActive()) MEs_[kFEDFatal]->fill(iFED - 600);
00160         if(crcError && MEs_[kCRC]->isActive()) MEs_[kCRC]->fill(iFED - 600);
00161       }
00162     }
00163   }
00164   
00165   void
00166   RawDataTask::runOnRawData(const EcalRawDataCollection &_dcchs, Collections)
00167   {
00168     using namespace std;
00169 
00170     if(hltTaskMode_ == 1) return;
00171 
00172     if(!l1A_){
00173       // majority vote on L1A.. is there no better implementation?
00174       map<int, int> l1aCounts;
00175       for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
00176         l1aCounts[dcchItr->getLV1()]++;
00177       }
00178       int maxVote(0);
00179       for(map<int, int>::iterator l1aItr(l1aCounts.begin()); l1aItr != l1aCounts.end(); ++l1aItr){
00180         if(l1aItr->second > maxVote){
00181           maxVote = l1aItr->second;
00182           l1A_ = l1aItr->first;
00183         }
00184       }
00185     }
00186 
00187     for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
00188       unsigned dccId(dcchItr->id());
00189 
00190       int dccL1A(dcchItr->getLV1());
00191       short dccL1AShort(dccL1A & 0xfff);
00192       int dccBX(dcchItr->getBX());
00193 
00194       if(dcchItr->getRunNumber() != run_) MEs_[kRunNumber]->fill(dccId);
00195       if(dcchItr->getOrbit() != orbit_) MEs_[kOrbit]->fill(dccId);
00196       if(dcchItr->getBasicTriggerType() != triggerType_) MEs_[kTriggerType]->fill(dccId);
00197       if(dccL1A != l1A_) MEs_[kL1ADCC]->fill(dccId);
00198       if(dccBX != bx_) MEs_[kBXDCC]->fill(dccId);
00199 
00200       const vector<short> &feStatus(dcchItr->getFEStatus());
00201       const vector<short> &feBxs(dcchItr->getFEBxs());
00202       const vector<short> &feL1s(dcchItr->getFELv1());
00203 
00204       bool feDesync(false);
00205       bool statusError(false);
00206 
00207       for(unsigned iFE(0); iFE < feStatus.size(); iFE++){
00208         if(!ccuExists(dccId, iFE + 1)) continue;
00209 
00210         short status(feStatus[iFE]);
00211 
00212         if(status != BXDesync && status != L1ABXDesync){ // BX desync not detected in the DCC
00213           if(feBxs[iFE] != dccBX && feBxs[iFE] != -1 && dccBX != -1){
00214             MEs_[kBXFE]->fill(dccId);
00215             feDesync = true;
00216           }
00217         }
00218 
00219         if(status != L1ADesync && status != L1ABXDesync){
00220           if(feL1s[iFE] + feL1Offset_ != dccL1AShort && feL1s[iFE] != -1 && dccL1AShort != 0){
00221             MEs_[kL1AFE]->fill(dccId);
00222             feDesync = true;
00223           }
00224         }
00225 
00226         if(iFE >= 68) continue;
00227 
00228         DetId id(getElectronicsMap()->dccTowerConstituents(dccId, iFE + 1).at(0));
00229         MEs_[kFEStatus]->fill(id, status + 0.5);
00230 
00231         switch(status){
00232         case Timeout:
00233         case HeaderError:
00234         case ChannelId:
00235         case LinkError:
00236         case BlockSize:
00237         case L1ADesync:
00238         case BXDesync:
00239         case L1ABXDesync:
00240         case HParity:
00241         case VParity:
00242           statusError = true;
00243           break;
00244         default:
00245           continue;
00246         }
00247       }
00248 
00249       if(feDesync) MEs_[kDesyncByLumi]->fill(dccId);
00250       if(feDesync) MEs_[kDesyncTotal]->fill(dccId);
00251       if(statusError) MEs_[kFEByLumi]->fill(dccId);
00252 
00253       const vector<short> &tccBx(dcchItr->getTCCBx());
00254       const vector<short> &tccL1(dcchItr->getTCCLv1());
00255 
00256       if(tccBx.size() == 4){ // EB uses tccBx[0]; EE uses all
00257         if(dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1){
00258           for(int iTCC(0); iTCC < 4; iTCC++){
00259 
00260             if(tccBx[iTCC] != dccBX && tccBx[iTCC] != -1 && dccBX != -1)
00261               MEs_[kBXTCC]->fill(dccId);
00262 
00263             if(tccL1[iTCC] != dccL1AShort && tccL1[iTCC] != -1 && dccL1AShort != 0)
00264               MEs_[kL1ATCC]->fill(dccId);
00265 
00266           }
00267         }else{
00268 
00269           if(tccBx[0] != dccBX && tccBx[0] != -1 && dccBX != -1)
00270             MEs_[kBXTCC]->fill(dccId);
00271 
00272           if(tccL1[0] != dccL1AShort && tccL1[0] != -1 && dccL1AShort != 0)
00273             MEs_[kL1ATCC]->fill(dccId);
00274 
00275         }
00276       }
00277 
00278       short srpBx(dcchItr->getSRPBx());
00279       short srpL1(dcchItr->getSRPLv1());
00280 
00281       if(srpBx != dccBX && srpBx != -1 && dccBX != -1)
00282         MEs_[kBXSRP]->fill(dccId);
00283 
00284       if(srpL1 != dccL1AShort && srpL1 != -1 && dccL1AShort != 0)
00285         MEs_[kL1ASRP]->fill(dccId);
00286 
00287       const int calibBX(3490);
00288 
00289       short runType(dcchItr->getRunType() + 1);
00290       if(runType < 0 || runType > 22) runType = 0;
00291       if(dccBX < calibBX) MEs_[kEventTypePreCalib]->fill(dccId, runType + 0.5, 1. / 54.);
00292       else if(dccBX == calibBX) MEs_[kEventTypeCalib]->fill(dccId, runType + 0.5, 1. / 54.);
00293       else MEs_[kEventTypePostCalib]->fill(dccId, runType + 0.5, 1. / 54.);
00294 
00295     }
00296   }
00297 
00298   /*static*/
00299   void
00300   RawDataTask::setMEData(std::vector<MEData>& _data)
00301   {
00302     BinService::AxisSpecs eventTypeAxis;
00303     eventTypeAxis.nbins = nEventTypes;
00304     eventTypeAxis.low = 0.;
00305     eventTypeAxis.high = nEventTypes;
00306 
00307     BinService::AxisSpecs feStatusAxis;
00308     feStatusAxis.nbins = nFEFlags;
00309     feStatusAxis.low = 0.;
00310     feStatusAxis.high = nFEFlags;
00311 
00312     _data[kEventTypePreCalib] = MEData("EventTypePreCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
00313     _data[kEventTypeCalib] = MEData("EventTypeCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
00314     _data[kEventTypePostCalib] = MEData("EventTypePostCalib", BinService::kEcal, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &eventTypeAxis);
00315     _data[kCRC] = MEData("CRC", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00316     _data[kRunNumber] = MEData("RunNumber", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00317     _data[kOrbit] = MEData("Orbit", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00318     _data[kTriggerType] = MEData("TriggerType", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00319     _data[kL1ADCC] = MEData("L1ADCC", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00320     _data[kL1AFE] = MEData("L1AFE", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00321     _data[kL1ATCC] = MEData("L1ATCC", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00322     _data[kL1ASRP] = MEData("L1ASRP", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00323     _data[kBXDCC] = MEData("BXDCC", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00324     _data[kBXFE] = MEData("BXFE", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00325     _data[kBXTCC] = MEData("BXTCC", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00326     _data[kBXSRP] = MEData("BXSRP", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00327     _data[kDesyncByLumi] = MEData("DesyncByLumi", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00328     _data[kDesyncTotal] = MEData("DesyncTotal", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00329     _data[kFEStatus] = MEData("FEStatus", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F, 0, &feStatusAxis);
00330     _data[kFEByLumi] = MEData("FEByLumi", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00331     _data[kFEDEntries] = MEData("FEDEntries", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00332     _data[kFEDFatal] = MEData("FEDFatal", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH1F);
00333   }
00334 
00335   DEFINE_ECALDQM_WORKER(RawDataTask);
00336 }