CMS 3D CMS Logo

CommissioningHistosUsingDb.cc
Go to the documentation of this file.
1 
12 #include <iostream>
13 
14 using namespace sistrip;
15 
16 // -----------------------------------------------------------------------------
21  runType_(type),
22  db_(db),
23  cabling_(0),
24  detInfo_(),
25  uploadAnal_(true),
26  uploadConf_(false)
27 {
29  << "[" << __PRETTY_FUNCTION__ << "]"
30  << " Constructing object...";
31 
32  // Build FEC cabling object from connections found in DB
33  SiStripFecCabling fec_cabling;
36  } else {
38  }
39 
40  // Build FED cabling from FEC cabling
43  std::stringstream ss;
44  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
45  << " Terse print out of FED cabling:" << std::endl;
46  cabling_->terse(ss);
47  LogTrace(mlDqmClient_) << ss.str();
48 
49  std::stringstream sss;
50  sss << "[CommissioningHistosUsingDb::" << __func__ << "]"
51  << " Summary of FED cabling:" << std::endl;
52  cabling_->summary(sss);
53  edm::LogVerbatim(mlDqmClient_) << sss.str();
54 
55 }
56 
57 // -----------------------------------------------------------------------------
62  db_(0),
63  cabling_(0),
64  detInfo_(),
67 {
69  << "[" << __PRETTY_FUNCTION__ << "]"
70  << " Constructing object..." << endl;
71 }
72 
73 // -----------------------------------------------------------------------------
76  if ( db_ ) { delete db_; }
78  << "[" << __PRETTY_FUNCTION__ << "]"
79  << " Destructing object...";
80 }
81 
82 // -----------------------------------------------------------------------------
85  buildDetInfo();
86  addDcuDetIds();
88  uploadAnalyses();
89 }
90 
91 // -----------------------------------------------------------------------------
94 
95  if ( !db_ ) {
97  << "[CommissioningHistosUsingDb::" << __func__ << "]"
98  << " NULL pointer to SiStripConfigDb interface!"
99  << " Aborting upload...";
100  return;
101  }
102 
104  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
105  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
106  for ( ; ip != jp; ++ip ) {
107 
109  << "[CommissioningHistosUsingDb::" << __func__ << "]"
110  << " Starting from partition " << ip->first
111  << " with versions:\n" << std::dec
112  << " Conn: " << ip->second.cabVersion().first << "." << ip->second.cabVersion().second << "\n"
113  << " FED: " << ip->second.fedVersion().first << "." << ip->second.fedVersion().second << "\n"
114  << " FEC: " << ip->second.fecVersion().first << "." << ip->second.fecVersion().second << "\n"
115  << " Mask: " << ip->second.maskVersion().first << "." << ip->second.maskVersion().second;
116 
117  // Upload commissioning analysis results
119  createAnalyses( anals );
120 
122  << "[CommissioningHistosUsingDb::" << __func__ << "]"
123  << " Created analysis descriptions for "
124  << anals.size() << " devices";
125 
126  // Update analysis descriptions with new commissioning results
127  if ( uploadAnal_ ) {
128  if ( uploadConf_ ) {
130  << "[CommissioningHistosUsingDb::" << __func__ << "]"
131  << " Uploading major version of analysis descriptions to DB"
132  << " (will be used for physics)...";
133  }
134  else {
136  << "[CommissioningHistosUsingDb::" << __func__ << "]"
137  << " Uploading minor version of analysis descriptions to DB"
138  << " (will not be used for physics)...";
139  }
140  db_->clearAnalysisDescriptions( ip->second.partitionName() );
141  db_->addAnalysisDescriptions( ip->second.partitionName(), anals );
142  db_->uploadAnalysisDescriptions( uploadConf_, ip->second.partitionName() );
144  << "[CommissioningHistosUsingDb::" << __func__ << "]"
145  << " Upload of analysis descriptions to DB finished!";
146  }
147  else {
149  << "[CommissioningHistosUsingDb::" << __func__ << "]"
150  << " TEST! No analysis descriptions will be uploaded to DB...";
151  }
152 
153  if ( uploadConf_ ) {
154  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
155  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
156  for ( ; ip != jp; ++ip ) {
157  DeviceFactory* df = db_->deviceFactory();
158  tkStateVector states = df->getCurrentStates();
159  tkStateVector::const_iterator istate = states.begin();
160  tkStateVector::const_iterator jstate = states.end();
161  while ( istate != jstate ) {
162  if ( *istate && ip->first == (*istate)->getPartitionName() ) { break; }
163  istate++;
164  }
165  // Set versions if state was found
166  if ( istate != states.end() ) {
168  << "[CommissioningHistosUsingDb::" << __func__ << "]"
169  << " Created new version for partition " << ip->first
170  << ". Current state:\n" << std::dec
171  << " Conn: " << (*istate)->getConnectionVersionMajorId() << "." << (*istate)->getConnectionVersionMinorId() << "\n"
172  << " FED: " << (*istate)->getFedVersionMajorId() << "." << (*istate)->getFedVersionMinorId() << "\n"
173  << " FEC: " << (*istate)->getFecVersionMajorId() << "." << (*istate)->getFecVersionMinorId() << "\n"
174  << " Mask: " << (*istate)->getMaskVersionMajorId() << "." << (*istate)->getMaskVersionMinorId();
175  }
176  }
177  }
178 
179  }
180 
181 }
182 
183 // -----------------------------------------------------------------------------
186 
187  if ( !cabling_ ) {
189  << "[CommissioningHistosUsingDb::" << __func__ << "]"
190  << " NULL pointer to SiStripFedCabling object!";
191  return;
192  }
193 
194  Analyses::iterator ianal = data().begin();
195  Analyses::iterator janal = data().end();
196  for ( ; ianal != janal; ++ianal ) {
197 
198  CommissioningAnalysis* anal = ianal->second;
199 
200  if ( !anal ) {
202  << "[CommissioningHistosUsingDb::" << __func__ << "]"
203  << " NULL pointer to CommissioningAnalysis object!";
204  return;
205  }
206 
207  SiStripFedKey fed_key = anal->fedKey();
208  SiStripFecKey fec_key = anal->fecKey();
209 
211  fed_key.fedChannel() );
212 
213  SiStripFedKey fed( conn.fedId(),
214  SiStripFedKey::feUnit( conn.fedCh() ),
215  SiStripFedKey::feChan( conn.fedCh() ) );
216 
217  SiStripFecKey fec( conn.fecCrate(),
218  conn.fecSlot(),
219  conn.fecRing(),
220  conn.ccuAddr(),
221  conn.ccuChan(),
222  conn.lldChannel() );
223 
224  if ( fed_key.path() != fed.path() ) {
225 
226  std::stringstream ss;
227  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
228  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
229  << " Incompatible FED key retrieved from cabling!" << std::endl
230  << " FED key from analysis object : " << fed_key.path() << std::endl
231  << " FED key from cabling object : " << fed.path() << std::endl
232  << " FED id/ch from analysis object: " << fed_key.fedId() << "/" << fed_key.fedChannel() << std::endl
233  << " FED id/ch from cabling object : " << conn.fedId() << "/" << conn.fedCh();
234  edm::LogWarning(mlDqmClient_) << ss.str();
235 
236  } else if ( fec_key.path() != fec.path() ) {
237 
238  std::stringstream ss;
239  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
240  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
241  << " Incompatible FEC key retrieved from cabling!" << std::endl
242  << " FEC key from analysis object : " << fec_key.path() << std::endl
243  << " FEC key from cabling object : " << fec.path();
244  edm::LogWarning(mlDqmClient_) << ss.str();
245 
246  } else {
247 
248  anal->dcuId( conn.dcuId() );
249  anal->detId( conn.detId() );
250 
251  }
252 
253  }
254 
255 }
256 
257 // -----------------------------------------------------------------------------
258 //
260 
262  << "[CommissioningHistosUsingDb::" << __func__ << "]"
263  << " Creating AnalysisDescriptions...";
264 
265  desc.clear();
266 
267 // uint16_t size = 0;
268 // std::stringstream ss;
269 // ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
270 // << " Analysis descriptions:" << std::endl;
271 
272  Analyses::iterator ianal = data().begin();
273  Analyses::iterator janal = data().end();
274  for ( ; ianal != janal; ++ianal ) {
275 
276  // create analysis description
277  create( desc, ianal );
278 
279 // // debug
280 // if ( ianal->second ) {
281 // if ( desc.size()/2 > size ) { // print every 2nd description
282 // size = desc.size()/2;
283 // ianal->second->print(ss);
284 // ss << (*(desc.end()-2))->toString();
285 // ss << (*(desc.end()-1))->toString();
286 // ss << std::endl;
287 // }
288 // }
289 
290  }
291 
292 // LogTrace(mlDqmClient_) << ss.str();
293 
294 }
295 
296 // -----------------------------------------------------------------------------
297 //
299 
300  detInfo_.clear();
301 
302  if ( !db() ) {
304  << "[CommissioningHistosUsingDb::" << __func__ << "]"
305  << " NULL pointer to SiStripConfigDb interface!";
306  return;
307  }
308 
309  SiStripDbParams::SiStripPartitions::const_iterator ii = db_->dbParams().partitions().begin();
310  SiStripDbParams::SiStripPartitions::const_iterator jj = db_->dbParams().partitions().end();
311  for ( ; ii != jj; ++ii ) {
312 
313  // Retrieve DCUs and DetIds for given partition
314  std::string pp = ii->second.partitionName();
317 
318  // Iterate through DCUs
319  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu = dcus.begin();
320  SiStripConfigDb::DeviceDescriptionsV::const_iterator jdcu = dcus.end();
321  for ( ; idcu != jdcu; ++idcu ) {
322 
323  // Extract DCU-FEH description
324  dcuDescription* dcu = dynamic_cast<dcuDescription*>( *idcu );
325  if ( !dcu ) { continue; }
326  if ( dcu->getDcuType() != "FEH" ) { continue; }
327 
328  // S.L. 29/1/2010
329  // HARDCODED!!! We have a broken module, known from Pisa integration tests
330  // We could really use a better solutin for this than hardcode it!!!
331  if ( dcu->getDcuHardId() == 16448250 ) continue; // fake dcu (0xfafafa)
332 
333  // Find TkDcuInfo object corresponding to given DCU description
334  SiStripConfigDb::DcuDetIdsV::const_iterator idet = dets.end();
335  idet = SiStripConfigDb::findDcuDetId( dets.begin(), dets.end(), dcu->getDcuHardId() );
336  if ( idet == dets.begin() ) { continue; }
337 
338  // Extract TkDcuInfo object
339  TkDcuInfo* det = idet->second;
340  if ( !det ) { continue; }
341 
342  // Build FEC key
343  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress( *dcu );
344  SiStripFecKey fec_key( addr.fecCrate_,
345  addr.fecSlot_,
346  addr.fecRing_,
347  addr.ccuAddr_,
348  addr.ccuChan_ );
349 
350  // Build DetInfo object
351  DetInfo info;
352  info.dcuId_ = det->getDcuHardId();
353  info.detId_ = det->getDetId();
354  info.pairs_ = det->getApvNumber()/2;
355 
356  // Add it to map
357  if ( fec_key.isValid() ) { detInfo_[pp][fec_key.key()] = info; }
358 
359  }
360  }
361 
362  // Debug
363  if ( edm::isDebugEnabled() ) {
364  std::stringstream ss;
365  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
366  << " List of modules for "
367  << detInfo_.size()
368  << " partitions, with their DCUids, DetIds, and nApvPairs: " << std::endl;
369  std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
370  std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
371  for ( ; ii != jj; ++ii ) {
372  ss << " Partition \"" << ii->first
373  << "\" has " << ii->second.size()
374  << " modules:"
375  << std::endl;
376  DetInfos::const_iterator iii = ii->second.begin();
377  DetInfos::const_iterator jjj = ii->second.end();
378  for ( ; iii != jjj; ++iii ) {
379  SiStripFecKey key = iii->first;
380  ss << " module= "
381  << key.fecCrate() << "/"
382  << key.fecSlot() << "/"
383  << key.fecRing() << "/"
384  << key.ccuAddr() << "/"
385  << key.ccuChan() << ", "
386  << std::hex
387  << " DCUid= "
388  << std::setw(8) << std::setfill('0') << iii->second.dcuId_
389  << " DetId= "
390  << std::setw(8) << std::setfill('0') << iii->second.detId_
391  << std::dec
392  << " nPairs= "
393  << iii->second.pairs_
394  << std::endl;
395  }
396  }
397  //LogTrace(mlDqmClient_) << ss.str();
398  }
399 
400 }
401 
402 // -----------------------------------------------------------------------------
403 //
404 std::pair<std::string,CommissioningHistosUsingDb::DetInfo> CommissioningHistosUsingDb::detInfo( const SiStripFecKey& key ) {
406  if ( tmp.isInvalid() ) { return std::make_pair("",DetInfo()); }
407  std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
408  std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
409  for ( ; ii != jj; ++ii ) {
410  DetInfos::const_iterator iii = ii->second.find( tmp.key() );
411  if ( iii != ii->second.end() ) { return std::make_pair(ii->first,iii->second); }
412  }
413  return std::make_pair("",DetInfo());
414 }
415 
416 // -----------------------------------------------------------------------------
417 //
420  std::pair<std::string,DetInfo> info = detInfo(key);
421  if ( info.second.dcuId_ != sistrip::invalid32_ ) {
422  if ( key.channel() == 2 && info.second.pairs_ == 2 ) { return false; }
423  else { return true; }
424  } else {
425  std::stringstream ss;
426  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
427  << " Cannot find module (crate/FEC/ring/CCU/module): "
428  << tmp.fecCrate() << "/"
429  << tmp.fecSlot() << "/"
430  << tmp.fecRing() << "/"
431  << tmp.ccuAddr() << "/"
432  << tmp.ccuChan()
433  << "!";
434  edm::LogWarning(mlDqmClient_) << ss.str();
435  return true;
436  }
437 }
438 
439 
440 
441 
const uint16_t & fecSlot() const
type
Definition: HCALResponse.h:21
bool isDebugEnabled()
const uint16_t & fecCrate() const
static const TGPicture * info(bool iBackgroundIsBlack)
DcuDetIds::range DcuDetIdsRange
const uint32_t & fedKey() const
const uint16_t & fecRing() 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
bool deviceIsPresent(const SiStripFecKey &)
DeviceFactory *const deviceFactory(std::string method_name="") const
static const uint32_t invalid32_
Definition: Constants.h:15
void uploadAnalysisDescriptions(bool calibration_for_physics=false, std::string partition="")
void terse(std::stringstream &) const
void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV &)
static const char mlDqmClient_[]
const uint16_t & fecSlot() const
uint16_t lldChannel() const
const uint16_t & fedId() const
sistrip classes
std::map< std::string, DetInfos > detInfo_
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_iterator_range partitions() const
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:395
const uint16_t & fecRing() const
const uint32_t & detId() const
static void buildFecCabling(SiStripConfigDb *const, SiStripFecCabling &, const sistrip::CablingSource &)
Class containning control, module, detector and connection information, at the level of a FED channel...
bool isInvalid() const
DeviceDescriptions::range DeviceDescriptionsRange
const uint32_t & dcuId() const
void clearAnalysisDescriptions(std::string partition="")
An interface class to the DeviceFactory.
const uint16_t & ccuChan() const
void summary(std::stringstream &ss) const
LEFT FOR COMPATIBILITY. SHOULD BE REPLACED BY PRINTSUMMARY.
const uint32_t & fecKey() const
const std::string & path() const
Definition: SiStripKey.h:126
DeviceAddress deviceAddress(const deviceDescription &)
uint16_t fedChannel() const
const uint16_t & ccuAddr() const
const uint32_t & dcuId() const
#define LogTrace(id)
ii
Definition: cuy.py:588
const uint16_t & fecCrate() const
static void getFedCabling(const SiStripFecCabling &in, SiStripFedCabling &out)
std::pair< std::string, DetInfo > detInfo(const SiStripFecKey &)
const uint16_t & feUnit() const
const SiStripDbParams & dbParams() const
const uint16_t & channel() const
Definition: SiStripKey.h:128
virtual void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
virtual void createAnalyses(SiStripConfigDb::AnalysisDescriptionsV &)
const uint16_t & ccuAddr() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
bool isValid() const
std::vector< AnalysisDescription * > AnalysisDescriptionsV
const uint16_t & feChan() const
const uint32_t & detId() const
const uint16_t & ccuChan() const
const uint16_t & fedId() const
SiStripConfigDb *const db() const
Abstract base for derived classes that provide analysis of commissioning histograms.
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
DcuDetIdsRange getDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:10
static void buildFecCablingFromDevices(SiStripConfigDb *const, SiStripFecCabling &)