9 #define MAXFEDCOARSE 15
23 <<
" Constructing object...";
30 <<
" Destructing object...";
38 <<
" NULL pointer to SiStripConfigDb interface!"
39 <<
" Aborting upload...";
49 <<
" Found invalid PLL settings (coarse > 15)"
50 <<
" Aborting update to database...";
57 <<
" Uploading APV settings to DB...";
60 <<
" Upload of APV settings to DB finished!";
63 <<
" Uploading FED delays to DB...";
66 <<
" Upload of FED delays to DB finished!";
69 <<
" TEST only! No APV settings will be uploaded to DB...";
80 <<
" Updated NO Latency settings. No analysis result available !";
85 uint16_t minCoarseDelay = 256;
86 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
87 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
89 if ((*idevice)->getDeviceType() == PLL) {
91 pllDescription*
desc = dynamic_cast<pllDescription*>(*idevice);
99 int delayCoarse =
desc->getDelayCoarse();
100 minCoarseDelay = minCoarseDelay < delayCoarse ? minCoarseDelay : delayCoarse;
108 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
109 dynamic_cast<SamplingAnalysis*>(it->second)->granularity() ==
sistrip::TRACKER)
110 anal = dynamic_cast<SamplingAnalysis*>(it->second);
114 uint16_t globalLatency = uint16_t(
ceil(
anal->maximum() / (-25.)));
115 float globalShift =
anal->maximum() - (globalLatency * (-25));
118 uint16_t
latency = globalLatency;
119 float shift[5] = {0.};
121 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
123 anal = dynamic_cast<SamplingAnalysis*>(it->second);
128 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
130 anal = dynamic_cast<SamplingAnalysis*>(it->second);
136 for (
int i = 0;
i < 5;
i++)
145 uint16_t updatedAPV = 0;
146 uint16_t updatedPLL = 0;
147 std::vector<SiStripFecKey>
invalid;
148 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
150 if ((*idevice)->getDeviceType() != APV25) {
154 apvDescription*
desc = dynamic_cast<apvDescription*>(*idevice);
161 std::stringstream
ss;
162 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
163 <<
" Updating latency APV settings for crate/FEC/slot/ring/CCU/i2cAddr " <<
addr.fecCrate_ <<
"/"
164 <<
addr.fecSlot_ <<
"/" <<
addr.fecRing_ <<
"/" <<
addr.ccuAddr_ <<
"/" <<
addr.ccuChan_ <<
"/" <<
addr.i2cAddr_
165 <<
" from " << static_cast<uint16_t>(
desc->getLatency());
167 ss <<
" to " << static_cast<uint16_t>(
desc->getLatency());
173 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
175 if ((*idevice)->getDeviceType() != PLL) {
179 pllDescription*
desc = dynamic_cast<pllDescription*>(*idevice);
183 if (
desc->getDelayCoarse() >= 15) {
195 int delayFine =
int(round((
delay - 25 * delayCoarse) * 24. / 25.));
196 if (delayFine == 24) {
200 delayCoarse -= minCoarseDelay;
202 if (delayCoarse > 15) {
208 std::stringstream
ss;
209 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
210 <<
" Updating coarse/fine PLL settings"
211 <<
" for Crate/FEC/slot/ring/CCU " << fec_path.
fecCrate() <<
"/" << fec_path.
fecSlot() <<
"/"
213 << static_cast<uint16_t>(
desc->getDelayCoarse()) <<
"/" << static_cast<uint16_t>(
desc->getDelayFine());
214 desc->setDelayCoarse(delayCoarse);
215 desc->setDelayFine(delayFine);
217 ss <<
" to " << static_cast<uint16_t>(
desc->getDelayCoarse()) <<
"/"
218 << static_cast<uint16_t>(
desc->getDelayFine());
227 uint16_t minDelay = 256;
228 uint16_t maxDelay = 0;
229 uint16_t fedDelayCoarse = 0;
230 for (
auto ifed =
feds.begin(); ifed !=
feds.end(); ifed++) {
232 if (
find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
237 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
242 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
244 fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
246 minDelay = minDelay < fedDelayCoarse ? minDelay : fedDelayCoarse;
247 maxDelay = maxDelay > fedDelayCoarse ? maxDelay : fedDelayCoarse;
252 int offset = (10 - minDelay) * 25;
257 for (SiStripConfigDb::FedDescriptionsV::const_iterator ifed =
feds.begin(); ifed !=
feds.end(); ifed++) {
259 if (
find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
264 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
269 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
271 int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
272 int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
275 int fedDelay =
int(fedDelayCoarse * 25. - fedDelayFine * 24. / 25. - round(
shift[iconn->fecCrate()]) +
offset);
276 fedDelayCoarse = (fedDelay / 25) + 1;
277 fedDelayFine = fedDelayCoarse * 25 - fedDelay;
278 if (fedDelayFine == 25) {
283 std::stringstream
ss;
284 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
285 <<
" Updating the FED delay"
286 <<
" for loop FED id/ch " << (*ifed)->getFedId() <<
"/" << iconn->fedCh() <<
" from "
287 << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay(fedChannel) <<
" to ";
288 (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
289 ss << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay(fedChannel);
296 <<
" Updated FED delays for " << ids.size() <<
" FEDs!";
300 std::stringstream
ss;
301 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
302 <<
" Found PLL coarse setting of 15"
303 <<
" (not allowed!) for following channels"
304 <<
" (Crate/FEC/slot/ring/CCU/LLD): ";
305 std::vector<SiStripFecKey>::iterator ikey =
invalid.begin();
306 std::vector<SiStripFecKey>::iterator jkey =
invalid.end();
307 for (; ikey != jkey; ++ikey) {
308 ss << ikey->fecCrate() <<
"/" << ikey->fecSlot() <<
"/" << ikey->fecRing() <<
"/" << ikey->ccuAddr() <<
"/"
309 << ikey->ccuChan() <<
", ";
317 <<
"Updated settings for " << updatedAPV <<
" APV devices and " << updatedPLL
333 uint16_t
latency = static_cast<uint16_t>((
anal->maximum() / (-25.)) + 0.5);
335 ApvLatencyAnalysisDescription*
tmp;
336 tmp =
new ApvLatencyAnalysisDescription(
latency,
353 typedef std::vector<std::string>
Strings;
355 Strings::const_iterator istr =
errors.begin();
356 Strings::const_iterator jstr =
errors.end();
357 for (; istr != jstr; ++istr) {
358 tmp->addComments(*istr);