File indexing completed on 2024-04-06 12:02:48
0001
0002
0003
0004
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/DTCCBConfigValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
0025 #include "CondFormats/DataRecord/interface/DTCCBConfigRcd.h"
0026
0027 DTCCBConfigValidateDBRead::DTCCBConfigValidateDBRead(edm::ParameterSet const& p)
0028 : dataFileName(p.getParameter<std::string>("chkFile")),
0029 elogFileName(p.getParameter<std::string>("logFile")),
0030 dtccbToken_(esConsumes()) {}
0031
0032 DTCCBConfigValidateDBRead::DTCCBConfigValidateDBRead(int i) : dtccbToken_(esConsumes()) {}
0033
0034 void DTCCBConfigValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup& context) {
0035 using namespace edm::eventsetup;
0036
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 conf = context.getHandle(dtccbToken_);
0044 std::cout << conf->version() << std::endl;
0045 std::cout << std::distance(conf->begin(), conf->end()) << " data in the container" << std::endl;
0046 int whe;
0047 int sta;
0048 int sec;
0049 std::vector<DTConfigKey> fullConf;
0050 std::vector<DTConfigKey> fchkConf;
0051 std::vector<int> ccbConf;
0052 std::vector<int> chkConf;
0053 int nbtype;
0054 int ibtype;
0055 int nbrick;
0056 int fkey;
0057 int bkey;
0058
0059 int status;
0060 chkFile >> nbtype;
0061 fullConf.reserve(nbtype);
0062 while (nbtype--) {
0063 chkFile >> ibtype >> fkey;
0064 DTConfigKey confKey;
0065 confKey.confType = ibtype;
0066 confKey.confKey = fkey;
0067 fchkConf.push_back(confKey);
0068 }
0069 fullConf = conf->fullKey();
0070 if (cfrDiff(fchkConf, fullConf))
0071 logFile << "MISMATCH IN WRITING AND READING full configuration" << std::endl;
0072
0073 while (chkFile >> whe >> sta >> sec >> nbrick) {
0074 chkConf.clear();
0075 while (nbrick--) {
0076 chkFile >> bkey;
0077 chkConf.push_back(bkey);
0078 }
0079 status = conf->configKey(whe, sta, sec, ccbConf);
0080 if (status)
0081 logFile << "ERROR while reading CCB configuration" << whe << " " << sta << " " << sec << " , status = " << status
0082 << std::endl;
0083 if (cfrDiff(chkConf, ccbConf))
0084 logFile << "MISMATCH WHEN READING CCB configuration " << whe << " " << sta << " " << sec << std::endl;
0085 }
0086 }
0087
0088 void DTCCBConfigValidateDBRead::endJob() {
0089 std::ifstream logFile(elogFileName.c_str());
0090 char* line = new char[1000];
0091 int errors = 0;
0092 std::cout << "CCBConfig validation result:" << std::endl;
0093 while (logFile.getline(line, 1000)) {
0094 std::cout << line << std::endl;
0095 errors++;
0096 }
0097 if (!errors) {
0098 std::cout << " ********************************* " << std::endl;
0099 std::cout << " *** *** " << std::endl;
0100 std::cout << " *** NO ERRORS FOUND *** " << std::endl;
0101 std::cout << " *** *** " << std::endl;
0102 std::cout << " ********************************* " << std::endl;
0103 }
0104 return;
0105 }
0106
0107 bool DTCCBConfigValidateDBRead::cfrDiff(const std::vector<int>& l_conf, const std::vector<int>& r_conf) {
0108 if (l_conf.size() != r_conf.size())
0109 return true;
0110 std::vector<int>::const_iterator l_iter = l_conf.begin();
0111 std::vector<int>::const_iterator l_iend = l_conf.end();
0112 std::vector<int>::const_iterator r_iter = r_conf.begin();
0113 std::vector<int>::const_iterator r_iend = r_conf.end();
0114 while ((l_iter != l_iend) && (r_iter != r_iend)) {
0115 if (*l_iter++ != *r_iter++)
0116 return true;
0117 }
0118 return false;
0119 }
0120
0121 bool DTCCBConfigValidateDBRead::cfrDiff(const std::vector<DTConfigKey>& l_conf,
0122 const std::vector<DTConfigKey>& r_conf) {
0123 if (l_conf.size() != r_conf.size())
0124 return true;
0125 std::vector<DTConfigKey>::const_iterator l_iter = l_conf.begin();
0126 std::vector<DTConfigKey>::const_iterator l_iend = l_conf.end();
0127 std::vector<DTConfigKey>::const_iterator r_iter = r_conf.begin();
0128 std::vector<DTConfigKey>::const_iterator r_iend = r_conf.end();
0129 while ((l_iter != l_iend) && (r_iter != r_iend)) {
0130 const DTConfigKey& l_key = *l_iter++;
0131 const DTConfigKey& r_key = *r_iter++;
0132 if (l_key.confType != r_key.confType)
0133 return true;
0134 if (l_key.confKey != r_key.confKey)
0135 return true;
0136 }
0137 return false;
0138 }
0139
0140 DEFINE_FWK_MODULE(DTCCBConfigValidateDBRead);