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/DTTPGParameters.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 DTTPGParameters::DTTPGParameters()
0032 : dataVersion(" "), nsPerCount(25.0 / 32.0), clockLength(32), dBuf(new DTBufferTree<int, int>) {
0033 dataList.reserve(250);
0034 }
0035
0036 DTTPGParameters::DTTPGParameters(const std::string& version)
0037 : dataVersion(version), nsPerCount(25.0 / 32.0), clockLength(32), dBuf(new DTBufferTree<int, int>) {
0038 dataList.reserve(250);
0039 }
0040
0041 DTTPGParameters& DTTPGParameters::operator=(DTTPGParameters const& rhs) {
0042 if (this != &rhs) {
0043 dataVersion = rhs.dataVersion;
0044 nsPerCount = rhs.nsPerCount;
0045 clockLength = rhs.clockLength;
0046 dataList = rhs.dataList;
0047 initialize();
0048 }
0049 return *this;
0050 }
0051
0052 DTTPGParametersId::DTTPGParametersId() : wheelId(0), stationId(0), sectorId(0) {}
0053
0054 DTTPGParametersData::DTTPGParametersData() : nClock(0), tPhase(0.0) {}
0055
0056
0057
0058
0059 DTTPGParameters::~DTTPGParameters() {}
0060
0061 DTTPGParametersId::~DTTPGParametersId() {}
0062
0063 DTTPGParametersData::~DTTPGParametersData() {}
0064
0065
0066
0067
0068 int DTTPGParameters::get(int wheelId, int stationId, int sectorId, int& nc, float& ph, DTTimeUnits::type unit) const {
0069 nc = 0;
0070 ph = 0.0;
0071
0072 std::vector<int> chanKey;
0073 chanKey.reserve(3);
0074 chanKey.push_back(wheelId);
0075 chanKey.push_back(stationId);
0076 chanKey.push_back(sectorId);
0077 int ientry;
0078 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0079 if (!searchStatus) {
0080 const DTTPGParametersData& data(dataList[ientry].second);
0081 nc = data.nClock;
0082 ph = data.tPhase;
0083 if (unit == DTTimeUnits::ns) {
0084 ph *= nsPerCount;
0085 }
0086 }
0087
0088 return searchStatus;
0089 }
0090
0091 int DTTPGParameters::get(const DTChamberId& id, int& nc, float& ph, DTTimeUnits::type unit) const {
0092 return get(id.wheel(), id.station(), id.sector(), nc, ph, unit);
0093 }
0094
0095 float DTTPGParameters::totalTime(int wheelId, int stationId, int sectorId, DTTimeUnits::type unit) const {
0096 int cl = 0;
0097 float ph = 0.0;
0098 get(wheelId, stationId, sectorId, cl, ph, unit);
0099 if (unit == DTTimeUnits::ns)
0100 return (cl * clock() * nsPerCount) + ph;
0101 else
0102 return (cl * clock()) + ph;
0103 }
0104
0105 float DTTPGParameters::totalTime(const DTChamberId& id, DTTimeUnits::type unit) const {
0106 return totalTime(id.wheel(), id.station(), id.sector(), unit);
0107 }
0108
0109 int DTTPGParameters::clock() const { return clockLength; }
0110
0111 float DTTPGParameters::unit() const { return nsPerCount; }
0112
0113 const std::string& DTTPGParameters::version() const { return dataVersion; }
0114
0115 std::string& DTTPGParameters::version() { return dataVersion; }
0116
0117 void DTTPGParameters::clear() {
0118 dataList.clear();
0119 initialize();
0120 return;
0121 }
0122
0123 int DTTPGParameters::set(int wheelId, int stationId, int sectorId, int nc, float ph, DTTimeUnits::type unit) {
0124 if (unit == DTTimeUnits::ns) {
0125 ph /= nsPerCount;
0126 }
0127
0128 std::vector<int> chanKey;
0129 chanKey.reserve(3);
0130 chanKey.push_back(wheelId);
0131 chanKey.push_back(stationId);
0132 chanKey.push_back(sectorId);
0133 int ientry;
0134 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0135
0136 if (!searchStatus) {
0137 DTTPGParametersData& data(dataList[ientry].second);
0138 data.nClock = nc;
0139 data.tPhase = ph;
0140 return -1;
0141 } else {
0142 DTTPGParametersId key;
0143 key.wheelId = wheelId;
0144 key.stationId = stationId;
0145 key.sectorId = sectorId;
0146 DTTPGParametersData data;
0147 data.nClock = nc;
0148 data.tPhase = ph;
0149 ientry = dataList.size();
0150 dataList.push_back(std::pair<DTTPGParametersId, DTTPGParametersData>(key, data));
0151 dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0152 return 0;
0153 }
0154
0155 return 99;
0156 }
0157
0158 int DTTPGParameters::set(const DTChamberId& id, int nc, float ph, DTTimeUnits::type unit) {
0159 return set(id.wheel(), id.station(), id.sector(), nc, ph, unit);
0160 }
0161
0162 void DTTPGParameters::setClock(int clock) { clockLength = clock; }
0163
0164 void DTTPGParameters::setUnit(float unit) { nsPerCount = unit; }
0165
0166 DTTPGParameters::const_iterator DTTPGParameters::begin() const { return dataList.begin(); }
0167
0168 DTTPGParameters::const_iterator DTTPGParameters::end() const { return dataList.end(); }
0169
0170 std::string DTTPGParameters::mapName() const {
0171 std::stringstream name;
0172 name << dataVersion << "_map_TTPG" << this;
0173 return name.str();
0174 }
0175
0176 void DTTPGParameters::initialize() {
0177 dBuf->clear();
0178
0179 int entryNum = 0;
0180 int entryMax = dataList.size();
0181 std::vector<int> chanKey;
0182 chanKey.reserve(3);
0183 while (entryNum < entryMax) {
0184 const DTTPGParametersId& chan = dataList[entryNum].first;
0185
0186 chanKey.clear();
0187 chanKey.push_back(chan.wheelId);
0188 chanKey.push_back(chan.stationId);
0189 chanKey.push_back(chan.sectorId);
0190 dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0191 }
0192
0193 return;
0194 }