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 const 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 }
41 
43  const edm::EventSetup& iSetup,
44  const std::string& processName,
45  bool& changed) {
46 
47  using namespace std;
48  using namespace edm;
49 
50  LogInfo("HLTConfigData") << "Called (R) with processName '"
51  << processName
52  << "' for " << iRun.id() << endl;
53 
55 
57  l1GtUtils_->getL1GtRunCache(iRun,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
58 
60  changed=changed_;
61  return inited_;
62 
63 }
64 
66 
67  using namespace std;
68  using namespace edm;
69 
70  const ProcessHistory::const_iterator hb(iHistory.begin());
71  const ProcessHistory::const_iterator he(iHistory.end());
72 
75 
77  if (processName_=="*") {
78  // auto-discovery of process name
79  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
80  if (iHistory.getConfigurationForProcess(hi->processName(),processConfiguration)) {
81  processPSet = edm::pset::Registry::instance()->getMapped(processConfiguration.parameterSetID());
82  if ((processPSet!=0) && (processPSet->exists("hltTriggerSummaryAOD"))) {
83  processName_=hi->processName();
84  }
85  }
86  }
87  LogInfo("HLTConfigData") << "Auto-discovered processName: '"
88  << processName_ << "'"
89  << endl;
90  }
91  if (processName_=="*") {
92  LogError("HLTConfigData") << "Auto-discovery of processName failed!"
93  << endl;
94  clear();
95  return;
96  }
97 
99  unsigned int n(0);
100  for (ProcessHistory::const_iterator hi=hb; hi!=he; ++hi) {
101  if (hi->processName()==processName_) {n++;}
102  }
103  if (n>1) {
104  LogError("HLTConfigProvider") << " ProcessName '"<< processName_
105  << " found " << n
106  << " times in history!" << endl;
107  clear();
108  return;
109  }
110 
113  if ((hltConfigData_ !=s_dummyHLTConfigData()) && (processConfiguration.parameterSetID() == hltConfigData_->id())) {
114  changed_ = false;
115  inited_ = true;
116  return;
117  } else {
118  getDataFrom(processConfiguration.parameterSetID());
119  }
120  } else {
121  LogError("HLTConfigProvider") << "Falling back to ProcessName-only init using ProcessName '"<<processName_<<"' !";
123  return;
124  }
125 }
126 
128 {
129  //is it in our registry?
131  const HLTConfigData* d = reg->getMapped(iID);
132  if(0 != d) {
133  changed_ = true;
134  inited_ = true;
135  hltConfigData_ = d;
136  } else {
137  const edm::ParameterSet* processPSet = 0;
138  if ( 0 != (processPSet = edm::pset::Registry::instance()->getMapped(iID))) {
139  if (not processPSet->id().isValid()) {
140  clear();
141  edm::LogError("HLTConfigProvider") << "ProcessPSet found is empty!";
142  changed_ = true;
143  inited_ = false;
145  return;
146  } else {
147  clear();
148  reg->insertMapped( HLTConfigData(processPSet));
149  changed_ = true;
150  inited_ = true;
151  hltConfigData_ = reg->getMapped(processPSet->id());
152  return;
153  }
154  } else {
155  clear();
156  edm::LogError("HLTConfigProvider") << "ProcessPSet not found in regsistry!";
157  changed_ = true;
158  inited_ = false;
160  return;
161  }
162  }
163  return;
164 }
165 
167 {
168  using namespace std;
169  using namespace edm;
170 
171  // Obtain ParameterSetID for requested process (with name
172  // processName) from pset registry
173  string pNames("");
174  string hNames("");
175  const ParameterSet* pset = 0;
176  ParameterSetID psetID;
177  unsigned int nPSets(0);
178  const edm::pset::Registry * registry_(pset::Registry::instance());
179  const edm::pset::Registry::const_iterator rb(registry_->begin());
180  const edm::pset::Registry::const_iterator re(registry_->end());
181  for (edm::pset::Registry::const_iterator i = rb; i != re; ++i) {
182  if (i->second.exists("@process_name")) {
183  const std::string pName(i->second.getParameter<string>("@process_name"));
184  pNames += pName+" ";
185  if ( pName == processName ) {
186  psetID = i->first;
187  nPSets++;
188  if ((hltConfigData_ != s_dummyHLTConfigData()) && (hltConfigData_->id()==psetID)) {
189  hNames += tableName();
190  } else if ( 0 != (pset = registry_->getMapped(psetID))) {
191  if (pset->exists("HLTConfigVersion")) {
192  const ParameterSet& HLTPSet(pset->getParameterSet("HLTConfigVersion"));
193  if (HLTPSet.exists("tableName")) {
194  hNames += HLTPSet.getParameter<string>("tableName")+" ";
195  }
196  }
197  }
198  }
199  }
200  }
201 
202  LogVerbatim("HLTConfigProvider") << "Unordered list of all process names found: "
203  << pNames << "." << endl;
204 
205  LogVerbatim("HLTConfigProvider") << "HLT TableName of each selected process: "
206  << hNames << "." << endl;
207 
208  if (nPSets==0) {
209  LogError("HLTConfigProvider") << " Process name '"
210  << processName
211  << "' not found in registry!" << endl;
212  clear();
213  return;
214  }
215  if (psetID==ParameterSetID()) {
216  LogError("HLTConfigProvider") << " Process name '"
217  << processName
218  << "' found but ParameterSetID invalid!"
219  << endl;
220  clear();
221  return;
222  }
223  if (nPSets>1) {
224  LogError("HLTConfigProvider") << " Process name '"
225  << processName
226  << " found " << nPSets
227  << " times in registry!" << endl;
228  clear();
229  return;
230  }
231 
232  getDataFrom(psetID);
233 
234  return;
235 
236 }
237 
239 {
240  // clear all data members
241 
242  processName_ = "";
243  inited_ = false;
244  changed_ = true;
246  *l1GtUtils_ = L1GtUtils();
247 
248  return;
249 }
250 
251 
253  // return hltPrescaleTable_.set();
254  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
255  int errorTech(0);
256  const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
257  int errorPhys(0);
258  const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
259  assert(psfsiTech==psfsiPhys);
260  if ( (errorTech==0) && (errorPhys==0) &&
261  (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
262  return psfsiPhys;
263  } else {
265  edm::LogError("HLTConfigData")
266  << " Error in determining HLT prescale set index from L1 data using L1GtUtils: "
267  << " Tech/Phys error = " << errorTech << "/" << errorPhys
268  << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
269  return -1;
270  }
271 }
272 
273 unsigned int HLTConfigProvider::prescaleValue(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
274  const int set(prescaleSet(iEvent,iSetup));
275  if (set<0) {
276  return 1;
277  } else {
278  return prescaleValue(static_cast<unsigned int>(set),trigger);
279  }
280 }
281 
282 std::pair<int,int> HLTConfigProvider::prescaleValues(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) const {
283 
284  // start with setting both L1T and HLT prescale values to 0
285  std::pair<int,int> result(std::pair<int,int>(0,0));
286 
287  // get HLT prescale (possible if HLT prescale set index is correctly found)
288  const int set(prescaleSet(iEvent,iSetup));
289  if (set<0) {
290  result.second = -1;
291  } else {
292  result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
293  }
294 
295  // get L1T prescale - works only for those hlt trigger paths with
296  // exactly one L1GT seed module which has exactly one L1T name as seed
297  const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
298  if (nL1GTSeedModules==0) {
299  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
300  result.first=1;
301  } else if (nL1GTSeedModules==1) {
302  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
303  const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
304  int l1error(0);
305  result.first = l1GtUtils_->prescaleFactor(iEvent,l1tname,l1error);
306  if (l1error!=0) {
307  edm::LogError("HLTConfigData")
308  << " Error in determining L1T prescale for HLT path: '" << trigger
309  << "' with L1T seed: '" << l1tname
310  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
311  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed as seed!" << std::endl
312  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."<< std::endl;
313  result.first = -1;
314  }
315  } else {
317  std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
318  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
319  dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
320  }
321  edm::LogError("HLTConfigData")
322  << " Error in determining L1T prescale for HLT path: '" << trigger
323  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
324  << ", with L1 seeds: " << dump
325  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
326  result.first = -1;
327  }
328 
329  return result;
330 }
331 
332 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 {
333 
334  std::pair<std::vector<std::pair<std::string,int> >,int> result;
335  result.first.clear();
336 
337  // get HLT prescale (possible if HLT prescale set index is correctly found)
338  const int set(prescaleSet(iEvent,iSetup));
339  if (set<0) {
340  result.second = -1;
341  } else {
342  result.second = static_cast<int>(prescaleValue(static_cast<unsigned int>(set),trigger));
343  }
344 
345  // get L1T prescale - works only for those hlt trigger paths with
346  // exactly one L1GT seed module which has exactly one L1T name as seed
347  const unsigned int nL1GTSeedModules(hltL1GTSeeds(trigger).size());
348  if (nL1GTSeedModules==0) {
349  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
350  result.first.clear();
351  } else if (nL1GTSeedModules==1) {
352  l1GtUtils_->getL1GtRunCache(iEvent,iSetup,useL1EventSetup,useL1GtTriggerMenuLite);
353  const std::string l1tname(hltL1GTSeeds(trigger).at(0).second);
355  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(),iSetup,l1tname);
356  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
357  result.first = l1Logical.prescaleFactors();
358  int l1error(l1Logical.isValid() ? 0 : 1);
359  for (unsigned int i=0; i<errorCodes.size(); ++i) {
360  l1error += std::abs(errorCodes[i].second);
361  }
362  if (l1error!=0) {
363  std::ostringstream message;
364  message
365  << " Error in determining L1T prescales for HLT path: '" << trigger
366  << "' with complex L1T seed: '" << l1tname
367  << "' using L1GtUtils: " << std::endl
368  << " isValid=" << l1Logical.isValid()
369  << " l1tname/error/prescale " << errorCodes.size()
370  << std::endl;
371  for (unsigned int i=0; i< errorCodes.size(); ++i) {
372  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/" << result.first[i].second;
373  }
374  message << ".";
375  edm::LogError("HLTConfigData") << message.str();
376  result.first.clear();
377  }
378  } else {
380  std::string dump("'"+hltL1GTSeeds(trigger).at(0).second+"'");
381  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
382  dump += " * '"+hltL1GTSeeds(trigger).at(i).second+"'";
383  }
384  edm::LogError("HLTConfigData")
385  << " Error in determining L1T prescale for HLT path: '" << trigger
386  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
387  << ", with L1 seeds: " << dump
388  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
389  result.first.clear();
390  }
391 
392  return result;
393 }
394 
395 const std::vector<std::string> HLTConfigProvider::matched(const std::vector<std::string>& inputs, const std::string& pattern) {
396  std::vector<std::string> matched;
397  const boost::regex regexp(edm::glob2reg(pattern));
398  const unsigned int n(inputs.size());
399  for (unsigned int i=0; i<n; ++i) {
400  const std::string& input(inputs[i]);
401  if (boost::regex_match(input,regexp)) matched.push_back(input);
402  }
403  return matched;
404 }
405 
407  const boost::regex regexp("_v[0-9]+$");
408  return boost::regex_replace(trigger,regexp,"");
409 }
410 
411 const std::vector<std::string> HLTConfigProvider::restoreVersion(const std::vector<std::string>& inputs, const std::string& trigger) {
412  return matched(inputs,trigger+"_v[0-9]+$");
413 }
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
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
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
processConfiguration
Definition: Schedule.cc:370
static const HLTConfigData * s_dummyHLTConfigData()
const std::vector< std::pair< std::string, int > > & prescaleFactors()
Definition: L1GtUtils.cc:2721
list pattern
Definition: chain.py:104
Run const & getRun() const
Definition: Event.cc:58
const std::string & tableName() const
HLT ConfDB table name.
std::string processName_
data members
static const std::string removeVersion(const std::string &trigger)
static std::string const input
Definition: EdmProvDump.cc:44
static ThreadSafeRegistry * instance()
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:230
const edm::ParameterSet & processPSet() const
ParameterSet of process.
bool getMapped(key_type const &k, value_type &result) const
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:103
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:22
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:16
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