File indexing completed on 2023-03-17 10:47:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "CondTools/DT/test/validate/DTCCBConfigValidateHandler.h"
0014
0015
0016
0017
0018 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
0019
0020
0021
0022
0023 #include <iostream>
0024 #include <fstream>
0025 #include <sstream>
0026
0027
0028
0029
0030
0031
0032
0033
0034 DTCCBConfigValidateHandler::DTCCBConfigValidateHandler(const edm::ParameterSet& ps)
0035 : firstRun(ps.getParameter<unsigned int>("firstRun")),
0036 lastRun(ps.getParameter<unsigned int>("lastRun")),
0037 dataVersion(ps.getParameter<std::string>("version")),
0038 dataFileName(ps.getParameter<std::string>("outFile")),
0039 elogFileName(ps.getParameter<std::string>("logFile")) {
0040 std::ofstream logFile(elogFileName.c_str());
0041 }
0042
0043
0044
0045
0046 DTCCBConfigValidateHandler::~DTCCBConfigValidateHandler() {}
0047
0048
0049
0050
0051 void DTCCBConfigValidateHandler::getNewObjects() {
0052 int runNumber = firstRun;
0053 while (runNumber <= lastRun)
0054 addNewObject(runNumber++);
0055 return;
0056 }
0057
0058 void DTCCBConfigValidateHandler::addNewObject(int runNumber) {
0059 DTCCBConfig* conf = new DTCCBConfig(dataVersion);
0060
0061 std::stringstream run_fn;
0062 run_fn << "run" << runNumber << dataFileName;
0063
0064 int status = 0;
0065 std::ofstream outFile(run_fn.str().c_str());
0066 std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0067 int whe;
0068 int sta;
0069 int sec;
0070 std::vector<DTConfigKey> fullConf;
0071 std::vector<int> ccbConf;
0072 std::vector<int> totConf;
0073 std::vector<int> chkConf;
0074 int nbtype;
0075 int nbrick;
0076 int fkey;
0077 int bkey;
0078
0079 nbtype = 7;
0080 fullConf.clear();
0081 fullConf.reserve(nbtype);
0082 outFile << --nbtype << std::endl;
0083 while (nbtype) {
0084 DTConfigKey confKey;
0085 fkey = random() & 0x00000fff;
0086 confKey.confType = nbtype;
0087 confKey.confKey = fkey;
0088 fullConf.push_back(confKey);
0089 outFile << nbtype << " " << fkey << std::endl;
0090 nbtype--;
0091 }
0092 conf->setFullKey(fullConf);
0093
0094 whe = 3;
0095 while (--whe >= -2) {
0096 sta = 5;
0097 while (--sta) {
0098 if (sta == 4)
0099 sec = 15;
0100 else
0101 sec = 13;
0102 while (--sec) {
0103 nbrick = 12;
0104 ccbConf.clear();
0105 ccbConf.reserve(nbrick);
0106 totConf.clear();
0107 totConf.reserve(nbrick);
0108 outFile << whe << " " << sta << " " << sec << " " << --nbrick << std::endl;
0109 while (nbrick > 6) {
0110 bkey = random() & 0x00000fff;
0111 ccbConf.push_back(bkey);
0112 totConf.push_back(bkey);
0113 outFile << bkey << std::endl;
0114 nbrick--;
0115 }
0116 status = conf->setConfigKey(whe, sta, sec, ccbConf);
0117 if (status)
0118 logFile << "ERROR while setting CCB configuration" << whe << " " << sta << " " << sec
0119 << " , status = " << status << std::endl;
0120 ccbConf.clear();
0121 while (nbrick) {
0122 bkey = random() & 0x00000fff;
0123 ccbConf.push_back(bkey);
0124 totConf.push_back(bkey);
0125 outFile << bkey << std::endl;
0126 nbrick--;
0127 }
0128 status = conf->appendConfigKey(whe, sta, sec, ccbConf);
0129 if (status != -1)
0130 logFile << "ERROR while appending CCB configuration " << whe << " " << sta << " " << sec
0131 << " , status = " << status << std::endl;
0132 status = conf->configKey(whe, sta, sec, chkConf);
0133 if (status)
0134 logFile << "ERROR while checking CCB configuration " << whe << " " << sta << " " << sec
0135 << " , status = " << status << std::endl;
0136 if (cfrDiff(totConf, chkConf))
0137 logFile << "MISMATCH WHEN WRITING CCB configuration " << whe << " " << sta << " " << sec << std::endl;
0138 }
0139 }
0140 }
0141
0142 cond::Time_t snc = runNumber;
0143 m_to_transfer.push_back(std::make_pair(conf, snc));
0144
0145 return;
0146 }
0147
0148 std::string DTCCBConfigValidateHandler::id() const { return dataVersion; }
0149
0150 bool DTCCBConfigValidateHandler::cfrDiff(const std::vector<int>& l_conf, const std::vector<int>& r_conf) {
0151 if (l_conf.size() != r_conf.size())
0152 return true;
0153 std::vector<int>::const_iterator l_iter = l_conf.begin();
0154 std::vector<int>::const_iterator l_iend = l_conf.end();
0155 std::vector<int>::const_iterator r_iter = r_conf.begin();
0156 std::vector<int>::const_iterator r_iend = r_conf.end();
0157 while ((l_iter != l_iend) && (r_iter != r_iend)) {
0158 if (*l_iter++ != *r_iter++)
0159 return true;
0160 }
0161 return false;
0162 }