File indexing completed on 2024-04-06 11:58:30
0001
0002
0003
0004
0005
0006
0007
0008 #include "DumpDBToFile.h"
0009 #include "DTCalibrationMap.h"
0010
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017
0018 #include <iostream>
0019 #include <fstream>
0020 #include <algorithm>
0021 #include <iterator>
0022
0023 using namespace edm;
0024 using namespace std;
0025
0026 DumpDBToFile::DumpDBToFile(const ParameterSet& pset) {
0027 theCalibFile = new DTCalibrationMap(pset.getUntrackedParameter<ParameterSet>("calibFileConfig"));
0028 theOutputFileName = pset.getUntrackedParameter<string>("outputFileName");
0029
0030 dbToDump = pset.getUntrackedParameter<string>("dbToDump", "TTrigDB");
0031 dbLabel = pset.getUntrackedParameter<string>("dbLabel", "");
0032 format = pset.getUntrackedParameter<string>("dbFormat", "Legacy");
0033
0034 if (dbToDump != "VDriftDB" && dbToDump != "TTrigDB" && dbToDump != "TZeroDB" && dbToDump != "NoiseDB" &&
0035 dbToDump != "DeadDB" && dbToDump != "ChannelsDB" && dbToDump != "RecoUncertDB")
0036 throw cms::Exception("IncorrectSetup") << "Parameter dbToDump is not valid, check the cfg file" << endl;
0037
0038 if (format != "Legacy" && format != "DTRecoConditions")
0039 throw cms::Exception("IncorrectSetup") << "Parameter format is not valid, check the cfg file" << endl;
0040
0041 if (dbToDump == "VDriftDB") {
0042 if (format == "Legacy") {
0043 mTimeMapToken_ = esConsumes<edm::Transition::BeginRun>();
0044 } else {
0045 vDriftToken_ = esConsumes<edm::Transition::BeginRun>();
0046 }
0047 } else if (dbToDump == "TTrigDB") {
0048 if (format == "Legacy") {
0049 tTrigMapToken_ = esConsumes<edm::Transition::BeginRun>();
0050 } else {
0051 tTrigToken_ = esConsumes<edm::Transition::BeginRun>();
0052 }
0053 } else if (dbToDump == "TZeroDB") {
0054 t0MapToken_ = esConsumes<edm::Transition::BeginRun>();
0055 } else if (dbToDump == "NoiseDB") {
0056 statusMapToken_ = esConsumes<edm::Transition::BeginRun>();
0057 } else if (dbToDump == "DeadDB") {
0058 deadMapToken_ = esConsumes<edm::Transition::BeginRun>();
0059 } else if (dbToDump == "ChannelsDB") {
0060 readOutMapToken_ = esConsumes<edm::Transition::BeginRun>();
0061 } else if (dbToDump == "RecoUncertDB") {
0062 uncertToken_ = esConsumes<edm::Transition::BeginRun>();
0063 }
0064 }
0065
0066 DumpDBToFile::~DumpDBToFile() {}
0067
0068 void DumpDBToFile::beginRun(const edm::Run&, const EventSetup& setup) {
0069
0070 if (dbToDump == "VDriftDB") {
0071 if (format == "Legacy") {
0072 mTimeMap = &setup.getData(mTimeMapToken_);
0073 } else if (format == "DTRecoConditions") {
0074 rconds = &setup.getData(vDriftToken_);
0075 }
0076 } else if (dbToDump == "TTrigDB") {
0077 if (format == "Legacy") {
0078 tTrigMap = &setup.getData(tTrigMapToken_);
0079 } else if (format == "DTRecoConditions") {
0080 rconds = &setup.getData(tTrigToken_);
0081 }
0082 } else if (dbToDump == "TZeroDB") {
0083 tZeroMap = &setup.getData(t0MapToken_);
0084 } else if (dbToDump == "NoiseDB") {
0085 statusMap = &setup.getData(statusMapToken_);
0086 } else if (dbToDump == "DeadDB") {
0087 deadMap = &setup.getData(deadMapToken_);
0088 } else if (dbToDump == "ChannelsDB") {
0089 channelsMap = &setup.getData(readOutMapToken_);
0090 } else if (dbToDump == "RecoUncertDB") {
0091 rconds = &setup.getData(uncertToken_);
0092 }
0093 }
0094
0095 void DumpDBToFile::endJob() {
0096 if (dbToDump != "ChannelsDB") {
0097
0098 if (dbToDump == "VDriftDB") {
0099 if (format == "Legacy") {
0100 int version = 1;
0101 int type = 1;
0102 int nfields = 1;
0103 cout << "[DumpDBToFile] MTime version: " << mTimeMap->version() << endl;
0104 for (DTMtime::const_iterator mtime = mTimeMap->begin(); mtime != mTimeMap->end(); ++mtime) {
0105 DTWireId wireId(
0106 (*mtime).first.wheelId, (*mtime).first.stationId, (*mtime).first.sectorId, (*mtime).first.slId, 0, 0);
0107 float vdrift;
0108 float reso;
0109 DetId detId(wireId.rawId());
0110
0111 mTimeMap->get(detId, vdrift, reso, DTVelocityUnits::cm_per_ns);
0112
0113
0114
0115
0116
0117
0118 vector<float> consts = {
0119 -1, -1, -1, vdrift, reso, -1, -1, -1, -1, -1, float(version * 1000 + type * 100 + nfields), vdrift};
0120 theCalibFile->addCell(wireId, consts);
0121 }
0122 } else if (format == "DTRecoConditions") {
0123 int version = rconds->version();
0124 int type = 1;
0125 string expr = rconds->getFormulaExpr();
0126 cout << "[DumpDBToFile] DTRecoConditions (vdrift) version: " << version << " expression: " << expr << endl;
0127 if (version != 1 || expr != "[0]")
0128 throw cms::Exception("Configuration") << "only version 1, type 1 is presently supported for VDriftDB";
0129 for (DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
0130 DTWireId wireId(irc->first);
0131 const vector<double>& data = irc->second;
0132 int nfields = data.size();
0133 float vdrift = data[0];
0134 float reso = 0;
0135 vector<float> consts(11 + nfields, -1);
0136 consts[3] = vdrift;
0137 consts[4] = reso;
0138 consts[10] = float(version * 1000 + type * 100 + nfields);
0139 std::copy(data.begin(), data.end(), consts.begin() + 11);
0140 theCalibFile->addCell(wireId, consts);
0141 }
0142 }
0143
0144
0145 } else if (dbToDump == "TTrigDB") {
0146 if (format == "Legacy") {
0147 int version = 1;
0148 int type = 1;
0149 int nfields = 1;
0150 cout << "[DumpDBToFile] TTrig version: " << tTrigMap->version() << endl;
0151 for (DTTtrig::const_iterator ttrig = tTrigMap->begin(); ttrig != tTrigMap->end(); ++ttrig) {
0152 DTWireId wireId(
0153 (*ttrig).first.wheelId, (*ttrig).first.stationId, (*ttrig).first.sectorId, (*ttrig).first.slId, 0, 0);
0154 DetId detId(wireId.rawId());
0155 float tmea;
0156 float trms;
0157 float kFactor;
0158
0159 tTrigMap->get(detId, tmea, trms, kFactor, DTTimeUnits::ns);
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 vector<float> consts = {tmea,
0170 trms,
0171 kFactor,
0172 -1,
0173 -1,
0174 -1,
0175 -1,
0176 -1,
0177 -1,
0178 -1,
0179 float(version * 1000 + type * 100 + nfields),
0180 tmea + trms * kFactor};
0181 theCalibFile->addCell(wireId, consts);
0182 }
0183 } else if (format == "DTRecoConditions") {
0184 int version = rconds->version();
0185 int type = 1;
0186 string expr = rconds->getFormulaExpr();
0187 if (version != 1 || expr != "[0]")
0188 throw cms::Exception("Configuration") << "only version 1, type 1 is presently supported for TTrigDB";
0189
0190 cout << "[DumpDBToFile] DTRecoConditions (ttrig) version: " << rconds->version() << " expression: " << expr
0191 << endl;
0192 for (DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
0193 DTWireId wireId(irc->first);
0194 const vector<double>& data = irc->second;
0195 int nfields = data.size();
0196 float ttrig = data[0];
0197 float sigma = 0;
0198 float kappa = 0;
0199
0200 vector<float> consts(11 + nfields, -1);
0201 consts[0] = ttrig;
0202 consts[1] = sigma;
0203 consts[2] = kappa;
0204 consts[10] = float(version * 1000 + type * 100 + nfields);
0205 std::copy(data.begin(), data.end(), consts.begin() + 11);
0206 theCalibFile->addCell(wireId, consts);
0207 }
0208 }
0209
0210
0211 } else if (dbToDump == "TZeroDB") {
0212 cout << "[DumpDBToFile] T0 version: " << tZeroMap->version() << endl;
0213 for (DTT0::const_iterator tzero = tZeroMap->begin(); tzero != tZeroMap->end(); ++tzero) {
0214
0215
0216
0217
0218
0219
0220
0221 int channelId = tzero->channelId;
0222 if (channelId == 0)
0223 continue;
0224 DTWireId wireId(channelId);
0225
0226 float t0mean;
0227 float t0rms;
0228
0229 tZeroMap->get(wireId, t0mean, t0rms, DTTimeUnits::counts);
0230
0231 vector<float> consts;
0232 consts.push_back(-1);
0233 consts.push_back(-1);
0234 consts.push_back(-1);
0235 consts.push_back(-1);
0236 consts.push_back(-1);
0237 consts.push_back(t0mean);
0238 consts.push_back(t0rms);
0239
0240 theCalibFile->addCell(wireId, consts);
0241 }
0242 } else if (dbToDump == "NoiseDB") {
0243 for (DTStatusFlag::const_iterator statusFlag = statusMap->begin(); statusFlag != statusMap->end(); ++statusFlag) {
0244 DTWireId wireId((*statusFlag).first.wheelId,
0245 (*statusFlag).first.stationId,
0246 (*statusFlag).first.sectorId,
0247 (*statusFlag).first.slId,
0248 (*statusFlag).first.layerId,
0249 (*statusFlag).first.cellId);
0250 cout << wireId << " Noisy Flag: " << (*statusFlag).second.noiseFlag << endl;
0251 vector<float> consts;
0252 consts.push_back(-1);
0253 consts.push_back(-1);
0254 consts.push_back(-1);
0255 consts.push_back(-1);
0256 consts.push_back(-1);
0257 consts.push_back(-9999999);
0258 consts.push_back(-9999999);
0259 consts.push_back((*statusFlag).second.noiseFlag);
0260
0261 theCalibFile->addCell(wireId, consts);
0262 }
0263 } else if (dbToDump == "DeadDB") {
0264 for (DTDeadFlag::const_iterator deadFlag = deadMap->begin(); deadFlag != deadMap->end(); ++deadFlag) {
0265 DTWireId wireId((*deadFlag).first.wheelId,
0266 (*deadFlag).first.stationId,
0267 (*deadFlag).first.sectorId,
0268 (*deadFlag).first.slId,
0269 (*deadFlag).first.layerId,
0270 (*deadFlag).first.cellId);
0271 cout << wireId << " Dead Flag: " << (*deadFlag).second.dead_TP << endl;
0272 vector<float> consts;
0273 consts.push_back(-1);
0274 consts.push_back(-1);
0275 consts.push_back(-1);
0276 consts.push_back(-1);
0277 consts.push_back(-1);
0278 consts.push_back(-9999999);
0279 consts.push_back(-9999999);
0280 consts.push_back((*deadFlag).second.dead_TP);
0281
0282 theCalibFile->addCell(wireId, consts);
0283 }
0284
0285
0286 } else if (dbToDump == "RecoUncertDB") {
0287 int version = rconds->version();
0288 string expr = rconds->getFormulaExpr();
0289 int type = 2;
0290 if (version != 1 || expr != "par[step]")
0291 throw cms::Exception("Configuration") << "only version 1, type 2 is presently supported for RecoUncertDB";
0292
0293 cout << "[DumpDBToFile] DTRecoConditions (uncerts) version: " << rconds->version() << " expression: " << expr
0294 << endl;
0295
0296 for (DTRecoConditions::const_iterator irc = rconds->begin(); irc != rconds->end(); ++irc) {
0297 DTWireId wireId(irc->first);
0298 const vector<double>& data = irc->second;
0299 int nfields = data.size();
0300 vector<float> consts(11 + nfields, -1);
0301 consts[10] = float(version * 1000 + type * 100 + nfields);
0302 std::copy(data.begin(), data.end(), consts.begin() + 11);
0303 theCalibFile->addCell(wireId, consts);
0304 }
0305 }
0306
0307 theCalibFile->writeConsts(theOutputFileName);
0308 }
0309
0310 else if (dbToDump == "ChannelsDB") {
0311 ofstream out(theOutputFileName.c_str());
0312 for (DTReadOutMapping::const_iterator roLink = channelsMap->begin(); roLink != channelsMap->end(); ++roLink) {
0313 out << roLink->dduId << ' ' << roLink->rosId << ' ' << roLink->robId << ' ' << roLink->tdcId << ' '
0314 << roLink->channelId << ' ' << roLink->wheelId << ' ' << roLink->stationId << ' ' << roLink->sectorId << ' '
0315 << roLink->slId << ' ' << roLink->layerId << ' ' << roLink->cellId << endl;
0316
0317 cout << "ddu " << roLink->dduId << ' ' << "ros " << roLink->rosId << ' ' << "rob " << roLink->robId << ' '
0318 << "tdc " << roLink->tdcId << ' ' << "channel " << roLink->channelId << ' ' << "->" << ' ' << "wheel "
0319 << roLink->wheelId << ' ' << "station " << roLink->stationId << ' ' << "sector " << roLink->sectorId << ' '
0320 << "superlayer " << roLink->slId << ' ' << "layer " << roLink->layerId << ' ' << "wire " << roLink->cellId
0321 << ' ' << endl;
0322 }
0323 }
0324 }