CMS 3D CMS Logo

CommissioningHistosUsingDb.cc
Go to the documentation of this file.
3 
14 #include <iostream>
15 
16 using namespace sistrip;
17 
18 // -----------------------------------------------------------------------------
22  runType_(type),
23  db_(db),
24  cabling_(nullptr),
25  detInfo_(),
26  uploadAnal_(true),
27  uploadConf_(false) {
28  LogTrace(mlDqmClient_) << "[" << __PRETTY_FUNCTION__ << "]"
29  << " Constructing object...";
30 }
31 
32 // -----------------------------------------------------------------------------
37  db_(nullptr),
39  detInfo_(),
42  LogTrace(mlDqmClient_) << "[" << __PRETTY_FUNCTION__ << "]"
43  << " Constructing object..." << endl;
44 }
45 
46 // -----------------------------------------------------------------------------
49  if (db_) {
50  delete db_;
51  }
52  LogTrace(mlDqmClient_) << "[" << __PRETTY_FUNCTION__ << "]"
53  << " Destructing object...";
54 }
55 
57  if (!db_) {
58  edm::LogError(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
59  << " NULL pointer to SiStripConfigDb interface!"
60  << " Cannot configure...";
61  } else {
62  // Build FEC cabling object from connections found in DB
63  SiStripFecCabling fec_cabling;
66  } else {
68  }
69 
70  // Build FED cabling from FEC cabling
73  std::stringstream ss;
74  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
75  << " Terse print out of FED cabling:" << std::endl;
76  cabling_->terse(ss);
77  LogTrace(mlDqmClient_) << ss.str();
78 
80  setup.get<TrackerTopologyRcd>().get(tTopo);
81  std::stringstream sss;
82  sss << "[CommissioningHistosUsingDb::" << __func__ << "]"
83  << " Summary of FED cabling:" << std::endl;
84  cabling_->summary(sss, tTopo.product());
85  edm::LogVerbatim(mlDqmClient_) << sss.str();
86  }
87 }
88 
89 // -----------------------------------------------------------------------------
92  buildDetInfo();
93  addDcuDetIds();
96 }
97 
98 // -----------------------------------------------------------------------------
101  if (!db_) {
102  edm::LogError(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
103  << " NULL pointer to SiStripConfigDb interface!"
104  << " Aborting upload...";
105  return;
106  }
107 
109  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
110  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
111  for (; ip != jp; ++ip) {
112  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
113  << " Starting from partition " << ip->first << " with versions:\n"
114  << std::dec << " Conn: " << ip->second.cabVersion().first << "."
115  << ip->second.cabVersion().second << "\n"
116  << " FED: " << ip->second.fedVersion().first << "."
117  << ip->second.fedVersion().second << "\n"
118  << " FEC: " << ip->second.fecVersion().first << "."
119  << ip->second.fecVersion().second << "\n"
120  << " Mask: " << ip->second.maskVersion().first << "."
121  << ip->second.maskVersion().second;
122 
123  // Upload commissioning analysis results
125  createAnalyses(anals);
126 
127  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
128  << " Created analysis descriptions for " << anals.size() << " devices";
129 
130  // Update analysis descriptions with new commissioning results
131  if (uploadAnal_) {
132  if (uploadConf_) {
133  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
134  << " Uploading major version of analysis descriptions to DB"
135  << " (will be used for physics)...";
136  } else {
137  edm::LogVerbatim(mlDqmClient_) << "[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());
144  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
145  << " Upload of analysis descriptions to DB finished!";
146  } else {
147  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
148  << " TEST! No analysis descriptions will be uploaded to DB...";
149  }
150 
151  if (uploadConf_) {
152  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
153  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
154  for (; ip != jp; ++ip) {
155  DeviceFactory* df = db_->deviceFactory();
156  tkStateVector states = df->getCurrentStates();
157  tkStateVector::const_iterator istate = states.begin();
158  tkStateVector::const_iterator jstate = states.end();
159  while (istate != jstate) {
160  if (*istate && ip->first == (*istate)->getPartitionName()) {
161  break;
162  }
163  istate++;
164  }
165  // Set versions if state was found
166  if (istate != states.end()) {
167  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
168  << " Created new version for partition " << ip->first << ". Current state:\n"
169  << std::dec << " Conn: " << (*istate)->getConnectionVersionMajorId() << "."
170  << (*istate)->getConnectionVersionMinorId() << "\n"
171  << " FED: " << (*istate)->getFedVersionMajorId() << "."
172  << (*istate)->getFedVersionMinorId() << "\n"
173  << " FEC: " << (*istate)->getFecVersionMajorId() << "."
174  << (*istate)->getFecVersionMinorId() << "\n"
175  << " Mask: " << (*istate)->getMaskVersionMajorId() << "."
176  << (*istate)->getMaskVersionMinorId();
177  }
178  }
179  }
180  }
181 }
182 
183 // -----------------------------------------------------------------------------
186  if (!cabling_) {
187  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
188  << " NULL pointer to SiStripFedCabling object!";
189  return;
190  }
191 
192  Analyses::iterator ianal = data().begin();
193  Analyses::iterator janal = data().end();
194  for (; ianal != janal; ++ianal) {
195  CommissioningAnalysis* anal = ianal->second;
196 
197  if (!anal) {
198  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
199  << " NULL pointer to CommissioningAnalysis object!";
200  return;
201  }
202 
203  SiStripFedKey fed_key = anal->fedKey();
204  SiStripFecKey fec_key = anal->fecKey();
205 
207 
209 
210  SiStripFecKey fec(
211  conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
212 
213  if (fed_key.path() != fed.path()) {
214  std::stringstream ss;
215  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
216  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
217  << " Incompatible FED key retrieved from cabling!" << std::endl
218  << " FED key from analysis object : " << fed_key.path() << std::endl
219  << " FED key from cabling object : " << fed.path() << std::endl
220  << " FED id/ch from analysis object: " << fed_key.fedId() << "/" << fed_key.fedChannel() << std::endl
221  << " FED id/ch from cabling object : " << conn.fedId() << "/" << conn.fedCh();
222  edm::LogWarning(mlDqmClient_) << ss.str();
223 
224  } else if (fec_key.path() != fec.path()) {
225  std::stringstream ss;
226  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
227  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
228  << " Incompatible FEC key retrieved from cabling!" << std::endl
229  << " FEC key from analysis object : " << fec_key.path() << std::endl
230  << " FEC key from cabling object : " << fec.path();
231  edm::LogWarning(mlDqmClient_) << ss.str();
232 
233  } else {
234  anal->dcuId(conn.dcuId());
235  anal->detId(conn.detId());
236  }
237  }
238 }
239 
240 // -----------------------------------------------------------------------------
241 //
243  LogTrace(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
244  << " Creating AnalysisDescriptions...";
245 
246  desc.clear();
247 
248  Analyses::iterator ianal = data().begin();
249  Analyses::iterator janal = data().end();
250  for (; ianal != janal; ++ianal) {
251  // create analysis description
252  create(desc, ianal);
253  }
254 }
255 
256 // -----------------------------------------------------------------------------
257 //
259  detInfo_.clear();
260 
261  if (!db()) {
262  edm::LogError(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
263  << " NULL pointer to SiStripConfigDb interface!";
264  return;
265  }
266 
267  SiStripDbParams::SiStripPartitions::const_iterator ii = db_->dbParams().partitions().begin();
268  SiStripDbParams::SiStripPartitions::const_iterator jj = db_->dbParams().partitions().end();
269  for (; ii != jj; ++ii) {
270  // Retrieve DCUs and DetIds for given partition
271  std::string pp = ii->second.partitionName();
274 
275  // Iterate through DCUs
276  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu = dcus.begin();
277  SiStripConfigDb::DeviceDescriptionsV::const_iterator jdcu = dcus.end();
278  for (; idcu != jdcu; ++idcu) {
279  // Extract DCU-FEH description
280  dcuDescription* dcu = dynamic_cast<dcuDescription*>(*idcu);
281  if (!dcu) {
282  continue;
283  }
284  if (dcu->getDcuType() != "FEH") {
285  continue;
286  }
287 
288  // S.L. 29/1/2010
289  // HARDCODED!!! We have a broken module, known from Pisa integration tests
290  // We could really use a better solutin for this than hardcode it!!!
291  if (dcu->getDcuHardId() == 16448250)
292  continue; // fake dcu (0xfafafa)
293 
294  // Find TkDcuInfo object corresponding to given DCU description
295  SiStripConfigDb::DcuDetIdsV::const_iterator idet = dets.end();
296  idet = SiStripConfigDb::findDcuDetId(dets.begin(), dets.end(), dcu->getDcuHardId());
297  if (idet == dets.begin()) {
298  continue;
299  }
300 
301  // Extract TkDcuInfo object
302  TkDcuInfo* det = idet->second;
303  if (!det) {
304  continue;
305  }
306 
307  // Build FEC key
309  SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_);
310 
311  // Build DetInfo object
312  DetInfo info;
313  info.dcuId_ = det->getDcuHardId();
314  info.detId_ = det->getDetId();
315  info.pairs_ = det->getApvNumber() / 2;
316 
317  // Add it to map
318  if (fec_key.isValid()) {
319  detInfo_[pp][fec_key.key()] = info;
320  }
321  }
322  }
323 
324  // Debug
325  if (edm::isDebugEnabled()) {
326  std::stringstream ss;
327  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
328  << " List of modules for " << detInfo_.size()
329  << " partitions, with their DCUids, DetIds, and nApvPairs: " << std::endl;
330  std::map<std::string, DetInfos>::const_iterator ii = detInfo_.begin();
331  std::map<std::string, DetInfos>::const_iterator jj = detInfo_.end();
332  for (; ii != jj; ++ii) {
333  ss << " Partition \"" << ii->first << "\" has " << ii->second.size() << " modules:" << std::endl;
334  DetInfos::const_iterator iii = ii->second.begin();
335  DetInfos::const_iterator jjj = ii->second.end();
336  for (; iii != jjj; ++iii) {
337  SiStripFecKey key = iii->first;
338  ss << " module= " << key.fecCrate() << "/" << key.fecSlot() << "/" << key.fecRing() << "/" << key.ccuAddr()
339  << "/" << key.ccuChan() << ", " << std::hex << " DCUid= " << std::setw(8) << std::setfill('0')
340  << iii->second.dcuId_ << " DetId= " << std::setw(8) << std::setfill('0') << iii->second.detId_ << std::dec
341  << " nPairs= " << iii->second.pairs_ << std::endl;
342  }
343  }
344  //LogTrace(mlDqmClient_) << ss.str();
345  }
346 }
347 
348 // -----------------------------------------------------------------------------
349 //
350 std::pair<std::string, CommissioningHistosUsingDb::DetInfo> CommissioningHistosUsingDb::detInfo(
351  const SiStripFecKey& key) {
353  if (tmp.isInvalid()) {
354  return std::make_pair("", DetInfo());
355  }
356  std::map<std::string, DetInfos>::const_iterator ii = detInfo_.begin();
357  std::map<std::string, DetInfos>::const_iterator jj = detInfo_.end();
358  for (; ii != jj; ++ii) {
359  DetInfos::const_iterator iii = ii->second.find(tmp.key());
360  if (iii != ii->second.end()) {
361  return std::make_pair(ii->first, iii->second);
362  }
363  }
364  return std::make_pair("", DetInfo());
365 }
366 
367 // -----------------------------------------------------------------------------
368 //
371  std::pair<std::string, DetInfo> info = detInfo(key);
372  if (info.second.dcuId_ != sistrip::invalid32_) {
373  if (key.channel() == 2 && info.second.pairs_ == 2) {
374  return false;
375  } else {
376  return true;
377  }
378  } else {
379  std::stringstream ss;
380  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
381  << " Cannot find module (crate/FEC/ring/CCU/module): " << tmp.fecCrate() << "/" << tmp.fecSlot() << "/"
382  << tmp.fecRing() << "/" << tmp.ccuAddr() << "/" << tmp.ccuChan() << "!";
383  edm::LogWarning(mlDqmClient_) << ss.str();
384  return true;
385  }
386 }
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)
std::map< std::string, DetInfos > detInfo_
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 &)
#define nullptr
static const char mlDqmClient_[]
const uint16_t & fecSlot() const
uint16_t lldChannel() const
void configure(const edm::ParameterSet &, const edm::EventSetup &) override
const uint16_t & fedId() const
sistrip classes
const uint32_t & key() const
Definition: SiStripKey.h:120
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:412
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:121
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:590
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:123
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...
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:73
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
tmp
align.sh
Definition: createJobs.py:716
T const * product() const
Definition: ESHandle.h:86
static void buildFecCablingFromDevices(SiStripConfigDb *const, SiStripFecCabling &)