CMS 3D CMS Logo

ApvTimingHistosUsingDb.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 
10 using namespace sistrip;
11 
12 // -----------------------------------------------------------------------------
15  DQMStore* bei,
16  SiStripConfigDb* const db,
18  : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("ApvTimingParameters"), bei, sistrip::APV_TIMING),
20  ApvTimingHistograms(pset.getParameter<edm::ParameterSet>("ApvTimingParameters"), bei) {
21  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
22  << " Constructing object...";
23  skipFecUpdate_ = this->pset().getParameter<bool>("SkipFecUpdate");
24  skipFedUpdate_ = this->pset().getParameter<bool>("SkipFedUpdate");
25  if (skipFecUpdate_)
26  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
27  << " Skipping update of FEC parameters.";
28  if (skipFedUpdate_)
29  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
30  << " Skipping update of FED parameters.";
31 
33  this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
35  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
36  << " Enabling selective update of FED parameters.";
37 }
38 
39 // -----------------------------------------------------------------------------
42  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
43  << " Destructing object...";
44 }
45 
46 // -----------------------------------------------------------------------------
49  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]";
50 
51  if (!db()) {
52  edm::LogError(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
53  << " NULL pointer to SiStripConfigDb interface!"
54  << " Aborting upload...";
55  return;
56  }
57 
58  if (!skipFecUpdate_) {
59  // Retrieve and update PLL device descriptions
61  bool upload = update(devices);
62 
63  // Check if new PLL settings are valid
64  if (!upload) {
65  edm::LogError(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
66  << " Found invalid PLL settings (coarse > 15)"
67  << " Aborting update to database...";
68  return;
69  }
70 
71  // Upload PLL device descriptions
72  if (doUploadConf()) {
73  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
74  << " Uploading PLL settings to DB...";
76  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
77  << " Upload of PLL settings to DB finished!";
78  } else {
79  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
80  << " TEST only! No PLL settings will be uploaded to DB...";
81  }
82 
83  } else {
84  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
85  << " No upload of PLL settings to DB, as defined by .cfg file!";
86  }
87 
88  if (!skipFedUpdate_) {
89  // Update FED descriptions with new ticker thresholds
91  update(feds);
92 
93  // Update FED descriptions with new ticker thresholds
94  if (doUploadConf()) {
95  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
96  << " Uploading FED ticker thresholds to DB...";
98  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
99  << " Upload of FED ticker thresholds to DB finished!";
100  } else {
101  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
102  << " TEST only! No FED ticker thresholds will be uploaded to DB...";
103  }
104 
105  } else {
106  LogTrace(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
107  << " No Upload of FED ticker thresholds to DB, as defined by .cfg file!";
108  }
109 }
110 
111 // -----------------------------------------------------------------------------
114  // Iterate through devices and update device descriptions
115  uint16_t updated = 0;
116  std::vector<SiStripFecKey> invalid;
117  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
118 
119  for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
120  // Check device type
121  if ((*idevice)->getDeviceType() != PLL) {
122  continue;
123  }
124 
125  // Cast to retrieve appropriate description object
126  pllDescription* desc = dynamic_cast<pllDescription*>(*idevice);
127  if (!desc) {
128  continue;
129  }
130 
131  // Retrieve device addresses from device description
133  SiStripFecKey fec_path;
134 
135  // PLL delay settings
136  uint32_t coarse = sistrip::invalid_;
137  uint32_t fine = sistrip::invalid_;
138 
139  // Iterate through LLD channels
140  for (uint16_t ichan = 0; ichan < sistrip::CHANS_PER_LLD; ichan++) {
141  // Construct key from device description
142  SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, ichan + 1);
143  fec_path = fec_key;
144 
145  // Locate appropriate analysis object
146  Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
147  if (iter != data(allowSelectiveUpload_).end()) {
148  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(iter->second);
149  if (!anal) {
150  edm::LogError(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
151  << " NULL pointer to analysis object!";
152  continue;
153  }
154 
155  // Calculate coarse and fine delays
156  int32_t delay = static_cast<int32_t>(rint(anal->delay()) * 24. / 25);
157  // first set course delay
158  coarse = static_cast<uint16_t>(desc->getDelayCoarse() + (delay / 24)) +
159  (static_cast<uint16_t>(desc->getDelayFine()) + (delay % 24)) / 24;
160  delay = delay % 24; // only bother with fine delay now
161  if ((static_cast<uint16_t>(desc->getDelayFine()) + delay) % 24 < 0) {
162  coarse -= 1;
163  delay += 24;
164  }
165  fine = (static_cast<uint16_t>(desc->getDelayFine()) + delay) % 24;
166 
167  // Record PPLs maximum coarse setting
168  if (coarse > 15) {
169  invalid.push_back(fec_key);
170  }
171 
172  } else {
173  if (deviceIsPresent(fec_key)) {
174  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
175  << " Unable to find FEC key with params crate/FEC/ring/CCU/module/LLD: "
176  << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
177  << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
178  << fec_key.channel();
179  }
180  }
181 
182  // Exit LLD channel loop if coarse and fine delays are known
183  if (coarse != sistrip::invalid_ && fine != sistrip::invalid_) {
184  break;
185  }
186 
187  } // lld channel loop
188 
189  // Update PLL settings
190  if (coarse != sistrip::invalid_ && fine != sistrip::invalid_) {
191  std::stringstream ss;
192  if (edm::isDebugEnabled()) {
193  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
194  << " Updating coarse/fine PLL settings"
195  << " for crate/FEC/ring/CCU/module " << fec_path.fecCrate() << "/" << fec_path.fecSlot() << "/"
196  << fec_path.fecRing() << "/" << fec_path.ccuAddr() << "/" << fec_path.ccuChan() << " from "
197  << static_cast<uint16_t>(desc->getDelayCoarse()) << "/" << static_cast<uint16_t>(desc->getDelayFine());
198  }
199  desc->setDelayCoarse(coarse);
200  desc->setDelayFine(fine);
201  updated++;
202  if (edm::isDebugEnabled()) {
203  ss << " to " << static_cast<uint16_t>(desc->getDelayCoarse()) << "/"
204  << static_cast<uint16_t>(desc->getDelayFine());
205  LogTrace(mlDqmClient_) << ss.str();
206  }
207 
208  } else {
209  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
210  << " Invalid PLL delay settings course/fine = " << coarse << "/" << fine
211  << " for crate/FEC/ring/CCU/module " << fec_path.fecCrate() << "/"
212  << fec_path.fecSlot() << "/" << fec_path.fecRing() << "/" << fec_path.ccuAddr()
213  << "/" << fec_path.ccuChan();
214  }
215  }
216 
217  // Check if invalid settings were found
218  if (!invalid.empty()) {
219  std::stringstream ss;
220  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
221  << " Found PLL coarse setting of >15"
222  << " (not allowed!) for " << invalid.size() << " channels";
223  ss << " (Example is crate/FEC/ring/CCU/module/LLD: " << invalid.front().fecCrate() << "/"
224  << invalid.front().fecSlot() << "/" << invalid.front().fecRing() << "/" << invalid.front().ccuAddr() << "/"
225  << invalid.front().ccuChan() << "/" << invalid.front().channel();
226  edm::LogWarning(mlDqmClient_) << ss.str();
227  return false;
228  }
229 
230  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
231  << " Updated PLL settings for " << updated << " modules";
232  return true;
233 }
234 
235 // -----------------------------------------------------------------------------
238  // Retrieve FED ids from cabling
239  auto ids = cabling()->fedIds();
240 
241  // Iterate through feds and update fed descriptions
242  uint16_t updated = 0;
243  for (auto ifed = feds.begin(); ifed != feds.end(); ++ifed) {
244  // If FED id not found in list (from cabling), then continue
245  if (find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
246  continue;
247  }
248 
249  for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
250  // Build FED and FEC keys
251  const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
252  if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
253  conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
254  conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_) {
255  continue;
256  }
257  SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
258  SiStripFecKey fec_key(
259  conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
260 
261  // Locate appropriate analysis object
262  Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
263  if (iter != data(allowSelectiveUpload_).end()) {
264  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(iter->second);
265  if (!anal) {
266  edm::LogError(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
267  << " NULL pointer to analysis object!";
268  continue;
269  }
270 
271  // Update frame finding threshold
272  Fed9U::Fed9UAddress addr(ichan);
273  uint16_t old_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
274  if (anal->isValid()) {
275  (*ifed)->setFrameThreshold(addr, anal->frameFindingThreshold());
276  updated++;
277  }
278  uint16_t new_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
279 
280  // Debug
281  std::stringstream ss;
282  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]";
283  if (anal->isValid()) {
284  ss << " Updating the frame-finding threshold"
285  << " from " << old_threshold << " to " << new_threshold << " using tick mark base/peak/height "
286  << anal->base() << "/" << anal->peak() << "/" << anal->height();
287  } else {
288  ss << " Cannot update the frame-finding threshold"
289  << " from " << old_threshold << " to a new value using invalid analysis ";
290  }
291  ss << " for crate/FEC/ring/CCU/module/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
292  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << fec_key.channel()
293  << " and FED id/ch " << fed_key.fedId() << "/" << fed_key.fedChannel();
294  anal->print(ss);
295  //LogTrace(mlDqmClient_) << ss.str();
296 
297  } else {
298  if (deviceIsPresent(fec_key)) {
299  std::stringstream ss;
300  ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
301  << " Unable to find analysis object and update ticker thresholds"
302  << " for key/crate/FEC/ring/CCU/module/LLD " << std::hex << std::setw(8) << std::setfill('0')
303  << fec_key.key() << std::dec << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
304  << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel()
305  << " and FED key/id/ch " << std::hex << std::setw(8) << std::setfill('0') << fed_key.key() << std::dec
306  << fed_key.fedId() << "/" << fed_key.fedChannel();
307  edm::LogWarning(mlDqmClient_) << ss.str();
308  }
309  }
310  }
311  }
312 
313  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistosUsingDb::" << __func__ << "]"
314  << " Updated ticker thresholds for " << updated << " channels on " << ids.size()
315  << " FEDs!";
316 }
317 
318 // -----------------------------------------------------------------------------
321  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(analysis->second);
322  if (!anal) {
323  return;
324  }
325 
326  SiStripFecKey fec_key(anal->fecKey());
327  SiStripFedKey fed_key(anal->fedKey());
328 
329  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
330  // std::stringstream ss;
331  // if ( anal->isValid() ) { ss << " TEST VALID "; }
332  // else { ss << " TEST INVALID "; }
333  // ss << std::hex << anal->fecKey() << std::dec << " "
334  // << anal->base() << " "
335  // << anal->peak() << " "
336  // << anal->height() << " "
337  // << ( anal->base() + anal->height() * ApvTimingAnalysis::frameFindingThreshold_ ) << " "
338  // << anal->frameFindingThreshold();
339  // edm::LogError("TEST") << ss.str();
340 
341  // Create description
342  TimingAnalysisDescription* tmp;
343  tmp = new TimingAnalysisDescription(anal->time(),
344  anal->refTime(),
345  anal->delay(),
346  anal->height(),
347  anal->base(),
348  anal->peak(),
349  anal->frameFindingThreshold(),
350  anal->optimumSamplingPoint(),
352  true, //@@ APV timing analysis (not FED timing)
353  fec_key.fecCrate(),
354  fec_key.fecSlot(),
355  fec_key.fecRing(),
356  fec_key.ccuAddr(),
357  fec_key.ccuChan(),
358  SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
359  db()->dbParams().partitions().begin()->second.partitionName(),
360  db()->dbParams().partitions().begin()->second.runNumber(),
361  anal->isValid(),
362  "",
363  fed_key.fedId(),
364  fed_key.feUnit(),
365  fed_key.feChan(),
366  fed_key.fedApv());
367 
368  // Add comments
369  typedef std::vector<std::string> Strings;
370  Strings errors = anal->getErrorCodes();
371  Strings::const_iterator istr = errors.begin();
372  Strings::const_iterator jstr = errors.end();
373  for (; istr != jstr; ++istr) {
374  tmp->addComments(*istr);
375  }
376 
377  // Store description
378  desc.push_back(tmp);
379  }
380 }
def upload(url, args, files)
const uint16_t & channel() const
Definition: SiStripKey.h:123
Log< level::Info, true > LogVerbatim
bool isDebugEnabled()
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void uploadConfigurations() override
const uint16_t & feChan() const
Analyses & data(bool getMaskedData=false)
const uint16_t & ccuAddr() const
const uint16_t & feUnit() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
bool deviceIsPresent(const SiStripFecKey &)
FedDescriptionsRange getFedDescriptions(std::string partition="")
std::vector< std::string > Strings
Definition: MsgTools.h:18
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
const uint16_t & ccuChan() const
FedDescriptions::range FedDescriptionsRange
static const float tickMarkHeightThreshold_
static const char mlDqmClient_[]
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const_iterator_range partitions() const
sistrip classes
bool update(SiStripConfigDb::DeviceDescriptionsRange)
#define LogTrace(id)
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
ApvTimingHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const, edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken)
uint16_t fedChannel() const
const uint16_t & i2cAddr() const
Class containning control, module, detector and connection information, at the level of a FED channel...
SiStripConfigDb *const db() const
DeviceDescriptions::range DeviceDescriptionsRange
static const uint16_t CHANS_PER_LLD
An interface class to the DeviceFactory.
const uint32_t & key() const
Definition: SiStripKey.h:120
DeviceAddress deviceAddress(const deviceDescription &)
SiStripFedCabling *const cabling() const
const uint16_t & fedId() const
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:16
const uint16_t & fecSlot() const
HLT enums.
static const uint16_t FEDCH_PER_FED
std::vector< AnalysisDescription * > AnalysisDescriptionsV
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:36
conn
Definition: getInfo.py:9
const edm::ParameterSet & pset() const
Definition: errors.py:1
const SiStripDbParams & dbParams() const
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
Log< level::Warning, false > LogWarning
void uploadDeviceDescriptions(std::string partition="")
const uint16_t & fecRing() const
tmp
align.sh
Definition: createJobs.py:716
Analysis for timing run using APV tick marks.
FedsConstIterRange fedIds() const
const uint16_t & fecCrate() const
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override