Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:48

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/DTLVStatusValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTLVStatus.h"
0025 #include "CondFormats/DataRecord/interface/DTLVStatusRcd.h"
0026 
0027 DTLVStatusValidateDBRead::DTLVStatusValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dtlvstatusToken_(esConsumes()) {}
0031 
0032 DTLVStatusValidateDBRead::DTLVStatusValidateDBRead(int i) : dtlvstatusToken_(esConsumes()) {}
0033 
0034 void DTLVStatusValidateDBRead::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 lv = context.getHandle(dtlvstatusToken_);
0044   std::cout << lv->version() << std::endl;
0045   std::cout << std::distance(lv->begin(), lv->end()) << " data in the container" << std::endl;
0046   int status;
0047   int whe;
0048   int sta;
0049   int sec;
0050   int flagCFE;
0051   int flagDFE;
0052   int flagCMC;
0053   int flagDMC;
0054   int ckflagCFE;
0055   int ckflagDFE;
0056   int ckflagCMC;
0057   int ckflagDMC;
0058 
0059   DTLVStatus::const_iterator iter = lv->begin();
0060   DTLVStatus::const_iterator iend = lv->end();
0061   while (iter != iend) {
0062     const DTLVStatusId& lvId = iter->first;
0063     const DTLVStatusData& lvData = iter->second;
0064     status = lv->get(lvId.wheelId, lvId.stationId, lvId.sectorId, flagCFE, flagDFE, flagCMC, flagDMC);
0065     if (status)
0066       logFile << "ERROR while getting LV status" << lvId.wheelId << " " << lvId.stationId << " " << lvId.sectorId
0067               << " , status = " << status << std::endl;
0068     if ((lvData.flagCFE != flagCFE) || (lvData.flagDFE != flagDFE) || (lvData.flagCMC != flagCMC) ||
0069         (lvData.flagDMC != flagDMC))
0070       logFile << "MISMATCH WHEN READING LV status" << lvId.wheelId << " " << lvId.stationId << " " << lvId.sectorId
0071               << " : " << lvData.flagCFE << " " << lvData.flagDFE << " " << lvData.flagCMC << " " << lvData.flagDMC
0072               << " -> " << flagCFE << " " << flagDFE << " " << flagCMC << " " << flagDMC << std::endl;
0073     iter++;
0074   }
0075 
0076   while (chkFile >> whe >> sta >> sec >> ckflagCFE >> ckflagDFE >> ckflagCMC >> ckflagDMC) {
0077     status = lv->get(whe, sta, sec, flagCFE, flagDFE, flagCMC, flagDMC);
0078     if ((ckflagCFE != flagCFE) || (ckflagDFE != flagDFE) || (ckflagCMC != flagCMC) || (ckflagDMC != flagDMC))
0079       logFile << "MISMATCH IN WRITING AND READING LV status " << whe << " " << sta << " " << sec << " : " << ckflagCFE
0080               << " " << ckflagDFE << " " << ckflagCMC << " " << ckflagDMC << " -> " << flagCFE << " " << flagDFE << " "
0081               << flagCMC << " " << flagDMC << std::endl;
0082   }
0083 }
0084 
0085 void DTLVStatusValidateDBRead::endJob() {
0086   std::ifstream logFile(elogFileName.c_str());
0087   char* line = new char[1000];
0088   int errors = 0;
0089   std::cout << "LV status validation result:" << std::endl;
0090   while (logFile.getline(line, 1000)) {
0091     std::cout << line << std::endl;
0092     errors++;
0093   }
0094   if (!errors) {
0095     std::cout << " ********************************* " << std::endl;
0096     std::cout << " ***                           *** " << std::endl;
0097     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0098     std::cout << " ***                           *** " << std::endl;
0099     std::cout << " ********************************* " << std::endl;
0100   }
0101   return;
0102 }
0103 
0104 DEFINE_FWK_MODULE(DTLVStatusValidateDBRead);