File indexing completed on 2024-04-06 12:18:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0011 #include "HLTrigger/HLTcore/interface/HLTConfigDataRegistry.h"
0012 #include "FWCore/Utilities/interface/RegexMatch.h"
0013 #include "FWCore/Utilities/interface/ThreadSafeRegistry.h"
0014 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0015 #include "FWCore/ParameterSet/interface/Registry.h"
0016 #include "FWCore/Framework/interface/Run.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/LuminosityBlock.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/Framework/interface/TriggerNamesService.h"
0025
0026 #include <regex>
0027
0028
0029 static const HLTConfigData* s_dummyHLTConfigData() {
0030 static const HLTConfigData dummyHLTConfigData;
0031 return &dummyHLTConfigData;
0032 }
0033
0034 HLTConfigProvider::HLTConfigProvider()
0035 : processName_(""), inited_(false), changed_(true), hltConfigData_(s_dummyHLTConfigData()) {}
0036
0037 bool HLTConfigProvider::init(const edm::Run& iRun,
0038 const edm::EventSetup& iSetup,
0039 const std::string& processName,
0040 bool& changed) {
0041 edm::LogInfo("HLTConfigProvider") << "Called (R) with processName '" << processName << "' for " << iRun.id();
0042
0043 init(iRun.processHistory(), processName);
0044
0045 processName_ = processName;
0046 changed = changed_;
0047 return inited_;
0048 }
0049
0050 void HLTConfigProvider::init(const edm::ProcessHistory& iHistory, const std::string& processName) {
0051 using namespace edm;
0052
0053 const ProcessHistory::const_iterator hb(iHistory.begin());
0054 const ProcessHistory::const_iterator he(iHistory.end());
0055
0056 ProcessConfiguration processConfiguration;
0057 const edm::ParameterSet* processPSet(nullptr);
0058
0059 processName_ = processName;
0060
0061 if (processName_ == "*") {
0062
0063 for (ProcessHistory::const_iterator hi = hb; hi != he; ++hi) {
0064 if (iHistory.getConfigurationForProcess(hi->processName(), processConfiguration)) {
0065 processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
0066 CMS_SA_ALLOW if ((processPSet != nullptr) && (processPSet->exists("hltTriggerSummaryAOD"))) {
0067 processName_ = hi->processName();
0068 }
0069 }
0070 }
0071 if (processName_ == "*") {
0072 LogError("HLTConfigProvider") << "Auto-discovery of processName failed!";
0073 clear();
0074 return;
0075 } else {
0076 LogInfo("HLTConfigProvider") << "Auto-discovered processName: '" << processName_ << "'";
0077 }
0078 }
0079 if (processName_ == "@currentProcess") {
0080 processName_ = edm::Service<edm::service::TriggerNamesService>()->getProcessName();
0081 }
0082
0083
0084 unsigned int n(0);
0085 for (ProcessHistory::const_iterator hi = hb; hi != he; ++hi) {
0086 if (hi->processName() == processName_) {
0087 n++;
0088 }
0089 }
0090 if (n > 1) {
0091 LogError("HLTConfigProvider") << " ProcessName '" << processName_ << " found " << n << " times in history!";
0092 clear();
0093 return;
0094 }
0095
0096
0097 if (iHistory.getConfigurationForProcess(processName_, processConfiguration)) {
0098 if ((hltConfigData_ != s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
0099 changed_ = false;
0100 inited_ = true;
0101 return;
0102 } else {
0103 getDataFrom(processConfiguration.parameterSetID());
0104 }
0105 } else {
0106 LogError("HLTConfigProvider") << "Falling back to ProcessName-only init using ProcessName '" << processName_
0107 << "' !";
0108 init(processName_);
0109 return;
0110 }
0111 }
0112
0113 void HLTConfigProvider::getDataFrom(const edm::ParameterSetID& iID) {
0114
0115 HLTConfigDataRegistry* reg = HLTConfigDataRegistry::instance();
0116 const HLTConfigData* d = reg->getMapped(iID);
0117 if (nullptr != d) {
0118 changed_ = true;
0119 inited_ = true;
0120 hltConfigData_ = d;
0121 } else {
0122 const edm::ParameterSet* processPSet = nullptr;
0123 if (nullptr != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
0124 if (not processPSet->id().isValid()) {
0125 clear();
0126 edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
0127 changed_ = true;
0128 inited_ = false;
0129 hltConfigData_ = s_dummyHLTConfigData();
0130 return;
0131 } else {
0132 clear();
0133 reg->insertMapped(HLTConfigData(processPSet));
0134 changed_ = true;
0135 inited_ = true;
0136 hltConfigData_ = reg->getMapped(processPSet->id());
0137 return;
0138 }
0139 } else {
0140 clear();
0141 edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
0142 changed_ = true;
0143 inited_ = false;
0144 hltConfigData_ = s_dummyHLTConfigData();
0145 return;
0146 }
0147 }
0148 return;
0149 }
0150
0151 void HLTConfigProvider::init(const std::string& processName) {
0152 using namespace edm;
0153
0154
0155
0156 std::string pNames("");
0157 std::string hNames("");
0158 const ParameterSet* pset = nullptr;
0159 ParameterSetID psetID;
0160 unsigned int nPSets(0);
0161 const edm::pset::Registry* registry_(pset::Registry::instance());
0162 const edm::pset::Registry::const_iterator rb(registry_->begin());
0163 const edm::pset::Registry::const_iterator re(registry_->end());
0164 for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
0165 CMS_SA_ALLOW if (i->second.existsAs<std::string>("@process_name", true) and
0166 i->second.existsAs<std::vector<std::string>>("@paths", true)) {
0167 const std::string pName(i->second.getParameter<std::string>("@process_name"));
0168 pNames += pName + " ";
0169 if (pName == processName) {
0170 psetID = i->first;
0171 nPSets++;
0172 if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id() == psetID)) {
0173 hNames += tableName();
0174 } else if (nullptr != (pset = registry_->getMapped(psetID))) {
0175 CMS_SA_ALLOW if (pset->exists("HLTConfigVersion")) {
0176 const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
0177 CMS_SA_ALLOW if (HLTPSet.exists("tableName")) {
0178 hNames += HLTPSet.getParameter<std::string>("tableName") + " ";
0179 }
0180 }
0181 }
0182 }
0183 }
0184 }
0185
0186 LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: " << pNames << ".";
0187
0188 LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: " << hNames << ".";
0189
0190 if (nPSets == 0) {
0191 LogError("HLTConfigProvider") << " Process name '" << processName << "' not found in registry!";
0192 clear();
0193 return;
0194 }
0195 if (psetID == ParameterSetID()) {
0196 LogError("HLTConfigProvider") << " Process name '" << processName << "' found but ParameterSetID invalid!";
0197 clear();
0198 return;
0199 }
0200 if (nPSets > 1) {
0201 LogError("HLTConfigProvider") << " Process name '" << processName << " found " << nPSets << " times in registry!";
0202 clear();
0203 return;
0204 }
0205
0206 getDataFrom(psetID);
0207
0208 return;
0209 }
0210
0211 void HLTConfigProvider::clear() {
0212
0213
0214 processName_ = "";
0215 inited_ = false;
0216 changed_ = true;
0217 hltConfigData_ = s_dummyHLTConfigData();
0218
0219 return;
0220 }
0221
0222 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs,
0223 const std::string& pattern) {
0224 std::vector<std::string> matched;
0225 const std::regex regexp(edm::glob2reg(pattern));
0226 const unsigned int n(inputs.size());
0227 for (unsigned int i = 0; i < n; ++i) {
0228 const std::string& input(inputs[i]);
0229 if (std::regex_match(input, regexp))
0230 matched.push_back(input);
0231 }
0232 return matched;
0233 }
0234
0235 const std::string HLTConfigProvider::removeVersion(const std::string& trigger) {
0236 const std::regex regexp("_v[0-9]+$");
0237 return std::regex_replace(trigger, regexp, "");
0238 }
0239
0240 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs,
0241 const std::string& trigger) {
0242 return matched(inputs, trigger + "_v[0-9]+$");
0243 }