9 #define MAXFEDCOARSE 15
20 <<
" Constructing object...";
27 <<
" Destructing object...";
35 <<
" NULL pointer to SiStripConfigDb interface!"
36 <<
" Aborting upload...";
46 <<
" Found invalid PLL settings (coarse > 15)"
47 <<
" Aborting update to database...";
54 <<
" Uploading APV settings to DB...";
57 <<
" Upload of APV settings to DB finished!";
60 <<
" Uploading FED delays to DB...";
63 <<
" Upload of FED delays to DB finished!";
66 <<
" TEST only! No APV settings will be uploaded to DB...";
77 <<
" Updated NO Latency settings. No analysis result available !";
82 uint16_t minCoarseDelay = 256;
83 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
84 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
86 if ((*idevice)->getDeviceType() == PLL) {
88 pllDescription*
desc = dynamic_cast<pllDescription*>(*idevice);
96 int delayCoarse =
desc->getDelayCoarse();
97 minCoarseDelay = minCoarseDelay < delayCoarse ? minCoarseDelay : delayCoarse;
105 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
106 dynamic_cast<SamplingAnalysis*>(it->second)->granularity() ==
sistrip::TRACKER)
107 anal = dynamic_cast<SamplingAnalysis*>(it->second);
111 uint16_t globalLatency = uint16_t(
ceil(
anal->maximum() / (-25.)));
112 float globalShift =
anal->maximum() - (globalLatency * (-25));
115 uint16_t
latency = globalLatency;
116 float shift[5] = {0.};
118 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
120 anal = dynamic_cast<SamplingAnalysis*>(it->second);
125 if (dynamic_cast<SamplingAnalysis*>(it->second) &&
127 anal = dynamic_cast<SamplingAnalysis*>(it->second);
133 for (
int i = 0;
i < 5;
i++)
142 uint16_t updatedAPV = 0;
143 uint16_t updatedPLL = 0;
144 std::vector<SiStripFecKey>
invalid;
145 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
147 if ((*idevice)->getDeviceType() != APV25) {
151 apvDescription*
desc = dynamic_cast<apvDescription*>(*idevice);
158 std::stringstream
ss;
159 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
160 <<
" Updating latency APV settings for crate/FEC/slot/ring/CCU/i2cAddr " <<
addr.fecCrate_ <<
"/"
161 <<
addr.fecSlot_ <<
"/" <<
addr.fecRing_ <<
"/" <<
addr.ccuAddr_ <<
"/" <<
addr.ccuChan_ <<
"/" <<
addr.i2cAddr_
162 <<
" from " << static_cast<uint16_t>(
desc->getLatency());
164 ss <<
" to " << static_cast<uint16_t>(
desc->getLatency());
170 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
172 if ((*idevice)->getDeviceType() != PLL) {
176 pllDescription*
desc = dynamic_cast<pllDescription*>(*idevice);
180 if (
desc->getDelayCoarse() >= 15) {
192 int delayFine =
int(round((
delay - 25 * delayCoarse) * 24. / 25.));
193 if (delayFine == 24) {
197 delayCoarse -= minCoarseDelay;
199 if (delayCoarse > 15) {
205 std::stringstream
ss;
206 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
207 <<
" Updating coarse/fine PLL settings"
208 <<
" for Crate/FEC/slot/ring/CCU " << fec_path.
fecCrate() <<
"/" << fec_path.
fecSlot() <<
"/"
210 << static_cast<uint16_t>(
desc->getDelayCoarse()) <<
"/" << static_cast<uint16_t>(
desc->getDelayFine());
211 desc->setDelayCoarse(delayCoarse);
212 desc->setDelayFine(delayFine);
214 ss <<
" to " << static_cast<uint16_t>(
desc->getDelayCoarse()) <<
"/"
215 << static_cast<uint16_t>(
desc->getDelayFine());
224 uint16_t minDelay = 256;
225 uint16_t maxDelay = 0;
226 uint16_t fedDelayCoarse = 0;
227 for (
auto ifed =
feds.begin(); ifed !=
feds.end(); ifed++) {
229 if (
find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
234 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
239 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
241 fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
243 minDelay = minDelay < fedDelayCoarse ? minDelay : fedDelayCoarse;
244 maxDelay = maxDelay > fedDelayCoarse ? maxDelay : fedDelayCoarse;
249 int offset = (10 - minDelay) * 25;
254 for (SiStripConfigDb::FedDescriptionsV::const_iterator ifed =
feds.begin(); ifed !=
feds.end(); ifed++) {
256 if (
find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
261 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
266 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
268 int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
269 int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
272 int fedDelay =
int(fedDelayCoarse * 25. - fedDelayFine * 24. / 25. - round(
shift[iconn->fecCrate()]) +
offset);
273 fedDelayCoarse = (fedDelay / 25) + 1;
274 fedDelayFine = fedDelayCoarse * 25 - fedDelay;
275 if (fedDelayFine == 25) {
280 std::stringstream
ss;
281 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
282 <<
" Updating the FED delay"
283 <<
" for loop FED id/ch " << (*ifed)->getFedId() <<
"/" << iconn->fedCh() <<
" from "
284 << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay(fedChannel) <<
" to ";
285 (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
286 ss << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay(fedChannel);
293 <<
" Updated FED delays for " << ids.size() <<
" FEDs!";
297 std::stringstream
ss;
298 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
299 <<
" Found PLL coarse setting of 15"
300 <<
" (not allowed!) for following channels"
301 <<
" (Crate/FEC/slot/ring/CCU/LLD): ";
302 std::vector<SiStripFecKey>::iterator ikey =
invalid.begin();
303 std::vector<SiStripFecKey>::iterator jkey =
invalid.end();
304 for (; ikey != jkey; ++ikey) {
305 ss << ikey->fecCrate() <<
"/" << ikey->fecSlot() <<
"/" << ikey->fecRing() <<
"/" << ikey->ccuAddr() <<
"/"
306 << ikey->ccuChan() <<
", ";
314 <<
"Updated settings for " << updatedAPV <<
" APV devices and " << updatedPLL
330 uint16_t
latency = static_cast<uint16_t>((
anal->maximum() / (-25.)) + 0.5);
332 ApvLatencyAnalysisDescription*
tmp;
333 tmp =
new ApvLatencyAnalysisDescription(
latency,
350 typedef std::vector<std::string>
Strings;
352 Strings::const_iterator istr =
errors.begin();
353 Strings::const_iterator jstr =
errors.end();
354 for (; istr != jstr; ++istr) {
355 tmp->addComments(*istr);