File indexing completed on 2024-04-06 12:02:42
0001 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0002
0003 #include <algorithm>
0004 #include <iostream>
0005 #include <iterator>
0006
0007 struct DetIdAndApvs {
0008 uint32_t detId;
0009 std::vector<uint16_t> apvs;
0010 };
0011
0012 void test(const std::vector<DetIdAndApvs>& detIdAndApvs,
0013 const std::vector<int>& latencyIndexes,
0014 std::vector<uint16_t>& latencies,
0015 const std::vector<int>& modeIndexes,
0016 std::vector<uint16_t>& modes,
0017 SiStripLatency& latency) {
0018 int i = 0;
0019 int flip = 0;
0020 int modeFlip = 0;
0021 std::vector<DetIdAndApvs>::const_iterator detIdAndApv = detIdAndApvs.begin();
0022 for (; detIdAndApv != detIdAndApvs.end(); ++detIdAndApv) {
0023 std::vector<uint16_t>::const_iterator apv = detIdAndApv->apvs.begin();
0024 for (; apv != detIdAndApv->apvs.end(); ++apv, ++i) {
0025
0026
0027 if (find(latencyIndexes.begin(), latencyIndexes.end(), i) != latencyIndexes.end()) {
0028 if (flip == 0) {
0029 flip = 1;
0030 } else {
0031 flip = 0;
0032 }
0033 }
0034
0035 if (find(modeIndexes.begin(), modeIndexes.end(), i) != modeIndexes.end()) {
0036 if (modeFlip == 10) {
0037 modeFlip = 0;
0038 } else {
0039 modeFlip = 10;
0040 }
0041 }
0042
0043
0044 latency.put(detIdAndApv->detId, *apv, 14 + flip, 37 + modeFlip);
0045
0046
0047 latencies.push_back(latency.latency(detIdAndApv->detId, *apv));
0048 modes.push_back(latency.mode(detIdAndApv->detId, *apv));
0049
0050 }
0051 }
0052
0053 std::vector<SiStripLatency::Latency> latenciesBeforeCompression = latency.allLatencyAndModes();
0054 std::cout << "Ranges before compression = " << latenciesBeforeCompression.size() << std::endl;
0055 latency.compress();
0056 std::vector<SiStripLatency::Latency> latenciesAfterCompression = latency.allLatencyAndModes();
0057 std::cout << "Ranges after compression = " << latenciesAfterCompression.size() << std::endl;
0058 }
0059
0060 void check(const std::vector<uint16_t>& latencies,
0061 const std::vector<uint16_t>& modes,
0062 const std::vector<DetIdAndApvs>& detIdAndApvs,
0063 SiStripLatency& latency) {
0064 if (latencies.size() != modes.size()) {
0065 std::cout << "Error: different size for latencies = " << latencies.size() << " and modes = " << modes.size()
0066 << std::endl;
0067 exit(1);
0068 }
0069 std::vector<DetIdAndApvs>::const_iterator detIdAndApv = detIdAndApvs.begin();
0070 std::vector<uint16_t>::const_iterator it = latencies.begin();
0071 std::vector<uint16_t>::const_iterator modeIt = modes.begin();
0072 detIdAndApv = detIdAndApvs.begin();
0073 int latencyErrorCount = 0;
0074 int modeErrorCount = 0;
0075 for (; detIdAndApv != detIdAndApvs.end(); ++detIdAndApv) {
0076 std::vector<uint16_t>::const_iterator apv = detIdAndApv->apvs.begin();
0077 for (; apv != detIdAndApv->apvs.end(); ++apv, ++it, ++modeIt) {
0078 uint32_t detId = detIdAndApv->detId;
0079 uint32_t detIdAndApvValue = (detId << 2) | (*apv);
0080 std::cout << "detId = " << detIdAndApv->detId << ", apv = " << *apv << ", detIdAndApv = " << detIdAndApvValue
0081 << std::endl;
0082 std::cout << "latency passed = " << *it << ", latency saved = " << latency.latency(detIdAndApv->detId, *apv)
0083 << std::endl;
0084 std::cout << "mode passed = " << *modeIt << ", mode saved = " << latency.mode(detIdAndApv->detId, *apv)
0085 << std::endl;
0086 if (*it != latency.latency(detIdAndApv->detId, *apv)) {
0087 std::cout << "ERROR: the latency values are different" << std::endl;
0088 ++latencyErrorCount;
0089 }
0090 if (*modeIt != latency.mode(detIdAndApv->detId, *apv)) {
0091 std::cout << "ERROR: the mode values are different" << std::endl;
0092 ++modeErrorCount;
0093 }
0094 }
0095 }
0096 std::cout << std::endl;
0097 std::cout << "Single latency value = " << latency.singleLatency() << std::endl;
0098 std::cout << "Single mode value = " << latency.singleMode() << std::endl;
0099
0100 std::ostream_iterator<uint16_t> output(std::cout, ", ");
0101
0102 std::vector<uint16_t> allLatenciesVector;
0103 latency.allLatencies(allLatenciesVector);
0104 std::cout << "All latencies in the Tracker = " << allLatenciesVector.size() << ", and are:" << std::endl;
0105 copy(allLatenciesVector.begin(), allLatenciesVector.end(), output);
0106 std::cout << std::endl;
0107
0108 std::vector<uint16_t> allModesVector;
0109 latency.allModes(allModesVector);
0110 std::cout << "All modes in the Tracker = " << allModesVector.size() << ", and are:" << std::endl;
0111 copy(allModesVector.begin(), allModesVector.end(), output);
0112 std::cout << std::endl;
0113
0114 std::cout << std::endl;
0115 std::cout << "Latency errors = " << latencyErrorCount << std::endl;
0116 std::cout << "Mode errors = " << modeErrorCount << std::endl;
0117 std::cout << std::endl;
0118 std::cout << "############################" << std::endl;
0119 std::cout << std::endl;
0120 }
0121
0122 int main() {
0123 std::vector<DetIdAndApvs> detIdAndApvs;
0124 DetIdAndApvs element1;
0125 element1.detId = 100000;
0126 element1.apvs.push_back(0);
0127 element1.apvs.push_back(1);
0128 element1.apvs.push_back(2);
0129 element1.apvs.push_back(3);
0130 detIdAndApvs.push_back(element1);
0131
0132 DetIdAndApvs element2;
0133 element2.detId = 100001;
0134 element2.apvs.push_back(0);
0135 element2.apvs.push_back(1);
0136 element2.apvs.push_back(2);
0137 element2.apvs.push_back(3);
0138 element2.apvs.push_back(4);
0139 element2.apvs.push_back(5);
0140 detIdAndApvs.push_back(element2);
0141
0142 DetIdAndApvs element3;
0143 element3.detId = 9998;
0144 element3.apvs.push_back(0);
0145 element3.apvs.push_back(1);
0146 element3.apvs.push_back(2);
0147 element3.apvs.push_back(3);
0148 element3.apvs.push_back(4);
0149 element3.apvs.push_back(5);
0150 detIdAndApvs.push_back(element3);
0151
0152 DetIdAndApvs element4;
0153 element4.detId = 9999;
0154 element4.apvs.push_back(0);
0155 element4.apvs.push_back(1);
0156 detIdAndApvs.push_back(element4);
0157
0158 DetIdAndApvs element5;
0159 element5.detId = 100002;
0160 element5.apvs.push_back(0);
0161 element5.apvs.push_back(1);
0162 element5.apvs.push_back(2);
0163 element5.apvs.push_back(3);
0164 element5.apvs.push_back(4);
0165 element5.apvs.push_back(5);
0166 detIdAndApvs.push_back(element5);
0167
0168 std::cout << "---------------------------------" << std::endl;
0169 std::cout << "Testing the SiStripLatency object" << std::endl;
0170 std::cout << "---------------------------------" << std::endl << std::endl;
0171
0172 std::cout << "Testing the empty case" << std::endl;
0173 std::cout << "----------------------" << std::endl;
0174
0175 std::vector<int> latencyIndexes;
0176 std::vector<uint16_t> latencies;
0177 std::vector<int> modeIndexes;
0178 std::vector<uint16_t> modes;
0179 SiStripLatency latency1;
0180 test(detIdAndApvs, latencyIndexes, latencies, modeIndexes, modes, latency1);
0181 std::cout << std::endl;
0182 std::cout << "Filling complete, starting check" << std::endl;
0183 std::cout << std::endl;
0184 check(latencies, modes, detIdAndApvs, latency1);
0185
0186 std::cout << std::endl;
0187 std::cout << "Testing a case with several ranges" << std::endl;
0188 std::cout << "----------------------------------" << std::endl;
0189 SiStripLatency latency2;
0190 latencyIndexes.push_back(3);
0191 latencyIndexes.push_back(5);
0192 latencyIndexes.push_back(10);
0193 latencyIndexes.push_back(11);
0194 latencies.clear();
0195 modeIndexes.push_back(4);
0196 modes.clear();
0197 test(detIdAndApvs, latencyIndexes, latencies, modeIndexes, modes, latency2);
0198 std::cout << std::endl;
0199 std::cout << "Filling complete, starting check" << std::endl;
0200 std::cout << std::endl;
0201 check(latencies, modes, detIdAndApvs, latency2);
0202
0203
0204
0205 std::cout << "Checking the method to retrieve all the unique combinations of latency and mode" << std::endl;
0206 SiStripLatency latency3;
0207 latency3.put(1, 0, 14, 37);
0208 latency3.put(2, 0, 14, 37);
0209 latency3.put(3, 0, 15, 37);
0210 latency3.put(4, 0, 15, 47);
0211 std::cout << "Stored three combinations of latency and mode: (14, 37), (15, 37) and (15, 47)" << std::endl;
0212
0213 std::vector<SiStripLatency::Latency> uniqueLatenciesAndModes(latency3.allUniqueLatencyAndModes());
0214 std::vector<SiStripLatency::Latency>::const_iterator it = uniqueLatenciesAndModes.begin();
0215 std::cout << "Reading back what is returned by the allUniqueLatencyAndModes method" << std::endl;
0216 for (; it != uniqueLatenciesAndModes.end(); ++it) {
0217 std::cout << "latency = " << int(it->latency) << ", mode = " << int(it->mode) << std::endl;
0218 }
0219 if (uniqueLatenciesAndModes.size() == 3) {
0220 std::cout << "Test passed" << std::endl;
0221 } else {
0222 std::cout << "ERROR: test not passed" << std::endl;
0223 }
0224
0225
0226 std::cout << "Checking the case with different modes, but same Read-out mode." << std::endl;
0227 SiStripLatency latency4;
0228 latency4.put(1, 0, 14, 37);
0229 latency4.put(2, 0, 14, 36);
0230 latency4.put(3, 0, 14, 37);
0231 latency4.put(4, 0, 14, 36);
0232 std::cout << "Stored two combinations of latency and mode: (14, 37), (14, 36)" << std::endl;
0233 std::cout << "The Read-out mode is the same and is deconvolution" << std::endl;
0234
0235 if (latency4.singleReadOutMode() == 0) {
0236 std::cout << "Test passed" << std::endl;
0237 } else {
0238 std::cout << "ERROR: test not passed" << std::endl;
0239 }
0240
0241 SiStripLatency latency5;
0242 latency5.put(1, 0, 14, 47);
0243 latency5.put(2, 0, 14, 46);
0244 latency5.put(3, 0, 14, 47);
0245 latency5.put(4, 0, 14, 46);
0246 std::cout << "Stored two combinations of latency and mode: (14, 47), (14, 46)" << std::endl;
0247 std::cout << "The Read-out mode is the same and is peak" << std::endl;
0248
0249 if (latency5.singleReadOutMode() == 1) {
0250 std::cout << "Test passed" << std::endl;
0251 } else {
0252 std::cout << "ERROR: test not passed" << std::endl;
0253 }
0254
0255 SiStripLatency latency6;
0256 latency6.put(1, 0, 14, 47);
0257 latency6.put(2, 0, 14, 46);
0258 latency6.put(3, 0, 14, 37);
0259 latency6.put(4, 0, 14, 36);
0260 std::cout << "Stored four combinations of latency and mode: (14, 47), (14, 46), (14, 37), (14, 36)" << std::endl;
0261 std::cout << "The Read-out mode is mixed" << std::endl;
0262
0263 if (latency6.singleReadOutMode() == -1) {
0264 std::cout << "Test passed" << std::endl;
0265 } else {
0266 std::cout << "ERROR: test not passed" << std::endl;
0267 }
0268
0269 return 0;
0270 }