CMS 3D CMS Logo

CommissioningHistosUsingDb.cc
Go to the documentation of this file.
11 #include <iostream>
12 
13 using namespace sistrip;
14 
15 // -----------------------------------------------------------------------------
21  runType_(type),
22  db_(db),
23  cabling_(nullptr),
24  detInfo_(),
25  uploadAnal_(true),
26  uploadConf_(false),
27  tTopoToken_{tTopoToken} {
28  LogTrace(mlDqmClient_) << "[" << __PRETTY_FUNCTION__ << "]"
29  << " Constructing object...";
30 }
31 
32 // -----------------------------------------------------------------------------
36  runType_(sistrip::UNDEFINED_RUN_TYPE),
37  db_(nullptr),
38  cabling_(nullptr),
39  detInfo_(),
40  uploadAnal_(false),
41  uploadConf_(false) {
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 
79  const auto& tTopo = setup.getData(tTopoToken_);
80  std::stringstream sss;
81  sss << "[CommissioningHistosUsingDb::" << __func__ << "]"
82  << " Summary of FED cabling:" << std::endl;
83  cabling_->summary(sss, &tTopo);
84  edm::LogVerbatim(mlDqmClient_) << sss.str();
85  }
86 }
87 
88 // -----------------------------------------------------------------------------
91  buildDetInfo();
92  addDcuDetIds();
95 }
96 
97 // -----------------------------------------------------------------------------
100  if (!db_) {
101  edm::LogError(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
102  << " NULL pointer to SiStripConfigDb interface!"
103  << " Aborting upload...";
104  return;
105  }
106 
108  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
109  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
110  for (; ip != jp; ++ip) {
111  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
112  << " Starting from partition " << ip->first << " with versions:\n"
113  << std::dec << " Conn: " << ip->second.cabVersion().first << "."
114  << ip->second.cabVersion().second << "\n"
115  << " FED: " << ip->second.fedVersion().first << "."
116  << ip->second.fedVersion().second << "\n"
117  << " FEC: " << ip->second.fecVersion().first << "."
118  << ip->second.fecVersion().second << "\n"
119  << " Mask: " << ip->second.maskVersion().first << "."
120  << ip->second.maskVersion().second;
121 
122  // Upload commissioning analysis results
124  createAnalyses(anals);
125 
126  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
127  << " Created analysis descriptions for " << anals.size() << " devices";
128 
129  // Update analysis descriptions with new commissioning results
130  if (uploadAnal_) {
131  if (uploadConf_) {
132  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
133  << " Uploading major version of analysis descriptions to DB"
134  << " (will be used for physics)...";
135  } else {
136  edm::LogVerbatim(mlDqmClient_) << "[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());
143  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
144  << " Upload of analysis descriptions to DB finished!";
145  } else {
146  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
147  << " TEST! No analysis descriptions will be uploaded to DB...";
148  }
149 
150  if (uploadConf_) {
151  SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
152  SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
153  for (; ip != jp; ++ip) {
154  DeviceFactory* df = db_->deviceFactory();
155  tkStateVector states = df->getCurrentStates();
156  tkStateVector::const_iterator istate = states.begin();
157  tkStateVector::const_iterator jstate = states.end();
158  while (istate != jstate) {
159  if (*istate && ip->first == (*istate)->getPartitionName()) {
160  break;
161  }
162  istate++;
163  }
164  // Set versions if state was found
165  if (istate != states.end()) {
166  edm::LogVerbatim(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
167  << " Created new version for partition " << ip->first << ". Current state:\n"
168  << std::dec << " Conn: " << (*istate)->getConnectionVersionMajorId() << "."
169  << (*istate)->getConnectionVersionMinorId() << "\n"
170  << " FED: " << (*istate)->getFedVersionMajorId() << "."
171  << (*istate)->getFedVersionMinorId() << "\n"
172  << " FEC: " << (*istate)->getFecVersionMajorId() << "."
173  << (*istate)->getFecVersionMinorId() << "\n"
174  << " Mask: " << (*istate)->getMaskVersionMajorId() << "."
175  << (*istate)->getMaskVersionMinorId();
176  }
177  }
178  }
179  }
180 }
181 
182 // -----------------------------------------------------------------------------
185  if (!cabling_) {
186  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
187  << " NULL pointer to SiStripFedCabling object!";
188  return;
189  }
190 
191  Analyses::iterator ianal = data().begin();
192  Analyses::iterator janal = data().end();
193  for (; ianal != janal; ++ianal) {
194  CommissioningAnalysis* anal = ianal->second;
195 
196  if (!anal) {
197  edm::LogWarning(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
198  << " NULL pointer to CommissioningAnalysis object!";
199  return;
200  }
201 
202  SiStripFedKey fed_key = anal->fedKey();
203  SiStripFecKey fec_key = anal->fecKey();
204 
206 
207  SiStripFedKey fed(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
208 
209  SiStripFecKey fec(
210  conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
211 
212  if (fed_key.path() != fed.path()) {
213  std::stringstream ss;
214  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
215  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
216  << " Incompatible FED key retrieved from cabling!" << std::endl
217  << " FED key from analysis object : " << fed_key.path() << std::endl
218  << " FED key from cabling object : " << fed.path() << std::endl
219  << " FED id/ch from analysis object: " << fed_key.fedId() << "/" << fed_key.fedChannel() << std::endl
220  << " FED id/ch from cabling object : " << conn.fedId() << "/" << conn.fedCh();
221  edm::LogWarning(mlDqmClient_) << ss.str();
222 
223  } else if (fec_key.path() != fec.path()) {
224  std::stringstream ss;
225  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
226  << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
227  << " Incompatible FEC key retrieved from cabling!" << std::endl
228  << " FEC key from analysis object : " << fec_key.path() << std::endl
229  << " FEC key from cabling object : " << fec.path();
230  edm::LogWarning(mlDqmClient_) << ss.str();
231 
232  } else {
233  anal->dcuId(conn.dcuId());
234  anal->detId(conn.detId());
235  }
236  }
237 }
238 
239 // -----------------------------------------------------------------------------
240 //
242  LogTrace(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
243  << " Creating AnalysisDescriptions...";
244 
245  desc.clear();
246 
247  Analyses::iterator ianal = data().begin();
248  Analyses::iterator janal = data().end();
249  for (; ianal != janal; ++ianal) {
250  // create analysis description
251  create(desc, ianal);
252  }
253 }
254 
255 // -----------------------------------------------------------------------------
256 //
258  detInfo_.clear();
259 
260  if (!db()) {
261  edm::LogError(mlDqmClient_) << "[CommissioningHistosUsingDb::" << __func__ << "]"
262  << " NULL pointer to SiStripConfigDb interface!";
263  return;
264  }
265 
266  SiStripDbParams::SiStripPartitions::const_iterator ii = db_->dbParams().partitions().begin();
267  SiStripDbParams::SiStripPartitions::const_iterator jj = db_->dbParams().partitions().end();
268  for (; ii != jj; ++ii) {
269  // Retrieve DCUs and DetIds for given partition
270  std::string pp = ii->second.partitionName();
273 
274  // Iterate through DCUs
275  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu = dcus.begin();
276  SiStripConfigDb::DeviceDescriptionsV::const_iterator jdcu = dcus.end();
277  for (; idcu != jdcu; ++idcu) {
278  // Extract DCU-FEH description
279  dcuDescription* dcu = dynamic_cast<dcuDescription*>(*idcu);
280  if (!dcu) {
281  continue;
282  }
283  if (dcu->getDcuType() != "FEH") {
284  continue;
285  }
286 
287  // S.L. 29/1/2010
288  // HARDCODED!!! We have a broken module, known from Pisa integration tests
289  // We could really use a better solutin for this than hardcode it!!!
290  if (dcu->getDcuHardId() == 16448250)
291  continue; // fake dcu (0xfafafa)
292 
293  // Find TkDcuInfo object corresponding to given DCU description
294  SiStripConfigDb::DcuDetIdsV::const_iterator idet = dets.end();
295  idet = SiStripConfigDb::findDcuDetId(dets.begin(), dets.end(), dcu->getDcuHardId());
296  if (idet == dets.begin()) {
297  continue;
298  }
299 
300  // Extract TkDcuInfo object
301  TkDcuInfo* det = idet->second;
302  if (!det) {
303  continue;
304  }
305 
306  // Build FEC key
308  SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_);
309 
310  // Build DetInfo object
311  DetInfo info;
312  info.dcuId_ = det->getDcuHardId();
313  info.detId_ = det->getDetId();
314  info.pairs_ = det->getApvNumber() / 2;
315 
316  // Add it to map
317  if (fec_key.isValid()) {
318  detInfo_[pp][fec_key.key()] = info;
319  }
320  }
321  }
322 
323  // Debug
324  if (edm::isDebugEnabled()) {
325  std::stringstream ss;
326  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
327  << " List of modules for " << detInfo_.size()
328  << " partitions, with their DCUids, DetIds, and nApvPairs: " << std::endl;
329  std::map<std::string, DetInfos>::const_iterator ii = detInfo_.begin();
330  std::map<std::string, DetInfos>::const_iterator jj = detInfo_.end();
331  for (; ii != jj; ++ii) {
332  ss << " Partition \"" << ii->first << "\" has " << ii->second.size() << " modules:" << std::endl;
333  DetInfos::const_iterator iii = ii->second.begin();
334  DetInfos::const_iterator jjj = ii->second.end();
335  for (; iii != jjj; ++iii) {
336  SiStripFecKey key = iii->first;
337  ss << " module= " << key.fecCrate() << "/" << key.fecSlot() << "/" << key.fecRing() << "/" << key.ccuAddr()
338  << "/" << key.ccuChan() << ", " << std::hex << " DCUid= " << std::setw(8) << std::setfill('0')
339  << iii->second.dcuId_ << " DetId= " << std::setw(8) << std::setfill('0') << iii->second.detId_ << std::dec
340  << " nPairs= " << iii->second.pairs_ << std::endl;
341  }
342  }
343  //LogTrace(mlDqmClient_) << ss.str();
344  }
345 }
346 
347 // -----------------------------------------------------------------------------
348 //
349 std::pair<std::string, CommissioningHistosUsingDb::DetInfo> CommissioningHistosUsingDb::detInfo(
350  const SiStripFecKey& key) {
352  if (tmp.isInvalid()) {
353  return std::make_pair("", DetInfo());
354  }
355  std::map<std::string, DetInfos>::const_iterator ii = detInfo_.begin();
356  std::map<std::string, DetInfos>::const_iterator jj = detInfo_.end();
357  for (; ii != jj; ++ii) {
358  DetInfos::const_iterator iii = ii->second.find(tmp.key());
359  if (iii != ii->second.end()) {
360  return std::make_pair(ii->first, iii->second);
361  }
362  }
363  return std::make_pair("", DetInfo());
364 }
365 
366 // -----------------------------------------------------------------------------
367 //
370  std::pair<std::string, DetInfo> info = detInfo(key);
371  if (info.second.dcuId_ != sistrip::invalid32_) {
372  if (key.channel() == 2 && info.second.pairs_ == 2) {
373  return false;
374  } else {
375  return true;
376  }
377  } else {
378  std::stringstream ss;
379  ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
380  << " Cannot find module (crate/FEC/ring/CCU/module): " << tmp.fecCrate() << "/" << tmp.fecSlot() << "/"
381  << tmp.fecRing() << "/" << tmp.ccuAddr() << "/" << tmp.ccuChan() << "!";
382  edm::LogWarning(mlDqmClient_) << ss.str();
383  return true;
384  }
385 }
void summary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
LEFT FOR COMPATIBILITY. SHOULD BE REPLACED BY PRINTSUMMARY.
Log< level::Info, true > LogVerbatim
bool isDebugEnabled()
static const TGPicture * info(bool iBackgroundIsBlack)
DcuDetIds::range DcuDetIdsRange
const uint16_t & feChan() const
Analyses & data(bool getMaskedData=false)
std::map< std::string, DetInfos > detInfo_
const uint16_t & feUnit() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
bool deviceIsPresent(const SiStripFecKey &)
static const uint32_t invalid32_
Definition: Constants.h:15
void uploadAnalysisDescriptions(bool calibration_for_physics=false, std::string partition="")
SiStripDetInfo::DetInfo DetInfo
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV &)
const std::string & path() const
Definition: SiStripKey.h:121
static const char mlDqmClient_[]
Log< level::Error, false > LogError
void configure(const edm::ParameterSet &, const edm::EventSetup &) override
const_iterator_range partitions() const
sistrip classes
#define LogTrace(id)
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:412
uint16_t fedChannel() 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...
SiStripConfigDb *const db() const
DeviceDescriptions::range DeviceDescriptionsRange
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void clearAnalysisDescriptions(std::string partition="")
An interface class to the DeviceFactory.
const uint32_t & key() const
Definition: SiStripKey.h:120
key
prepare the HTCondor submission files and eventually submit them
DeviceAddress deviceAddress(const deviceDescription &)
ii
Definition: cuy.py:589
const uint16_t & fedId() const
static void getFedCabling(const SiStripFecCabling &in, SiStripFedCabling &out)
bool isValid() const override
std::pair< std::string, DetInfo > detInfo(const SiStripFecKey &)
virtual void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
virtual void createAnalyses(SiStripConfigDb::AnalysisDescriptionsV &)
void terse(std::stringstream &) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
std::vector< AnalysisDescription * > AnalysisDescriptionsV
conn
Definition: getInfo.py:9
const SiStripDbParams & dbParams() const
Abstract base for derived classes that provide analysis of commissioning histograms.
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
Log< level::Warning, false > LogWarning
DcuDetIdsRange getDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:10
tmp
align.sh
Definition: createJobs.py:716
DeviceFactory *const deviceFactory(std::string method_name="") const
static void buildFecCablingFromDevices(SiStripConfigDb *const, SiStripFecCabling &)