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