CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedsFullNoiseHistosUsingDb.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>("PedsFullNoiseParameters"),
18  bei,
19  sistrip::PEDS_FULL_NOISE ),
21  sistrip::PEDS_FULL_NOISE ),
22  PedsFullNoiseHistograms( pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"),
23  bei )
24 {
26  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
27  << " Constructing object...";
28  highThreshold_ = this->pset().getParameter<double>("HighThreshold");
29  lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
31  << "[PedsFullNoiseHistosUsingDb::" << __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");
36  addBadStrips_ = this->pset().getParameter<bool>("AddBadStrips");
38  << "[PedestalsHistosUsingDb::" << __func__ << "]"
39  << " Disabling strips: " << disableBadStrips_
40  << " ; keeping previously disabled strips: " << keepStripsDisabled_;
41 }
42 
43 // -----------------------------------------------------------------------------
47  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
48  << " Destructing object...";
49 }
50 
51 // -----------------------------------------------------------------------------
55  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]";
56 
57  if ( !db() ) {
59  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
60  << " NULL pointer to SiStripConfigDb interface!"
61  << " Aborting upload...";
62  return;
63  }
64 
65  // Update FED descriptions with new peds/noise values
67  update( feds );
68  if ( doUploadConf() ) {
70  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
71  << " Uploading pedestals/noise to DB...";
74  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
75  << " Completed database upload of " << feds.size()
76  << " FED descriptions!";
77  } else {
79  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
80  << " TEST! No pedestals/noise values will be uploaded to DB...";
81  }
82 
83 }
84 
85 // -----------------------------------------------------------------------------
88 
89  // Iterate through feds and update fed descriptions
90  uint16_t updated = 0;
91  SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
92  for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
93 
94  for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
95 
96  // Build FED and FEC keys
97  const FedChannelConnection& conn = cabling()->fedConnection( (*ifed)->getFedId(), ichan );
98  if ( conn.fecCrate()== sistrip::invalid_ ||
99  conn.fecSlot() == sistrip::invalid_ ||
100  conn.fecRing() == sistrip::invalid_ ||
101  conn.ccuAddr() == sistrip::invalid_ ||
102  conn.ccuChan() == sistrip::invalid_ ||
103  conn.lldChannel() == sistrip::invalid_ ) { continue; }
104 
105  SiStripFedKey fed_key( conn.fedId(),
106  SiStripFedKey::feUnit( conn.fedCh() ),
107  SiStripFedKey::feChan( conn.fedCh() ) );
108  SiStripFecKey fec_key( conn.fecCrate(),
109  conn.fecSlot(),
110  conn.fecRing(),
111  conn.ccuAddr(),
112  conn.ccuChan(),
113  conn.lldChannel() );
114 
115  // Locate appropriate analysis object
116  Analyses::const_iterator iter = data().find( fec_key.key() );
117  if ( iter != data().end() ) {
118 
119  PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>( iter->second );
120  if ( !anal ) {
122  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
123  << " NULL pointer to analysis object!";
124  continue;
125  }
126 
127  // Determine the pedestal shift to apply
128  uint32_t pedshift = 127;
129  for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
130  uint32_t pedmin = (uint32_t) anal->pedsMin()[iapv];
131  pedshift = pedmin < pedshift ? pedmin : pedshift;
132  }
133 
134  // Iterate through APVs and strips
135  for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
136  for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) {
137 
138  // get the information on the strip as it was on the db
139  Fed9U::Fed9UAddress addr( ichan, iapv, istr );
140  Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip( addr );
141  if(temp.getDisable()) {
142  std::cout<<"Already Disabled: "<<conn.fecCrate()
143  <<" "<<conn.fecSlot()
144  <<" "<<conn.fecRing()
145  <<" "<<conn.ccuAddr()
146  <<" "<<conn.ccuChan()
147  <<" "<<conn.lldChannel()
148  <<" "<<iapv*128+istr<<std::endl;
149  }
150  // determine whether we need to disable the strip
151  bool disableStrip = false;
152  if ( addBadStrips_ ) {
153  disableStrip = temp.getDisable();
154  SiStripFedKey fed_key(anal->fedKey());
155  if(!disableStrip){
156  PedsFullNoiseAnalysis::VInt dead = anal->dead()[iapv];
157  if ( find( dead.begin(), dead.end(), istr ) != dead.end() ) {
158  disableStrip = true;
159  std::cout<<"Disabling Dead: "<<conn.fecCrate()
160  <<" "<<conn.fecSlot()
161  <<" "<<conn.fecRing()
162  <<" "<<conn.ccuAddr()
163  <<" "<<conn.ccuChan()
164  <<" "<<conn.lldChannel()
165  <<" "<<iapv*128+istr<<std::endl;
166  }
167  PedsFullNoiseAnalysis::VInt noisy = anal->noisy()[iapv];
168  if ( find( noisy.begin(), noisy.end(), istr ) != noisy.end() ) {
169  disableStrip = true;
170  std::cout<<"Disabling Noisy: "<<conn.fecCrate()
171  <<" "<<conn.fecSlot()
172  <<" "<<conn.fecRing()
173  <<" "<<conn.ccuAddr()
174  <<" "<<conn.ccuChan()
175  <<" "<<conn.lldChannel()
176  <<" "<<iapv*128+istr<<std::endl;
177  }
178  }
179  } else if ( keepStripsDisabled_ ) {
180  disableStrip = temp.getDisable();
181  } else if (disableBadStrips_) {
182  PedsFullNoiseAnalysis::VInt dead = anal->dead()[iapv];
183  if ( find( dead.begin(), dead.end(), istr ) != dead.end() ) {
184  disableStrip = true;
185  std::cout<<"Disabling Dead: "<<conn.fecCrate()
186  <<" "<<conn.fecSlot()
187  <<" "<<conn.fecRing()
188  <<" "<<conn.ccuAddr()
189  <<" "<<conn.ccuChan()
190  <<" "<<conn.lldChannel()
191  <<" "<<iapv*128+istr<<std::endl;
192  }
193  PedsFullNoiseAnalysis::VInt noisy = anal->noisy()[iapv];
194  if ( find( noisy.begin(), noisy.end(), istr ) != noisy.end() ) {
195  disableStrip = true;
196  std::cout<<"Disabling Noisy: "<<conn.fecCrate()
197  <<" "<<conn.fecSlot()
198  <<" "<<conn.fecRing()
199  <<" "<<conn.ccuAddr()
200  <<" "<<conn.ccuChan()
201  <<" "<<conn.lldChannel()
202  <<" "<<iapv*128+istr<<std::endl;
203  }
204  }
205 
206  Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr]-pedshift ),
209  anal->noise()[iapv][istr],
210  disableStrip );
211 
212  std::stringstream ss;
213  if ( data.getDisable() && edm::isDebugEnabled() ) {
214  ss << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
215  << " Disabling strip in Fed9UStripDescription object..." << std::endl
216  << " for FED id/channel and APV/strip : "
217  << fed_key.fedId() << "/"
218  << fed_key.fedChannel() << " "
219  << iapv << "/"
220  << istr << std::endl
221  << " and crate/FEC/ring/CCU/module : "
222  << fec_key.fecCrate() << "/"
223  << fec_key.fecSlot() << "/"
224  << fec_key.fecRing() << "/"
225  << fec_key.ccuAddr() << "/"
226  << fec_key.ccuChan() << std::endl
227  << " from ped/noise/high/low/disable : "
228  << static_cast<uint16_t>( temp.getPedestal() ) << "/"
229  << static_cast<uint16_t>( temp.getHighThreshold() ) << "/"
230  << static_cast<uint16_t>( temp.getLowThreshold() ) << "/"
231  << static_cast<uint16_t>( temp.getNoise() ) << "/"
232  << static_cast<uint16_t>( temp.getDisable() ) << std::endl;
233  }
234  (*ifed)->getFedStrips().setStrip( addr, data );
235  if ( data.getDisable() && edm::isDebugEnabled() ) {
236  ss << " to ped/noise/high/low/disable : "
237  << static_cast<uint16_t>( data.getPedestal() ) << "/"
238  << static_cast<uint16_t>( data.getHighThreshold() ) << "/"
239  << static_cast<uint16_t>( data.getLowThreshold() ) << "/"
240  << static_cast<uint16_t>( data.getNoise() ) << "/"
241  << static_cast<uint16_t>( data.getDisable() ) << std::endl;
242  LogTrace(mlDqmClient_) << ss.str();
243  }
244 
245  } // end loop on strips
246  } // end loop on apvs
247  updated++;
248 
249  } else {
250  if ( deviceIsPresent(fec_key) ) {
252  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
253  << " Unable to find pedestals/noise for FedKey/Id/Ch: "
254  << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
255  << (*ifed)->getFedId() << "/"
256  << ichan
257  << " and device with FEC/slot/ring/CCU/LLD "
258  << fec_key.fecCrate() << "/"
259  << fec_key.fecSlot() << "/"
260  << fec_key.fecRing() << "/"
261  << fec_key.ccuAddr() << "/"
262  << fec_key.ccuChan() << "/"
263  << fec_key.channel();
264  }
265  }
266  }
267  }
268 
270  << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
271  << " Updated FED pedestals/noise for "
272  << updated << " channels";
273 }
274 
275 // -----------------------------------------------------------------------------
278  Analysis analysis ) {
279 
280  PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>( analysis->second );
281  if ( !anal ) { return; }
282 
283  SiStripFecKey fec_key( anal->fecKey() );
284  SiStripFedKey fed_key( anal->fedKey() );
285 
286  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
287 
288  // Create description
289  PedestalsAnalysisDescription* tmp;
290  tmp = new PedestalsAnalysisDescription(
291  anal->dead()[iapv],
292  anal->noisy()[iapv],
293  anal->pedsMean()[iapv],
294  anal->pedsSpread()[iapv],
295  anal->noiseMean()[iapv],
296  anal->noiseSpread()[iapv],
297  anal->rawMean()[iapv],
298  anal->rawSpread()[iapv],
299  anal->pedsMax()[iapv],
300  anal->pedsMin()[iapv],
301  anal->noiseMax()[iapv],
302  anal->noiseMin()[iapv],
303  anal->rawMax()[iapv],
304  anal->rawMin()[iapv],
305  fec_key.fecCrate(),
306  fec_key.fecSlot(),
307  fec_key.fecRing(),
308  fec_key.ccuAddr(),
309  fec_key.ccuChan(),
310  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
311  db()->dbParams().partitions().begin()->second.partitionName(),
312  db()->dbParams().partitions().begin()->second.runNumber(),
313  anal->isValid(),
314  "",
315  fed_key.fedId(),
316  fed_key.feUnit(),
317  fed_key.feChan(),
318  fed_key.fedApv()
319  );
320 
321  // Add comments
322  typedef std::vector<std::string> Strings;
323  Strings errors = anal->getErrorCodes();
324  Strings::const_iterator istr = errors.begin();
325  Strings::const_iterator jstr = errors.end();
326  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
327 
328  // Store description
329  desc.push_back( tmp );
330 
331  }
332 
333 }
334 
const uint16_t & fecSlot() const
T getParameter(std::string const &) const
bool isDebugEnabled()
const VFloat & rawMean() const
const uint16_t & fecCrate() const
void update(SiStripConfigDb::FedDescriptionsRange)
const uint32_t & fedKey() const
PedsFullNoiseHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *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
tuple db
Definition: EcalCondDB.py:151
FedDescriptions::range FedDescriptionsRange
static const char mlDqmClient_[]
const VVFloat & peds() const
const VFloat & noiseMax() 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
Histogram-based analysis for pedestal run.
const uint32_t & key() const
Definition: SiStripKey.h:125
const VVInt & noisy() const
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 & noiseMin() const
const_iterator_range partitions() const
const VFloat & pedsSpread() const
const uint16_t & fecRing() const
Class containning control, module, detector and connection information, at the level of a FED channel...
const VFloat & pedsMax() const
An interface class to the DeviceFactory.
const uint16_t & ccuChan() const
const VFloat & pedsMean() const
const VFloat & pedsMin() const
const uint32_t & fecKey() const
const VFloat & rawMin() const
const VFloat & rawSpread() const
uint16_t fedChannel() const
const uint16_t & ccuAddr() const
#define LogTrace(id)
std::vector< uint16_t > VInt
const VFloat & rawMax() const
const VVFloat & noise() const
const uint16_t & feUnit() const
const SiStripDbParams & dbParams() const
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:16
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 & fedId() const
tuple cout
Definition: gather_cfg.py:121
SiStripConfigDb *const db() const
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
const VFloat & noiseSpread() const
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const
const VVInt & dead() const
const VFloat & noiseMean() const
static const uint16_t APVS_PER_FEDCH
tuple conn
Definition: results_mgr.py:53