CMS 3D CMS Logo

DaqScopeModeHistosUsingDb.cc
Go to the documentation of this file.
7 #include <iostream>
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
13  DQMStore* bei,
14  SiStripConfigDb* const db,
17  pset.getParameter<edm::ParameterSet>("DaqScopeModeParameters"), bei, sistrip::DAQ_SCOPE_MODE),
19  DaqScopeModeHistograms(pset.getParameter<edm::ParameterSet>("DaqScopeModeParameters"), bei) {
20  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
21  << " Constructing object...";
22  highThreshold_ = this->pset().getParameter<double>("HighThreshold");
23  lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
24  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
25  << " Set FED zero suppression high/low threshold to " << highThreshold_ << "/"
26  << lowThreshold_;
27  disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
28  keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
29  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
30  << " Disabling strips: " << disableBadStrips_
31  << " ; keeping previously disabled strips: " << keepStripsDisabled_;
33  this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
34  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
35  << " Selective upload of modules set to : " << allowSelectiveUpload_;
36 
38  this->pset().existsAs<bool>("SkipPedestalUpdate") ? this->pset().getParameter<bool>("SkipPedestalUpdate") : false;
40  this->pset().existsAs<bool>("SkipTickUpdate") ? this->pset().getParameter<bool>("SkipTickUpdate") : false;
41  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
42  << " Perform pedestal upload set to : " << skipPedestalUpdate_;
43  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
44  << " Perform tick-mark upload set to : " << skipTickUpdate_;
45 }
46 
47 // -----------------------------------------------------------------------------
49  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
50  << " Destructing object...";
51 }
52 
53 // -----------------------------------------------------------------------------
55  LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]";
56 
57  if (!db()) {
58  edm::LogError(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
59  << " NULL pointer to SiStripConfigDb interface!"
60  << " Aborting upload...";
61  return;
62  }
63 
64  // Update FED descriptions with new peds/noise values as well as tick-marks (no PLL delays, for these ones please use the Timing run
66  update(feds);
67 
68  if (doUploadConf()) {
69  edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
70  << " Uploading FED information to DB...";
72  edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
73  << " Completed database upload of " << feds.size() << " FED descriptions!";
74  } else {
75  edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
76  << " No FED values will be uploaded to DB...";
77  }
78 }
79 
80 // -----------------------------------------------------------------------------
82  // Retrieve FED ids from cabling
83  auto ids = cabling()->fedIds();
84 
85  // Iterate through feds and update fed descriptions
86  uint16_t updated_peds = 0;
87  uint16_t updated_ticks = 0;
88  SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
89  for (ifed = feds.begin(); ifed != feds.end(); ifed++) {
90  // If FED id not found in list (from cabling), then continue
91  if (find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
92  continue;
93  }
94 
95  for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
96  // Build FED and FEC keys
97  const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
98 
99  if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
100  conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
101  conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_) {
102  continue;
103  }
104 
105  SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
106 
107  SiStripFecKey fec_key(
108  conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
109 
110  // Locate appropriate analysis object
111  Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
112 
113  if (iter != data(allowSelectiveUpload_).end()) {
114  // Check if analysis is valid
115  if (!iter->second->isValid()) {
116  edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
117  << " Skipping invalid channel with coordinates: FedKey/Id/Ch: " << hex
118  << setw(8) << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId()
119  << "/" << ichan << " and device with FEC/slot/ring/CCU/LLD "
120  << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
121  << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
122  << fec_key.channel();
123  continue;
124  }
125 
126  DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(iter->second);
127  if (!anal) {
128  edm::LogError(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
129  << " NULL pointer to analysis object!";
130  continue;
131  }
132 
134  if (not skipPedestalUpdate_) {
135  // Determine the pedestal shift to apply
136  uint32_t pedshift = 127;
137  for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
138  uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
139  pedshift = pedmin < pedshift ? pedmin : pedshift;
140  std::stringstream ss;
141  ss << "iapv: " << iapv << " pedsMin()[iapv]: " << anal->pedsMin()[iapv] << " pedmin: " << pedmin
142  << " pedshift: " << pedshift;
143  edm::LogWarning(mlDqmClient_) << ss.str();
144  }
145 
146  // Iterate through APVs and strips
147  for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
148  for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
149  // Patch added by R.B. (I'm back! ;-), requested by J.F. and S.L. (04/11/2010)
150  if (anal->peds()[iapv][istr] < 1.) { //@@ ie, zero
152  << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
153  << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: " << hex << setw(8)
154  << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/" << ichan
155  << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot()
156  << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
157  << fec_key.channel();
158  continue; //@@ do not upload
159  }
160 
161  // get the information on the strip as it was on the db
162  Fed9U::Fed9UAddress addr(ichan, iapv, istr);
163  Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip(addr);
164 
165  // determine whether we need to disable the strip
166  bool disableStrip = false;
167  if (keepStripsDisabled_) {
168  disableStrip = temp.getDisable();
169  } else if (disableBadStrips_) {
170  DaqScopeModeAnalysis::VInt dead = anal->dead()[iapv];
171  if (find(dead.begin(), dead.end(), istr) != dead.end())
172  disableStrip = true;
173  DaqScopeModeAnalysis::VInt noisy = anal->noisy()[iapv];
174  if (find(noisy.begin(), noisy.end(), istr) != noisy.end())
175  disableStrip = true;
176  }
177 
178  Fed9U::Fed9UStripDescription data(static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift),
181  anal->noise()[iapv][istr],
182  disableStrip);
183 
184  std::stringstream ss;
185  if (data.getDisable() && edm::isDebugEnabled()) {
186  ss << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
187  << " Disabling strip in Fed9UStripDescription object..." << std::endl
188  << " for FED id/channel and APV/strip : " << fed_key.fedId() << "/" << fed_key.fedChannel() << " "
189  << iapv << "/" << istr << std::endl
190  << " and crate/FEC/ring/CCU/module : " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
191  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << std::endl
192  << " from ped/noise/high/low/disable : " << static_cast<uint16_t>(temp.getPedestal()) << "/"
193  << static_cast<uint16_t>(temp.getHighThreshold()) << "/"
194  << static_cast<uint16_t>(temp.getLowThreshold()) << "/" << static_cast<uint16_t>(temp.getNoise())
195  << "/" << static_cast<uint16_t>(temp.getDisable()) << std::endl;
196  }
197 
198  // update strip inf
199  (*ifed)->getFedStrips().setStrip(addr, data);
200 
201  if (data.getDisable() && edm::isDebugEnabled()) {
202  ss << " to ped/noise/high/low/disable : " << static_cast<uint16_t>(data.getPedestal()) << "/"
203  << static_cast<uint16_t>(data.getHighThreshold()) << "/"
204  << static_cast<uint16_t>(data.getLowThreshold()) << "/" << static_cast<uint16_t>(data.getNoise())
205  << "/" << static_cast<uint16_t>(data.getDisable()) << std::endl;
206  LogTrace(mlDqmClient_) << ss.str();
207  }
208  } // end loop on strips
209  } // end loop on apvs
210  updated_peds++;
211  }
212 
213  // if one wants to update the frame finding threhsolds
214  if (not skipTickUpdate_) {
215  // Update frame finding threshold
216  Fed9U::Fed9UAddress addr(ichan);
217  uint16_t old_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
218  if (anal->isValid()) {
219  (*ifed)->setFrameThreshold(addr, anal->frameFindingThreshold());
220  updated_ticks++;
221  }
222  uint16_t new_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
223 
224  std::stringstream ss;
225  ss << "LLD channel : old frame threshold " << old_threshold << " new frame threshold " << new_threshold
226  << std::endl;
227  edm::LogWarning(mlDqmClient_) << ss.str();
228 
229  // Debug
230  ss.clear();
231  ss << "[DaqScopeModeHistosUsingDb::" << __func__ << "]";
232  if (anal->isValid()) {
233  ss << " Updating the frame-finding threshold"
234  << " from " << old_threshold << " to " << new_threshold << " using tick mark base/peak/height "
235  << anal->base() << "/" << anal->peak() << "/" << anal->height();
236  } else {
237  ss << " Cannot update the frame-finding threshold"
238  << " from " << old_threshold << " to a new value using invalid analysis ";
239  }
240  ss << " for crate/FEC/ring/CCU/module/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
241  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << fec_key.channel()
242  << " and FED id/ch " << fed_key.fedId() << "/" << fed_key.fedChannel();
243  anal->print(ss);
244  LogTrace(mlDqmClient_) << ss.str();
245  }
246  } else {
247  if (deviceIsPresent(fec_key)) {
248  edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
249  << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
250  << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
251  << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate()
252  << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/"
253  << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
254  }
255  }
256  }
257  }
258 
259  edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
260  << " Updated FED parameters for pedestal/noise " << updated_peds << " channels"
261  << " Updated FED parameters for frame finding thresholds " << updated_ticks
262  << " channels";
263 }
264 
265 // -----------------------------------------------------------------------------
267  DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(analysis->second);
268  if (!anal) {
269  return;
270  }
271 
272  SiStripFecKey fec_key(anal->fecKey());
273  SiStripFedKey fed_key(anal->fedKey());
274 
275  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
276  // Create description for the pedestal table
277  PedestalsAnalysisDescription* peds_tmp;
278  peds_tmp = new PedestalsAnalysisDescription(anal->dead()[iapv],
279  anal->noisy()[iapv],
280  anal->pedsMean()[iapv],
281  anal->pedsSpread()[iapv],
282  anal->noiseMean()[iapv],
283  anal->noiseSpread()[iapv],
284  anal->rawMean()[iapv],
285  anal->rawSpread()[iapv],
286  anal->pedsMax()[iapv],
287  anal->pedsMin()[iapv],
288  anal->noiseMax()[iapv],
289  anal->noiseMin()[iapv],
290  anal->rawMax()[iapv],
291  anal->rawMin()[iapv],
292  fec_key.fecCrate(),
293  fec_key.fecSlot(),
294  fec_key.fecRing(),
295  fec_key.ccuAddr(),
296  fec_key.ccuChan(),
297  SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
298  db()->dbParams().partitions().begin()->second.partitionName(),
299  db()->dbParams().partitions().begin()->second.runNumber(),
300  anal->isValid(),
301  "",
302  fed_key.fedId(),
303  fed_key.feUnit(),
304  fed_key.feChan(),
305  fed_key.fedApv());
306 
307  // Add comments
308  typedef std::vector<std::string> Strings;
309  Strings errors = anal->getErrorCodes();
310  Strings::const_iterator istr = errors.begin();
311  Strings::const_iterator jstr = errors.end();
312  for (; istr != jstr; ++istr) {
313  peds_tmp->addComments(*istr);
314  }
315 
316  // Store description
317  desc.push_back(peds_tmp);
318 
319  // Create description
320  TimingAnalysisDescription* timing_tmp;
321  timing_tmp = new TimingAnalysisDescription(-1.,
322  -1.,
323  -1.,
324  anal->height(),
325  anal->base(),
326  anal->peak(),
327  anal->frameFindingThreshold(),
328  -1.,
330  true, //@@ APV timing analysis (not FED timing)
331  fec_key.fecCrate(),
332  fec_key.fecSlot(),
333  fec_key.fecRing(),
334  fec_key.ccuAddr(),
335  fec_key.ccuChan(),
336  SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
337  db()->dbParams().partitions().begin()->second.partitionName(),
338  db()->dbParams().partitions().begin()->second.runNumber(),
339  anal->isValid(),
340  "",
341  fed_key.fedId(),
342  fed_key.feUnit(),
343  fed_key.feChan(),
344  fed_key.fedApv());
345 
346  istr = errors.begin();
347  jstr = errors.end();
348  for (; istr != jstr; ++istr) {
349  timing_tmp->addComments(*istr);
350  }
351  desc.push_back(timing_tmp);
352  }
353 }
Log< level::Info, true > LogVerbatim
bool isDebugEnabled()
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const uint16_t & feChan() const
Analyses & data(bool getMaskedData=false)
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
EventSelector::Strings Strings
bool deviceIsPresent(const SiStripFecKey &)
FedDescriptionsRange getFedDescriptions(std::string partition="")
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
FedDescriptions::range FedDescriptionsRange
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:172
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
DaqScopeModeHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const, edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken)
#define LogTrace(id)
static const float tickMarkHeightThreshold_
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
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
An interface class to the DeviceFactory.
const uint32_t & key() const
Definition: SiStripKey.h:120
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override
SiStripFedCabling *const cabling() const
std::vector< uint16_t > VInt
const uint16_t & fedId() const
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:16
void update(SiStripConfigDb::FedDescriptionsRange)
HLT enums.
static const uint16_t FEDCH_PER_FED
std::vector< AnalysisDescription * > AnalysisDescriptionsV
const edm::ParameterSet & pset() const
Definition: errors.py:1
const SiStripDbParams & dbParams() const
Log< level::Warning, false > LogWarning
FedsConstIterRange fedIds() const
static const uint16_t APVS_PER_FEDCH
Analysis for scope mode data.