Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-05 02:38:57

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/DTRangeT0ValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTRangeT0.h"
0025 #include "CondFormats/DataRecord/interface/DTRangeT0Rcd.h"
0026 
0027 DTRangeT0ValidateDBRead::DTRangeT0ValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dtrangeToken_(esConsumes()) {}
0031 
0032 DTRangeT0ValidateDBRead::DTRangeT0ValidateDBRead(int i) : dtrangeToken_(esConsumes()) {}
0033 
0034 void DTRangeT0ValidateDBRead::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 tR = context.getHandle(dtrangeToken_);
0044   std::cout << tR->version() << std::endl;
0045   std::cout << std::distance(tR->begin(), tR->end()) << " data in the container" << std::endl;
0046   int status;
0047   int whe;
0048   int sta;
0049   int sec;
0050   int qua;
0051   int t0min;
0052   int t0max;
0053   int ckt0min;
0054   int ckt0max;
0055 
0056   DTRangeT0::const_iterator iter = tR->begin();
0057   DTRangeT0::const_iterator iend = tR->end();
0058   while (iter != iend) {
0059     const DTRangeT0Id& tRId = iter->first;
0060     const DTRangeT0Data& tRData = iter->second;
0061     status = tR->get(tRId.wheelId, tRId.stationId, tRId.sectorId, tRId.slId, t0min, t0max);
0062     if (status)
0063       logFile << "ERROR while getting range T0" << tRId.wheelId << " " << tRId.stationId << " " << tRId.sectorId << " "
0064               << tRId.slId << " , status = " << status << std::endl;
0065     if ((std::abs(tRData.t0min - t0min) > 0.0001) || (std::abs(tRData.t0max - t0max) > 0.0001))
0066       logFile << "MISMATCH WHEN READING range T0" << tRId.wheelId << " " << tRId.stationId << " " << tRId.sectorId
0067               << " " << tRId.slId << " : " << tRData.t0min << " " << tRData.t0max << " -> " << t0min << " " << t0max
0068               << std::endl;
0069     iter++;
0070   }
0071 
0072   while (chkFile >> whe >> sta >> sec >> qua >> ckt0min >> ckt0max) {
0073     status = tR->get(whe, sta, sec, qua, t0min, t0max);
0074     if ((std::abs(ckt0min - t0min) > 0.0001) || (std::abs(ckt0max - t0max) > 0.0001))
0075       logFile << "MISMATCH IN WRITING AND READING range T0 " << whe << " " << sta << " " << sec << " " << qua << " : "
0076               << ckt0min << " " << ckt0max << " -> " << t0min << " " << t0max << std::endl;
0077   }
0078 }
0079 
0080 void DTRangeT0ValidateDBRead::endJob() {
0081   std::ifstream logFile(elogFileName.c_str());
0082   char* line = new char[1000];
0083   int errors = 0;
0084   std::cout << "Range T0 validation result:" << std::endl;
0085   while (logFile.getline(line, 1000)) {
0086     std::cout << line << std::endl;
0087     errors++;
0088   }
0089   if (!errors) {
0090     std::cout << " ********************************* " << std::endl;
0091     std::cout << " ***                           *** " << std::endl;
0092     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0093     std::cout << " ***                           *** " << std::endl;
0094     std::cout << " ********************************* " << std::endl;
0095   }
0096   return;
0097 }
0098 
0099 DEFINE_FWK_MODULE(DTRangeT0ValidateDBRead);