CMS 3D CMS Logo

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