CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMServices/Components/src/QualityTester.cc

Go to the documentation of this file.
00001 /*
00002  * \file QualityTester.cc
00003  *
00004  * $Date: 2010/07/20 02:58:28 $
00005  * $Revision: 1.19 $
00006  * \author M. Zanetti - CERN PH
00007  *
00008  */
00009 
00010 #include "DQMServices/Components/interface/QualityTester.h"
00011 #include "DQMServices/ClientConfig/interface/QTestHandle.h"
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 #include "FWCore/ParameterSet/interface/FileInPath.h"
00017 #include <stdio.h>
00018 #include <sstream>
00019 #include <math.h>
00020 
00021 using namespace edm;
00022 using namespace std;
00023 
00024 QualityTester::QualityTester(const ParameterSet& ps)
00025 {
00026   prescaleFactor          = ps.getUntrackedParameter<int>("prescaleFactor", 1);
00027   getQualityTestsFromFile = ps.getUntrackedParameter<bool>("getQualityTestsFromFile", true);
00028   Label                   = ps.getUntrackedParameter<string>("label","");
00029   reportThreshold = ps.getUntrackedParameter<string>("reportThreshold", "");
00030   testInEventloop = ps.getUntrackedParameter<bool>("testInEventloop",false);
00031   qtestOnEndRun   = ps.getUntrackedParameter<bool>("qtestOnEndRun",true);
00032   qtestOnEndJob   = ps.getUntrackedParameter<bool>("qtestOnEndJob",false);
00033   qtestOnEndLumi  = ps.getUntrackedParameter<bool>("qtestOnEndLumi",false);
00034   verboseQT       = ps.getUntrackedParameter<bool>("verboseQT", true);
00035 
00036   bei = &*edm::Service<DQMStore>();
00037 
00038   qtHandler=new QTestHandle;
00039 
00040   // if you use this module, it's non-sense not to provide the QualityTests.xml
00041   if (getQualityTestsFromFile) {
00042     edm::FileInPath qtlist = ps.getUntrackedParameter<edm::FileInPath>("qtList");
00043     qtHandler->configureTests(FileInPath(qtlist).fullPath(), bei);
00044   }
00045 
00046 
00047   nEvents = 0;
00048 
00049 }
00050 
00051 void QualityTester::beginRun(const edm::Run& run , const edm::EventSetup& iSetup){
00052 
00053   // if getQualityTestsFromFile is False, it means that the end-user wants them from the Database
00054   if (!getQualityTestsFromFile) {
00055     edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("DQMXMLFileRcd"));
00056     if(recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
00057       throw cms::Exception ("Record not found") << "Record \"DQMXMLFileRcd" 
00058                                                 << "\" does not exist!" << std::endl;
00059     }
00060 //     std::cout << "Reading XML from Database" << std::endl ;
00061     edm::ESHandle<FileBlob> xmlfile;
00062     iSetup.get<DQMXMLFileRcd>().get(Label,xmlfile);
00063     boost::scoped_ptr<std::vector<unsigned char> > vc( (*xmlfile).getUncompressedBlob() );
00064     std::string xmlstr="";
00065     for(std::vector<unsigned char>::iterator it=vc->begin();it!=vc->end();it++){
00066       xmlstr += *it;
00067     }
00068 
00069     qtHandler->configureTests(xmlstr,bei,1);
00070 
00071   }
00072 }
00073 
00074 QualityTester::~QualityTester()
00075 {
00076   delete qtHandler;
00077 }
00078 
00079 void QualityTester::analyze(const edm::Event& e, const edm::EventSetup& c) 
00080 {
00081   if (testInEventloop) {
00082     nEvents++;
00083     if (getQualityTestsFromFile
00084         && prescaleFactor > 0 
00085         && nEvents % prescaleFactor == 0)  {
00086       performTests();
00087     }
00088   }
00089 }
00090 
00091 void QualityTester::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
00092 {
00093   if (!testInEventloop&&qtestOnEndLumi) {
00094     if (getQualityTestsFromFile
00095         && prescaleFactor > 0
00096         && lumiSeg.id().luminosityBlock() % prescaleFactor == 0) {
00097       performTests();
00098     }
00099   }
00100 }
00101 
00102 void QualityTester::endRun(const Run& r, const EventSetup& context){
00103   if (qtestOnEndRun) performTests();
00104 }
00105 
00106 void QualityTester::endJob(){
00107   if (qtestOnEndJob) performTests();
00108 }
00109 
00110 void QualityTester::performTests(void)
00111 {
00112     // done here because new ME can appear while processing data
00113     qtHandler->attachTests(bei,verboseQT);
00114 
00115     edm::LogVerbatim ("QualityTester") << "Running the Quality Test";
00116 
00117     bei->runQTests();
00118 
00119     if (reportThreshold.size() != 0)
00120     {
00121       std::map< std::string, std::vector<std::string> > theAlarms
00122         = qtHandler->checkDetailedQTStatus(bei);
00123 
00124       for (std::map<std::string,std::vector<std::string> >::iterator itr = theAlarms.begin();
00125            itr != theAlarms.end(); ++itr)
00126       {
00127         const std::string &alarmType = itr->first;
00128         const std::vector<std::string> &msgs = itr->second;
00129         if ((reportThreshold == "black")
00130             || (reportThreshold == "orange" && (alarmType == "orange" || alarmType == "red"))
00131             || (reportThreshold == "red" && alarmType == "red"))
00132         {
00133           std::cout << std::endl;
00134           std::cout << "Error Type: " << alarmType << std::endl;
00135           for (std::vector<std::string>::const_iterator msg = msgs.begin();
00136                msg != msgs.end(); ++msg)
00137             std::cout << *msg << std::endl;
00138         }
00139       }
00140       std::cout << std::endl;
00141     }
00142 }