Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "FWCore/PrescaleService/interface/PrescaleService.h"
00011 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00012 #include "FWCore/ParameterSet/interface/Registry.h"
00013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00015 #include "FWCore/Utilities/interface/Exception.h"
00016
00017 #include <set>
00018 #include <algorithm>
00019
00020
00021 namespace edm {
00022 namespace service {
00023
00025
00027
00028
00029 PrescaleService::PrescaleService(ParameterSet const& iPS,ActivityRegistry& iReg)
00030 : configured_(false)
00031 , lvl1Labels_(iPS.getParameter<std::vector<std::string> >("lvl1Labels"))
00032 , nLvl1Index_(lvl1Labels_.size())
00033 , iLvl1IndexDefault_(0)
00034 , vpsetPrescales_(iPS.getParameterSetVector("prescaleTable"))
00035 , prescaleTable_()
00036 {
00037 std::string lvl1DefaultLabel=
00038 iPS.getUntrackedParameter<std::string>("lvl1DefaultLabel","");
00039 for (unsigned int i = 0; i < lvl1Labels_.size(); ++i) {
00040 if (lvl1Labels_[i] == lvl1DefaultLabel) iLvl1IndexDefault_ = i;
00041 }
00042
00043 iReg.watchPostBeginJob(this, &PrescaleService::postBeginJob);
00044 iReg.watchPostEndJob(this, &PrescaleService::postEndJob);
00045
00046 iReg.watchPreProcessEvent(this, &PrescaleService::preEventProcessing);
00047 iReg.watchPostProcessEvent(this, &PrescaleService::postEventProcessing);
00048
00049 iReg.watchPreModule(this, &PrescaleService::preModule);
00050 iReg.watchPostModule(this, &PrescaleService::postModule);
00051 }
00052
00053
00054 PrescaleService::~PrescaleService() {
00055 }
00056
00058
00060
00061 void PrescaleService::reconfigure(ParameterSet const& iPS) {
00062 vpsetPrescales_.clear();
00063 prescaleTable_.clear();
00064 iLvl1IndexDefault_ = 0;
00065 lvl1Labels_ = iPS.getParameter<std::vector<std::string> >("lvl1Labels");
00066 nLvl1Index_ = lvl1Labels_.size();
00067 vpsetPrescales_ = iPS.getParameterSetVector("prescaleTable");
00068 std::string lvl1DefaultLabel=
00069 iPS.getUntrackedParameter<std::string>("lvl1DefaultLabel");
00070 for (unsigned int i=0; i < lvl1Labels_.size(); ++i) {
00071 if (lvl1Labels_[i] == lvl1DefaultLabel) iLvl1IndexDefault_ = i;
00072 }
00073 configure();
00074 }
00075
00076 void PrescaleService::postBeginJob() {
00077 if (!configured_) {
00078 configure();
00079 }
00080 }
00081
00082
00083 void PrescaleService::configure()
00084 {
00085 configured_ = true;
00086
00087 ParameterSet prcPS = getProcessParameterSet();
00088
00089
00090 std::set<std::string> prescalerModules;
00091 std::vector<std::string> allModules=prcPS.getParameter<std::vector<std::string> >("@all_modules");
00092 for(unsigned int i = 0; i < allModules.size(); ++i) {
00093 ParameterSet const& pset = prcPS.getParameterSet(allModules[i]);
00094 std::string moduleLabel = pset.getParameter<std::string>("@module_label");
00095 std::string moduleType = pset.getParameter<std::string>("@module_type");
00096 if (moduleType == "HLTPrescaler") prescalerModules.insert(moduleLabel);
00097 }
00098
00099
00100 std::set<std::string> prescaledPathSet;
00101 std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
00102 for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
00103 std::string pathName = allPaths[iP];
00104 std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
00105 for (unsigned int iM = 0; iM < modules.size(); ++iM) {
00106 std::string moduleLabel = modules[iM];
00107 if (prescalerModules.erase(moduleLabel)>0) {
00108 std::set<std::string>::const_iterator itPath=prescaledPathSet.find(pathName);
00109 if (itPath==prescaledPathSet.end()) {
00110 prescaledPathSet.insert(pathName);
00111 } else {
00112 throw cms::Exception("DuplicatePrescaler")
00113 <<"path '"<<pathName<<"' has more than one HLTPrescaler!";
00114 }
00115 }
00116 }
00117 }
00118
00119 std::vector<std::string> prescaledPaths;
00120 for (unsigned int iVPSet=0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
00121 ParameterSet psetPrescales = vpsetPrescales_[iVPSet];
00122 std::string pathName = psetPrescales.getParameter<std::string>("pathName");
00123 if (prescaledPathSet.erase(pathName) > 0) {
00124 std::vector<unsigned int> prescales =
00125 psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
00126 if (prescales.size()!=nLvl1Index_) {
00127 throw cms::Exception("PrescaleTableMismatch")
00128 << "path '" << pathName << "' has unexpected number of prescales";
00129 }
00130 prescaleTable_[pathName] = prescales;
00131 }
00132 else {
00133 throw cms::Exception("PrescaleTableUnknownPath")
00134 <<"path '"<<pathName<<"' is invalid or does not "
00135 <<"contain any HLTPrescaler";
00136 }
00137 }
00138 }
00139
00140
00141 unsigned int PrescaleService::getPrescale(std::string const& prescaledPath)
00142 {
00143 return getPrescale(iLvl1IndexDefault_, prescaledPath);
00144 }
00145
00146
00147 unsigned int PrescaleService::getPrescale(unsigned int lvl1Index,
00148 std::string const& prescaledPath)
00149 {
00150 if (lvl1Index >= nLvl1Index_) {
00151 throw cms::Exception("InvalidLvl1Index")
00152 <<"lvl1Index '"<<lvl1Index<<"' exceeds number of prescale columns";
00153 }
00154
00155 if (!configured_) {
00156 configure();
00157 }
00158
00159 PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
00160 return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
00161 }
00162
00163
00164 void PrescaleService::fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
00165 edm::ParameterSetDescription desc;
00166
00167 std::vector<std::string> defaultVector;
00168 defaultVector.push_back(std::string("default"));
00169 desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
00170
00171
00172
00173
00174
00175 std::vector<edm::ParameterSet> defaultVPSet;
00176 edm::ParameterSet pset0;
00177 pset0.addParameter<std::string>("pathName", std::string("HLTPath"));
00178 std::vector<unsigned> defaultVectorU;
00179 defaultVectorU.push_back(1u);
00180 pset0.addParameter<std::vector<unsigned> >("prescales", defaultVectorU);
00181 defaultVPSet.push_back(pset0);
00182
00183 edm::ParameterSetDescription validator;
00184 validator.add<std::string>("pathName");
00185 validator.add<std::vector<unsigned int> >("prescales");
00186
00187 desc.addVPSet("prescaleTable", validator, defaultVPSet);
00188
00189 desc.addUntracked<std::string>("lvl1DefaultLabel", std::string("default"));
00190
00191 descriptions.add("PrescaleService", desc);
00192 }
00193
00194 }
00195 }