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/DTMtimeValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTMtime.h"
0025 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
0026 #include "CondFormats/DTObjects/interface/DTRecoConditions.h"
0027 #include "CondFormats/DataRecord/interface/DTRecoConditionsVdriftRcd.h"
0028 
0029 DTMtimeValidateDBRead::DTMtimeValidateDBRead(edm::ParameterSet const& p)
0030     : dataFileName(p.getParameter<std::string>("chkFile")),
0031       elogFileName(p.getParameter<std::string>("logFile")),
0032       readLegacyVDriftDB(p.getParameter<bool>("readLegacyVDriftDB")),
0033       dtmtTimeToken_(esConsumes()),
0034       dtrecoCondToken_(esConsumes()) {}
0035 
0036 DTMtimeValidateDBRead::DTMtimeValidateDBRead(int i) : dtmtTimeToken_(esConsumes()), dtrecoCondToken_(esConsumes()) {}
0037 
0038 void DTMtimeValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup& context) {
0039   using namespace edm::eventsetup;
0040   // Context is not used.
0041   std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0042   std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
0043   std::stringstream run_fn;
0044   run_fn << "run" << e.id().run() << dataFileName;
0045   std::ifstream chkFile(run_fn.str().c_str());
0046   std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0047 
0048   int whe;
0049   int sta;
0050   int sec;
0051   int qua;
0052   float mTime;
0053   float mTrms;
0054   float ckmt;
0055   float ckrms;
0056   if (readLegacyVDriftDB) {  //legacy format
0057     auto mT = context.getHandle(dtmtTimeToken_);
0058     std::cout << mT->version() << std::endl;
0059     std::cout << std::distance(mT->begin(), mT->end()) << " data in the container" << std::endl;
0060 
0061     int status;
0062     DTMtime::const_iterator iter = mT->begin();
0063     DTMtime::const_iterator iend = mT->end();
0064     while (iter != iend) {
0065       const DTMtimeId& mTId = iter->first;
0066       const DTMtimeData& mTData = iter->second;
0067       status = mT->get(mTId.wheelId, mTId.stationId, mTId.sectorId, mTId.slId, mTime, mTrms, DTTimeUnits::counts);
0068       if (status)
0069         logFile << "ERROR while getting sl Mtime " << mTId.wheelId << " " << mTId.stationId << " " << mTId.sectorId
0070                 << " " << mTId.slId << " , status = " << status << std::endl;
0071       if ((fabs(mTData.mTime - mTime) > 0.01) || (fabs(mTData.mTrms - mTrms) > 0.0001))
0072         logFile << "MISMATCH WHEN READING sl Mtime " << mTId.wheelId << " " << mTId.stationId << " " << mTId.sectorId
0073                 << " " << mTId.slId << " : " << mTData.mTime << " " << mTData.mTrms << " -> " << mTime << " " << mTrms
0074                 << std::endl;
0075       iter++;
0076     }
0077 
0078     while (chkFile >> whe >> sta >> sec >> qua >> ckmt >> ckrms) {
0079       status = mT->get(whe, sta, sec, qua, mTime, mTrms, DTTimeUnits::counts);
0080       if ((fabs(ckmt - mTime) > 0.01) || (fabs(ckrms - mTrms) > 0.0001))
0081         logFile << "MISMATCH IN WRITING AND READING sl Mtime " << whe << " " << sta << " " << sec << " " << qua << " : "
0082                 << ckmt << " " << ckrms << " -> " << mTime << " " << mTrms << std::endl;
0083     }
0084   } else {
0085     //hVdrift;
0086     //context.get<DTRecoConditionsVdriftRcd>().get(hVdrift);
0087     const DTRecoConditions* vDriftMap_ = &context.getData(dtrecoCondToken_);
0088     // Consistency check: no parametrization is implemented for the time being
0089     int version = vDriftMap_->version();
0090     if (version != 1) {
0091       throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
0092     }
0093     while (chkFile >> whe >> sta >> sec >> qua >> ckmt >> ckrms) {
0094       mTime = vDriftMap_->get(DTWireId(whe, sta, sec, 1, 0, 0));
0095       if ((fabs(ckmt - mTime) > 0.01))
0096         logFile << "MISMATCH IN WRITING AND READING sl Mtime " << whe << " " << sta << " " << sec << " " << qua << " : "
0097                 << ckmt << " " << ckrms << " -> " << mTime << " --- " << std::endl;
0098     }
0099   }
0100 }
0101 
0102 void DTMtimeValidateDBRead::endJob() {
0103   std::ifstream logFile(elogFileName.c_str());
0104   char* line = new char[1000];
0105   int errors = 0;
0106   std::cout << "Mtime validation result:" << std::endl;
0107   while (logFile.getline(line, 1000)) {
0108     std::cout << line << std::endl;
0109     errors++;
0110   }
0111   if (!errors) {
0112     std::cout << " ********************************* " << std::endl;
0113     std::cout << " ***                           *** " << std::endl;
0114     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0115     std::cout << " ***                           *** " << std::endl;
0116     std::cout << " ********************************* " << std::endl;
0117   }
0118   return;
0119 }
0120 
0121 DEFINE_FWK_MODULE(DTMtimeValidateDBRead);