CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdio.h>
18 #include <sstream>
19 #include <math.h>
20 
21 using namespace edm;
22 using namespace std;
23 
25 {
26  prescaleFactor = ps.getUntrackedParameter<int>("prescaleFactor", 1);
27  getQualityTestsFromFile = ps.getUntrackedParameter<bool>("getQualityTestsFromFile", true);
28  Label = ps.getUntrackedParameter<string>("label","");
29  reportThreshold = ps.getUntrackedParameter<string>("reportThreshold", "");
30  testInEventloop = ps.getUntrackedParameter<bool>("testInEventloop",false);
31  qtestOnEndRun = ps.getUntrackedParameter<bool>("qtestOnEndRun",true);
32  qtestOnEndJob = ps.getUntrackedParameter<bool>("qtestOnEndJob",false);
33  qtestOnEndLumi = ps.getUntrackedParameter<bool>("qtestOnEndLumi",false);
34  verboseQT = ps.getUntrackedParameter<bool>("verboseQT", true);
35 
36  bei = &*edm::Service<DQMStore>();
37 
38  qtHandler=new QTestHandle;
39 
40  // if you use this module, it's non-sense not to provide the QualityTests.xml
41  if (getQualityTestsFromFile) {
43  qtHandler->configureTests(FileInPath(qtlist).fullPath(), bei);
44  }
45 
46 
47  nEvents = 0;
48 
49 }
50 
51 void QualityTester::beginRun(const edm::Run& run , const edm::EventSetup& iSetup){
52 
53  // if getQualityTestsFromFile is False, it means that the end-user wants them from the Database
57  throw cms::Exception ("Record not found") << "Record \"DQMXMLFileRcd"
58  << "\" does not exist!" << std::endl;
59  }
60 // std::cout << "Reading XML from Database" << std::endl ;
62  iSetup.get<DQMXMLFileRcd>().get(Label,xmlfile);
63  std::unique_ptr<std::vector<unsigned char> > vc( (*xmlfile).getUncompressedBlob() );
64  std::string xmlstr="";
65  for(std::vector<unsigned char>::iterator it=vc->begin();it!=vc->end();it++){
66  xmlstr += *it;
67  }
68 
69  qtHandler->configureTests(xmlstr,bei,1);
70 
71  }
72 }
73 
75 {
76  delete qtHandler;
77 }
78 
80 {
81  if (testInEventloop) {
82  nEvents++;
84  && prescaleFactor > 0
85  && nEvents % prescaleFactor == 0) {
86  performTests();
87  }
88  }
89 }
90 
91 void QualityTester::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
92 {
95  && prescaleFactor > 0
96  && lumiSeg.id().luminosityBlock() % prescaleFactor == 0) {
97  performTests();
98  }
99  }
100 }
101 
102 void QualityTester::endRun(const Run& r, const EventSetup& context){
103  if (qtestOnEndRun) performTests();
104 }
105 
107  if (qtestOnEndJob) performTests();
108 }
109 
111 {
112  // done here because new ME can appear while processing data
113  qtHandler->attachTests(bei,verboseQT);
114 
115  edm::LogVerbatim ("QualityTester") << "Running the Quality Test";
116 
117  bei->runQTests();
118 
119  if (reportThreshold.size() != 0)
120  {
121  std::map< std::string, std::vector<std::string> > theAlarms
122  = qtHandler->checkDetailedQTStatus(bei);
123 
124  for (std::map<std::string,std::vector<std::string> >::iterator itr = theAlarms.begin();
125  itr != theAlarms.end(); ++itr)
126  {
127  const std::string &alarmType = itr->first;
128  const std::vector<std::string> &msgs = itr->second;
129  if ((reportThreshold == "black")
130  || (reportThreshold == "orange" && (alarmType == "orange" || alarmType == "red"))
131  || (reportThreshold == "red" && alarmType == "red"))
132  {
133  std::cout << std::endl;
134  std::cout << "Error Type: " << alarmType << std::endl;
135  for (std::vector<std::string>::const_iterator msg = msgs.begin();
136  msg != msgs.end(); ++msg)
137  std::cout << *msg << std::endl;
138  }
139  }
140  std::cout << std::endl;
141  }
142 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
perform the actual quality tests
tuple xmlfile
Make an XML representation of the misalignment.
void endRun(const edm::Run &r, const edm::EventSetup &c)
const T & get() const
Definition: EventSetup.h:56
LuminosityBlockNumber_t luminosityBlock() const
virtual ~QualityTester()
Destructor.
heterocontainer::HCTypeTag TypeTag
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
QualityTester(const edm::ParameterSet &ps)
Constructor.
void performTests(void)
tuple cout
Definition: gather_cfg.py:145
UInt_t nEvents
Definition: hcalCalib.cc:42
Definition: Run.h:42
void beginRun(const edm::Run &, const edm::EventSetup &)
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:125