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) {
157  hSystFractionVsLS = new DTTimeEvolutionHisto(ibooker, "EnabledROChannelsVsLS", "% RO channels", 500, 5, true, 3);
158  }
159  } // end attempt to make these bookings only once!
160 
161  //FR moved here from beginRun
162 
163  if (checkUros) {
164  if (chamberMapUros.empty())
165  fillChamberMap(igetter, context);
166  } else {
167  if (chamberMap.empty())
168  fillChamberMap(igetter, context);
169  }
170 
171  //FR moved here from beginLuminosityBlock
172  run = lumiSeg.run();
173 
174  //FR moved here from endLuminosityBlock
175  // counts number of lumiSegs
176  nLumiSegs = lumiSeg.id().luminosityBlock();
177 
178  // prescale factor
179  if (nLumiSegs % prescaleFactor != 0 || offlineMode)
180  return;
181 
182  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
183  << "[DTBlockedROChannelsTest]: End of LS " << nLumiSegs
184  << ". Client called in online mode, performing client operations";
185 
186  performClientDiagnostic(igetter);
187 
188  // counts number of updats
189  nupdates++;
190 }
191 
193  if (offlineMode) {
194  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
195  << "[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
196  performClientDiagnostic(igetter);
197  }
198 }
199 
201  //FR: I've commented the if below. Either in online mode or in offline mode, when the diagnostic is called
202  // compute first the number of events. It will be: event/lumisection in the online case, it will be: total number
203  // of events (neventsPrev=0) in the offline case, when the diagnostic is called only once from the dqmEndJob
204 
205  //if(nevents == 0) { // hack to work also in offline DQM
206  MonitorElement* procEvt = igetter.get("DT/EventInfo/processedEvents");
207  if (procEvt != nullptr) {
208  int procEvents = procEvt->getIntValue();
209  nevents = procEvents - neventsPrev;
210  neventsPrev = procEvents;
211  }
212  //}
213 
214  double totalPerc = prevTotalPerc;
215  // check again!
216  if (nevents != 0) { // skip the computation if no events in the last LS
217 
218  // reset the histos
219  summaryHisto->Reset();
220  for (int wheel = -2; wheel != 3; ++wheel) {
221  wheelHistos[wheel]->Reset();
222  }
223 
224  totalPerc = 0.;
225 
226  if (checkUros) {
227  // loop over all chambers and fill the wheel plots
228  for (map<DTChamberId, DTLinkBinsMap>::iterator chAndLinks = chamberMapUros.begin();
229  chAndLinks != chamberMapUros.end();
230  ++chAndLinks) {
231  DTChamberId chId = (*chAndLinks).first;
232  double scale = 1.;
233  int sectorForPlot = chId.sector();
234  if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
235  sectorForPlot = 4;
236  scale = 0.5;
237  } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
238  sectorForPlot = 10;
239  scale = 0.5;
240  }
241 
242  // NOTE: can be called only ONCE per event per each chamber
243  double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
244  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
245  totalPerc += chPercent * scale * 1. /
246  240.; // CB has to be 240 as double stations are taken into account by scale factor
247 
248  // Fill the summary
249  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
250  }
251  } //Uros case
252  else { //Legacy case
253  // loop over all chambers and fill the wheel plots
254  for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
255  ++chAndRobs) {
256  DTChamberId chId = (*chAndRobs).first;
257  double scale = 1.;
258  int sectorForPlot = chId.sector();
259  if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
260  sectorForPlot = 4;
261  scale = 0.5;
262  } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
263  sectorForPlot = 10;
264  scale = 0.5;
265  }
266 
267  // NOTE: can be called only ONCE per event per each chamber
268  double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
269  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
270  totalPerc += chPercent * scale * 1. /
271  240.; // CB has to be 240 as double stations are taken into account by scale factor
272 
273  // Fill the summary
274  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
275  }
276  } //Legacy case
277  } //nevents != 0
278 
279  if (!offlineMode) { // fill trend histo only in online
282  prevTotalPerc = totalPerc;
283  }
284 }
285 
286 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int rob, int& wheel, int& station, int& sector) {
287  int dummy = 0;
288  return mapping->readOutToGeometry(dduId, ros, rob, 2, 2, wheel, station, sector, dummy, dummy, dummy);
289 }
290 
292  : rosBin(ros), init_(true), rosValue(0) {
293  // get the pointer to the corresondig histo
294  // Legacy
295  stringstream mename;
296  mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros << "/FED" << fed << "_ROS" << ros << "_ROSError";
297  rosHName = mename.str();
298 
299  stringstream whname;
300  whname << "DT/00-DataIntegrity/FED" << fed << "/FED" << fed << "_ROSStatus";
301  dduHName = whname.str();
302 
303  meROS = igetter.get(rosHName);
304  meDDU = igetter.get(dduHName);
305 }
306 
307 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap() : init_(true), meROS(nullptr), meDDU(nullptr) {}
308 
310 
311 // add a rob to the set of robs
312 void DTBlockedROChannelsTest::DTRobBinsMap::addRobBin(int robBin) { robsAndValues[robBin] = getValueRobBin(robBin); }
313 
315  if (init_)
316  return 0;
317  int value = 0;
318  if (meROS) {
319  value += (int)meROS->getBinContent(9, robBin);
320  value += (int)meROS->getBinContent(11, robBin);
321  }
322  return value;
323 }
324 
326  int value = 0;
327  if (meDDU) {
328  value += (int)meDDU->getBinContent(2, rosBin);
329  value += (int)meDDU->getBinContent(10, rosBin);
330  }
331  return value;
332 }
333 
335  // check that this is a valid ROB for this map (= it has been added!)
336  if (robsAndValues.find(robBin) == robsAndValues.end()) {
337  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
338  << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
339  return false;
340  }
341 
342  int newValue = getValueRobBin(robBin);
343  if (newValue > robsAndValues[robBin]) {
344  robsAndValues[robBin] = newValue;
345  return true;
346  }
347  return false;
348 }
349 
351  meROS = igetter.get(rosHName);
352  meDDU = igetter.get(dduHName);
353  int nChangedROBs = 0;
354 
355  // check if ros status has changed
356  int newValue = getValueRos();
357  if (newValue > rosValue) {
358  rosValue = newValue;
359  return 0.;
360  }
361 
362  for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
363  ++robAndValue) {
364  if (robChanged((*robAndValue).first))
365  nChangedROBs++;
366  }
367  return 1. - ((double)nChangedROBs / (double)robsAndValues.size());
368 }
369 
371  meROS = igetter.get(rosHName);
372  meDDU = igetter.get(dduHName);
373 
374  rosValue = getValueRos();
375  for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
376  ++robAndValue) {
377  robChanged((*robAndValue).first);
378  }
379 }
380 
381 // uROS starting on 2018
383  : init_(true) {
384  int wheel = (ddu - 770) % 5 - 2;
385 
386  // get the pointer to the corresondig histo
387  urosHName = "DT/00-DataIntegrity/Wheel" + to_string(wheel) + "/Sector" + to_string(ros) + "/W" + to_string(wheel) +
388  "_Sector" + to_string(ros) + "_ROSError";
389  meuROS = igetter.get(urosHName);
390 }
391 
393 
395 
397  linksAndValues[linkBin] = getValueLinkBin(linkBin);
398 }
399 
401  if (!init_)
402  return 0;
403  int value = 0;
404  if (meuROS) {
405  value += (int)meuROS->getBinContent(5, linkBin); //ONLY NotOKFlag
406  }
407  return value;
408 }
409 
411  // check that this is a valid Link for this map (= it has been added!)
412  if (linksAndValues.find(linkBin) == linksAndValues.end()) {
413  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
414  << "[DTLinkBinsMap]***Error: Link: " << linkBin << " is not valid" << endl;
415  return false;
416  }
417 
418  int newValue = getValueLinkBin(linkBin);
419  if (newValue > linksAndValues[linkBin]) {
420  linksAndValues[linkBin] = newValue;
421  return true;
422  }
423  return false;
424 }
425 
427  meuROS = igetter.get(urosHName);
428  int nChangedLinks = 0;
429 
430  for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
431  ++linkAndValue) {
432  if (linkChanged((*linkAndValue).first))
433  nChangedLinks++;
434  }
435  return 1. - ((double)nChangedLinks / (double)linksAndValues.size());
436 }
437 
439  meuROS = igetter.get(urosHName);
440 
441  for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
442  ++linkAndValue) {
443  linkChanged((*linkAndValue).first);
444  }
445 }
446 
447 // Conversions
448 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
449  int ros = theROS(slot, link);
450 
451  int ddu = 772;
452  //if (crate == 1368) { ddu = 775; }
453  //Needed just in case this FED should be used due to fibers lenght
454 
455  if (crate == FEDNumbering::MINDTUROSFEDID) {
456  if (slot < 7)
457  ddu = 770;
458  else
459  ddu = 771;
460  }
461 
462  if (crate == (FEDNumbering::MINDTUROSFEDID + 1)) {
463  ddu = 772;
464  }
465 
466  if (crate == FEDNumbering::MAXDTUROSFEDID) {
467  if (slot < 7)
468  ddu = 773;
469  else
470  ddu = 774;
471  }
472 
473  if (ros > 6 && tenDDU && ddu < 775)
474  ddu += 5;
475 
476  return ddu;
477 }
478 
479 int DTBlockedROChannelsTest::theROS(int slot, int link) {
480  if (slot % 6 == 5)
481  return link + 1;
482 
483  int ros = (link / 24) + 3 * (slot % 6) - 2;
484  return ros;
485 }
486 
487 int DTBlockedROChannelsTest::theROB(int slot, int link) {
488  if (slot % 6 == 5)
489  return 23;
490 
491  int rob = link % 24;
492  if (rob < 15)
493  return rob;
494  if (rob == 15)
495  return 24;
496  return rob - 1;
497 }
498 
499 // 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:42
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)
std::string to_string(const V &value)
Definition: OMSAccess.h:77
void fillChamberMap(DQMStore::IGetter &igetter, const edm::EventSetup &c)
#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:212
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:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
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