00001 #include "DQM/HcalMonitorTasks/interface/HcalDataIntegrityTask.h"
00002 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00003 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
00004 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00005 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00006 #include <iostream>
00007
00008 HcalDataIntegrityTask::HcalDataIntegrityTask(const edm::ParameterSet& ps)
00009 {
00010
00011 Online_ = ps.getUntrackedParameter<bool>("online",false);
00012 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
00013 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
00014 debug_ = ps.getUntrackedParameter<int>("debug",0);
00015 prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal");
00016 if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00017 prefixME_.append("/");
00018 subdir_ = ps.getUntrackedParameter<std::string>("TaskFolder","HcalDataIntegrityTask");
00019 if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00020 subdir_.append("/");
00021 subdir_=prefixME_+subdir_;
00022 AllowedCalibTypes_ = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00023 skipOutOfOrderLS_ = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
00024 NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00025 makeDiagnostics_ = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00026
00027
00028 inputLabelRawData_ = ps.getUntrackedParameter<edm::InputTag>("RawDataLabel",edm::InputTag("source"));
00029 inputLabelReport_ = ps.getUntrackedParameter<edm::InputTag>("UnpackerReportLabel",edm::InputTag("hcalDigis"));
00030
00031 }
00032
00033 HcalDataIntegrityTask::~HcalDataIntegrityTask() {}
00034
00035 void HcalDataIntegrityTask::reset()
00036 {
00037 if (debug_>0) std::cout <<"HcalDataIntegrityTask::reset()"<<std::endl;
00038 HcalBaseDQMonitor::reset();
00039 fedEntries_->Reset();
00040 fedFatal_->Reset();
00041 fedNonFatal_->Reset();
00042
00043 }
00044
00045 void HcalDataIntegrityTask::cleanup()
00046 {
00047 if(dbe_)
00048 {
00049 dbe_->setCurrentFolder(subdir_);
00050 dbe_->removeContents();
00051 }
00052
00053 }
00054
00055
00056 void HcalDataIntegrityTask::beginRun(const edm::Run& run, const edm::EventSetup& c)
00057 {
00058
00059 if (debug_>0) std::cout <<"HcalDataIntegrityTask::beginRun(): task = '"<<subdir_<<"'"<<std::endl;
00060
00061 HcalBaseDQMonitor::beginRun(run, c);
00062 if (mergeRuns_ && tevt_>0) return;
00063
00064 if (debug_>1) std::cout<<"\t<HcalDataIntegrityTask::getting eMap..."<<std::endl;
00065 edm::ESHandle<HcalDbService> pSetup;
00066 c.get<HcalDbRecord>().get( pSetup );
00067 readoutMap_=pSetup->getHcalMapping();
00068
00069 if (tevt_==0)
00070 this->setup();
00071
00072 if (mergeRuns_==false)
00073 this->reset();
00074
00075 }
00076
00077
00078 void HcalDataIntegrityTask::setup()
00079 {
00080
00081 HcalBaseDQMonitor::setup();
00082
00083
00084 static size_t iphirange = IPHIMAX - IPHIMIN;
00085 static size_t ietarange = IETAMAX - IETAMIN;
00086
00087 std::vector<uint64_t> phatv (iphirange + 1, 0);
00088
00089 if (debug_>0) std::cout <<"<HcalDataIntegrityTask::setup> Clearing old vectors"<<std::endl;
00090
00091 phatmap.clear();
00092 HBmap.clear();
00093 HEmap.clear();
00094 HFmap.clear();
00095 HOmap.clear();
00096 problemhere.clear();
00097 problemHB.clear();
00098 problemHE.clear();
00099 problemHF.clear();
00100 problemHO.clear();
00101
00102
00103 phatmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00104 HBmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00105 HEmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00106 HFmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00107 HOmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00108 std::vector<bool> probvect (iphirange + 1, 0);
00109
00110 problemhere = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00111 problemHB = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00112 problemHE = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00113 problemHF = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00114 problemHO = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00115
00116
00117
00118 if(debug_>1)
00119 std::cout << "About to pushback fedUnpackList_" << std::endl;
00120
00121
00122 firstFED_ = FEDNumbering::MINHCALFEDID;
00123 for (int i=FEDNumbering::MINHCALFEDID;
00124 i<=FEDNumbering::MAXHCALFEDID;
00125 ++i)
00126 {
00127 if(debug_>1) std::cout << "[DFMon:]Pushback for fedUnpackList_: " << i <<std::endl;
00128 fedUnpackList_.push_back(i);
00129 }
00130
00131 if ( dbe_ )
00132 {
00133
00134 if (debug_>1)
00135 std::cout <<"\t<HcalDataIntegrityTask> Setting folder to "<<subdir_<<std::endl;
00136
00137 dbe_->setCurrentFolder(subdir_);
00138
00139 fedEntries_ = dbe_->book1D("FEDEntries","# entries per HCAL FED",32,700,732);
00140 fedFatal_ = dbe_->book1D("FEDFatal","# fatal errors HCAL FED",32,700,732);
00141 fedNonFatal_ = dbe_->book1D("FEDNonFatal","# non-fatal errors HCAL FED",32,700,732);
00142 }
00143
00144 this->reset();
00145 return;
00146 }
00147
00148 void HcalDataIntegrityTask::analyze(edm::Event const&e, edm::EventSetup const&s)
00149 {
00150 if (!IsAllowedCalibType()) return;
00151 if (LumiInOrder(e.luminosityBlock())==false) return;
00152
00153
00154
00155 edm::Handle<FEDRawDataCollection> rawraw;
00156
00157
00158 if (!(e.getByLabel(inputLabelRawData_,rawraw)))
00159 {
00160 if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" raw data with label "<<inputLabelRawData_<<" not available";
00161 return;
00162 }
00163
00164 edm::Handle<HcalUnpackerReport> report;
00165 if (!(e.getByLabel(inputLabelReport_,report)))
00166 {
00167 if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" UnpackerReport with label "<<inputLabelReport_<<" \not available";
00168 return;
00169 }
00170
00171
00172 HcalBaseDQMonitor::analyze(e,s);
00173
00174 processEvent(*rawraw, *report, *readoutMap_);
00175 }
00176
00177
00178
00179 void HcalDataIntegrityTask::processEvent(const FEDRawDataCollection& rawraw,
00180 const HcalUnpackerReport& report,
00181 const HcalElectronicsMap& emap){
00182
00183 if(!dbe_)
00184 {
00185 std::cout<<"HcalDataIntegrityTask::processEvent DQMStore not instantiated!!!"<<std::endl;
00186 return;
00187 }
00188
00189
00190 for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++)
00191 {
00192 const FEDRawData& fed = rawraw.FEDData(*i);
00193 if (fed.size()<12) continue;
00194 unpack(fed,emap);
00195 }
00196
00197 return;
00198 }
00199
00200
00201
00202 void HcalDataIntegrityTask::unpack(const FEDRawData& raw,
00203 const HcalElectronicsMap& emap){
00204
00205 const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00206 if(!dccHeader) return;
00207
00208
00209 unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
00210 FEDTrailer trailer = FEDTrailer(trailer_ptr);
00211
00212 int dccid=dccHeader->getSourceId();
00213
00215 bool CDFProbThisDCC = false;
00216
00217 if (!dccHeader->thereIsASecondCDFHeaderWord())
00218 {
00219 CDFProbThisDCC = true;
00220 }
00221
00222
00223 CDFvers_it = CDFversionNumber_list.find(dccid);
00224 if (CDFvers_it == CDFversionNumber_list.end())
00225 {
00226 CDFversionNumber_list.insert(std::pair<int,short>
00227 (dccid,dccHeader->getCDFversionNumber() ) );
00228 CDFvers_it = CDFversionNumber_list.find(dccid);
00229 }
00230
00231 if (dccHeader->getCDFversionNumber()!= CDFvers_it->second)
00232 {
00233 CDFProbThisDCC = true;
00234 }
00235
00236
00237 CDFEvT_it = CDFEventType_list.find(dccid);
00238 if (CDFEvT_it == CDFEventType_list.end())
00239 {
00240 CDFEventType_list.insert(std::pair<int,short>
00241 (dccid,dccHeader->getCDFEventType() ) );
00242 CDFEvT_it = CDFEventType_list.find(dccid);
00243 }
00244
00245 if (dccHeader->getCDFEventType()!= CDFEvT_it->second)
00246 {
00247
00248
00249 }
00250
00251
00252 if (dccHeader->BOEshouldBe5Always()!=5)
00253 {
00254 CDFProbThisDCC = true;
00255 }
00256
00257
00258 if (dccHeader->thereIsAThirdCDFHeaderWord())
00259 {
00260 CDFProbThisDCC = true;
00261 }
00262
00263
00264
00265 CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00266 if (CDFReservedBits_it == CDFReservedBits_list.end()) {
00267 CDFReservedBits_list.insert(std::pair<int,short>
00268 (dccid,dccHeader->getSlink64ReservedBits() ) );
00269 CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00270 }
00271
00272 if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second)
00273 {
00274
00275
00276 }
00277
00278
00279 if (dccHeader->BOEshouldBeZeroAlways() !=0)
00280 {
00281 CDFProbThisDCC = true;
00282 }
00283
00284
00285 if (trailer.moreTrailers())
00286 {
00287 CDFProbThisDCC = true;
00288 }
00289
00290
00291
00292 if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) )
00293 {
00294 CDFProbThisDCC = true;
00295 }
00296
00297 if (!trailer.check())
00298 {
00299 CDFProbThisDCC = true;
00300 }
00301
00302 if (CDFProbThisDCC)
00303 fedFatal_->Fill(dccid);
00304 fedEntries_->Fill(dccid);
00305
00306 return;
00307 }
00308
00309 DEFINE_FWK_MODULE(HcalDataIntegrityTask);
00310