Go to the documentation of this file.00001
00012 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00013 #include "FWCore/Utilities/interface/RegexMatch.h"
00014 #include "FWCore/Utilities/interface/ThreadSafeRegistry.h"
00015 #include "FWCore/ParameterSet/interface/Registry.h"
00016 #include "FWCore/Framework/interface/Run.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/LuminosityBlock.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022
00023 #include <boost/regex.hpp>
00024
00025 typedef edm::detail::ThreadSafeRegistry<edm::ParameterSetID, HLTConfigData> HLTConfigDataRegistry;
00026
00027
00028 static const HLTConfigData* s_dummyHLTConfigData()
00029 { static HLTConfigData dummyHLTConfigData;
00030 return &dummyHLTConfigData;
00031 }
00032
00033 HLTConfigProvider::HLTConfigProvider():
00034 processName_(""),
00035 inited_(false),
00036 changed_(true),
00037 hltConfigData_(s_dummyHLTConfigData()),
00038 l1GtUtils_(new L1GtUtils())
00039 {
00040 }
00041
00042 bool HLTConfigProvider::init(const edm::Run& iRun,
00043 const edm::EventSetup& iSetup,
00044 const std::string& processName,
00045 bool& changed) {
00046
00047 using namespace std;
00048 using namespace edm;
00049
00050 LogInfo("HLTConfigData") << "Called (R) with processName '"
00051 << processName
00052 << "' for " << iRun.id() << endl;
00053
00054 init(iRun.processHistory(),processName);
00055
00058
00059 processName_=processName;
00060 changed=changed_;
00061 return inited_;
00062
00063 }
00064
00065 void HLTConfigProvider::init(const edm::ProcessHistory& iHistory, const std::string& processName) {
00066
00067 using namespace std;
00068 using namespace edm;
00069
00070 const ProcessHistory::const_iterator hb(iHistory.begin());
00071 const ProcessHistory::const_iterator he(iHistory.end());
00072
00073 ProcessConfiguration processConfiguration;
00074 const edm::ParameterSet* processPSet(0);
00075
00076 processName_=processName;
00077 if (processName_=="*") {
00078
00079 for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
00080 if (iHistory.getConfigurationForProcess(hi->processName(),processConfiguration)) {
00081 processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
00082 if ((processPSet!=0) && (processPSet->exists("hltTriggerSummaryAOD"))) {
00083 processName_=hi->processName();
00084 }
00085 }
00086 }
00087 LogInfo("HLTConfigData") << "Auto-discovered processName: '"
00088 << processName_ << "'"
00089 << endl;
00090 }
00091 if (processName_=="*") {
00092 clear();
00093 LogError("HLTConfigData") << "Auto-discovery of processName failed!"
00094 << endl;
00095 return;
00096 }
00097
00099 unsigned int n(0);
00100 for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
00101 if (hi->processName()==processName_) {n++;}
00102 }
00103 if (n>1) {
00104 clear();
00105 LogError("HLTConfigProvider") << " ProcessName '"<< processName_
00106 << " found " << n
00107 << " times in history!" << endl;
00108 return;
00109 }
00110
00112 if (iHistory.getConfigurationForProcess(processName_,processConfiguration)) {
00113 if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
00114 changed_ = false;
00115 inited_ = true;
00116 return;
00117 } else {
00118 getDataFrom(processConfiguration.parameterSetID());
00119 }
00120 } else {
00121 LogError("HLTConfigProvider") << "Falling back to processName-only init!";
00122 clear();
00123 init(processName_);
00124 if (!inited_) {
00125 LogError("HLTConfigProvider") << "ProcessName not found in history!";
00126 }
00127 return;
00128 }
00129 }
00130
00131 void HLTConfigProvider::getDataFrom(const edm::ParameterSetID& iID)
00132 {
00133
00134 HLTConfigDataRegistry* reg = HLTConfigDataRegistry::instance();
00135 const HLTConfigData* d = reg->getMapped(iID);
00136 if(0 != d) {
00137 changed_ = true;
00138 inited_ = true;
00139 hltConfigData_ = d;
00140 } else {
00141 const edm::ParameterSet* processPSet = 0;
00142 if ( 0 != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
00143 if (not processPSet->id().isValid()) {
00144 clear();
00145 edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
00146 changed_ = true;
00147 inited_ = false;
00148 hltConfigData_ = s_dummyHLTConfigData();
00149 return;
00150 } else {
00151 clear();
00152 reg->insertMapped( HLTConfigData(processPSet));
00153 changed_ = true;
00154 inited_ = true;
00155 hltConfigData_ = reg->getMapped(processPSet->id());
00156 return;
00157 }
00158 } else {
00159 clear();
00160 edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
00161 changed_ = true;
00162 inited_ = false;
00163 hltConfigData_ = s_dummyHLTConfigData();
00164 return;
00165 }
00166 }
00167 return;
00168 }
00169
00170 void HLTConfigProvider::init(const std::string& processName)
00171 {
00172 using namespace std;
00173 using namespace edm;
00174
00175
00176
00177 string pNames("");
00178 string hNames("");
00179 const ParameterSet* pset = 0;
00180 ParameterSetID psetID;
00181 unsigned int nPSets(0);
00182 const edm::pset::Registry * registry_(pset::Registry::instance());
00183 const edm::pset::Registry::const_iterator rb(registry_->begin());
00184 const edm::pset::Registry::const_iterator re(registry_->end());
00185 for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
00186 if (i->second.exists("@process_name")) {
00187 const std::string pName(i->second.getParameter<string>("@process_name"));
00188 pNames += pName+" ";
00189 if ( pName == processName ) {
00190 psetID = i->first;
00191 nPSets++;
00192 if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
00193 hNames += tableName();
00194 } else if ( 0 != (pset = registry_->getMapped(psetID))) {
00195 if (pset->exists("HLTConfigVersion")) {
00196 const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
00197 if (HLTPSet.exists("tableName")) {
00198 hNames += HLTPSet.getParameter<string>("tableName")+" ";
00199 }
00200 }
00201 }
00202 }
00203 }
00204 }
00205
00206 LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: "
00207 << pNames << "." << endl;
00208
00209 LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: "
00210 << hNames << "." << endl;
00211
00212 if (nPSets==0) {
00213 clear();
00214 LogError("HLTConfigProvider") << " Process name '"
00215 << processName
00216 << "' not found in registry!" << endl;
00217 return;
00218 }
00219 if (psetID==ParameterSetID()) {
00220 clear();
00221 LogError("HLTConfigProvider") << " Process name '"
00222 << processName
00223 << "' found but ParameterSetID invalid!"
00224 << endl;
00225 return;
00226 }
00227 if (nPSets>1) {
00228 clear();
00229 LogError("HLTConfigProvider") << " Process name '"
00230 << processName
00231 << " found " << nPSets
00232 << " times in registry!" << endl;
00233 return;
00234 }
00235
00236 getDataFrom(psetID);
00237
00238 return;
00239
00240 }
00241
00242 void HLTConfigProvider::clear()
00243 {
00244
00245
00246 processName_ = "";
00247 inited_ = false;
00248 changed_ = true;
00249 hltConfigData_ = s_dummyHLTConfigData();
00250 *l1GtUtils_ = L1GtUtils();
00251
00252 return;
00253 }
00254
00255
00256 int HLTConfigProvider::prescaleSet(const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
00257
00258 l1GtUtils_->retrieveL1EventSetup(iSetup);
00259 int errorTech(0);
00260 const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
00261 int errorPhys(0);
00262 const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
00263 assert(psfsiTech==psfsiPhys);
00264 if ( (errorTech==0) && (errorPhys==0) &&
00265 (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
00266 return psfsiPhys;
00267 } else {
00269 edm::LogError("HLTConfigData")
00270 << " Error in determining HLT prescale set index from L1 data using L1GtUtils: "
00271 << " Tech/Phys error = " << errorTech << "/" << errorPhys
00272 << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
00273 return -1;
00274 }
00275 }
00276
00277 unsigned int HLTConfigProvider::prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
00278 const int set(prescaleSet(iEvent,iSetup));
00279 if (set<0) {
00280 return 1;
00281 } else {
00282 return prescaleValue(static_cast<unsigned int>(set),trigger);
00283 }
00284 }
00285
00286 std::pair<int,int> HLTConfigProvider::prescaleValues(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
00287
00288
00289 std::pair<int,int> result(std::pair<int,int>(0,0));
00290
00291
00292 const int set(prescaleSet(iEvent,iSetup));
00293 if (set<0) {
00294 result.second = -1;
00295 } else {
00296 result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
00297 }
00298
00299
00300
00301 const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
00302 if (nL1GTSeedModules==0) {
00303
00304 result.first=1;
00305 } else if (nL1GTSeedModules==1) {
00306 l1GtUtils_->retrieveL1EventSetup(iSetup);
00307 const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
00308 int l1error(0);
00309 result.first = l1GtUtils_->prescaleFactor(iEvent,l1tname,l1error);
00310 if (l1error!=0) {
00311 edm::LogError("HLTConfigData")
00312 << " Error in determining L1T prescale for HLT path: '" << trigger
00313 << "' with L1T seed: '" << l1tname
00314 << "' using L1GtUtils: error code: " << l1error
00315 << ". (Note: only a single L1T name, not a bit number, is allowed as seed for a proper determination of the L1T prescale!)";
00316 result.first = -1;
00317 }
00318 } else {
00320 std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
00321 for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
00322 dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
00323 }
00324 edm::LogError("HLTConfigData")
00325 << " Error in determining L1T prescale for HLT path: '" << trigger
00326 << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
00327 << ", with L1 seeds: " << dump
00328 << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
00329 result.first = -1;
00330 }
00331
00332 return result;
00333 }
00334
00335 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs, const std::string& pattern) {
00336 std::vector<std::string> matched;
00337 const boost::regex regexp(edm::glob2reg(pattern));
00338 const unsigned int n(inputs.size());
00339 for (unsigned int i=0; i<n; ++i) {
00340 const std::string& input(inputs[i]);
00341 if (boost::regex_match(input,regexp)) matched.push_back(input);
00342 }
00343 return matched;
00344 }
00345
00346 const std::string HLTConfigProvider::removeVersion(const std::string& trigger) {
00347 const boost::regex regexp("_v[0-9]+$");
00348 return boost::regex_replace(trigger,regexp,"");
00349 }
00350
00351 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs, const std::string& trigger) {
00352 return matched(inputs,trigger+"_v[0-9]+$");
00353 }