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