CMS 3D CMS Logo

QualityTester.cc
Go to the documentation of this file.
1 /*
2  * \file QualityTester.cc
3  *
4  * \author M. Zanetti - CERN PH
5  *
6  */
7 
15 
16 #include <memory>
17 #include <cstdio>
18 #include <sstream>
19 #include <cmath>
20 
21 using namespace edm;
22 using namespace std;
23 
25  prescaleFactor = ps.getUntrackedParameter<int>("prescaleFactor", 1);
26  getQualityTestsFromFile = ps.getUntrackedParameter<bool>("getQualityTestsFromFile", true);
27  Label = ps.getUntrackedParameter<string>("label", "");
28  reportThreshold = ps.getUntrackedParameter<string>("reportThreshold", "");
29  testInEventloop = ps.getUntrackedParameter<bool>("testInEventloop", false);
30  qtestOnEndRun = ps.getUntrackedParameter<bool>("qtestOnEndRun", true);
31  qtestOnEndJob = ps.getUntrackedParameter<bool>("qtestOnEndJob", false);
32  qtestOnEndLumi = ps.getUntrackedParameter<bool>("qtestOnEndLumi", false);
33  verboseQT = ps.getUntrackedParameter<bool>("verboseQT", true);
34 
35  bei = &*edm::Service<DQMStore>();
36 
37  qtHandler = new QTestHandle;
38 
39  // if you use this module, it's non-sense not to provide the QualityTests.xml
40  if (getQualityTestsFromFile) {
42  qtHandler->configureTests(FileInPath(qtlist).fullPath(), bei);
43  }
44 
45  nEvents = 0;
46 }
47 
48 void QualityTester::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
49  // if getQualityTestsFromFile is False, it means that the end-user wants them from the Database
54  throw cms::Exception("Record not found") << "Record \"DQMXMLFileRcd"
55  << "\" does not exist!" << std::endl;
56  }
57  // std::cout << "Reading XML from Database" << std::endl ;
59  iSetup.get<DQMXMLFileRcd>().get(Label, xmlfile);
60  std::unique_ptr<std::vector<unsigned char> > vc((*xmlfile).getUncompressedBlob());
61  std::string xmlstr = "";
62  for (unsigned char& it : *vc) {
63  xmlstr += it;
64  }
65 
66  qtHandler->configureTests(xmlstr, bei, true);
67  }
68 }
69 
70 QualityTester::~QualityTester() { delete qtHandler; }
71 
73  if (testInEventloop) {
74  nEvents++;
76  performTests();
77  }
78  }
79 }
80 
81 void QualityTester::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
83  if (getQualityTestsFromFile && prescaleFactor > 0 && lumiSeg.id().luminosityBlock() % prescaleFactor == 0) {
84  performTests();
85  }
86  }
87 }
88 
89 void QualityTester::endRun(const Run& r, const EventSetup& context) {
90  if (qtestOnEndRun)
91  performTests();
92 }
93 
95  if (qtestOnEndJob)
96  performTests();
97 }
98 
100  // done here because new ME can appear while processing data
101  qtHandler->attachTests(bei, verboseQT);
102 
103  edm::LogVerbatim("QualityTester") << "Running the Quality Test";
104 
105  bei->runQTests();
106 
107  if (!reportThreshold.empty()) {
108  std::map<std::string, std::vector<std::string> > theAlarms = qtHandler->checkDetailedQTStatus(bei);
109 
110  for (auto& theAlarm : theAlarms) {
111  const std::string& alarmType = theAlarm.first;
112  const std::vector<std::string>& msgs = theAlarm.second;
113  if ((reportThreshold == "black") ||
114  (reportThreshold == "orange" && (alarmType == "orange" || alarmType == "red")) ||
115  (reportThreshold == "red" && alarmType == "red")) {
116  std::cout << std::endl;
117  std::cout << "Error Type: " << alarmType << std::endl;
118  for (auto const& msg : msgs)
119  std::cout << msg << std::endl;
120  }
121  }
122  std::cout << std::endl;
123  }
124 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c) override
perform the actual quality tests
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
~QualityTester() override
Destructor.
void endJob() override
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
void performTests()
xmlfile
Make an XML representation of the misalignment.
void endRun(const edm::Run &r, const edm::EventSetup &c) override
LuminosityBlockNumber_t luminosityBlock() const
tuple msg
Definition: mps_check.py:285
heterocontainer::HCTypeTag TypeTag
HLT enums.
QualityTester(const edm::ParameterSet &ps)
Constructor.
T get() const
Definition: EventSetup.h:73
UInt_t nEvents
Definition: hcalCalib.cc:41
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45