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