Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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