CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ApvTimingHistosUsingDb.cc
Go to the documentation of this file.
1 // Last commit: $Id: ApvTimingHistosUsingDb.cc,v 1.31 2010/04/21 14:26:25 dstrom Exp $
2 
9 #include <iostream>
10 
11 using namespace sistrip;
12 
13 // -----------------------------------------------------------------------------
16  DQMStore* bei,
17  SiStripConfigDb* const db )
18  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("ApvTimingParameters"),
19  bei,
20  sistrip::APV_TIMING ),
22  sistrip::APV_TIMING ),
23  ApvTimingHistograms( pset.getParameter<edm::ParameterSet>("ApvTimingParameters"),
24  bei )
25 {
27  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
28  << " Constructing object...";
29  skipFecUpdate_ = this->pset().getParameter<bool>("SkipFecUpdate");
30  skipFedUpdate_ = this->pset().getParameter<bool>("SkipFedUpdate");
31  if (skipFecUpdate_)
33  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
34  << " Skipping update of FEC parameters.";
35  if (skipFedUpdate_)
37  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
38  << " Skipping update of FED parameters.";
39 }
40 
41 // -----------------------------------------------------------------------------
45  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
46  << " Destructing object...";
47 }
48 
49 // -----------------------------------------------------------------------------
53  << "[ApvTimingHistosUsingDb::" << __func__ << "]";
54 
55  if ( !db() ) {
57  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
58  << " NULL pointer to SiStripConfigDb interface!"
59  << " Aborting upload...";
60  return;
61  }
62 
63  if ( !skipFecUpdate_ ) {
64 
65  // Retrieve and update PLL device descriptions
67  bool upload = update( devices );
68 
69  // Check if new PLL settings are valid
70  if ( !upload ) {
72  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
73  << " Found invalid PLL settings (coarse > 15)"
74  << " Aborting update to database...";
75  return;
76  }
77 
78  // Upload PLL device descriptions
79  if ( doUploadConf() ) {
81  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
82  << " Uploading PLL settings to DB...";
85  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
86  << " Upload of PLL settings to DB finished!";
87  } else {
89  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
90  << " TEST only! No PLL settings will be uploaded to DB...";
91  }
92 
93  } else {
95  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
96  << " No upload of PLL settings to DB, as defined by .cfg file!";
97  }
98 
99  if ( !skipFedUpdate_ ) {
100 
101  // Update FED descriptions with new ticker thresholds
103  update( feds );
104 
105  // Update FED descriptions with new ticker thresholds
106  if ( doUploadConf() ) {
108  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
109  << " Uploading FED ticker thresholds to DB...";
112  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
113  << " Upload of FED ticker thresholds to DB finished!";
114  } else {
116  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
117  << " TEST only! No FED ticker thresholds will be uploaded to DB...";
118  }
119 
120  } else {
122  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
123  << " No Upload of FED ticker thresholds to DB, as defined by .cfg file!";
124  }
125 
126 }
127 
128 // -----------------------------------------------------------------------------
131 
132  // Iterate through devices and update device descriptions
133  uint16_t updated = 0;
134  std::vector<SiStripFecKey> invalid;
135  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
136 
137  for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
138 
139  // Check device type
140  if ( (*idevice)->getDeviceType() != PLL ) { continue; }
141 
142  // Cast to retrieve appropriate description object
143  pllDescription* desc = dynamic_cast<pllDescription*>( *idevice );
144  if ( !desc ) { continue; }
145 
146  // Retrieve device addresses from device description
147  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
148  SiStripFecKey fec_path;
149 
150  // PLL delay settings
151  uint32_t coarse = sistrip::invalid_;
152  uint32_t fine = sistrip::invalid_;
153 
154  // Iterate through LLD channels
155  for ( uint16_t ichan = 0; ichan < sistrip::CHANS_PER_LLD; ichan++ ) {
156 
157  // Construct key from device description
158  SiStripFecKey fec_key( addr.fecCrate_,
159  addr.fecSlot_,
160  addr.fecRing_,
161  addr.ccuAddr_,
162  addr.ccuChan_,
163  ichan+1 );
164  fec_path = fec_key;
165 
166  // Locate appropriate analysis object
167  Analyses::const_iterator iter = data().find( fec_key.key() );
168  if ( iter != data().end() ) {
169 
170  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( iter->second );
171  if ( !anal ) {
173  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
174  << " NULL pointer to analysis object!";
175  continue;
176  }
177 
178  // Calculate coarse and fine delays
179  int32_t delay = static_cast<int32_t>( rint( anal->delay() )*24./25 );
180  // first set course delay
181  coarse = static_cast<uint16_t>( desc->getDelayCoarse() + (delay/24) )
182  + ( static_cast<uint16_t>( desc->getDelayFine() ) + (delay%24) ) / 24;
183  delay = delay % 24; // only bother with fine delay now
184  if ( ( static_cast<uint16_t>( desc->getDelayFine() ) + delay ) % 24 < 0 ) {
185  coarse -= 1;
186  delay += 24;
187  }
188  fine = ( static_cast<uint16_t>( desc->getDelayFine() ) + delay ) % 24;
189 
190  // Record PPLs maximum coarse setting
191  if ( coarse > 15 ) { invalid.push_back(fec_key); }
192 
193  } else {
194  if ( deviceIsPresent(fec_key) ) {
196  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
197  << " Unable to find FEC key with params crate/FEC/ring/CCU/module/LLD: "
198  << fec_key.fecCrate() << "/"
199  << fec_key.fecSlot() << "/"
200  << fec_key.fecRing() << "/"
201  << fec_key.ccuAddr() << "/"
202  << fec_key.ccuChan() << "/"
203  << fec_key.channel();
204  }
205  }
206 
207  // Exit LLD channel loop if coarse and fine delays are known
208  if ( coarse != sistrip::invalid_ &&
209  fine != sistrip::invalid_ ) { break; }
210 
211  } // lld channel loop
212 
213  // Update PLL settings
214  if ( coarse != sistrip::invalid_ &&
215  fine != sistrip::invalid_ ) {
216 
217  std::stringstream ss;
218  if ( edm::isDebugEnabled() ) {
219  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
220  << " Updating coarse/fine PLL settings"
221  << " for crate/FEC/ring/CCU/module "
222  << fec_path.fecCrate() << "/"
223  << fec_path.fecSlot() << "/"
224  << fec_path.fecRing() << "/"
225  << fec_path.ccuAddr() << "/"
226  << fec_path.ccuChan()
227  << " from "
228  << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
229  << static_cast<uint16_t>( desc->getDelayFine() );
230  }
231  desc->setDelayCoarse(coarse);
232  desc->setDelayFine(fine);
233  updated++;
234  if ( edm::isDebugEnabled() ) {
235  ss << " to "
236  << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
237  << static_cast<uint16_t>( desc->getDelayFine() );
238  LogTrace(mlDqmClient_) << ss.str();
239  }
240 
241  } else {
243  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
244  << " Invalid PLL delay settings course/fine = "
245  << coarse << "/" << fine
246  << " for crate/FEC/ring/CCU/module "
247  << fec_path.fecCrate() << "/"
248  << fec_path.fecSlot() << "/"
249  << fec_path.fecRing() << "/"
250  << fec_path.ccuAddr() << "/"
251  << fec_path.ccuChan();
252  }
253 
254  }
255 
256  // Check if invalid settings were found
257  if ( !invalid.empty() ) {
258  std::stringstream ss;
259  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
260  << " Found PLL coarse setting of >15"
261  << " (not allowed!) for "
262  << invalid.size()
263  << " channels";
264  ss << " (Example is crate/FEC/ring/CCU/module/LLD: "
265  << invalid.front().fecCrate() << "/"
266  << invalid.front().fecSlot() << "/"
267  << invalid.front().fecRing() << "/"
268  << invalid.front().ccuAddr() << "/"
269  << invalid.front().ccuChan() << "/"
270  << invalid.front().channel();
271  edm::LogWarning(mlDqmClient_) << ss.str();
272  return false;
273  }
274 
276  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
277  << " Updated PLL settings for "
278  << updated << " modules";
279  return true;
280 
281 }
282 
283 // -----------------------------------------------------------------------------
286 
287  // Retrieve FED ids from cabling
288  std::vector<uint16_t> ids = cabling()->feds();
289 
290  // Iterate through feds and update fed descriptions
291  uint16_t updated = 0;
292  SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
293  for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
294 
295  // If FED id not found in list (from cabling), then continue
296  if ( find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) { continue; }
297 
298  for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
299 
300  // Build FED and FEC keys
301  const FedChannelConnection& conn = cabling()->connection( (*ifed)->getFedId(), ichan );
302  if ( conn.fecCrate() == sistrip::invalid_ ||
303  conn.fecSlot() == sistrip::invalid_ ||
304  conn.fecRing() == sistrip::invalid_ ||
305  conn.ccuAddr() == sistrip::invalid_ ||
306  conn.ccuChan() == sistrip::invalid_ ||
307  conn.lldChannel() == sistrip::invalid_ ) { continue; }
308  SiStripFedKey fed_key( conn.fedId(),
309  SiStripFedKey::feUnit( conn.fedCh() ),
310  SiStripFedKey::feChan( conn.fedCh() ) );
311  SiStripFecKey fec_key( conn.fecCrate(),
312  conn.fecSlot(),
313  conn.fecRing(),
314  conn.ccuAddr(),
315  conn.ccuChan(),
316  conn.lldChannel() );
317 
318  // Locate appropriate analysis object
319  Analyses::const_iterator iter = data().find( fec_key.key() );
320  if ( iter != data().end() ) {
321 
322  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( iter->second );
323  if ( !anal ) {
325  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
326  << " NULL pointer to analysis object!";
327  continue;
328  }
329 
330  // Update frame finding threshold
331  Fed9U::Fed9UAddress addr( ichan );
332  uint16_t old_threshold = static_cast<uint16_t>( (*ifed)->getFrameThreshold( addr ) );
333  if ( anal->isValid() ) {
334  (*ifed)->setFrameThreshold( addr, anal->frameFindingThreshold() );
335  updated++;
336  }
337  uint16_t new_threshold = static_cast<uint16_t>( (*ifed)->getFrameThreshold( addr ) );
338 
339  // Debug
340  std::stringstream ss;
341  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]";
342  if ( anal->isValid() ) {
343  ss << " Updating the frame-finding threshold"
344  << " from " << old_threshold
345  << " to " << new_threshold
346  << " using tick mark base/peak/height "
347  << anal->base() << "/"
348  << anal->peak() << "/"
349  << anal->height();
350  } else {
351  ss << " Cannot update the frame-finding threshold"
352  << " from " << old_threshold
353  << " to a new value using invalid analysis ";
354  }
355  ss << " for crate/FEC/ring/CCU/module/LLD "
356  << fec_key.fecCrate() << "/"
357  << fec_key.fecSlot() << "/"
358  << fec_key.fecRing() << "/"
359  << fec_key.ccuAddr() << "/"
360  << fec_key.ccuChan()
361  << fec_key.channel()
362  << " and FED id/ch "
363  << fed_key.fedId() << "/"
364  << fed_key.fedChannel();
365  anal->print(ss);
366  //LogTrace(mlDqmClient_) << ss.str();
367 
368  } else {
369  if ( deviceIsPresent(fec_key) ) {
370  std::stringstream ss;
371  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
372  << " Unable to find analysis object and update ticker thresholds"
373  << " for key/crate/FEC/ring/CCU/module/LLD "
374  << std::hex << std::setw(8) << std::setfill('0') << fec_key.key() << std::dec
375  << fec_key.fecCrate() << "/"
376  << fec_key.fecSlot() << "/"
377  << fec_key.fecRing() << "/"
378  << fec_key.ccuAddr() << "/"
379  << fec_key.ccuChan() << "/"
380  << fec_key.channel()
381  << " and FED key/id/ch "
382  << std::hex << std::setw(8) << std::setfill('0') << fed_key.key() << std::dec
383  << fed_key.fedId() << "/"
384  << fed_key.fedChannel();
385  edm::LogWarning(mlDqmClient_) << ss.str();
386  }
387  }
388  }
389  }
390 
392  << "[ApvTimingHistosUsingDb::" << __func__ << "]"
393  << " Updated ticker thresholds for " << updated
394  << " channels on " << ids.size() << " FEDs!";
395 
396 }
397 
398 // -----------------------------------------------------------------------------
401  Analysis analysis ) {
402 
403  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( analysis->second );
404  if ( !anal ) { return; }
405 
406  SiStripFecKey fec_key( anal->fecKey() );
407  SiStripFedKey fed_key( anal->fedKey() );
408 
409  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
410 
411 // std::stringstream ss;
412 // if ( anal->isValid() ) { ss << " TEST VALID "; }
413 // else { ss << " TEST INVALID "; }
414 // ss << std::hex << anal->fecKey() << std::dec << " "
415 // << anal->base() << " "
416 // << anal->peak() << " "
417 // << anal->height() << " "
418 // << ( anal->base() + anal->height() * ApvTimingAnalysis::frameFindingThreshold_ ) << " "
419 // << anal->frameFindingThreshold();
420 // edm::LogError("TEST") << ss.str();
421 
422  // Create description
423  TimingAnalysisDescription* tmp;
424  tmp = new TimingAnalysisDescription( anal->time(),
425  anal->refTime(),
426  anal->delay(),
427  anal->height(),
428  anal->base(),
429  anal->peak(),
430  anal->frameFindingThreshold(),
431  anal->optimumSamplingPoint(),
433  true, //@@ APV timing analysis (not FED timing)
434  fec_key.fecCrate(),
435  fec_key.fecSlot(),
436  fec_key.fecRing(),
437  fec_key.ccuAddr(),
438  fec_key.ccuChan(),
439  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
440  db()->dbParams().partitions().begin()->second.partitionName(),
441  db()->dbParams().partitions().begin()->second.runNumber(),
442  anal->isValid(),
443  "",
444  fed_key.fedId(),
445  fed_key.feUnit(),
446  fed_key.feChan(),
447  fed_key.fedApv() );
448 
449  // Add comments
450  typedef std::vector<std::string> Strings;
451  Strings errors = anal->getErrorCodes();
452  Strings::const_iterator istr = errors.begin();
453  Strings::const_iterator jstr = errors.end();
454  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
455 
456  // Store description
457  desc.push_back( tmp );
458 
459  }
460 
461 }
const uint16_t & fecSlot() const
T getParameter(std::string const &) const
bool isDebugEnabled()
const uint16_t & fecCrate() const
const std::vector< uint16_t > & feds() const
const uint32_t & fedKey() const
const uint16_t & fecRing() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:57
const uint16_t & fedCh() const
const edm::ParameterSet & pset() const
bool deviceIsPresent(const SiStripFecKey &)
FedDescriptionsRange getFedDescriptions(std::string partition="")
std::vector< std::string > Strings
Definition: MsgTools.h:18
const float & refTime() const
tuple db
Definition: EcalCondDB.py:151
FedDescriptions::range FedDescriptionsRange
static const float tickMarkHeightThreshold_
static const char mlDqmClient_[]
const FedChannelConnection & connection(uint16_t fed_id, uint16_t fed_ch) const
ApvTimingHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const )
const uint16_t & fecSlot() const
const float & optimumSamplingPoint() const
uint16_t lldChannel() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const uint16_t & i2cAddr() const
const uint16_t & fedId() const
bool update(SiStripConfigDb::DeviceDescriptionsRange)
const float & base() const
const uint32_t & key() const
Definition: SiStripKey.h:126
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:46
const_iterator_range partitions() const
const uint16_t & fecRing() const
Class containning control, module, detector and connection information, at the level of a FED channel...
DeviceDescriptions::range DeviceDescriptionsRange
static const uint16_t CHANS_PER_LLD
An interface class to the DeviceFactory.
const uint16_t & ccuChan() const
const uint32_t & fecKey() const
DeviceAddress deviceAddress(const deviceDescription &)
uint16_t fedChannel() const
const float & peak() const
const uint16_t & ccuAddr() const
const float & time() const
#define LogTrace(id)
const float & delay() const
void print(std::stringstream &, uint32_t not_used=0)
const uint16_t & fecCrate() const
uint16_t frameFindingThreshold() const
const uint16_t & feUnit() const
const SiStripDbParams & dbParams() const
const uint16_t & channel() const
Definition: SiStripKey.h:129
void uploadFedDescriptions(std::string partition="")
const uint16_t & ccuAddr() const
static const uint16_t invalid_
Definition: Constants.h:17
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static const uint16_t FEDCH_PER_FED
std::vector< AnalysisDescription * > AnalysisDescriptionsV
const uint16_t & feChan() const
const uint16_t & ccuChan() const
const uint16_t & fedId() const
SiStripConfigDb *const db() const
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
Analysis for timing run using APV tick marks.
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const
const float & height() const
tuple conn
Definition: results_mgr.py:53