CMS 3D CMS Logo

HLTConfigProvider.cc
Go to the documentation of this file.
1 
21 
22 #include <regex>
23 
24 
25 // an empty dummy config data used when we fail to initialize
27 { static const HLTConfigData dummyHLTConfigData;
28  return &dummyHLTConfigData;
29 }
30 
32  processName_(""),
33  inited_(false),
34  changed_(true),
35  hltConfigData_(s_dummyHLTConfigData())
36 {
37 }
38 
40  const edm::EventSetup& iSetup,
41  const std::string& processName,
42  bool& changed) {
43 
44  using namespace std;
45  using namespace edm;
46 
47  LogInfo("HLTConfigProvider")
48  << "Called (R) with processName '" << processName << "' for " << iRun.id() << endl;
49 
51 
53  changed=changed_;
54  return inited_;
55 
56 }
57 
59 
60  using namespace std;
61  using namespace edm;
62 
63  const ProcessHistory::const_iterator hb(iHistory.begin());
64  const ProcessHistory::const_iterator he(iHistory.end());
65 
66  ProcessConfiguration processConfiguration;
67  const edm::ParameterSet* processPSet(nullptr);
68 
70  if (processName_=="*") {
71  // auto-discovery of process name
73  if (iHistory.getConfigurationForProcess(hi->processName(),processConfiguration)) {
74  processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
75  if ((processPSet!=nullptr) && (processPSet->exists("hltTriggerSummaryAOD"))) {
76  processName_=hi->processName();
77  }
78  }
79  }
80  LogInfo("HLTConfigProvider")
81  << "Auto-discovered processName: '" << processName_ << "'" << endl;
82  }
83  if (processName_=="*") {
84  LogError("HLTConfigProvider")
85  << "Auto-discovery of processName failed!" << endl;
86  clear();
87  return;
88  }
89 
91  unsigned int n(0);
93  if (hi->processName()==processName_) {n++;}
94  }
95  if (n>1) {
96  LogError("HLTConfigProvider")
97  << " ProcessName '"<< processName_ << " found " << n << " times in history!" << endl;
98  clear();
99  return;
100  }
101 
103  if (iHistory.getConfigurationForProcess(processName_,processConfiguration)) {
104  if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
105  changed_ = false;
106  inited_ = true;
107  return;
108  } else {
109  getDataFrom(processConfiguration.parameterSetID());
110  }
111  } else {
112  LogError("HLTConfigProvider")
113  << "Falling back to ProcessName-only init using ProcessName '"<<processName_<<"' !";
115  return;
116  }
117 }
118 
120 {
121  //is it in our registry?
123  const HLTConfigData* d = reg->getMapped(iID);
124  if(nullptr != d) {
125  changed_ = true;
126  inited_ = true;
127  hltConfigData_ = d;
128  } else {
129  const edm::ParameterSet* processPSet = nullptr;
130  if ( nullptr != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
131  if (not processPSet->id().isValid()) {
132  clear();
133  edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
134  changed_ = true;
135  inited_ = false;
137  return;
138  } else {
139  clear();
140  reg->insertMapped( HLTConfigData(processPSet));
141  changed_ = true;
142  inited_ = true;
143  hltConfigData_ = reg->getMapped(processPSet->id());
144  return;
145  }
146  } else {
147  clear();
148  edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
149  changed_ = true;
150  inited_ = false;
152  return;
153  }
154  }
155  return;
156 }
157 
159 {
160  using namespace std;
161  using namespace edm;
162 
163  // Obtain ParameterSetID for requested process (with name
164  // processName) from pset registry
165  string pNames("");
166  string hNames("");
167  const ParameterSet* pset = nullptr;
168  ParameterSetID psetID;
169  unsigned int nPSets(0);
170  const edm::pset::Registry * registry_(pset::Registry::instance());
171  const edm::pset::Registry::const_iterator rb(registry_->begin());
172  const edm::pset::Registry::const_iterator re(registry_->end());
173  for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
174  if (i->second.exists("@process_name")) {
175  const std::string pName(i->second.getParameter<string>("@process_name"));
176  pNames += pName+" ";
177  if ( pName == processName ) {
178  psetID = i->first;
179  nPSets++;
180  if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
181  hNames += tableName();
182  } else if ( nullptr != (pset = registry_->getMapped(psetID))) {
183  if (pset->exists("HLTConfigVersion")) {
184  const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
185  if (HLTPSet.exists("tableName")) {
186  hNames += HLTPSet.getParameter<string>("tableName")+" ";
187  }
188  }
189  }
190  }
191  }
192  }
193 
194  LogVerbatim("HLTConfigProvider")
195  << "Unordered list of all process names found: " << pNames << "." << endl;
196 
197  LogVerbatim("HLTConfigProvider")
198  << "HLT TableName of each selected process: " << hNames << "." << endl;
199 
200  if (nPSets==0) {
201  LogError("HLTConfigProvider")
202  << " Process name '" << processName << "' not found in registry!" << endl;
203  clear();
204  return;
205  }
206  if (psetID==ParameterSetID()) {
207  LogError("HLTConfigProvider")
208  << " Process name '" << processName << "' found but ParameterSetID invalid!" << endl;
209  clear();
210  return;
211  }
212  if (nPSets>1) {
213  LogError("HLTConfigProvider")
214  << " Process name '" << processName << " found " << nPSets << " times in registry!" << endl;
215  clear();
216  return;
217  }
218 
219  getDataFrom(psetID);
220 
221  return;
222 
223 }
224 
226 {
227  // clear all data members
228 
229  processName_ = "";
230  inited_ = false;
231  changed_ = true;
233 
234  return;
235 }
236 
237 
238 
239 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs, const std::string& pattern) {
240  std::vector<std::string> matched;
241  const std::regex regexp(edm::glob2reg(pattern));
242  const unsigned int n(inputs.size());
243  for (unsigned int i=0; i<n; ++i) {
244  const std::string& input(inputs[i]);
245  if (std::regex_match(input,regexp)) matched.push_back(input);
246  }
247  return matched;
248 }
249 
251  const std::regex regexp("_v[0-9]+$");
252  return std::regex_replace(trigger,regexp,"");
253 }
254 
255 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs, const std::string& trigger) {
256  return matched(inputs,trigger+"_v[0-9]+$");
257 }
collection_type::const_iterator const_iterator
T getParameter(std::string const &) const
const_iterator begin() const
map_type::const_iterator const_iterator
Definition: Registry.h:63
RunID const & id() const
Definition: RunBase.h:39
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
bool insertMapped(value_type const &v)
const_iterator end() const
Definition: Registry.h:69
static PFTauRenderPlugin instance
void getDataFrom(const edm::ParameterSetID &iID)
ParameterSetID id() const
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:22
bool exists(std::string const &parameterName) const
checks if a parameter exists
static const HLTConfigData * s_dummyHLTConfigData()
const std::string & tableName() const
HLT ConfDB table name.
std::string processName_
data members
bool changed() const
changed?
static const std::string removeVersion(const std::string &trigger)
static std::string const input
Definition: EdmProvDump.cc:44
static ThreadSafeRegistry * instance()
const HLTConfigData * hltConfigData_
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
const edm::ParameterSet & processPSet() const
ParameterSet of process.
bool getMapped(key_type const &k, value_type &result) const
const_iterator begin() const
Definition: Registry.h:65
ProcessHistory const & processHistory() const
Definition: Run.cc:111
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:18
Hash< ParameterSetType > ParameterSetID
HLTConfigProvider()
c&#39;tor
const std::string & processName() const
process name
static const std::vector< std::string > restoreVersion(const std::vector< std::string > &inputs, const std::string &trigger)
ParameterSet const & getParameterSet(std::string const &) const
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const_iterator end() const
HLT enums.
bool isValid() const
Definition: Hash.h:151
edm::ParameterSetID id() const
technical: id() function needed for use with ThreadSafeRegistry
static Registry * instance()
Definition: Registry.cc:12
Definition: Run.h:42