CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTConfigProvider.cc
Go to the documentation of this file.
1 
21 
22 #include <boost/regex.hpp>
23 
24 static const bool useL1EventSetup(true);
25 static const bool useL1GtTriggerMenuLite(false);
26 
27 // an empty dummy config data used when we fail to initialize
29 { static HLTConfigData dummyHLTConfigData;
30  return &dummyHLTConfigData;
31 }
32 
34  processName_(""),
35  inited_(false),
36  changed_(true),
37  hltConfigData_(s_dummyHLTConfigData()),
38  l1GtUtils_(new L1GtUtils())
39 {
40  // HLTConfigDataRegistry::instance()->extra().increment();
41 }
42 
43 //HLTConfigProvider::~HLTConfigProvider() {
44 // if (HLTConfigDataRegistry::instance()->extra().decrement()==0) {
45 // HLTConfigDataRegistry::instance()->data().clear();
46 // }
47 //}
48 
51 }
52 
55 }
56 
59 }
60 
63 }
64 
66  const edm::EventSetup& iSetup,
67  const std::string& processName,
68  bool& changed) {
69 
70  using namespace std;
71  using namespace edm;
72 
73  LogInfo("HLTConfigData") << "Called (R) with processName '"
74  << processName
75  << "' for " << iRun.id() << endl;
76 
78 
80  l1GtUtils_->getL1GtRunCache(iRun,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
81 
83  changed=changed_;
84  return inited_;
85 
86 }
87 
89 
90  using namespace std;
91  using namespace edm;
92 
93  const ProcessHistory::const_iterator hb(iHistory.begin());
94  const ProcessHistory::const_iterator he(iHistory.end());
95 
98 
100  if (processName_=="*") {
101  // auto-discovery of process name
102  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
103  if (iHistory.getConfigurationForProcess(hi->processName(),processConfiguration)) {
104  processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
105  if ((processPSet!=0) && (processPSet->exists("hltTriggerSummaryAOD"))) {
106  processName_=hi->processName();
107  }
108  }
109  }
110  LogInfo("HLTConfigData") << "Auto-discovered processName: '"
111  << processName_ << "'"
112  << endl;
113  }
114  if (processName_=="*") {
115  clear();
116  LogError("HLTConfigData") << "Auto-discovery of processName failed!"
117  << endl;
118  return;
119  }
120 
122  unsigned int n(0);
123  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
124  if (hi->processName()==processName_) {n++;}
125  }
126  if (n>1) {
127  clear();
128  LogError("HLTConfigProvider") << " ProcessName '"<< processName_
129  << " found " << n
130  << " times in history!" << endl;
131  return;
132  }
133 
136  if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
137  changed_ = false;
138  inited_ = true;
139  return;
140  } else {
141  getDataFrom(processConfiguration.parameterSetID());
142  }
143  } else {
144  LogError("HLTConfigProvider") << "Falling back to processName-only init!";
145  clear();
147  if (!inited_) {
148  LogError("HLTConfigProvider") << "ProcessName not found in history!";
149  }
150  return;
151  }
152 }
153 
155 {
156  //is it in our registry?
158  const HLTConfigData* d = reg->getMapped(iID);
159  if(0 != d) {
160  changed_ = true;
161  inited_ = true;
162  hltConfigData_ = d;
163  } else {
164  const edm::ParameterSet* processPSet = 0;
165  if ( 0 != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
166  if (not processPSet->id().isValid()) {
167  clear();
168  edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
169  changed_ = true;
170  inited_ = false;
172  return;
173  } else {
174  clear();
175  reg->insertMapped( HLTConfigData(processPSet));
176  changed_ = true;
177  inited_ = true;
178  hltConfigData_ = reg->getMapped(processPSet->id());
179  return;
180  }
181  } else {
182  clear();
183  edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
184  changed_ = true;
185  inited_ = false;
187  return;
188  }
189  }
190  return;
191 }
192 
194 {
195  using namespace std;
196  using namespace edm;
197 
198  // Obtain ParameterSetID for requested process (with name
199  // processName) from pset registry
200  string pNames("");
201  string hNames("");
202  const ParameterSet* pset = 0;
203  ParameterSetID psetID;
204  unsigned int nPSets(0);
205  const edm::pset::Registry * registry_(pset::Registry::instance());
206  const edm::pset::Registry::const_iterator rb(registry_->begin());
207  const edm::pset::Registry::const_iterator re(registry_->end());
208  for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
209  if (i->second.exists("@process_name")) {
210  const std::string pName(i->second.getParameter<string>("@process_name"));
211  pNames += pName+" ";
212  if ( pName == processName ) {
213  psetID = i->first;
214  nPSets++;
215  if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
216  hNames += tableName();
217  } else if ( 0 != (pset = registry_->getMapped(psetID))) {
218  if (pset->exists("HLTConfigVersion")) {
219  const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
220  if (HLTPSet.exists("tableName")) {
221  hNames += HLTPSet.getParameter<string>("tableName")+" ";
222  }
223  }
224  }
225  }
226  }
227  }
228 
229  LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: "
230  << pNames << "." << endl;
231 
232  LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: "
233  << hNames << "." << endl;
234 
235  if (nPSets==0) {
236  clear();
237  LogError("HLTConfigProvider") << " Process name '"
238  << processName
239  << "' not found in registry!" << endl;
240  return;
241  }
242  if (psetID==ParameterSetID()) {
243  clear();
244  LogError("HLTConfigProvider") << " Process name '"
245  << processName
246  << "' found but ParameterSetID invalid!"
247  << endl;
248  return;
249  }
250  if (nPSets>1) {
251  clear();
252  LogError("HLTConfigProvider") << " Process name '"
253  << processName
254  << " found " << nPSets
255  << " times in registry!" << endl;
256  return;
257  }
258 
259  getDataFrom(psetID);
260 
261  return;
262 
263 }
264 
266 {
267  // clear all data members
268 
269  processName_ = "";
270  inited_ = false;
271  changed_ = true;
273  *l1GtUtils_ = L1GtUtils();
274 
275  return;
276 }
277 
278 
280  // return hltPrescaleTable_.set();
281  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
282  int errorTech(0);
283  const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
284  int errorPhys(0);
285  const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
286  assert(psfsiTech==psfsiPhys);
287  if ( (errorTech==0) && (errorPhys==0) &&
288  (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
289  return psfsiPhys;
290  } else {
292  edm::LogError("HLTConfigData")
293  << " Error in determining HLT prescale set index from L1 data using L1GtUtils: "
294  << " Tech/Phys error = " << errorTech << "/" << errorPhys
295  << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
296  return -1;
297  }
298 }
299 
300 unsigned int HLTConfigProvider::prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
301  const int set(prescaleSet(iEvent,iSetup));
302  if (set<0) {
303  return 1;
304  } else {
305  return prescaleValue(static_cast<unsigned int>(set),trigger);
306  }
307 }
308 
309 std::pair<int,int> HLTConfigProvider::prescaleValues(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
310 
311  // start with setting both L1T and HLT prescale values to 0
312  std::pair<int,int> result(std::pair<int,int>(0,0));
313 
314  // get HLT prescale (possible if HLT prescale set index is correctly found)
315  const int set(prescaleSet(iEvent,iSetup));
316  if (set<0) {
317  result.second = -1;
318  } else {
319  result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
320  }
321 
322  // get L1T prescale - works only for those hlt trigger paths with
323  // exactly one L1GT seed module which has exactly one L1T name as seed
324  const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
325  if (nL1GTSeedModules==0) {
326  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
327  result.first=1;
328  } else if (nL1GTSeedModules==1) {
329  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
330  const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
331  int l1error(0);
332  result.first = l1GtUtils_->prescaleFactor(iEvent,l1tname,l1error);
333  if (l1error!=0) {
334  edm::LogError("HLTConfigData")
335  << " Error in determining L1T prescale for HLT path: '" << trigger
336  << "' with L1T seed: '" << l1tname
337  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
338  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed as seed!" << std::endl
339  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."<< std::endl;
340  result.first = -1;
341  }
342  } else {
344  std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
345  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
346  dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
347  }
348  edm::LogError("HLTConfigData")
349  << " Error in determining L1T prescale for HLT path: '" << trigger
350  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
351  << ", with L1 seeds: " << dump
352  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
353  result.first = -1;
354  }
355 
356  return result;
357 }
358 
359 std::pair<std::vector<std::pair<std::string,int> >,int> HLTConfigProvider::prescaleValuesInDetail(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
360 
361  std::pair<std::vector<std::pair<std::string,int> >,int> result;
362  result.first.clear();
363 
364  // get HLT prescale (possible if HLT prescale set index is correctly found)
365  const int set(prescaleSet(iEvent,iSetup));
366  if (set<0) {
367  result.second = -1;
368  } else {
369  result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
370  }
371 
372  // get L1T prescale - works only for those hlt trigger paths with
373  // exactly one L1GT seed module which has exactly one L1T name as seed
374  const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
375  if (nL1GTSeedModules==0) {
376  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
377  result.first.clear();
378  } else if (nL1GTSeedModules==1) {
379  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
380  const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
382  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(),iSetup,l1tname);
383  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
384  result.first = l1Logical.prescaleFactors();
385  int l1error(l1Logical.isValid() ? 0 : 1);
386  for (unsigned int i=0; i<errorCodes.size(); ++i) {
387  l1error += std::abs(errorCodes[i].second);
388  }
389  if (l1error!=0) {
390  std::ostringstream message;
391  message
392  << " Error in determining L1T prescales for HLT path: '" << trigger
393  << "' with complex L1T seed: '" << l1tname
394  << "' using L1GtUtils: " << std::endl
395  << " isValid=" << l1Logical.isValid()
396  << " l1tname/error/prescale " << errorCodes.size()
397  << std::endl;
398  for (unsigned int i=0; i< errorCodes.size(); ++i) {
399  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/" << result.first[i].second;
400  }
401  message << ".";
402  edm::LogError("HLTConfigData") << message.str();
403  result.first.clear();
404  }
405  } else {
407  std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
408  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
409  dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
410  }
411  edm::LogError("HLTConfigData")
412  << " Error in determining L1T prescale for HLT path: '" << trigger
413  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
414  << ", with L1 seeds: " << dump
415  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
416  result.first.clear();
417  }
418 
419  return result;
420 }
421 
422 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs, const std::string& pattern) {
423  std::vector<std::string> matched;
424  const boost::regex regexp(edm::glob2reg(pattern));
425  const unsigned int n(inputs.size());
426  for (unsigned int i=0; i<n; ++i) {
427  const std::string& input(inputs[i]);
428  if (boost::regex_match(input,regexp)) matched.push_back(input);
429  }
430  return matched;
431 }
432 
434  const boost::regex regexp("_v[0-9]+$");
435  return boost::regex_replace(trigger,regexp,"");
436 }
437 
438 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs, const std::string& trigger) {
439  return matched(inputs,trigger+"_v[0-9]+$");
440 }
unsigned int size() const
number of trigger paths in trigger table
collection_type::const_iterator const_iterator
void dump(const std::string &what) const
Dumping config info to cout.
T getParameter(std::string const &) const
const_iterator begin() const
int i
Definition: DBlmapReader.cc:9
map_type::const_iterator const_iterator
Definition: Registry.h:63
RunID const & id() const
Definition: RunBase.h:41
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
const int logicalExpressionRunUpdate(const edm::Run &, const edm::EventSetup &, const std::string &)
Definition: L1GtUtils.cc:2578
const_iterator end() const
Definition: Registry.h:69
static PFTauRenderPlugin instance
void getDataFrom(const edm::ParameterSetID &iID)
ParameterSetID id() const
static ThreadSafeRegistry * instance()
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:22
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger) const
bool getMapped(key_type const &k, value_type &result) const
processConfiguration
Definition: Schedule.cc:362
static const HLTConfigData * s_dummyHLTConfigData()
const std::vector< std::pair< std::string, int > > & prescaleFactors()
Definition: L1GtUtils.cc:2721
Run const & getRun() const
Definition: Event.cc:61
const std::string & tableName() const
HLT ConfDB table name.
std::string processName_
data members
bool insertMapped(value_type const &v)
bool changed() const
changed?
static const std::string removeVersion(const std::string &trigger)
static std::string const input
Definition: EdmProvDump.cc:44
const HLTConfigData * hltConfigData_
U second(std::pair< T, U > const &p)
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
boost::shared_ptr< L1GtUtils > l1GtUtils_
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
int iEvent
Definition: GenABIO.cc:243
const edm::ParameterSet & processPSet() const
ParameterSet of process.
tuple result
Definition: query.py:137
const_iterator begin() const
Definition: Registry.h:65
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ProcessHistory const & processHistory() const
Definition: Run.cc:108
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:20
Hash< ParameterSetType > ParameterSetID
HLTConfigProvider()
c&#39;tor
static const bool useL1GtTriggerMenuLite(false)
const std::string & processName() const
process name
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup) const
static const std::vector< std::string > restoreVersion(const std::vector< std::string > &inputs, const std::string &trigger)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger) const
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
const_iterator end() const
static const bool useL1EventSetup(true)
bool isValid() const
Definition: Hash.h:150
volatile std::atomic< bool > shutdown_flag false
edm::ParameterSetID id() const
technical: id() function needed for use with ThreadSafeRegistry
static Registry * instance()
Definition: Registry.cc:14
bool isValid()
return true if the logical expression is syntactically correct
Definition: L1GtUtils.h:97
Definition: Run.h:41
list at
Definition: asciidump.py:428
const std::vector< std::pair< std::string, int > > & errorCodes(const edm::Event &)
Definition: L1GtUtils.cc:2747