File indexing completed on 2024-04-06 12:02:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "CondFormats/DTObjects/interface/DTMtime.h"
0012
0013
0014
0015
0016 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0017
0018
0019
0020
0021 #include <iostream>
0022 #include <sstream>
0023
0024
0025
0026
0027
0028
0029
0030
0031 DTMtime::DTMtime() : dataVersion(" "), nsPerCount(25.0 / 32.0), dBuf(new DTBufferTree<int, int>) {
0032 dataList.reserve(1000);
0033 }
0034
0035 DTMtime::DTMtime(const std::string& version)
0036 : dataVersion(version), nsPerCount(25.0 / 32.0), dBuf(new DTBufferTree<int, int>) {
0037 dataList.reserve(1000);
0038 }
0039
0040 DTMtimeId::DTMtimeId() : wheelId(0), stationId(0), sectorId(0), slId(0), layerId(0), cellId(0) {}
0041
0042 DTMtimeData::DTMtimeData() : mTime(0.0), mTrms(0.0) {}
0043
0044
0045
0046
0047 DTMtime::~DTMtime() {}
0048
0049 DTMtimeId::~DTMtimeId() {}
0050
0051 DTMtimeData::~DTMtimeData() {}
0052
0053
0054
0055
0056 int DTMtime::get(
0057 int wheelId, int stationId, int sectorId, int slId, float& mTime, float& mTrms, DTTimeUnits::type unit) const {
0058 return get(wheelId, stationId, sectorId, slId, 0, 0, mTime, mTrms, unit);
0059 }
0060
0061 int DTMtime::get(
0062 int wheelId, int stationId, int sectorId, int slId, float& mTime, float& mTrms, DTVelocityUnits::type unit) const {
0063 return get(wheelId, stationId, sectorId, slId, 0, 0, mTime, mTrms, unit);
0064 }
0065
0066 int DTMtime::get(int wheelId,
0067 int stationId,
0068 int sectorId,
0069 int slId,
0070 int layerId,
0071 int cellId,
0072 float& mTime,
0073 float& mTrms,
0074 DTTimeUnits::type unit) const {
0075 mTime = mTrms = 0.0;
0076
0077 std::vector<int> chanKey;
0078 chanKey.reserve(6);
0079 chanKey.push_back(wheelId);
0080 chanKey.push_back(stationId);
0081 chanKey.push_back(sectorId);
0082 chanKey.push_back(slId);
0083 chanKey.push_back(layerId);
0084 chanKey.push_back(cellId);
0085 int ientry;
0086 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0087 if (!searchStatus) {
0088 const DTMtimeData& data(dataList[ientry].second);
0089 mTime = data.mTime;
0090 mTrms = data.mTrms;
0091 if (unit == DTTimeUnits::ns) {
0092 mTime *= nsPerCount;
0093 mTrms *= nsPerCount;
0094 }
0095 }
0096
0097 return searchStatus;
0098 }
0099
0100 int DTMtime::get(int wheelId,
0101 int stationId,
0102 int sectorId,
0103 int slId,
0104 int layerId,
0105 int cellId,
0106 float& mTime,
0107 float& mTrms,
0108 DTVelocityUnits::type unit) const {
0109 int status = get(wheelId, stationId, sectorId, slId, layerId, cellId, mTime, mTrms, DTTimeUnits::counts);
0110 if (unit == DTVelocityUnits::cm_per_count) {
0111 mTime = 2.1 / mTime;
0112 mTrms *= mTime;
0113 }
0114 if (unit == DTVelocityUnits::cm_per_ns) {
0115 mTime = 2.1 / mTime;
0116 mTrms *= mTime;
0117 mTime /= nsPerCount;
0118 }
0119 return status;
0120 }
0121
0122 int DTMtime::get(const DTSuperLayerId& id, float& mTime, float& mTrms, DTTimeUnits::type unit) const {
0123 return get(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, mTime, mTrms, unit);
0124 }
0125
0126 int DTMtime::get(const DTSuperLayerId& id, float& mTime, float& mTrms, DTVelocityUnits::type unit) const {
0127 return get(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, mTime, mTrms, unit);
0128 }
0129
0130 int DTMtime::get(const DetId& id, float& mTime, float& mTrms, DTTimeUnits::type unit) const {
0131 DTWireId wireId(id.rawId());
0132 return get(wireId.wheel(),
0133 wireId.station(),
0134 wireId.sector(),
0135 wireId.superLayer(),
0136 wireId.layer(),
0137 wireId.wire(),
0138 mTime,
0139 mTrms,
0140 unit);
0141 }
0142
0143 int DTMtime::get(const DetId& id, float& mTime, float& mTrms, DTVelocityUnits::type unit) const {
0144 DTWireId wireId(id.rawId());
0145 return get(wireId.wheel(),
0146 wireId.station(),
0147 wireId.sector(),
0148 wireId.superLayer(),
0149 wireId.layer(),
0150 wireId.wire(),
0151 mTime,
0152 mTrms,
0153 unit);
0154 }
0155
0156 float DTMtime::unit() const { return nsPerCount; }
0157
0158 const std::string& DTMtime::version() const { return dataVersion; }
0159
0160 std::string& DTMtime::version() { return dataVersion; }
0161
0162 void DTMtime::clear() {
0163 dataList.clear();
0164 initialize();
0165 return;
0166 }
0167
0168 int DTMtime::set(int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTTimeUnits::type unit) {
0169 return set(wheelId, stationId, sectorId, slId, 0, 0, mTime, mTrms, unit);
0170 }
0171
0172 int DTMtime::set(
0173 int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTVelocityUnits::type unit) {
0174 return set(wheelId, stationId, sectorId, slId, 0, 0, mTime, mTrms, unit);
0175 }
0176
0177 int DTMtime::set(int wheelId,
0178 int stationId,
0179 int sectorId,
0180 int slId,
0181 int layerId,
0182 int cellId,
0183 float mTime,
0184 float mTrms,
0185 DTTimeUnits::type unit) {
0186 if (unit == DTTimeUnits::ns) {
0187 mTime /= nsPerCount;
0188 mTrms /= nsPerCount;
0189 }
0190
0191 std::vector<int> chanKey;
0192 chanKey.reserve(6);
0193 chanKey.push_back(wheelId);
0194 chanKey.push_back(stationId);
0195 chanKey.push_back(sectorId);
0196 chanKey.push_back(slId);
0197 chanKey.push_back(layerId);
0198 chanKey.push_back(cellId);
0199 int ientry;
0200 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0201
0202 if (!searchStatus) {
0203 DTMtimeData& data(dataList[ientry].second);
0204 data.mTime = mTime;
0205 data.mTrms = mTrms;
0206 return -1;
0207 } else {
0208 DTMtimeId key;
0209 key.wheelId = wheelId;
0210 key.stationId = stationId;
0211 key.sectorId = sectorId;
0212 key.slId = slId;
0213 key.layerId = layerId;
0214 key.cellId = cellId;
0215 DTMtimeData data;
0216 data.mTime = mTime;
0217 data.mTrms = mTrms;
0218 ientry = dataList.size();
0219 dataList.push_back(std::pair<DTMtimeId, DTMtimeData>(key, data));
0220 dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0221 return 0;
0222 }
0223
0224 return 99;
0225 }
0226
0227 int DTMtime::set(int wheelId,
0228 int stationId,
0229 int sectorId,
0230 int slId,
0231 int layerId,
0232 int cellId,
0233 float mTime,
0234 float mTrms,
0235 DTVelocityUnits::type unit) {
0236 if (unit == DTVelocityUnits::cm_per_count) {
0237 mTrms /= mTime;
0238 mTime = 2.1 / mTime;
0239 }
0240 if (unit == DTVelocityUnits::cm_per_ns) {
0241 mTime *= nsPerCount;
0242 mTrms /= mTime;
0243 mTime = 2.1 / mTime;
0244 }
0245 return set(wheelId, stationId, sectorId, slId, layerId, cellId, mTime, mTrms, DTTimeUnits::counts);
0246 }
0247
0248 int DTMtime::set(const DTSuperLayerId& id, float mTime, float mTrms, DTTimeUnits::type unit) {
0249 return set(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, mTime, mTrms, unit);
0250 }
0251
0252 int DTMtime::set(const DTSuperLayerId& id, float mTime, float mTrms, DTVelocityUnits::type unit) {
0253 return set(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, mTime, mTrms, unit);
0254 }
0255
0256 int DTMtime::set(const DetId& id, float mTime, float mTrms, DTTimeUnits::type unit) {
0257 DTWireId wireId(id.rawId());
0258 return set(wireId.wheel(),
0259 wireId.station(),
0260 wireId.sector(),
0261 wireId.superLayer(),
0262 wireId.layer(),
0263 wireId.wire(),
0264 mTime,
0265 mTrms,
0266 unit);
0267 }
0268
0269 int DTMtime::set(const DetId& id, float mTime, float mTrms, DTVelocityUnits::type unit) {
0270 DTWireId wireId(id.rawId());
0271 return set(wireId.wheel(),
0272 wireId.station(),
0273 wireId.sector(),
0274 wireId.superLayer(),
0275 wireId.layer(),
0276 wireId.wire(),
0277 mTime,
0278 mTrms,
0279 unit);
0280 }
0281
0282 void DTMtime::setUnit(float unit) { nsPerCount = unit; }
0283
0284 DTMtime::const_iterator DTMtime::begin() const { return dataList.begin(); }
0285
0286 DTMtime::const_iterator DTMtime::end() const { return dataList.end(); }
0287
0288 std::string DTMtime::mapName() const {
0289 std::stringstream name;
0290 name << dataVersion << "_map_Mtime" << this;
0291 return name.str();
0292 }
0293
0294 void DTMtime::initialize() {
0295 dBuf->clear();
0296
0297 int entryNum = 0;
0298 int entryMax = dataList.size();
0299 std::vector<int> chanKey;
0300 chanKey.reserve(6);
0301 while (entryNum < entryMax) {
0302 const DTMtimeId& chan = dataList[entryNum].first;
0303
0304 chanKey.clear();
0305 chanKey.push_back(chan.wheelId);
0306 chanKey.push_back(chan.stationId);
0307 chanKey.push_back(chan.sectorId);
0308 chanKey.push_back(chan.slId);
0309 chanKey.push_back(chan.layerId);
0310 chanKey.push_back(chan.cellId);
0311 dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0312 }
0313
0314 return;
0315 }