Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:47:51

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDAnalyzer for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include <cmath>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <map>
0016 #include <sstream>
0017 #include <stdexcept>
0018 #include <string>
0019 
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 #include "CondTools/DT/test/validate/DTHVStatusValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTHVStatus.h"
0025 #include "CondFormats/DataRecord/interface/DTHVStatusRcd.h"
0026 
0027 DTHVStatusValidateDBRead::DTHVStatusValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dthvstatusToken_(esConsumes()) {}
0031 
0032 DTHVStatusValidateDBRead::DTHVStatusValidateDBRead(int i) : dthvstatusToken_(esConsumes()) {}
0033 
0034 void DTHVStatusValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup& context) {
0035   using namespace edm::eventsetup;
0036   // Context is not used.
0037   std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0038   std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
0039   std::stringstream run_fn;
0040   run_fn << "run" << e.id().run() << dataFileName;
0041   std::ifstream chkFile(run_fn.str().c_str());
0042   std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0043   auto hv = context.getHandle(dthvstatusToken_);
0044   std::cout << hv->version() << std::endl;
0045   std::cout << std::distance(hv->begin(), hv->end()) << " data in the container" << std::endl;
0046   int status;
0047   int whe;
0048   int sta;
0049   int sec;
0050   int qua;
0051   int lay;
0052   int l_p;
0053   int fCell;
0054   int lCell;
0055   int flagA;
0056   int flagC;
0057   int flagS;
0058   int ckfCell;
0059   int cklCell;
0060   int ckflagA;
0061   int ckflagC;
0062   int ckflagS;
0063 
0064   DTHVStatus::const_iterator iter = hv->begin();
0065   DTHVStatus::const_iterator iend = hv->end();
0066   while (iter != iend) {
0067     const DTHVStatusId& hvId = iter->first;
0068     const DTHVStatusData& hvData = iter->second;
0069     status = hv->get(hvId.wheelId,
0070                      hvId.stationId,
0071                      hvId.sectorId,
0072                      hvId.slId,
0073                      hvId.layerId,
0074                      hvId.partId,
0075                      fCell,
0076                      lCell,
0077                      flagA,
0078                      flagC,
0079                      flagS);
0080     if (status)
0081       logFile << "ERROR while getting HV status" << hvId.wheelId << " " << hvId.stationId << " " << hvId.sectorId << " "
0082               << hvId.slId << " " << hvId.layerId << " " << hvId.partId << " , status = " << status << std::endl;
0083     if ((hvData.fCell != fCell) || (hvData.lCell != lCell) || (hvData.flagA != flagA) || (hvData.flagC != flagC) ||
0084         (hvData.flagS != flagS))
0085       logFile << "MISMATCH WHEN READING HV status" << hvId.wheelId << " " << hvId.stationId << " " << hvId.sectorId
0086               << " " << hvId.slId << " : " << hvData.fCell << " " << hvData.lCell << " " << hvData.flagA << " "
0087               << hvData.flagC << " " << hvData.flagS << " -> " << fCell << " " << lCell << " " << flagA << " " << flagC
0088               << " " << flagS << std::endl;
0089     iter++;
0090   }
0091 
0092   while (chkFile >> whe >> sta >> sec >> qua >> lay >> l_p >> ckfCell >> cklCell >> ckflagA >> ckflagC >> ckflagS) {
0093     status = hv->get(whe, sta, sec, qua, lay, l_p, fCell, lCell, flagA, flagC, flagS);
0094     if (!flagA && !flagC && !flagS)
0095       ckfCell = cklCell = 0;
0096     if ((ckfCell != fCell) || (cklCell != lCell) || (ckflagA != flagA) || (ckflagC != flagC) || (ckflagS != flagS))
0097       logFile << "MISMATCH IN WRITING AND READING HV status " << whe << " " << sta << " " << sec << " " << qua << " : "
0098               << ckfCell << " " << cklCell << " " << ckflagA << " " << ckflagC << " " << ckflagS << " -> " << fCell
0099               << " " << lCell << " " << flagA << " " << flagC << " " << flagS << std::endl;
0100   }
0101 }
0102 
0103 void DTHVStatusValidateDBRead::endJob() {
0104   std::ifstream logFile(elogFileName.c_str());
0105   char* line = new char[1000];
0106   int errors = 0;
0107   std::cout << "HV status validation result:" << std::endl;
0108   while (logFile.getline(line, 1000)) {
0109     std::cout << line << std::endl;
0110     errors++;
0111   }
0112   if (!errors) {
0113     std::cout << " ********************************* " << std::endl;
0114     std::cout << " ***                           *** " << std::endl;
0115     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0116     std::cout << " ***                           *** " << std::endl;
0117     std::cout << " ********************************* " << std::endl;
0118   }
0119   return;
0120 }
0121 
0122 DEFINE_FWK_MODULE(DTHVStatusValidateDBRead);