00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "FWCore/PrescaleService/interface/PrescaleService.h"
00011 #include "FWCore/ParameterSet/interface/Registry.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014
00015 #include <set>
00016 #include <algorithm>
00017
00018
00019 using namespace std;
00020
00021
00022 namespace edm {
00023 namespace service {
00024
00026
00028
00029
00030 PrescaleService::PrescaleService(const ParameterSet& iPS,ActivityRegistry&iReg)
00031 throw (cms::Exception)
00032 : nLvl1Index_(0)
00033 , iLvl1IndexDefault_(0)
00034 {
00035 reconfigure(iPS);
00036
00037 iReg.watchPostBeginJob(this,&PrescaleService::postBeginJob);
00038 iReg.watchPostEndJob(this,&PrescaleService::postEndJob);
00039
00040 iReg.watchPreProcessEvent(this,&PrescaleService::preEventProcessing);
00041 iReg.watchPostProcessEvent(this,&PrescaleService::postEventProcessing);
00042
00043 iReg.watchPreModule(this,&PrescaleService::preModule);
00044 iReg.watchPostModule(this,&PrescaleService::postModule);
00045 }
00046
00047
00048
00049 PrescaleService::~PrescaleService()
00050 {
00051
00052 }
00053
00054
00056
00058
00059
00060 void PrescaleService::reconfigure(const ParameterSet &iPS)
00061 {
00062
00063 ParameterSet prcPS = getProcessParameterSet();
00064
00065
00066 set<string> prescalerModules;
00067 vector<string> allModules=prcPS.getParameter<vector<string> >("@all_modules");
00068 for(unsigned int i=0;i<allModules.size();i++) {
00069 ParameterSet pset = prcPS.getParameter<ParameterSet>(allModules[i]);
00070 string moduleLabel = pset.getParameter<std::string>("@module_label");
00071 string moduleType = pset.getParameter<std::string>("@module_type");
00072 if (moduleType=="HLTPrescaler") prescalerModules.insert(moduleLabel);
00073 }
00074
00075
00076 std::set<string> prescaledPathSet;
00077 vector<string> allPaths = prcPS.getParameter< vector<string> >("@paths");
00078 for (unsigned int iP=0;iP<allPaths.size();iP++) {
00079 string pathName = allPaths[iP];
00080 vector<string> modules = prcPS.getParameter< vector<string> >(pathName);
00081 for (unsigned int iM=0;iM<modules.size();iM++) {
00082 string moduleLabel = modules[iM];
00083 if (prescalerModules.erase(moduleLabel)>0) {
00084 set<string>::const_iterator itPath=prescaledPathSet.find(pathName);
00085 if (itPath==prescaledPathSet.end())
00086 prescaledPathSet.insert(pathName);
00087 else throw cms::Exception("DuplicatePrescaler")
00088 <<"path '"<<pathName<<"' has more than one HLTPrescaler!";
00089 }
00090 }
00091 }
00092
00093
00094 lvl1Labels_ = iPS.getParameter< vector<string> >("lvl1Labels");
00095 nLvl1Index_ = lvl1Labels_.size();
00096
00097 string lvl1DefaultLabel=
00098 iPS.getUntrackedParameter<string>("lvl1DefaultLabel","");
00099 for (unsigned int i=0;i<lvl1Labels_.size();i++)
00100 if (lvl1Labels_[i]==lvl1DefaultLabel) iLvl1IndexDefault_=i;
00101
00102 vector<ParameterSet> vpsetPrescales=
00103 iPS.getParameter< vector<ParameterSet> >("prescaleTable");
00104
00105 vector<string> prescaledPaths;
00106 for (unsigned int iVPSet=0;iVPSet<vpsetPrescales.size();iVPSet++) {
00107 ParameterSet psetPrescales = vpsetPrescales[iVPSet];
00108 string pathName = psetPrescales.getParameter<string>("pathName");
00109 if (prescaledPathSet.erase(pathName)>0) {
00110 vector<unsigned int> prescales =
00111 psetPrescales.getParameter<vector<unsigned int> >("prescales");
00112 if (prescales.size()!=nLvl1Index_) {
00113 throw cms::Exception("PrescaleTableMismatch")
00114 <<"path '"<<pathName<<"' has unexpected number of prescales";
00115 }
00116 prescaleTable_[pathName] = prescales;
00117 }
00118 else {
00119 throw cms::Exception("PrescaleTableUnknownPath")
00120 <<"path '"<<pathName<<"' is invalid or does not "
00121 <<"contain any HLTPrescaler";
00122 }
00123 }
00124 }
00125
00126
00127 unsigned int PrescaleService::getPrescale(const std::string& prescaledPath)
00128 throw (cms::Exception)
00129 {
00130 return getPrescale(iLvl1IndexDefault_, prescaledPath);
00131 }
00132
00133
00134 unsigned int PrescaleService::getPrescale(unsigned int lvl1Index,
00135 const std::string& prescaledPath)
00136 throw (cms::Exception)
00137 {
00138 if (lvl1Index>=nLvl1Index_)
00139 throw cms::Exception("InvalidLvl1Index")
00140 <<"lvl1Index '"<<lvl1Index<<"' exceeds number of prescale columns";
00141
00142 boost::mutex::scoped_lock scoped_lock(mutex_);
00143 PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
00144 return (it==prescaleTable_.end()) ? 1 : it->second[lvl1Index];
00145 }
00146
00147
00148 }
00149 }