00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineSummaryClient.h"
00002
00003
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013
00014 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00015 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00016 #include <boost/algorithm/string.hpp>
00017
00018 EgHLTOfflineSummaryClient::EgHLTOfflineSummaryClient(const edm::ParameterSet& iConfig):
00019 egHLTSumHistName_("egHLTTrigSum"),isSetup_(false)
00020 {
00021 dirName_=iConfig.getParameter<std::string>("DQMDirName");
00022 dbe_ = edm::Service<DQMStore>().operator->();
00023 if (!dbe_) {
00024 edm::LogError("EgHLTOfflineSummaryClient") << "unable to get DQMStore service, no summary histograms will be produced";
00025 }else{
00026 if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00027 dbe_->setVerbose(0);
00028 }
00029 dbe_->setCurrentFolder(dirName_);
00030 }
00031
00032 eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00033 phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00034 eleHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNamesForSumBit");
00035 phoHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNamesForSumBit");
00036
00037
00038 filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00039 hltTag_ = iConfig.getParameter<std::string>("hltTag");
00040
00041 usePathNames_ = iConfig.getParameter<bool>("usePathNames");
00042
00043
00044
00045
00046
00047 fillQTestData_(iConfig,egHLTSumHistXBins_,"egHLTSumQTests");
00048 fillQTestData_(iConfig,eleQTestsForSumBit_,"egHLTEleQTestsForSumBit");
00049 fillQTestData_(iConfig,phoQTestsForSumBit_,"egHLTPhoQTestsForSumBit");
00050
00051
00052
00053 runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
00054 runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
00055 runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
00056
00057
00058
00059
00060
00061
00062
00063 }
00064
00065
00066 EgHLTOfflineSummaryClient::~EgHLTOfflineSummaryClient()
00067 {
00068
00069 }
00070
00071 void EgHLTOfflineSummaryClient::beginJob()
00072 {
00073
00074
00075 }
00076
00077 void EgHLTOfflineSummaryClient::endJob()
00078 {
00079 if(runClientEndJob_) runClient_();
00080 }
00081
00082 void EgHLTOfflineSummaryClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00083 {
00084 if(!isSetup_){
00085 bool changed;
00086 HLTConfigProvider hltConfig;
00087 hltConfig.init(run,c,hltTag_,changed);
00088 if(filterInactiveTriggers_){
00089 std::vector<std::string> activeFilters;
00090
00091 egHLT::trigTools::getActiveFilters(hltConfig,activeFilters);
00092
00093 egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeFilters);
00094 egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNames_,activeFilters);
00095 egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNamesForSumBit_,activeFilters);
00096 egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNamesForSumBit_,activeFilters);
00097
00098 }
00099 getEgHLTFiltersToMon_(egHLTFiltersToMon_);
00100
00101 if(usePathNames_) egHLT::trigTools::translateFiltersToPathNames(hltConfig,egHLTFiltersToMon_,egHLTFiltersToMonPaths_);
00102 isSetup_=true;
00103 }
00104 }
00105
00106
00107 void EgHLTOfflineSummaryClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00108 {
00109 if(runClientEndRun_) runClient_();
00110 }
00111
00112
00113 void EgHLTOfflineSummaryClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00114 {
00115
00116 }
00117
00118 void EgHLTOfflineSummaryClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00119 {
00120
00121 if(runClientEndLumiBlock_) runClient_();
00122 }
00123
00124 void EgHLTOfflineSummaryClient::runClient_()
00125 {
00126
00127 MonitorElement* egHLTSumME = getEgHLTSumHist_();
00128
00129 for(size_t filterNr=0;filterNr<egHLTFiltersToMon_.size();filterNr++){
00130 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00131
00132 egHLTSumME->setBinContent(xBinNr+1,filterNr+1,
00133 getQTestResults_(egHLTFiltersToMon_[filterNr],egHLTSumHistXBins_[xBinNr].qTestPatterns));
00134 }
00135 }
00136
00137 MonitorElement* hltEleSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Electron");
00138 MonitorElement* hltPhoSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Photon");
00139 dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContents/");
00140 if(hltEleSumBit==NULL) hltEleSumBit = dbe_->bookFloat("HLT_Electron");
00141 if(hltPhoSumBit==NULL) hltPhoSumBit = dbe_->bookFloat("HLT_Photon");
00142
00143
00144 float eleSumBit=1.;
00145 for(size_t filterNr=0;filterNr<eleHLTFilterNamesForSumBit_.size() && eleSumBit==1;filterNr++){
00146 for(size_t testNr=0;testNr<eleQTestsForSumBit_.size() && eleSumBit==1;testNr++){
00147 if(getQTestResults_(eleHLTFilterNamesForSumBit_[filterNr],eleQTestsForSumBit_[testNr].qTestPatterns)==0) eleSumBit=0;
00148
00149 }
00150 }
00151 hltEleSumBit->Fill(eleSumBit);
00152
00153 float phoSumBit=1.;
00154 for(size_t filterNr=0;filterNr<phoHLTFilterNamesForSumBit_.size() && phoSumBit==1;filterNr++){
00155 for(size_t testNr=0;testNr<phoQTestsForSumBit_.size() && phoSumBit==1;testNr++){
00156 if(getQTestResults_(phoHLTFilterNamesForSumBit_[filterNr],phoQTestsForSumBit_[testNr].qTestPatterns)==0) phoSumBit=0;
00157 }
00158 }
00159 hltPhoSumBit->Fill(phoSumBit);
00160
00161
00162
00163 }
00164 void EgHLTOfflineSummaryClient::splitStringsToPairs_(const std::vector<std::string>& stringsToSplit,std::vector<std::pair<std::string,std::string> >& splitStrings)
00165 {
00166 splitStrings.clear();
00167 splitStrings.reserve(stringsToSplit.size());
00168 for(size_t stringNr=0;stringNr<stringsToSplit.size();stringNr++){
00169 std::vector<std::string> tempSplitStrings;
00170 boost::split(tempSplitStrings,stringsToSplit[stringNr],boost::is_any_of(std::string(":")));
00171 if(tempSplitStrings.size()==2){
00172 splitStrings.push_back(std::make_pair(tempSplitStrings[0],tempSplitStrings[1]));
00173 }else{
00174 edm::LogWarning("EgHLTOfflineSummaryClient") <<" Error : entry "<<stringsToSplit[stringNr]<<" is not of form A:B, ignoring (ie this quailty test isnt being included in the sumamry hist) ";
00175 }
00176 }
00177 }
00178
00179
00180
00181 MonitorElement* EgHLTOfflineSummaryClient::getEgHLTSumHist_()
00182 {
00183 MonitorElement* egHLTSumHist = dbe_->get(dirName_+"/"+egHLTSumHistName_);
00184 if(egHLTSumHist==NULL){
00185 TH2F* hist = new TH2F(egHLTSumHistName_.c_str(),"E/g HLT Offline Summary",egHLTSumHistXBins_.size(),0.,1.,egHLTFiltersToMon_.size(),0.,1.);
00186 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00187 hist->GetXaxis()->SetBinLabel(xBinNr+1,egHLTSumHistXBins_[xBinNr].name.c_str());
00188 }
00189
00190 for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00191 if(usePathNames_ && egHLTFiltersToMonPaths_.size()==egHLTFiltersToMon_.size()){
00192 hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMonPaths_[yBinNr].c_str());
00193 }else{
00194 hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMon_[yBinNr].c_str());
00195 }
00196 }
00197 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00198 for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00199 hist->SetBinContent(xBinNr+1,yBinNr+1,-2);
00200 }
00201 }
00202
00203 dbe_->setCurrentFolder(dirName_);
00204 egHLTSumHist = dbe_->book2D(egHLTSumHistName_,hist);
00205 }
00206 return egHLTSumHist;
00207
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 void EgHLTOfflineSummaryClient::getEgHLTFiltersToMon_(std::vector<std::string>& filterNames)const
00220 {
00221 std::set<std::string> filterNameSet;
00222 for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00223 for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00224
00225
00226
00227 std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00228 }
00229
00230
00231
00232 int EgHLTOfflineSummaryClient::getQTestResults_(const std::string& filterName,const std::vector<std::string>& patterns)const
00233 {
00234 int nrFail =0;
00235 int nrQTests=0;
00236 for(size_t patternNr=0;patternNr<patterns.size();patternNr++){
00237 std::vector<MonitorElement*> monElems = dbe_->getMatchingContents(dirName_+"/"+filterName+patterns[patternNr]);
00238
00239 for(size_t monElemNr=0;monElemNr<monElems.size();monElemNr++){
00240
00241 std::vector<QReport*> qTests = monElems[monElemNr]->getQReports();
00242 nrQTests+=qTests.size();
00243
00244 if(monElems[monElemNr]->hasError()) nrFail++;
00245 }
00246 }
00247 if(nrQTests==0) return -1;
00248 else if(nrFail==0) return 1;
00249 else return 0;
00250 }
00251
00252
00253 void EgHLTOfflineSummaryClient::fillQTestData_(const edm::ParameterSet& iConfig,std::vector<SumHistBinData>& qTests,const std::string& label)
00254 {
00255 std::vector<edm::ParameterSet> qTestPara = iConfig.getParameter<std::vector<edm::ParameterSet> >(label);
00256 qTests.resize(qTestPara.size());
00257 for(size_t testNr=0;testNr<qTestPara.size();testNr++){
00258 qTests[testNr].name = qTestPara[testNr].getParameter<std::string>("name");
00259 qTests[testNr].qTestPatterns = qTestPara[testNr].getParameter<std::vector<std::string> >("qTestsToCheck");
00260 }
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288