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  Analyses::iterator ianal = data().begin();
281  Analyses::iterator janal = data().end();
282  for ( ; ianal != janal; ++ianal ) {
283  // create analysis description
284  create( desc, ianal );
285  }
286 
287 }
288 
289 // -----------------------------------------------------------------------------
290 //
292 
293  detInfo_.clear();
294 
295  if ( !db() ) {
297  << "[CommissioningHistosUsingDb::" << __func__ << "]"
298  << " NULL pointer to SiStripConfigDb interface!";
299  return;
300  }
301 
302  SiStripDbParams::SiStripPartitions::const_iterator ii = db_->dbParams().partitions().begin();
303  SiStripDbParams::SiStripPartitions::const_iterator jj = db_->dbParams().partitions().end();
304  for ( ; ii != jj; ++ii ) {
305 
306  // Retrieve DCUs and DetIds for given partition
307  std::string pp = ii->second.partitionName();
310 
311  // Iterate through DCUs
312  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu = dcus.begin();
313  SiStripConfigDb::DeviceDescriptionsV::const_iterator jdcu = dcus.end();
314  for ( ; idcu != jdcu; ++idcu ) {
315 
316  // Extract DCU-FEH description
317  dcuDescription* dcu = dynamic_cast<dcuDescription*>( *idcu );
318  if ( !dcu ) { continue; }
319  if ( dcu->getDcuType() != "FEH" ) { continue; }
320 
321  // S.L. 29/1/2010
322  // HARDCODED!!! We have a broken module, known from Pisa integration tests
323  // We could really use a better solutin for this than hardcode it!!!
324  if ( dcu->getDcuHardId() == 16448250 ) continue; // fake dcu (0xfafafa)
325 
326  // Find TkDcuInfo object corresponding to given DCU description
327  SiStripConfigDb::DcuDetIdsV::const_iterator idet = dets.end();
328  idet = SiStripConfigDb::findDcuDetId( dets.begin(), dets.end(), dcu->getDcuHardId() );
329  if ( idet == dets.begin() ) { continue; }
330 
331  // Extract TkDcuInfo object
332  TkDcuInfo* det = idet->second;
333  if ( !det ) { continue; }
334 
335  // Build FEC key
336  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress( *dcu );
337  SiStripFecKey fec_key( addr.fecCrate_,
338  addr.fecSlot_,
339  addr.fecRing_,
340  addr.ccuAddr_,
341  addr.ccuChan_ );
342 
343  // Build DetInfo object
344  DetInfo info;
345  info.dcuId_ = det->getDcuHardId();
346  info.detId_ = det->getDetId();
347  info.pairs_ = det->getApvNumber()/2;
348 
349  // Add it to map
350  if ( fec_key.isValid() ) { detInfo_[pp][fec_key.key()] = info; }
351 
352  }
353  }
354 
355  // Debug
356  if ( edm::isDebugEnabled() ) {
357  std::stringstream ss;
358  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
359  << " List of modules for "
360  << detInfo_.size()
361  << " partitions, with their DCUids, DetIds, and nApvPairs: " << std::endl;
362  std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
363  std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
364  for ( ; ii != jj; ++ii ) {
365  ss << " Partition \"" << ii->first
366  << "\" has " << ii->second.size()
367  << " modules:"
368  << std::endl;
369  DetInfos::const_iterator iii = ii->second.begin();
370  DetInfos::const_iterator jjj = ii->second.end();
371  for ( ; iii != jjj; ++iii ) {
372  SiStripFecKey key = iii->first;
373  ss << " module= "
374  << key.fecCrate() << "/"
375  << key.fecSlot() << "/"
376  << key.fecRing() << "/"
377  << key.ccuAddr() << "/"
378  << key.ccuChan() << ", "
379  << std::hex
380  << " DCUid= "
381  << std::setw(8) << std::setfill('0') << iii->second.dcuId_
382  << " DetId= "
383  << std::setw(8) << std::setfill('0') << iii->second.detId_
384  << std::dec
385  << " nPairs= "
386  << iii->second.pairs_
387  << std::endl;
388  }
389  }
390  //LogTrace(mlDqmClient_) << ss.str();
391  }
392 
393 }
394 
395 // -----------------------------------------------------------------------------
396 //
397 std::pair<std::string,CommissioningHistosUsingDb::DetInfo> CommissioningHistosUsingDb::detInfo( const SiStripFecKey& key ) {
399  if ( tmp.isInvalid() ) { return std::make_pair("",DetInfo()); }
400  std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
401  std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
402  for ( ; ii != jj; ++ii ) {
403  DetInfos::const_iterator iii = ii->second.find( tmp.key() );
404  if ( iii != ii->second.end() ) { return std::make_pair(ii->first,iii->second); }
405  }
406  return std::make_pair("",DetInfo());
407 }
408 
409 // -----------------------------------------------------------------------------
410 //
413  std::pair<std::string,DetInfo> info = detInfo(key);
414  if ( info.second.dcuId_ != sistrip::invalid32_ ) {
415  if ( key.channel() == 2 && info.second.pairs_ == 2 ) { return false; }
416  else { return true; }
417  } else {
418  std::stringstream ss;
419  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
420  << " Cannot find module (crate/FEC/ring/CCU/module): "
421  << tmp.fecCrate() << "/"
422  << tmp.fecSlot() << "/"
423  << tmp.fecRing() << "/"
424  << tmp.ccuAddr() << "/"
425  << tmp.ccuChan()
426  << "!";
427  edm::LogWarning(mlDqmClient_) << ss.str();
428  return true;
429  }
430 }
431 
432 
433 
434 
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
Analyses & data(bool getMaskedData=false)
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:589
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
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
T get() const
Definition: EventSetup.h:63
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 &)