CMS 3D CMS Logo

PedestalsHistosUsingDb.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 )
17  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("PedestalsParameters"),
18  bei,
19  sistrip::PEDESTALS ),
21  sistrip::PEDESTALS ),
22  PedestalsHistograms( pset.getParameter<edm::ParameterSet>("PedestalsParameters"),
23  bei )
24 {
26  << "[PedestalsHistosUsingDb::" << __func__ << "]"
27  << " Constructing object...";
28  highThreshold_ = this->pset().getParameter<double>("HighThreshold");
29  lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
31  << "[PedestalsHistosUsingDb::" << __func__ << "]"
32  << " Set FED zero suppression high/low threshold to "
33  << highThreshold_ << "/" << lowThreshold_;
34  disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
35  keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
37  << "[PedestalsHistosUsingDb::" << __func__ << "]"
38  << " Disabling strips: " << disableBadStrips_
39  << " ; keeping previously disabled strips: " << keepStripsDisabled_;
40 
41  allowSelectiveUpload_ = this->pset().existsAs<bool>("doSelectiveUpload")?this->pset().getParameter<bool>("doSelectiveUpload"):false;
43  << "[PedestalsHistosUsingDb::" << __func__ << "]"
44  << " Selective upload of modules set to : " << allowSelectiveUpload_;
45 }
46 
47 // -----------------------------------------------------------------------------
51  << "[PedestalsHistosUsingDb::" << __func__ << "]"
52  << " Destructing object...";
53 }
54 
55 // -----------------------------------------------------------------------------
59  << "[PedestalsHistosUsingDb::" << __func__ << "]";
60 
61  if ( !db() ) {
63  << "[PedestalsHistosUsingDb::" << __func__ << "]"
64  << " NULL pointer to SiStripConfigDb interface!"
65  << " Aborting upload...";
66  return;
67  }
68 
69  // Update FED descriptions with new peds/noise values
71  update( feds );
72  if ( doUploadConf() ) {
74  << "[PedestalsHistosUsingDb::" << __func__ << "]"
75  << " Uploading pedestals/noise to DB...";
78  << "[PedestalsHistosUsingDb::" << __func__ << "]"
79  << " Completed database upload of " << feds.size()
80  << " FED descriptions!";
81  } else {
83  << "[PedestalsHistosUsingDb::" << __func__ << "]"
84  << " TEST! No pedestals/noise values will be uploaded to DB...";
85  }
86 
87 }
88 
89 // -----------------------------------------------------------------------------
92 
93  // Iterate through feds and update fed descriptions
94  uint16_t updated = 0;
95  SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
96  for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
97 
98  for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
99 
100  // Build FED and FEC keys
101  const FedChannelConnection& conn = cabling()->fedConnection( (*ifed)->getFedId(), ichan );
102  if ( conn.fecCrate() == sistrip::invalid_ ||
103  conn.fecSlot() == sistrip::invalid_ ||
104  conn.fecRing() == sistrip::invalid_ ||
105  conn.ccuAddr() == sistrip::invalid_ ||
106  conn.ccuChan() == sistrip::invalid_ ||
107  conn.lldChannel() == sistrip::invalid_ ) { continue; }
108  SiStripFedKey fed_key( conn.fedId(),
109  SiStripFedKey::feUnit( conn.fedCh() ),
110  SiStripFedKey::feChan( conn.fedCh() ) );
111  SiStripFecKey fec_key( conn.fecCrate(),
112  conn.fecSlot(),
113  conn.fecRing(),
114  conn.ccuAddr(),
115  conn.ccuChan(),
116  conn.lldChannel() );
117 
118  // Locate appropriate analysis object
119  Analyses::const_iterator iter = data(allowSelectiveUpload_).find( fec_key.key() );
120  if ( iter != data(allowSelectiveUpload_).end() ) {
121 
122  // Check if analysis is valid
123  if ( !iter->second->isValid() ) {
124  continue;
125  }
126 
127  PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( iter->second );
128  if ( !anal ) {
130  << "[PedestalsHistosUsingDb::" << __func__ << "]"
131  << " NULL pointer to analysis object!";
132  continue;
133  }
134 
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 << " pedshift: " << pedshift;
142  edm::LogWarning(mlDqmClient_) << ss.str();
143  }
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 
150  // get the information on the strip as it was on the db
151  Fed9U::Fed9UAddress addr( ichan, iapv, istr );
152  Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip( addr );
153 
154 
155  if ( anal->peds()[iapv][istr] < 1.) { //@@ ie, zero
157  << "[PedestalsHistosUsingDb::" << __func__ << "]"
158  << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: "
159  << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
160  << (*ifed)->getFedId() << "/"
161  << ichan
162  << " and device with FEC/slot/ring/CCU/LLD "
163  << fec_key.fecCrate() << "/"
164  << fec_key.fecSlot() << "/"
165  << fec_key.fecRing() << "/"
166  << fec_key.ccuAddr() << "/"
167  << fec_key.ccuChan() << "/"
168  << fec_key.channel();
169  continue; //@@ do not upload
170  }
171 
172  // determine whether we need to disable the strip
173  bool disableStrip = false;
174  if ( keepStripsDisabled_ ) {
175  disableStrip = temp.getDisable();
176  } else if (disableBadStrips_) {
177  PedestalsAnalysis::VInt dead = anal->dead()[iapv];
178  if ( find( dead.begin(), dead.end(), istr ) != dead.end() ) disableStrip = true;
179  PedestalsAnalysis::VInt noisy = anal->noisy()[iapv];
180  if ( find( noisy.begin(), noisy.end(), istr ) != noisy.end() ) disableStrip = true;
181  }
182 
183  Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr]-pedshift ),
186  anal->noise()[iapv][istr],
187  disableStrip );
188 
189  std::stringstream ss;
190  if ( data.getDisable() && edm::isDebugEnabled() ) {
191  ss << "[PedestalsHistosUsingDb::" << __func__ << "]"
192  << " Disabling strip in Fed9UStripDescription object..." << std::endl
193  << " for FED id/channel and APV/strip : "
194  << fed_key.fedId() << "/"
195  << fed_key.fedChannel() << " "
196  << iapv << "/"
197  << istr << std::endl
198  << " and crate/FEC/ring/CCU/module : "
199  << fec_key.fecCrate() << "/"
200  << fec_key.fecSlot() << "/"
201  << fec_key.fecRing() << "/"
202  << fec_key.ccuAddr() << "/"
203  << fec_key.ccuChan() << std::endl
204  << " from ped/noise/high/low/disable : "
205  << static_cast<uint16_t>( temp.getPedestal() ) << "/"
206  << static_cast<uint16_t>( temp.getHighThreshold() ) << "/"
207  << static_cast<uint16_t>( temp.getLowThreshold() ) << "/"
208  << static_cast<uint16_t>( temp.getNoise() ) << "/"
209  << static_cast<uint16_t>( temp.getDisable() ) << std::endl;
210  }
211  (*ifed)->getFedStrips().setStrip( addr, data );
212  if ( data.getDisable() && edm::isDebugEnabled() ) {
213  ss << " to ped/noise/high/low/disable : "
214  << static_cast<uint16_t>( data.getPedestal() ) << "/"
215  << static_cast<uint16_t>( data.getHighThreshold() ) << "/"
216  << static_cast<uint16_t>( data.getLowThreshold() ) << "/"
217  << static_cast<uint16_t>( data.getNoise() ) << "/"
218  << static_cast<uint16_t>( data.getDisable() ) << std::endl;
219  LogTrace(mlDqmClient_) << ss.str();
220  }
221 
222  } // end loop on strips
223  } // end loop on apvs
224  updated++;
225 
226  } else {
227  if ( deviceIsPresent(fec_key) ) {
229  << "[PedestalsHistosUsingDb::" << __func__ << "]"
230  << " Unable to find pedestals/noise for FedKey/Id/Ch: "
231  << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
232  << (*ifed)->getFedId() << "/"
233  << ichan
234  << " and device with FEC/slot/ring/CCU/LLD "
235  << fec_key.fecCrate() << "/"
236  << fec_key.fecSlot() << "/"
237  << fec_key.fecRing() << "/"
238  << fec_key.ccuAddr() << "/"
239  << fec_key.ccuChan() << "/"
240  << fec_key.channel();
241  }
242  }
243  }
244  }
245 
247  << "[PedestalsHistosUsingDb::" << __func__ << "]"
248  << " Updated FED pedestals/noise for "
249  << updated << " channels";
250 
251 }
252 
253 // -----------------------------------------------------------------------------
256  Analysis analysis ) {
257 
258  PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( analysis->second );
259  if ( !anal ) { return; }
260 
261  SiStripFecKey fec_key( anal->fecKey() );
262  SiStripFedKey fed_key( anal->fedKey() );
263 
264  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
265 
266  // Create description
267  PedestalsAnalysisDescription* tmp;
268  tmp = new PedestalsAnalysisDescription(
269  anal->dead()[iapv],
270  anal->noisy()[iapv],
271  anal->pedsMean()[iapv],
272  anal->pedsSpread()[iapv],
273  anal->noiseMean()[iapv],
274  anal->noiseSpread()[iapv],
275  anal->rawMean()[iapv],
276  anal->rawSpread()[iapv],
277  anal->pedsMax()[iapv],
278  anal->pedsMin()[iapv],
279  anal->noiseMax()[iapv],
280  anal->noiseMin()[iapv],
281  anal->rawMax()[iapv],
282  anal->rawMin()[iapv],
283  fec_key.fecCrate(),
284  fec_key.fecSlot(),
285  fec_key.fecRing(),
286  fec_key.ccuAddr(),
287  fec_key.ccuChan(),
288  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
289  db()->dbParams().partitions().begin()->second.partitionName(),
290  db()->dbParams().partitions().begin()->second.runNumber(),
291  anal->isValid(),
292  "",
293  fed_key.fedId(),
294  fed_key.feUnit(),
295  fed_key.feChan(),
296  fed_key.fedApv()
297  );
298 
299  // Add comments
300  typedef std::vector<std::string> Strings;
301  Strings errors = anal->getErrorCodes();
302  Strings::const_iterator istr = errors.begin();
303  Strings::const_iterator jstr = errors.end();
304  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
305 
306  // Store description
307  desc.push_back( tmp );
308 
309  }
310 
311 }
312 
const uint16_t & fecSlot() const
T getParameter(std::string const &) const
bool isDebugEnabled()
const VFloat & rawMax() const
void update(SiStripConfigDb::FedDescriptionsRange)
const VFloat & pedsMean() const
const uint16_t & fecCrate() 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
PedestalsHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const )
const VVInt & noisy() const
Analyses & data(bool getMaskedData=false)
bool isValid() const override
const VVFloat & peds() const
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 &)
FedDescriptionsRange getFedDescriptions(std::string partition="")
std::vector< std::string > Strings
Definition: MsgTools.h:18
FedDescriptions::range FedDescriptionsRange
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 uint16_t & i2cAddr() const
const uint16_t & fedId() const
sistrip classes
const uint32_t & key() const
Definition: SiStripKey.h:125
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
const VFloat & noiseMean() const
const_iterator_range partitions() const
const uint16_t & fecRing() const
const VFloat & pedsMin() const
Class containning control, module, detector and connection information, at the level of a FED channel...
const VVFloat & noise() const
An interface class to the DeviceFactory.
const uint16_t & ccuChan() const
Histogram-based analysis for pedestal run.
const uint32_t & fecKey() const
const VVInt & dead() const
uint16_t fedChannel() const
const VFloat & rawMin() const
const uint16_t & ccuAddr() const
const VFloat & rawSpread() const
#define LogTrace(id)
std::vector< uint16_t > VInt
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override
const VFloat & rawMean() const
void uploadConfigurations() override
const uint16_t & feUnit() const
const SiStripDbParams & dbParams() const
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:16
const VFloat & pedsSpread() const
const VFloat & pedsMax() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
static const uint16_t FEDCH_PER_FED
std::vector< AnalysisDescription * > AnalysisDescriptionsV
const uint16_t & feChan() const
const uint16_t & fedId() const
const VFloat & noiseSpread() const
Definition: errors.py:1
SiStripConfigDb *const db() const
const VFloat & noiseMax() const
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const
static const uint16_t APVS_PER_FEDCH
const VFloat & noiseMin() const