Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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