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/DTDeadFlagValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTDeadFlag.h"
0025 #include "CondFormats/DataRecord/interface/DTDeadFlagRcd.h"
0026 
0027 DTDeadFlagValidateDBRead::DTDeadFlagValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dtdeadflagToken_(esConsumes()) {}
0031 
0032 DTDeadFlagValidateDBRead::DTDeadFlagValidateDBRead(int i) : dtdeadflagToken_(esConsumes()) {}
0033 
0034 void DTDeadFlagValidateDBRead::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 df = context.getHandle(dtdeadflagToken_);
0044   std::cout << df->version() << std::endl;
0045   std::cout << std::distance(df->begin(), df->end()) << " data in the container" << std::endl;
0046   int whe;
0047   int sta;
0048   int sec;
0049   int qua;
0050   int lay;
0051   int cel;
0052 
0053   bool dead_HV;
0054   bool dead_TP;
0055   bool dead_RO;
0056   bool discCat;
0057   bool ckdead_HV;
0058   bool ckdead_TP;
0059   bool ckdead_RO;
0060   bool ckdiscCat;
0061 
0062   int status;
0063   DTDeadFlag::const_iterator iter = df->begin();
0064   DTDeadFlag::const_iterator iend = df->end();
0065   while (iter != iend) {
0066     const DTDeadFlagId& dfId = iter->first;
0067     const DTDeadFlagData& dfData = iter->second;
0068     status = df->get(dfId.wheelId,
0069                      dfId.stationId,
0070                      dfId.sectorId,
0071                      dfId.slId,
0072                      dfId.layerId,
0073                      dfId.cellId,
0074                      dead_HV,
0075                      dead_TP,
0076                      dead_RO,
0077                      discCat);
0078     if (status)
0079       logFile << "ERROR while getting cell flags " << dfId.wheelId << " " << dfId.stationId << " " << dfId.sectorId
0080               << " " << dfId.slId << " " << dfId.layerId << " " << dfId.cellId << " , status = " << status << std::endl;
0081     if ((dfData.dead_HV ^ dead_HV) || (dfData.dead_TP ^ dead_TP) || (dfData.dead_RO ^ dead_RO) ||
0082         (dfData.discCat ^ discCat))
0083       logFile << "MISMATCH WHEN READING cell flags " << dfId.wheelId << " " << dfId.stationId << " " << dfId.sectorId
0084               << " " << dfId.slId << " " << dfId.layerId << " " << dfId.cellId << " : " << dfData.dead_HV << " "
0085               << dfData.dead_TP << " " << dfData.dead_RO << " " << dfData.discCat << " -> " << dead_HV << " " << dead_TP
0086               << " " << dead_RO << " " << discCat << std::endl;
0087     iter++;
0088   }
0089 
0090   while (chkFile >> whe >> sta >> sec >> qua >> lay >> cel >> ckdead_HV >> ckdead_TP >> ckdead_RO >> ckdiscCat) {
0091     status = df->get(whe, sta, sec, qua, lay, cel, dead_HV, dead_TP, dead_RO, discCat);
0092     if ((ckdead_HV ^ dead_HV) || (ckdead_TP ^ dead_TP) || (ckdead_RO ^ dead_RO) || (ckdiscCat ^ discCat))
0093       logFile << "MISMATCH IN WRITING AND READING cell flags " << whe << " " << sta << " " << sec << " " << qua << " "
0094               << lay << " " << cel << " : " << ckdead_HV << " " << ckdead_TP << " " << ckdead_RO << " " << ckdiscCat
0095               << " -> " << dead_HV << " " << dead_TP << " " << dead_RO << " " << discCat << std::endl;
0096   }
0097 }
0098 
0099 void DTDeadFlagValidateDBRead::endJob() {
0100   std::ifstream logFile(elogFileName.c_str());
0101   char* line = new char[1000];
0102   int errors = 0;
0103   std::cout << "DeadFlags validation result:" << std::endl;
0104   while (logFile.getline(line, 1000)) {
0105     std::cout << line << std::endl;
0106     errors++;
0107   }
0108   if (!errors) {
0109     std::cout << " ********************************* " << std::endl;
0110     std::cout << " ***                           *** " << std::endl;
0111     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0112     std::cout << " ***                           *** " << std::endl;
0113     std::cout << " ********************************* " << std::endl;
0114   }
0115   return;
0116 }
0117 
0118 DEFINE_FWK_MODULE(DTDeadFlagValidateDBRead);