CMS 3D CMS Logo

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