10 #define MAXFEDCOARSE 15
12 using namespace sistrip;
29 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
30 <<
" Constructing object...";
37 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
38 <<
" Destructing object...";
47 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
48 <<
" NULL pointer to SiStripConfigDb interface!"
49 <<
" Aborting upload...";
59 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
60 <<
" Found invalid PLL settings (coarse > 15)"
61 <<
" Aborting update to database...";
68 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
69 <<
" Uploading APV settings to DB...";
72 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
73 <<
" Upload of APV settings to DB finished!";
76 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
77 <<
" Uploading FED delays to DB...";
80 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
81 <<
" Upload of FED delays to DB finished!";
84 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
85 <<
" TEST only! No APV settings will be uploaded to DB...";
98 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
99 <<
" Updated NO Latency settings. No analysis result available !" ;
104 uint16_t minCoarseDelay = 256;
105 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
106 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
108 if ( (*idevice)->getDeviceType() == PLL ) {
110 pllDescription* desc =
dynamic_cast<pllDescription*
>( *idevice );
118 int delayCoarse = desc->getDelayCoarse();
119 minCoarseDelay = minCoarseDelay < delayCoarse ? minCoarseDelay : delayCoarse;
127 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
129 anal = dynamic_cast<SamplingAnalysis*>( it->second );
131 if(!anal)
return false;
132 uint16_t globalLatency = uint16_t(ceil(anal->
maximum()/(-25.)));
133 float globalShift = anal->
maximum()-(globalLatency*(-25));
136 uint16_t latency = globalLatency;
137 float shift[5] = {0.};
139 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
141 anal = dynamic_cast<SamplingAnalysis*>( it->second );
142 latency = uint16_t(ceil(anal->
maximum()/(-25.)))>latency ? uint16_t(ceil(anal->
maximum()/(-25.))) : latency;
145 if(dynamic_cast<SamplingAnalysis*>( it->second ) &&
147 anal = dynamic_cast<SamplingAnalysis*>( it->second );
151 latency = globalLatency;
152 for(
int i=0;
i<5;
i++) shift[
i] = globalShift;
157 latency -= minCoarseDelay;
160 uint16_t updatedAPV = 0;
161 uint16_t updatedPLL = 0;
162 std::vector<SiStripFecKey>
invalid;
163 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
165 if ( (*idevice)->getDeviceType() != APV25 ) {
continue; }
167 apvDescription* desc =
dynamic_cast<apvDescription*
>( *idevice );
168 if ( !desc ) {
continue; }
172 std::stringstream ss;
173 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
174 <<
" Updating latency APV settings for crate/FEC/slot/ring/CCU/i2cAddr "
182 <<
static_cast<uint16_t
>(desc->getLatency());
183 desc->setLatency(latency);
185 <<
static_cast<uint16_t
>(desc->getLatency());
191 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
193 if ( (*idevice)->getDeviceType() != PLL ) {
continue; }
195 pllDescription* desc =
dynamic_cast<pllDescription*
>( *idevice );
196 if ( !desc ) {
continue; }
197 if ( desc->getDelayCoarse() >= 15 ) {
continue; }
209 float delay = desc->getDelayCoarse()*25+desc->getDelayFine()*25./24. + shift[addr.
fecCrate_];
210 int delayCoarse = int(delay/25);
211 int delayFine = int(round((delay-25*delayCoarse)*24./25.));
212 if(delayFine==24) { delayFine=0; ++delayCoarse; }
213 delayCoarse -= minCoarseDelay;
215 if ( delayCoarse > 15 ) { invalid.push_back(fec_key); delayCoarse =
sistrip::invalid_; }
219 std::stringstream ss;
220 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
221 <<
" Updating coarse/fine PLL settings"
222 <<
" for Crate/FEC/slot/ring/CCU "
229 <<
static_cast<uint16_t
>( desc->getDelayCoarse() ) <<
"/"
230 << static_cast<uint16_t>( desc->getDelayFine() );
231 desc->setDelayCoarse(delayCoarse);
232 desc->setDelayFine(delayFine);
235 <<
static_cast<uint16_t
>( desc->getDelayCoarse() ) <<
"/"
236 << static_cast<uint16_t>( desc->getDelayFine() );
245 uint16_t minDelay = 256;
246 uint16_t maxDelay = 0;
247 uint16_t fedDelayCoarse = 0;
248 for ( SiStripConfigDb::FedDescriptionsV::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
250 if (
find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) {
continue; }
251 const std::vector<FedChannelConnection>& conns =
cabling()->
connections((*ifed)->getFedId());
253 for ( std::vector<FedChannelConnection>::const_iterator iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
257 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
259 fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
261 minDelay = minDelay<fedDelayCoarse ? minDelay : fedDelayCoarse;
262 maxDelay = maxDelay>fedDelayCoarse ? maxDelay : fedDelayCoarse;
267 int offset = (10-minDelay)*25;
271 for ( SiStripConfigDb::FedDescriptionsV::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
273 if (
find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) {
continue; }
274 const std::vector<FedChannelConnection>& conns =
cabling()->
connections((*ifed)->getFedId());
276 for ( std::vector<FedChannelConnection>::const_iterator iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
280 Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
282 int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
283 int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
286 int fedDelay = int(fedDelayCoarse*25. - fedDelayFine*24./25. - round(shift[iconn->fecCrate()]) + offset);
287 fedDelayCoarse = (fedDelay/25)+1;
288 fedDelayFine = fedDelayCoarse*25-fedDelay;
289 if(fedDelayFine==25) { fedDelayFine = 0; --fedDelayCoarse; }
291 std::stringstream ss;
292 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
293 <<
" Updating the FED delay"
294 <<
" for loop FED id/ch "
295 << (*ifed)->getFedId() <<
"/" << iconn->fedCh()
297 << (*ifed)->getCoarseDelay( fedChannel) <<
"/" << (*ifed)->getFineDelay( fedChannel)
299 (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
300 ss << (*ifed)->getCoarseDelay(fedChannel) <<
"/" << (*ifed)->getFineDelay( fedChannel);
307 <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
308 <<
" Updated FED delays for " << ids.size() <<
" FEDs!";
311 if ( !invalid.empty() ) {
312 std::stringstream ss;
313 ss <<
"[LatencyHistosUsingDb::" << __func__ <<
"]"
314 <<
" Found PLL coarse setting of 15"
315 <<
" (not allowed!) for following channels"
316 <<
" (Crate/FEC/slot/ring/CCU/LLD): ";
317 std::vector<SiStripFecKey>::iterator ikey = invalid.begin();
318 std::vector<SiStripFecKey>::iterator jkey = invalid.end();
319 for ( ; ikey != jkey; ++ikey ) {
320 ss << ikey->fecCrate() <<
"/"
321 << ikey->fecSlot() <<
"/"
322 << ikey->fecRing() <<
"/"
323 << ikey->ccuAddr() <<
"/"
324 << ikey->ccuChan() <<
", ";
332 <<
"[LatencyHistosUsingDb::" << __func__ <<
"] "
333 <<
"Updated settings for " << updatedAPV <<
" APV devices and " << updatedPLL <<
" PLL devices.";
343 if ( !anal ) {
return; }
348 uint16_t latency =
static_cast<uint16_t
>( ( anal->
maximum() / (-25.) ) + 0.5 );
350 ApvLatencyAnalysisDescription*
tmp;
351 tmp =
new ApvLatencyAnalysisDescription( latency,
358 db()->dbParams().partitions().
begin()->
second.partitionName(),
368 typedef std::vector<std::string>
Strings;
370 Strings::const_iterator istr = errors.begin();
371 Strings::const_iterator jstr = errors.end();
372 for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
375 desc.push_back( tmp );
virtual void uploadConfigurations()
T getParameter(std::string const &) const
Analysis for latency run.
const std::vector< uint16_t > & feds() const
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 )
DeviceDescriptions::range DeviceDescriptionsRange
An interface class to the DeviceFactory.
bool doUploadConf() const
const uint32_t & fecKey() const
virtual ~LatencyHistosUsingDb()
DeviceAddress deviceAddress(const deviceDescription &)
unsigned int offset(bool)
const uint16_t & fecCrate() const
const SiStripDbParams & dbParams() const
void uploadFedDescriptions(std::string partition="")
const uint16_t & ccuAddr() const
static const uint16_t invalid_
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.
const std::vector< FedChannelConnection > & connections(uint16_t fed_id) const