CMS 3D CMS Logo

DTBlockedROChannelsTest.cc
Go to the documentation of this file.
1 /*
2  * \file DTBlockedROChannelsTest.cc
3  *
4  * \author G. Cerminara - University and INFN Torino
5  *
6  */
7 
9 
10 //Framework
17 #include <iostream>
18 #include <string>
19 
20 using namespace std;
21 using namespace edm;
22 
24  : nevents(0),
25  neventsPrev(0),
26  prevNLumiSegs(0),
27  prevTotalPerc(0),
28  mappingToken_(esConsumes<edm::Transition::BeginRun>()),
29  hSystFractionVsLS(nullptr) {
30  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest") << "[DTBlockedROChannelsTest]: Constructor";
31 
32  // prescale on the # of LS to update the test
33  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
34 
35  offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
36 
37  checkUros = ps.getUntrackedParameter<bool>("checkUros", true);
38 }
39 
41  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
42  << "DataIntegrityTest: analyzed " << nupdates << " updates";
43 }
44 
46  // get the RO mapping
47  mapping = &setup.getData(mappingToken_);
48  nupdates = 0;
49  return;
50 }
51 
53  int dummy = 0;
54  bool tenDDU = !mapping->readOutToGeometry(779, 7, 1, 1, 1, dummy, dummy, dummy, dummy, dummy, dummy);
55 
56  if (checkUros) {
57  for (int crate = FEDNumbering::MINDTUROSFEDID; crate <= FEDNumbering::MAXDTUROSFEDID; ++crate) { //loop over FEDs
58  for (int mapSlot = 1; mapSlot != 13; ++mapSlot) { //loop over mapSlot
59  for (int link = 0; link != 72; ++link) { //loop over links
60  //skip non existing links
61  if (mapSlot == 6)
62  continue;
63  if (crate == 1370 && mapSlot > 5)
64  continue;
65  if ((mapSlot == 5 || mapSlot == 11) && link > 11)
66  continue;
67 
68  int wheel = 0;
69  int station = 0;
70  int sector = 0;
71 
72  int dduId = theDDU(crate, mapSlot, link, tenDDU);
73  int ros = theROS(mapSlot, link);
74  int rob = theROB(mapSlot, link);
75 
76  // mapping->readOutToGeometry(dduId,ros,rob,2,2,wheel,station,sector,dummy,dummy,dummy);
77  readOutToGeometry(dduId, ros, rob, wheel, station, sector);
78  if (station > 0) {
79  //std::cout<<" FED "<<crate<<" mapSlot "<< mapSlot<<" Link "<<link<<" Wh "<<wheel<<" station "<<station<<" sector "<<sector <<endl;
81  if (chamberMapUros.find(chId) == chamberMapUros.end()) {
82  chamberMapUros[chId] = DTLinkBinsMap(igetter, dduId, ros);
83  chamberMapUros[chId].addLinkBin(link % 24);
84  }
85  chamberMapUros[chId].addLinkBin(link % 24);
86  } else {
87  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
88  << "[DTLinkBinsMap] FED: " << crate << "mapSlot: " << mapSlot << " Link: " << link
89  << " not in the mapping!" << endl;
90  }
91  } //loop on links
92  } //loop on mapSlots
93  } //loop on crates
94  } //checkUros
95  else {
96  // fill the map of the robs per chamber
97  // //FIXME: monitoring only real used FEDs
98  for (int dduId = FEDNumbering::MINDTFEDID; dduId <= FEDNumbering::MAXDTFEDID; ++dduId) { //loop over DDUs
99  for (int ros = 1; ros != 13; ++ros) { // loop over ROSs
100  for (int rob = 1; rob != 26; ++rob) { // loop over ROBs
101  int wheel = 0;
102  int station = 0;
103  int sector = 0;
104  if (!mapping->readOutToGeometry(dduId, ros, rob - 1, 0, 2, wheel, station, sector, dummy, dummy, dummy) ||
105  !mapping->readOutToGeometry(dduId, ros, rob - 1, 0, 16, wheel, station, sector, dummy, dummy, dummy)) {
107  if (chamberMap.find(chId) == chamberMap.end()) {
108  chamberMap[chId] = DTRobBinsMap(igetter, dduId, ros);
109  chamberMap[chId].addRobBin(rob);
110  }
111  chamberMap[chId].addRobBin(rob);
112  } else {
113  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
114  << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob - 1 << " not in the mapping!"
115  << endl;
116  }
117  }
118  }
119  }
120  // loop over all chambers and remove the init flag
121  for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
122  ++chAndRobs) {
123  chAndRobs->second.init(false);
124  }
125  } //Legacy
126 }
127 
129  DQMStore::IGetter& igetter,
130  edm::LuminosityBlock const& lumiSeg,
131  edm::EventSetup const& context) {
132  //FR moved the following from beginJob!
133 
134  // book the summary histogram
135 
136  if (wheelHistos.empty()) { // this is an attempt to make these bookings only once!
137 
138  ibooker.setCurrentFolder("DT/00-ROChannels");
139  summaryHisto = ibooker.book2D("ROChannelSummary", "Summary Blocked RO Channels", 12, 1, 13, 5, -2, 3);
140  summaryHisto->setAxisTitle("Sector", 1);
141  summaryHisto->setAxisTitle("Wheel", 2);
142 
143  for (int wheel = -2; wheel != 3; ++wheel) {
144  stringstream namestream;
145  namestream << "ROChannelSummary_W" << wheel;
146  stringstream titlestream;
147  titlestream << "Blocked RO Channels (Wh " << wheel << ")";
148  wheelHistos[wheel] = ibooker.book2D(namestream.str().c_str(), titlestream.str().c_str(), 12, 1, 13, 4, 1, 5);
149  wheelHistos[wheel]->setAxisTitle("Sector", 1);
150  wheelHistos[wheel]->setBinLabel(1, "MB1", 2);
151  wheelHistos[wheel]->setBinLabel(2, "MB2", 2);
152  wheelHistos[wheel]->setBinLabel(3, "MB3", 2);
153  wheelHistos[wheel]->setBinLabel(4, "MB4", 2);
154  }
155 
156  if (!offlineMode) {
158  new DTTimeEvolutionHisto(ibooker, "EnabledROChannelsVsLS", "Fraction of RO channels", 500, 5, true, 3);
159  }
160  } // end attempt to make these bookings only once!
161 
162  //FR moved here from beginRun
163 
164  if (checkUros) {
165  if (chamberMapUros.empty())
166  fillChamberMap(igetter, context);
167  } else {
168  if (chamberMap.empty())
169  fillChamberMap(igetter, context);
170  }
171 
172  //FR moved here from beginLuminosityBlock
173  run = lumiSeg.run();
174 
175  //FR moved here from endLuminosityBlock
176  // counts number of lumiSegs
177  nLumiSegs = lumiSeg.id().luminosityBlock();
178 
179  // prescale factor
180  if (nLumiSegs % prescaleFactor != 0 || offlineMode)
181  return;
182 
183  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
184  << "[DTBlockedROChannelsTest]: End of LS " << nLumiSegs
185  << ". Client called in online mode, performing client operations";
186 
187  performClientDiagnostic(igetter);
188 
189  // counts number of updats
190  nupdates++;
191 }
192 
194  if (offlineMode) {
195  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
196  << "[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
197  performClientDiagnostic(igetter);
198  }
199 }
200 
202  //FR: I've commented the if below. Either in online mode or in offline mode, when the diagnostic is called
203  // compute first the number of events. It will be: event/lumisection in the online case, it will be: total number
204  // of events (neventsPrev=0) in the offline case, when the diagnostic is called only once from the dqmEndJob
205 
206  //if(nevents == 0) { // hack to work also in offline DQM
207  MonitorElement* procEvt = igetter.get("DT/EventInfo/processedEvents");
208  if (procEvt != nullptr) {
209  int procEvents = procEvt->getIntValue();
210  nevents = procEvents - neventsPrev;
211  neventsPrev = procEvents;
212  }
213  //}
214 
215  double totalPerc = prevTotalPerc;
216  // check again!
217  if (nevents != 0) { // skip the computation if no events in the last LS
218 
219  // reset the histos
220  summaryHisto->Reset();
221  for (int wheel = -2; wheel != 3; ++wheel) {
222  wheelHistos[wheel]->Reset();
223  }
224 
225  totalPerc = 0.;
226 
227  if (checkUros) {
228  // loop over all chambers and fill the wheel plots
229  for (map<DTChamberId, DTLinkBinsMap>::iterator chAndLinks = chamberMapUros.begin();
230  chAndLinks != chamberMapUros.end();
231  ++chAndLinks) {
232  DTChamberId chId = (*chAndLinks).first;
233  double scale = 1.;
234  int sectorForPlot = chId.sector();
235  if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
236  sectorForPlot = 4;
237  scale = 0.5;
238  } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
239  sectorForPlot = 10;
240  scale = 0.5;
241  }
242 
243  // NOTE: can be called only ONCE per event per each chamber
244  double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
245  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
246  totalPerc += chPercent * scale * 1. /
247  240.; // CB has to be 240 as double stations are taken into account by scale factor
248 
249  // Fill the summary
250  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
251  }
252  } //Uros case
253  else { //Legacy case
254  // loop over all chambers and fill the wheel plots
255  for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
256  ++chAndRobs) {
257  DTChamberId chId = (*chAndRobs).first;
258  double scale = 1.;
259  int sectorForPlot = chId.sector();
260  if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
261  sectorForPlot = 4;
262  scale = 0.5;
263  } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
264  sectorForPlot = 10;
265  scale = 0.5;
266  }
267 
268  // NOTE: can be called only ONCE per event per each chamber
269  double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
270  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
271  totalPerc += chPercent * scale * 1. /
272  240.; // CB has to be 240 as double stations are taken into account by scale factor
273 
274  // Fill the summary
275  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
276  }
277  } //Legacy case
278  } //nevents != 0
279 
280  if (!offlineMode) { // fill trend histo only in online
283  prevTotalPerc = totalPerc;
284  }
285 }
286 
287 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int rob, int& wheel, int& station, int& sector) {
288  int dummy = 0;
289  return mapping->readOutToGeometry(dduId, ros, rob, 2, 2, wheel, station, sector, dummy, dummy, dummy);
290 }
291 
293  : rosBin(ros), init_(true), rosValue(0) {
294  // get the pointer to the corresondig histo
295  // Legacy
296  stringstream mename;
297  mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros << "/FED" << fed << "_ROS" << ros << "_ROSError";
298  rosHName = mename.str();
299 
300  stringstream whname;
301  whname << "DT/00-DataIntegrity/FED" << fed << "/FED" << fed << "_ROSStatus";
302  dduHName = whname.str();
303 
304  meROS = igetter.get(rosHName);
305  meDDU = igetter.get(dduHName);
306 }
307 
308 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap() : init_(true), meROS(nullptr), meDDU(nullptr) {}
309 
311 
312 // add a rob to the set of robs
313 void DTBlockedROChannelsTest::DTRobBinsMap::addRobBin(int robBin) { robsAndValues[robBin] = getValueRobBin(robBin); }
314 
316  if (init_)
317  return 0;
318  int value = 0;
319  if (meROS) {
320  value += (int)meROS->getBinContent(9, robBin);
321  value += (int)meROS->getBinContent(11, robBin);
322  }
323  return value;
324 }
325 
327  int value = 0;
328  if (meDDU) {
329  value += (int)meDDU->getBinContent(2, rosBin);
330  value += (int)meDDU->getBinContent(10, rosBin);
331  }
332  return value;
333 }
334 
336  // check that this is a valid ROB for this map (= it has been added!)
337  if (robsAndValues.find(robBin) == robsAndValues.end()) {
338  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
339  << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
340  return false;
341  }
342 
343  int newValue = getValueRobBin(robBin);
344  if (newValue > robsAndValues[robBin]) {
345  robsAndValues[robBin] = newValue;
346  return true;
347  }
348  return false;
349 }
350 
352  meROS = igetter.get(rosHName);
353  meDDU = igetter.get(dduHName);
354  int nChangedROBs = 0;
355 
356  // check if ros status has changed
357  int newValue = getValueRos();
358  if (newValue > rosValue) {
359  rosValue = newValue;
360  return 0.;
361  }
362 
363  for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
364  ++robAndValue) {
365  if (robChanged((*robAndValue).first))
366  nChangedROBs++;
367  }
368  return 1. - ((double)nChangedROBs / (double)robsAndValues.size());
369 }
370 
372  meROS = igetter.get(rosHName);
373  meDDU = igetter.get(dduHName);
374 
375  rosValue = getValueRos();
376  for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
377  ++robAndValue) {
378  robChanged((*robAndValue).first);
379  }
380 }
381 
382 // uROS starting on 2018
384  : init_(true) {
385  int wheel = (ddu - 770) % 5 - 2;
386 
387  // get the pointer to the corresondig histo
388  urosHName = "DT/00-DataIntegrity/Wheel" + to_string(wheel) + "/Sector" + to_string(ros) + "/W" + to_string(wheel) +
389  "_Sector" + to_string(ros) + "_ROSError";
390  meuROS = igetter.get(urosHName);
391 }
392 
394 
396 
398  linksAndValues[linkBin] = getValueLinkBin(linkBin);
399 }
400 
402  if (!init_)
403  return 0;
404  int value = 0;
405  if (meuROS) {
406  value += (int)meuROS->getBinContent(5, linkBin); //ONLY NotOKFlag
407  }
408  return value;
409 }
410 
412  // check that this is a valid Link for this map (= it has been added!)
413  if (linksAndValues.find(linkBin) == linksAndValues.end()) {
414  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
415  << "[DTLinkBinsMap]***Error: Link: " << linkBin << " is not valid" << endl;
416  return false;
417  }
418 
419  int newValue = getValueLinkBin(linkBin);
420  if (newValue > linksAndValues[linkBin]) {
421  linksAndValues[linkBin] = newValue;
422  return true;
423  }
424  return false;
425 }
426 
428  meuROS = igetter.get(urosHName);
429  int nChangedLinks = 0;
430 
431  for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
432  ++linkAndValue) {
433  if (linkChanged((*linkAndValue).first))
434  nChangedLinks++;
435  }
436  return 1. - ((double)nChangedLinks / (double)linksAndValues.size());
437 }
438 
440  meuROS = igetter.get(urosHName);
441 
442  for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
443  ++linkAndValue) {
444  linkChanged((*linkAndValue).first);
445  }
446 }
447 
448 // Conversions
449 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
450  int ros = theROS(slot, link);
451 
452  int ddu = 772;
453  //if (crate == 1368) { ddu = 775; }
454  //Needed just in case this FED should be used due to fibers lenght
455 
457  if (slot < 7)
458  ddu = 770;
459  else
460  ddu = 771;
461  }
462 
463  if (crate == (FEDNumbering::MINDTUROSFEDID + 1)) {
464  ddu = 772;
465  }
466 
468  if (slot < 7)
469  ddu = 773;
470  else
471  ddu = 774;
472  }
473 
474  if (ros > 6 && tenDDU && ddu < 775)
475  ddu += 5;
476 
477  return ddu;
478 }
479 
481  if (slot % 6 == 5)
482  return link + 1;
483 
484  int ros = (link / 24) + 3 * (slot % 6) - 2;
485  return ros;
486 }
487 
489  if (slot % 6 == 5)
490  return 23;
491 
492  int rob = link % 24;
493  if (rob < 15)
494  return rob;
495  if (rob == 15)
496  return 24;
497  return rob - 1;
498 }
499 
500 // FIXME: move to SealModule
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
int station() const
Return the station number.
Definition: DTChamberId.h:45
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
int theROB(int slot, int link)
DTTimeEvolutionHisto * hSystFractionVsLS
void accumulateValueTimeSlot(float value)
std::map< DTChamberId, DTLinkBinsMap > chamberMapUros
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::map< int, MonitorElement * > wheelHistos
void performClientDiagnostic(DQMStore::IGetter &igetter)
DQM Client operations.
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic in online mode.
std::map< DTChamberId, DTRobBinsMap > chamberMap
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
int theROS(int slot, int link)
void fillChamberMap(DQMStore::IGetter &igetter, const edm::EventSetup &c)
static std::string to_string(const XMLCh *ch)
#define LogTrace(id)
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
edm::ESGetToken< DTReadOutMapping, DTReadOutMappingRcd > mappingToken_
DTBlockedROChannelsTest(const edm::ParameterSet &ps)
Constructor.
void readNewValues(DQMStore::IGetter &igetter)
Transition
Definition: Transition.h:12
const DTReadOutMapping * mapping
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: value.py:1
void readNewValues(DQMStore::IGetter &igetter)
LuminosityBlockID id() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
int theDDU(int crate, int slot, int link, bool tenDDU)
void updateTimeSlot(int ls, int nEventsInLS)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
int readOutToGeometry(int dduId, int rosNumber, int robNumber, int &wheel, int &station, int &sector)
double getChamberPercentage(DQMStore::IGetter &)
void beginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
Log< level::Warning, false > LogWarning
~DTBlockedROChannelsTest() override
Destructor.
double getChamberPercentage(DQMStore::IGetter &)
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
virtual int64_t getIntValue() const