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 #include <stdio.h>
16 #include <sstream>
17 #include <math.h>
18 
19 using namespace edm;
20 using namespace std;
21 
23 {
24  prescaleFactor = ps.getUntrackedParameter<int>("prescaleFactor", 1);
25  getQualityTestsFromFile = ps.getUntrackedParameter<bool>("getQualityTestsFromFile", true);
26  Label = ps.getUntrackedParameter<string>("label","");
27  reportThreshold = ps.getUntrackedParameter<string>("reportThreshold", "");
28  testInEventloop = ps.getUntrackedParameter<bool>("testInEventloop",false);
29  qtestOnEndRun = ps.getUntrackedParameter<bool>("qtestOnEndRun",true);
30  qtestOnEndJob = ps.getUntrackedParameter<bool>("qtestOnEndJob",false);
31  qtestOnEndLumi = ps.getUntrackedParameter<bool>("qtestOnEndLumi",false);
32  verboseQT = ps.getUntrackedParameter<bool>("verboseQT", true);
33 
34  bei = &*edm::Service<DQMStore>();
35 
36  qtHandler=new QTestHandle;
37 
38  // if you use this module, it's non-sense not to provide the QualityTests.xml
39  if (getQualityTestsFromFile) {
41  qtHandler->configureTests(FileInPath(qtlist).fullPath(), bei);
42  }
43 
44 
45  nEvents = 0;
46 
47 }
48 
49 void QualityTester::beginRun(const edm::Run& run , const edm::EventSetup& iSetup){
50 
51  // if getQualityTestsFromFile is False, it means that the end-user wants them from the Database
55  throw cms::Exception ("Record not found") << "Record \"DQMXMLFileRcd"
56  << "\" does not exist!" << std::endl;
57  }
58 // std::cout << "Reading XML from Database" << std::endl ;
60  iSetup.get<DQMXMLFileRcd>().get(Label,xmlfile);
61  boost::scoped_ptr<std::vector<unsigned char> > vc( (*xmlfile).getUncompressedBlob() );
62  std::string xmlstr="";
63  for(std::vector<unsigned char>::iterator it=vc->begin();it!=vc->end();it++){
64  xmlstr += *it;
65  }
66 
67  qtHandler->configureTests(xmlstr,bei,1);
68 
69  }
70 }
71 
73 {
74  delete qtHandler;
75 }
76 
78 {
79  if (testInEventloop) {
80  nEvents++;
82  && prescaleFactor > 0
83  && nEvents % prescaleFactor == 0) {
84  performTests();
85  }
86  }
87 }
88 
89 void QualityTester::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
90 {
91  if (!testInEventloop&&qtestOnEndLumi) {
93  && prescaleFactor > 0
94  && lumiSeg.id().luminosityBlock() % prescaleFactor == 0) {
95  performTests();
96  }
97  }
98 }
99 
100 void QualityTester::endRun(const Run& r, const EventSetup& context){
101  if (qtestOnEndRun) performTests();
102 }
103 
105  if (qtestOnEndJob) performTests();
106 }
107 
109 {
110  // done here because new ME can appear while processing data
111  qtHandler->attachTests(bei,verboseQT);
112 
113  edm::LogVerbatim ("QualityTester") << "Running the Quality Test";
114 
115  bei->runQTests();
116 
117  if (reportThreshold.size() != 0)
118  {
119  std::map< std::string, std::vector<std::string> > theAlarms
120  = qtHandler->checkDetailedQTStatus(bei);
121 
122  for (std::map<std::string,std::vector<std::string> >::iterator itr = theAlarms.begin();
123  itr != theAlarms.end(); ++itr)
124  {
125  const std::string &alarmType = itr->first;
126  const std::vector<std::string> &msgs = itr->second;
127  if ((reportThreshold == "black")
128  || (reportThreshold == "orange" && (alarmType == "orange" || alarmType == "red"))
129  || (reportThreshold == "red" && alarmType == "red"))
130  {
131  std::cout << std::endl;
132  std::cout << "Error Type: " << alarmType << std::endl;
133  for (std::vector<std::string>::const_iterator msg = msgs.begin();
134  msg != msgs.end(); ++msg)
135  std::cout << *msg << std::endl;
136  }
137  }
138  std::cout << std::endl;
139  }
140 }
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:55
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:121
UInt_t nEvents
Definition: hcalCalib.cc:42
Definition: Run.h:41
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