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/DTStatusFlagValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
0025 #include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
0026 
0027 DTStatusFlagValidateDBRead::DTStatusFlagValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dtstatusFlagToken_(esConsumes()) {}
0031 
0032 DTStatusFlagValidateDBRead::DTStatusFlagValidateDBRead(int i) : dtstatusFlagToken_(esConsumes()) {}
0033 
0034 void DTStatusFlagValidateDBRead::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 sf = context.getHandle(dtstatusFlagToken_);
0044   std::cout << sf->version() << std::endl;
0045   std::cout << std::distance(sf->begin(), sf->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 noiseFlag;
0054   bool feMask;
0055   bool tdcMask;
0056   bool trigMask;
0057   bool deadFlag;
0058   bool nohvFlag;
0059   bool cknoiseFlag;
0060   bool ckfeMask;
0061   bool cktdcMask;
0062   bool cktrigMask;
0063   bool ckdeadFlag;
0064   bool cknohvFlag;
0065 
0066   int status;
0067   DTStatusFlag::const_iterator iter = sf->begin();
0068   DTStatusFlag::const_iterator iend = sf->end();
0069   while (iter != iend) {
0070     const DTStatusFlagId& sfId = iter->first;
0071     const DTStatusFlagData& sfData = iter->second;
0072     status = sf->get(sfId.wheelId,
0073                      sfId.stationId,
0074                      sfId.sectorId,
0075                      sfId.slId,
0076                      sfId.layerId,
0077                      sfId.cellId,
0078                      noiseFlag,
0079                      feMask,
0080                      tdcMask,
0081                      trigMask,
0082                      deadFlag,
0083                      nohvFlag);
0084     if (status)
0085       logFile << "ERROR while getting cell flags " << sfId.wheelId << " " << sfId.stationId << " " << sfId.sectorId
0086               << " " << sfId.slId << " " << sfId.layerId << " " << sfId.cellId << " , status = " << status << std::endl;
0087     if ((sfData.noiseFlag ^ noiseFlag) || (sfData.feMask ^ feMask) || (sfData.tdcMask ^ tdcMask) ||
0088         (sfData.trigMask ^ trigMask) || (sfData.deadFlag ^ deadFlag) || (sfData.nohvFlag ^ nohvFlag))
0089       logFile << "MISMATCH WHEN READING cell flags " << sfId.wheelId << " " << sfId.stationId << " " << sfId.sectorId
0090               << " " << sfId.slId << " " << sfId.layerId << " " << sfId.cellId << " : " << sfData.noiseFlag << " "
0091               << sfData.feMask << " " << sfData.tdcMask << " " << sfData.trigMask << " " << sfData.deadFlag << " "
0092               << sfData.nohvFlag << " -> " << noiseFlag << " " << feMask << " " << tdcMask << " " << trigMask << " "
0093               << deadFlag << " " << nohvFlag << std::endl;
0094     iter++;
0095   }
0096 
0097   while (chkFile >> whe >> sta >> sec >> qua >> lay >> cel >> cknoiseFlag >> ckfeMask >> cktdcMask >> cktrigMask >>
0098          ckdeadFlag >> cknohvFlag) {
0099     status = sf->get(whe, sta, sec, qua, lay, cel, noiseFlag, feMask, tdcMask, trigMask, deadFlag, nohvFlag);
0100     if ((cknoiseFlag ^ noiseFlag) || (ckfeMask ^ feMask) || (cktdcMask ^ tdcMask) || (cktrigMask ^ trigMask) ||
0101         (ckdeadFlag ^ deadFlag) || (cknohvFlag ^ nohvFlag))
0102       logFile << "MISMATCH IN WRITING AND READING cell flags " << whe << " " << sta << " " << sec << " " << qua << " "
0103               << lay << " " << cel << " : " << cknoiseFlag << " " << ckfeMask << " " << cktdcMask << " " << cktrigMask
0104               << " " << ckdeadFlag << " " << cknohvFlag << " -> " << noiseFlag << " " << feMask << " " << tdcMask << " "
0105               << trigMask << " " << deadFlag << " " << nohvFlag << std::endl;
0106   }
0107 }
0108 
0109 void DTStatusFlagValidateDBRead::endJob() {
0110   std::ifstream logFile(elogFileName.c_str());
0111   char* line = new char[1000];
0112   int errors = 0;
0113   std::cout << "StatusFlags validation result:" << std::endl;
0114   while (logFile.getline(line, 1000)) {
0115     std::cout << line << std::endl;
0116     errors++;
0117   }
0118   if (!errors) {
0119     std::cout << " ********************************* " << std::endl;
0120     std::cout << " ***                           *** " << std::endl;
0121     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0122     std::cout << " ***                           *** " << std::endl;
0123     std::cout << " ********************************* " << std::endl;
0124   }
0125   return;
0126 }
0127 
0128 DEFINE_FWK_MODULE(DTStatusFlagValidateDBRead);