File indexing completed on 2024-04-06 12:02:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <memory>
0012
0013 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
0014
0015
0016
0017
0018 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 DTCCBConfig::DTCCBConfig() : timeStamp(0), dataVersion(" "), dBuf(new DTBufferTreeUniquePtr) { dataList.reserve(1000); }
0032
0033 DTCCBConfig::DTCCBConfig(const std::string& version)
0034 : timeStamp(0), dataVersion(version), dBuf(new DTBufferTreeUniquePtr) {
0035 dataList.reserve(1000);
0036 }
0037
0038 DTCCBId::DTCCBId() : wheelId(0), stationId(0), sectorId(0) {}
0039
0040 DTConfigKey::DTConfigKey() : confType(0), confKey(0) {}
0041
0042
0043
0044
0045 DTCCBConfig::~DTCCBConfig() {}
0046
0047 DTCCBId::~DTCCBId() {}
0048
0049 DTConfigKey::~DTConfigKey() {}
0050
0051
0052
0053
0054 std::vector<DTConfigKey> DTCCBConfig::fullKey() const { return fullConfigKey; }
0055
0056 int DTCCBConfig::stamp() const { return timeStamp; }
0057
0058 int DTCCBConfig::configKey(int wheelId, int stationId, int sectorId, std::vector<int>& confKey) const {
0059 confKey.clear();
0060
0061 std::vector<int> chanKey{wheelId, stationId, sectorId};
0062 std::vector<int> const* confPtr;
0063 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
0064 if (!searchStatus)
0065 confKey = *confPtr;
0066
0067 return searchStatus;
0068 }
0069
0070 int DTCCBConfig::configKey(const DTChamberId& id, std::vector<int>& confKey) const {
0071 return configKey(id.wheel(), id.station(), id.sector(), confKey);
0072 }
0073
0074 DTCCBConfig::ccb_config_map DTCCBConfig::configKeyMap() const {
0075 ccb_config_map keyList;
0076 std::vector<std::pair<DTCCBId, int>*> tempList;
0077 const_iterator d_iter = begin();
0078 const_iterator d_iend = end();
0079 while (d_iter != d_iend)
0080 tempList.push_back(new std::pair<DTCCBId, int>(*d_iter++));
0081 std::vector<std::pair<DTCCBId, int>*>::iterator t_iter = tempList.begin();
0082 std::vector<std::pair<DTCCBId, int>*>::iterator t_iend = tempList.end();
0083 while (t_iter != t_iend) {
0084 std::pair<DTCCBId, int>* ptr = *t_iter++;
0085 if (ptr == nullptr)
0086 continue;
0087 DTCCBId& ccbId = ptr->first;
0088 std::vector<int> cfgKeys;
0089 cfgKeys.push_back(ptr->second);
0090 std::vector<std::pair<DTCCBId, int>*>::iterator n_iter(t_iter);
0091 while (n_iter != t_iend) {
0092 std::pair<DTCCBId, int>*& pck = *n_iter++;
0093 if (pck == nullptr)
0094 continue;
0095 DTCCBId& chkId = pck->first;
0096 if ((chkId.wheelId == ccbId.wheelId) && (chkId.stationId == ccbId.stationId) &&
0097 (chkId.sectorId == ccbId.sectorId)) {
0098 cfgKeys.push_back(pck->second);
0099 delete pck;
0100 pck = nullptr;
0101 }
0102 }
0103 keyList.push_back(std::pair<DTCCBId, std::vector<int> >(ccbId, cfgKeys));
0104 delete ptr;
0105 }
0106 return keyList;
0107 }
0108
0109 const std::string& DTCCBConfig::version() const { return dataVersion; }
0110
0111 std::string& DTCCBConfig::version() { return dataVersion; }
0112
0113 void DTCCBConfig::clear() {
0114 dataList.clear();
0115 initialize();
0116 return;
0117 }
0118
0119 void DTCCBConfig::setFullKey(const std::vector<DTConfigKey>& key) { fullConfigKey = key; }
0120
0121 void DTCCBConfig::setStamp(int s) { timeStamp = s; }
0122
0123 int DTCCBConfig::setConfigKey(int wheelId, int stationId, int sectorId, const std::vector<int>& confKey) {
0124 std::vector<int> chanKey{wheelId, stationId, sectorId};
0125
0126 std::vector<int>* confPtr;
0127 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
0128
0129 if (!searchStatus) {
0130 std::vector<std::pair<DTCCBId, int> > tempList;
0131 const_iterator iter = dataList.begin();
0132 const_iterator iend = dataList.end();
0133 while (iter != iend) {
0134 const DTCCBId& ccbId(iter->first);
0135 if ((ccbId.wheelId != wheelId) || (ccbId.stationId != stationId) || (ccbId.sectorId != sectorId))
0136 tempList.push_back(*iter);
0137 ++iter;
0138 }
0139 dataList = tempList;
0140 DTCCBId ccbId;
0141 ccbId.wheelId = wheelId;
0142 ccbId.stationId = stationId;
0143 ccbId.sectorId = sectorId;
0144 std::vector<int>::const_iterator cfgIter = confKey.begin();
0145 std::vector<int>::const_iterator cfgIend = confKey.end();
0146 while (cfgIter != cfgIend)
0147 dataList.push_back(std::pair<DTCCBId, int>(ccbId, *cfgIter++));
0148 *confPtr = confKey;
0149 return -1;
0150 } else {
0151 dBuf->insert(chanKey.begin(), chanKey.end(), std::make_unique<std::vector<int> >(confKey));
0152 DTCCBId ccbId;
0153 ccbId.wheelId = wheelId;
0154 ccbId.stationId = stationId;
0155 ccbId.sectorId = sectorId;
0156 std::vector<int>::const_iterator cfgIter = confKey.begin();
0157 std::vector<int>::const_iterator cfgIend = confKey.end();
0158 while (cfgIter != cfgIend)
0159 dataList.push_back(std::pair<DTCCBId, int>(ccbId, *cfgIter++));
0160 return 0;
0161 }
0162 }
0163
0164 int DTCCBConfig::setConfigKey(const DTChamberId& id, const std::vector<int>& confKey) {
0165 return setConfigKey(id.wheel(), id.station(), id.sector(), confKey);
0166 }
0167
0168 int DTCCBConfig::appendConfigKey(int wheelId, int stationId, int sectorId, const std::vector<int>& confKey) {
0169 std::vector<int> chanKey{wheelId, stationId, sectorId};
0170
0171 DTCCBId ccbId;
0172 ccbId.wheelId = wheelId;
0173 ccbId.stationId = stationId;
0174 ccbId.sectorId = sectorId;
0175 std::vector<int>::const_iterator iter = confKey.begin();
0176 std::vector<int>::const_iterator iend = confKey.end();
0177 int key;
0178
0179 std::vector<int>* confPtr;
0180 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
0181
0182 if (searchStatus) {
0183 std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
0184 confPtr = newVector.get();
0185 dBuf->insert(chanKey.begin(), chanKey.end(), std::move(newVector));
0186 }
0187
0188 while (iter != iend) {
0189 key = *iter++;
0190 dataList.push_back(std::pair<DTCCBId, int>(ccbId, key));
0191 confPtr->push_back(key);
0192 }
0193
0194 if (!searchStatus) {
0195 return -1;
0196 } else {
0197 return 0;
0198 }
0199 }
0200
0201 int DTCCBConfig::appendConfigKey(const DTChamberId& id, const std::vector<int>& confKey) {
0202 return appendConfigKey(id.wheel(), id.station(), id.sector(), confKey);
0203 }
0204
0205 DTCCBConfig::const_iterator DTCCBConfig::begin() const { return dataList.begin(); }
0206
0207 DTCCBConfig::const_iterator DTCCBConfig::end() const { return dataList.end(); }
0208
0209 void DTCCBConfig::initialize() {
0210 dBuf->clear();
0211
0212 const_iterator iter = dataList.begin();
0213 const_iterator iend = dataList.end();
0214 std::vector<int> chanKey;
0215 chanKey.reserve(3);
0216 while (iter != iend) {
0217 const DTCCBId& chan = iter->first;
0218
0219 chanKey.clear();
0220 chanKey.push_back(chan.wheelId);
0221 chanKey.push_back(chan.stationId);
0222 chanKey.push_back(chan.sectorId);
0223 std::vector<int>* ccbConfPtr;
0224 int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ccbConfPtr);
0225
0226 if (searchStatus) {
0227 std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
0228 ccbConfPtr = newVector.get();
0229 dBuf->insert(chanKey.begin(), chanKey.end(), std::move(newVector));
0230 }
0231 ccbConfPtr->push_back(iter->second);
0232
0233 iter++;
0234 }
0235 }