CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedestalsHistosUsingDb.cc
Go to the documentation of this file.
1 // Last commit: $Id: PedestalsHistosUsingDb.cc,v 1.27 2010/04/21 14:26:28 dstrom 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>("PedestalsParameters"),
19  bei,
20  sistrip::PEDESTALS ),
22  sistrip::PEDESTALS ),
23  PedestalsHistograms( pset.getParameter<edm::ParameterSet>("PedestalsParameters"),
24  bei )
25 {
27  << "[PedestalsHistosUsingDb::" << __func__ << "]"
28  << " Constructing object...";
29  highThreshold_ = this->pset().getParameter<double>("HighThreshold");
30  lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
32  << "[PedestalsHistosUsingDb::" << __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");
38  << "[PedestalsHistosUsingDb::" << __func__ << "]"
39  << " Disabling strips: " << disableBadStrips_
40  << " ; keeping previously disabled strips: " << keepStripsDisabled_;
41 }
42 
43 // -----------------------------------------------------------------------------
47  << "[PedestalsHistosUsingDb::" << __func__ << "]"
48  << " Destructing object...";
49 }
50 
51 // -----------------------------------------------------------------------------
55  << "[PedestalsHistosUsingDb::" << __func__ << "]";
56 
57  if ( !db() ) {
59  << "[PedestalsHistosUsingDb::" << __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  << "[PedestalsHistosUsingDb::" << __func__ << "]"
71  << " Uploading pedestals/noise to DB...";
74  << "[PedestalsHistosUsingDb::" << __func__ << "]"
75  << " Completed database upload of " << feds.size()
76  << " FED descriptions!";
77  } else {
79  << "[PedestalsHistosUsingDb::" << __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()->connection( (*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  SiStripFedKey fed_key( conn.fedId(),
105  SiStripFedKey::feUnit( conn.fedCh() ),
106  SiStripFedKey::feChan( conn.fedCh() ) );
107  SiStripFecKey fec_key( conn.fecCrate(),
108  conn.fecSlot(),
109  conn.fecRing(),
110  conn.ccuAddr(),
111  conn.ccuChan(),
112  conn.lldChannel() );
113 
114  // Locate appropriate analysis object
115  Analyses::const_iterator iter = data().find( fec_key.key() );
116  if ( iter != data().end() ) {
117 
118  PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( iter->second );
119  if ( !anal ) {
121  << "[PedestalsHistosUsingDb::" << __func__ << "]"
122  << " NULL pointer to analysis object!";
123  continue;
124  }
125 
126  // Determine the pedestal shift to apply
127  uint32_t pedshift = 127;
128  for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
129  uint32_t pedmin = (uint32_t) anal->pedsMin()[iapv];
130  pedshift = pedmin < pedshift ? pedmin : pedshift;
131  }
132 
133  // Iterate through APVs and strips
134  for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
135  for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) {
136 
137  // get the information on the strip as it was on the db
138  Fed9U::Fed9UAddress addr( ichan, iapv, istr );
139  Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip( addr );
140 
141  // determine whether we need to disable the strip
142  bool disableStrip = false;
143  if ( keepStripsDisabled_ ) {
144  disableStrip = temp.getDisable();
145  } else if (disableBadStrips_) {
146  PedestalsAnalysis::VInt dead = anal->dead()[iapv];
147  if ( find( dead.begin(), dead.end(), istr ) != dead.end() ) disableStrip = true;
148  PedestalsAnalysis::VInt noisy = anal->noisy()[iapv];
149  if ( find( noisy.begin(), noisy.end(), istr ) != noisy.end() ) disableStrip = true;
150  }
151 
152  Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr]-pedshift ),
155  anal->noise()[iapv][istr],
156  disableStrip );
157 
158  std::stringstream ss;
159  if ( data.getDisable() && edm::isDebugEnabled() ) {
160  ss << "[PedestalsHistosUsingDb::" << __func__ << "]"
161  << " Disabling strip in Fed9UStripDescription object..." << std::endl
162  << " for FED id/channel and APV/strip : "
163  << fed_key.fedId() << "/"
164  << fed_key.fedChannel() << " "
165  << iapv << "/"
166  << istr << std::endl
167  << " and crate/FEC/ring/CCU/module : "
168  << fec_key.fecCrate() << "/"
169  << fec_key.fecSlot() << "/"
170  << fec_key.fecRing() << "/"
171  << fec_key.ccuAddr() << "/"
172  << fec_key.ccuChan() << std::endl
173  << " from ped/noise/high/low/disable : "
174  << static_cast<uint16_t>( temp.getPedestal() ) << "/"
175  << static_cast<uint16_t>( temp.getHighThreshold() ) << "/"
176  << static_cast<uint16_t>( temp.getLowThreshold() ) << "/"
177  << static_cast<uint16_t>( temp.getNoise() ) << "/"
178  << static_cast<uint16_t>( temp.getDisable() ) << std::endl;
179  }
180  (*ifed)->getFedStrips().setStrip( addr, data );
181  if ( data.getDisable() && edm::isDebugEnabled() ) {
182  ss << " to ped/noise/high/low/disable : "
183  << static_cast<uint16_t>( data.getPedestal() ) << "/"
184  << static_cast<uint16_t>( data.getHighThreshold() ) << "/"
185  << static_cast<uint16_t>( data.getLowThreshold() ) << "/"
186  << static_cast<uint16_t>( data.getNoise() ) << "/"
187  << static_cast<uint16_t>( data.getDisable() ) << std::endl;
188  LogTrace(mlDqmClient_) << ss.str();
189  }
190 
191  } // end loop on strips
192  } // end loop on apvs
193  updated++;
194 
195  } else {
196  if ( deviceIsPresent(fec_key) ) {
198  << "[PedestalsHistosUsingDb::" << __func__ << "]"
199  << " Unable to find pedestals/noise for FedKey/Id/Ch: "
200  << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
201  << (*ifed)->getFedId() << "/"
202  << ichan
203  << " and device with FEC/slot/ring/CCU/LLD "
204  << fec_key.fecCrate() << "/"
205  << fec_key.fecSlot() << "/"
206  << fec_key.fecRing() << "/"
207  << fec_key.ccuAddr() << "/"
208  << fec_key.ccuChan() << "/"
209  << fec_key.channel();
210  }
211  }
212  }
213  }
214 
216  << "[PedestalsHistosUsingDb::" << __func__ << "]"
217  << " Updated FED pedestals/noise for "
218  << updated << " channels";
219 
220 }
221 
222 // -----------------------------------------------------------------------------
225  Analysis analysis ) {
226 
227  PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( analysis->second );
228  if ( !anal ) { return; }
229 
230  SiStripFecKey fec_key( anal->fecKey() );
231  SiStripFedKey fed_key( anal->fedKey() );
232 
233  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
234 
235  // Create description
236  PedestalsAnalysisDescription* tmp;
237  tmp = new PedestalsAnalysisDescription(
238  anal->dead()[iapv],
239  anal->noisy()[iapv],
240  anal->pedsMean()[iapv],
241  anal->pedsSpread()[iapv],
242  anal->noiseMean()[iapv],
243  anal->noiseSpread()[iapv],
244  anal->rawMean()[iapv],
245  anal->rawSpread()[iapv],
246  anal->pedsMax()[iapv],
247  anal->pedsMin()[iapv],
248  anal->noiseMax()[iapv],
249  anal->noiseMin()[iapv],
250  anal->rawMax()[iapv],
251  anal->rawMin()[iapv],
252  fec_key.fecCrate(),
253  fec_key.fecSlot(),
254  fec_key.fecRing(),
255  fec_key.ccuAddr(),
256  fec_key.ccuChan(),
257  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
258  db()->dbParams().partitions().begin()->second.partitionName(),
259  db()->dbParams().partitions().begin()->second.runNumber(),
260  anal->isValid(),
261  "",
262  fed_key.fedId(),
263  fed_key.feUnit(),
264  fed_key.feChan(),
265  fed_key.fedApv()
266  );
267 
268  // Add comments
269  typedef std::vector<std::string> Strings;
270  Strings errors = anal->getErrorCodes();
271  Strings::const_iterator istr = errors.begin();
272  Strings::const_iterator jstr = errors.end();
273  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
274 
275  // Store description
276  desc.push_back( tmp );
277 
278  }
279 
280 }
281 
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
const uint32_t & fedKey() const
PedestalsHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const )
const VVInt & noisy() const
const VVFloat & peds() 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
bool isValid() 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
const uint32_t & key() const
Definition: SiStripKey.h:126
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 & 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
const VFloat & rawMean() const
const uint16_t & feUnit() const
const SiStripDbParams & dbParams() const
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:17
const VFloat & pedsSpread() const
const VFloat & pedsMax() const
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
const VFloat & noiseSpread() const
SiStripConfigDb *const db() const
const VFloat & noiseMax() const
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
SiStripFedCabling *const cabling() const
const VString & getErrorCodes() const
static const uint16_t APVS_PER_FEDCH
tuple conn
Definition: results_mgr.py:53
const VFloat & noiseMin() const