9 #define MAXFEDCOARSE 15
11 using namespace sistrip;
28 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
29 <<
" Constructing object...";
36 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
37 <<
" Destructing object...";
46 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
47 <<
" NULL pointer to SiStripConfigDb interface!"
48 <<
" Aborting upload...";
58 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
59 <<
" Found invalid PLL settings (coarse > 15)"
60 <<
" Aborting update to database...";
67 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
68 <<
" Uploading APV settings to DB...";
71 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
72 <<
" Upload of APV settings to DB finished!";
75 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
76 <<
" Uploading FED delays to DB...";
79 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
80 <<
" Upload of FED delays to DB finished!";
83 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
84 <<
" TEST only! No APV settings will be uploaded to DB...";
97 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
98 <<
" Updated NO Latency settings. No analysis result available !" ;
103 uint16_t minCoarseDelay = 256;
104 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
105 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
107 if ( (*idevice)->getDeviceType() == PLL ) {
109 pllDescription* desc =
dynamic_cast<pllDescription*
>( *idevice );
117 int delayCoarse = desc->getDelayCoarse();
118 minCoarseDelay = minCoarseDelay < delayCoarse ? minCoarseDelay : delayCoarse;
126 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
128 anal = dynamic_cast<SamplingAnalysis*>( it->second );
130 if(!anal)
return false;
131 uint16_t globalLatency = uint16_t(ceil(anal->
maximum()/(-25.)));
132 float globalShift = anal->
maximum()-(globalLatency*(-25));
135 uint16_t latency = globalLatency;
136 float shift[5] = {0.};
138 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
140 anal = dynamic_cast<SamplingAnalysis*>( it->second );
141 latency = uint16_t(ceil(anal->
maximum()/(-25.)))>latency ? uint16_t(ceil(anal->
maximum()/(-25.))) : latency;
144 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
146 anal = dynamic_cast<SamplingAnalysis*>( it->second );
150 latency = globalLatency;
151 for(
int i=0;
i<5;
i++) shift[
i] = globalShift;
156 latency -= minCoarseDelay;
159 uint16_t updatedAPV = 0;
160 uint16_t updatedPLL = 0;
161 std::vector<SiStripFecKey>
invalid;
162 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
164 if ( (*idevice)->getDeviceType() != APV25 ) {
continue; }
166 apvDescription* desc =
dynamic_cast<apvDescription*
>( *idevice );
167 if ( !desc ) {
continue; }
171 std::stringstream
ss;
172 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
173 <<
" Updating latency APV settings for crate/FEC/slot/ring/CCU/i2cAddr "
181 <<
static_cast<uint16_t
>(desc->getLatency());
182 desc->setLatency(latency);
184 <<
static_cast<uint16_t
>(desc->getLatency());
190 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
192 if ( (*idevice)->getDeviceType() != PLL ) {
continue; }
194 pllDescription* desc =
dynamic_cast<pllDescription*
>( *idevice );
195 if ( !desc ) {
continue; }
196 if ( desc->getDelayCoarse() >= 15 ) {
continue; }
208 float delay = desc->getDelayCoarse()*25+desc->getDelayFine()*25./24. + shift[addr.
fecCrate_];
209 int delayCoarse = int(delay/25);
210 int delayFine = int(round((delay-25*delayCoarse)*24./25.));
211 if(delayFine==24) { delayFine=0; ++delayCoarse; }
212 delayCoarse -= minCoarseDelay;
214 if ( delayCoarse > 15 ) { invalid.push_back(fec_key); delayCoarse =
sistrip::invalid_; }
218 std::stringstream
ss;
219 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
220 <<
" Updating coarse/fine PLL settings"
221 <<
" for Crate/FEC/slot/ring/CCU "
228 <<
static_cast<uint16_t
>( desc->getDelayCoarse() ) <<
"/"
229 << static_cast<uint16_t>( desc->getDelayFine() );
230 desc->setDelayCoarse(delayCoarse);
231 desc->setDelayFine(delayFine);
234 <<
static_cast<uint16_t
>( desc->getDelayCoarse() ) <<
"/"
235 << static_cast<uint16_t>( desc->getDelayFine() );
244 uint16_t minDelay = 256;
245 uint16_t maxDelay = 0;
246 uint16_t fedDelayCoarse = 0;
247 for (
auto ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
249 if (
find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) {
continue; }
252 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
256 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
258 fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
260 minDelay = minDelay<fedDelayCoarse ? minDelay : fedDelayCoarse;
261 maxDelay = maxDelay>fedDelayCoarse ? maxDelay : fedDelayCoarse;
266 int offset = (10-minDelay)*25;
270 for ( SiStripConfigDb::FedDescriptionsV::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
272 if (
find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) {
continue; }
275 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
279 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
281 int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
282 int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
285 int fedDelay = int(fedDelayCoarse*25. - fedDelayFine*24./25. - round(shift[iconn->fecCrate()]) + offset);
286 fedDelayCoarse = (fedDelay/25)+1;
287 fedDelayFine = fedDelayCoarse*25-fedDelay;
288 if(fedDelayFine==25) { fedDelayFine = 0; --fedDelayCoarse; }
290 std::stringstream
ss;
291 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
292 <<
" Updating the FED delay"
293 <<
" for loop FED id/ch "
294 << (*ifed)->getFedId() <<
"/" << iconn->fedCh()
296 << (*ifed)->getCoarseDelay( fedChannel) <<
"/" << (*ifed)->getFineDelay( fedChannel)
298 (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
299 ss << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay( fedChannel);
306 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
307 <<
" Updated FED delays for " << ids.size() <<
" FEDs!";
310 if ( !invalid.empty() ) {
311 std::stringstream
ss;
312 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
313 <<
" Found PLL coarse setting of 15"
314 <<
" (not allowed!) for following channels"
315 <<
" (Crate/FEC/slot/ring/CCU/LLD): ";
316 std::vector<SiStripFecKey>::iterator ikey = invalid.begin();
317 std::vector<SiStripFecKey>::iterator jkey = invalid.end();
318 for ( ; ikey != jkey; ++ikey ) {
319 ss << ikey->fecCrate() <<
"/"
320 << ikey->fecSlot() <<
"/"
321 << ikey->fecRing() <<
"/"
322 << ikey->ccuAddr() <<
"/"
323 << ikey->ccuChan() <<
", ";
331 <<
"[LatencyHistosUsingDb::" << __func__ <<
"] "
332 <<
"Updated settings for " << updatedAPV <<
" APV devices and " << updatedPLL <<
" PLL devices.";
342 if ( !anal ) {
return; }
347 uint16_t latency =
static_cast<uint16_t
>( ( anal->
maximum() / (-25.) ) + 0.5 );
349 ApvLatencyAnalysisDescription*
tmp;
350 tmp =
new ApvLatencyAnalysisDescription( latency,
357 db()->dbParams().partitions().
begin()->
second.partitionName(),
367 typedef std::vector<std::string>
Strings;
369 Strings::const_iterator istr = errors.begin();
370 Strings::const_iterator jstr = errors.end();
371 for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
374 desc.push_back( tmp );
virtual void uploadConfigurations()
T getParameter(std::string const &) const
Analysis for latency run.
const uint32_t & fedKey() const
Analyses::iterator Analysis
const uint16_t & fecRing() const
A container class for generic run and event-related info, information required by the commissioning a...
virtual void configure(const edm::ParameterSet &, const edm::EventSetup &)
const edm::ParameterSet & pset() const
virtual bool isValid() const
FedDescriptionsRange getFedDescriptions(std::string partition="")
bool update(SiStripConfigDb::DeviceDescriptionsRange, SiStripConfigDb::FedDescriptionsRange)
FedDescriptions::range FedDescriptionsRange
static const char mlDqmClient_[]
const uint16_t & fecSlot() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const uint32_t & key() const
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
U second(std::pair< T, U > const &p)
const_iterator_range partitions() const
LatencyHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const )
FedsConstIterRange fedIds() const
DeviceDescriptions::range DeviceDescriptionsRange
An interface class to the DeviceFactory.
bool doUploadConf() const
const uint32_t & fecKey() const
virtual ~LatencyHistosUsingDb()
DeviceAddress deviceAddress(const deviceDescription &)
const uint16_t & fecCrate() const
const SiStripDbParams & dbParams() const
void uploadFedDescriptions(std::string partition="")
const uint16_t & ccuAddr() const
static const uint16_t invalid_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
std::vector< std::vector< double > > tmp
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static unsigned int const shift
const uint16_t & ccuChan() const
const float & maximum() const
SiStripConfigDb *const db() const
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const
tuple size
Write out results.