CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Enumerations | Functions
hltDiff.cc File Reference
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <memory>
#include <algorithm>
#include <cstring>
#include <unistd.h>
#include <getopt.h>
#include <cmath>
#include <boost/algorithm/string.hpp>
#include <TFile.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TGraphAsymmErrors.h>
#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/Registry.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/HLTReco/interface/TriggerObject.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/FWLite/interface/Handle.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/FWLite/interface/ChainEvent.h"
#include "HLTrigger/HLTcore/interface/HLTConfigData.h"

Go to the source code of this file.

Classes

struct  SummaryOutputProducer::Event
 
struct  SummaryOutputProducer::GenericSummary
 
class  HLTCommonConfig
 
class  HLTConfigDataEx
 
class  HLTConfigInterface
 
class  HltDiff
 
struct  JsonOutputProducer::JsonConfiguration
 
struct  JsonOutputProducer::JsonConfigurationBlock
 
struct  JsonOutputProducer::JsonEvent
 
struct  JsonOutputProducer::JsonEventState
 
class  JsonOutputProducer
 
struct  JsonOutputProducer::JsonTriggerEventState
 
struct  JsonOutputProducer::JsonVars
 
struct  SummaryOutputProducer::Pair
 
class  SummaryOutputProducer
 
struct  TriggerDiff
 
struct  SummaryOutputProducer::TriggerSummary
 
class  HLTCommonConfig::View
 

Enumerations

enum  State {
  InvalidLinkId, InvalidROCId, InvalidPixelId, Unknown,
  Ready = edm::hlt::Ready, Pass = edm::hlt::Pass, Fail = edm::hlt::Fail, Exception = edm::hlt::Exception,
  Prescaled, Invalid
}
 

Functions

bool check_file (std::string const &file)
 
bool check_files (std::vector< std::string > const &files)
 
void error (std::ostream &out)
 
void error (std::ostream &out, const char *message)
 
void error (std::ostream &out, const std::string &message)
 
const char * event_state (bool state)
 
std::unique_ptr< HLTConfigDataExgetHLTConfigData (fwlite::EventBase const &event, std::string process)
 
std::string getProcessNameFromBranch (std::string const &branch)
 
int main (int argc, char **argv)
 
std::ostream & operator<< (std::ostream &out, TriggerDiff diff)
 
const char * path_state (State state)
 
State prescaled_state (int state, int path, int module, HLTConfigInterface const &config)
 
void print_detailed_path_state (std::ostream &out, State state, int path, int module, HLTConfigInterface const &config)
 
void print_trigger_candidates (std::ostream &out, trigger::TriggerEvent const &summary, edm::InputTag const &filter)
 
void print_trigger_collection (std::ostream &out, trigger::TriggerEvent const &summary, std::string const &tag)
 
std::string strip_process_name (std::string const &s)
 

Enumeration Type Documentation

enum State
Enumerator
InvalidLinkId 
InvalidROCId 
InvalidPixelId 
Unknown 
Ready 
Pass 
Fail 
Exception 
Prescaled 
Invalid 

Definition at line 241 of file hltDiff.cc.

Function Documentation

bool check_file ( std::string const &  file)

Definition at line 1224 of file hltDiff.cc.

References validate-o2o-wbm::f.

Referenced by check_files().

1224  {
1225  std::unique_ptr<TFile> f(TFile::Open(file.c_str()));
1226  return (f and not f->IsZombie());
1227 }
bool check_files ( std::vector< std::string > const &  files)

Definition at line 1229 of file hltDiff.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, check_file(), and mergeVDriftHistosByStation::file.

Referenced by HltDiff::compare().

1229  {
1230  bool flag = true;
1231  for (auto const& file : files)
1232  if (not check_file(file)) {
1233  flag = false;
1234  std::cerr << "hltDiff: error: file " << file << " does not exist, or is not a regular file." << std::endl;
1235  }
1236  return flag;
1237 }
bool check_file(std::string const &file)
Definition: hltDiff.cc:1224
void error ( std::ostream &  out)

Definition at line 43 of file hltDiff.cc.

43 { out << "Try 'hltDiff --help' for more information" << std::endl; }
void error ( std::ostream &  out,
const char *  message 
)

Definition at line 45 of file hltDiff.cc.

References relativeConstraints::error.

45  {
46  out << message << std::endl;
47  error(out);
48 }
void error ( std::ostream &  out,
const std::string &  message 
)

Definition at line 50 of file hltDiff.cc.

References relativeConstraints::error.

50  {
51  out << message << std::endl;
52  error(out);
53 }
const char* event_state ( bool  state)

Definition at line 113 of file hltDiff.cc.

Referenced by HltDiff::compare().

113 { return state ? "accepted" : "rejected"; }
std::unique_ptr<HLTConfigDataEx> getHLTConfigData ( fwlite::EventBase const &  event,
std::string  process 
)

Definition at line 362 of file hltDiff.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, submitPVResolutionJobs::config, beamvalidation::exit(), edm::pset::Registry::getMapped(), getProcessNameFromBranch(), isotrackTrainRegressor::history, edm::pset::Registry::instance(), edm::ProcessConfiguration::parameterSetID(), and TrackValidation_cff::pset.

Referenced by HltDiff::compare().

362  {
363  auto const& history = event.processHistory();
364  if (process.empty()) {
365  // determine the process name from the most recent "TriggerResults" object
366  auto const& branch =
367  event.getBranchNameFor(edm::Wrapper<edm::TriggerResults>::typeInfo(), "TriggerResults", "", process.c_str());
369  }
370 
372  if (not history.getConfigurationForProcess(process, config)) {
373  std::cerr << "error: the process " << process << " is not in the Process History" << std::endl;
374  exit(1);
375  }
377  if (pset == nullptr) {
378  std::cerr << "error: the configuration for the process " << process << " is not available in the Provenance"
379  << std::endl;
380  exit(1);
381  }
382  return std::make_unique<HLTConfigDataEx>(HLTConfigData(pset));
383 }
ParameterSetID const & parameterSetID() const
std::string getProcessNameFromBranch(std::string const &branch)
Definition: hltDiff.cc:356
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
tuple config
parse the configuration file
tuple process
Definition: LaserDQM_cfg.py:3
static Registry * instance()
Definition: Registry.cc:12
std::string getProcessNameFromBranch ( std::string const &  branch)

Definition at line 356 of file hltDiff.cc.

References submitPVValidationJobs::split().

Referenced by getHLTConfigData().

356  {
357  std::vector<boost::iterator_range<std::string::const_iterator>> tokens;
358  boost::split(tokens, branch, boost::is_any_of("_."), boost::token_compress_off);
359  return boost::copy_range<std::string>(tokens[3]);
360 }
int main ( int  argc,
char **  argv 
)

Definition at line 1628 of file hltDiff.cc.

References c, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, relativeConstraints::error, beamvalidation::exit(), ValidationMatrix::hlt, and SiStripPI::max.

1628  {
1629  // options
1630  const char optstring[] = "dfo:O:n:N:m:pcjrF:v::hq";
1631  const option longopts[] = {
1632  option{"debug", no_argument, nullptr, 'd'},
1633  option{"file-check", no_argument, nullptr, 'f'},
1634  option{"old-files", required_argument, nullptr, 'o'},
1635  option{"old-process", required_argument, nullptr, 'O'},
1636  option{"new-files", required_argument, nullptr, 'n'},
1637  option{"new-process", required_argument, nullptr, 'N'},
1638  option{"max-events", required_argument, nullptr, 'm'},
1639  option{"prescales", no_argument, nullptr, 'p'},
1640  option{"csv-output", optional_argument, nullptr, 'c'},
1641  option{"json-output", optional_argument, nullptr, 'j'},
1642  option{"root-output", optional_argument, nullptr, 'r'},
1643  option{"output-file", optional_argument, nullptr, 'F'},
1644  option{"verbose", optional_argument, nullptr, 'v'},
1645  option{"help", no_argument, nullptr, 'h'},
1646  option{"quiet", no_argument, nullptr, 'q'},
1647  };
1648 
1649  // Creating an HltDiff object with the default configuration
1650  auto hlt = new HltDiff();
1651 
1652  // parse the command line options
1653  int c = -1;
1654  while ((c = getopt_long(argc, argv, optstring, longopts, nullptr)) != -1) {
1655  switch (c) {
1656  case 'd':
1657  hlt->debug = true;
1658  break;
1659 
1660  case 'f':
1661  hlt->file_check = true;
1662  break;
1663 
1664  case 'o':
1665  hlt->old_files.emplace_back(optarg);
1666  while (optind < argc) {
1667  if (argv[optind][0] == '-')
1668  break;
1669  hlt->old_files.emplace_back(argv[optind]);
1670  ++optind;
1671  }
1672  break;
1673 
1674  case 'O':
1675  hlt->old_process = optarg;
1676  break;
1677 
1678  case 'n':
1679  hlt->new_files.emplace_back(optarg);
1680  while (optind < argc) {
1681  if (argv[optind][0] == '-')
1682  break;
1683  hlt->new_files.emplace_back(argv[optind]);
1684  ++optind;
1685  }
1686  break;
1687 
1688  case 'N':
1689  hlt->new_process = optarg;
1690  break;
1691 
1692  case 'm':
1693  hlt->max_events = atoi(optarg);
1694  break;
1695 
1696  case 'p':
1697  hlt->ignore_prescales = false;
1698  break;
1699 
1700  case 'c':
1701  hlt->csv_out = true;
1702  break;
1703 
1704  case 'j':
1705  hlt->json_out = true;
1706  break;
1707 
1708  case 'r':
1709  hlt->root_out = true;
1710  break;
1711 
1712  case 'F':
1713  hlt->output_file = optarg;
1714  break;
1715 
1716  case 'v':
1717  hlt->verbose = 1;
1718  if (optarg) {
1719  hlt->verbose = std::max(1, atoi(optarg));
1720  } else if (!optarg && nullptr != argv[optind] && '-' != argv[optind][0]) {
1721  // workaround for a bug in getopt which doesn't allow space before optional arguments
1722  const char* tmp_optarg = argv[optind++];
1723  hlt->verbose = std::max(1, atoi(tmp_optarg));
1724  }
1725  break;
1726 
1727  case 'h':
1728  hlt->usage(std::cerr);
1729  exit(0);
1730  break;
1731 
1732  case 'q':
1733  hlt->quiet = true;
1734  break;
1735 
1736  default:
1737  error(std::cerr);
1738  exit(1);
1739  break;
1740  }
1741  }
1742 
1743  if (hlt->old_files.empty()) {
1744  error(std::cerr, "hltDiff: please specify the 'old' file(s)");
1745  exit(1);
1746  }
1747  if (hlt->new_files.empty()) {
1748  error(std::cerr, "hltDiff: please specify the 'new' file(s)");
1749  exit(1);
1750  }
1751 
1752  hlt->compare();
1753 
1754  return 0;
1755 }
const edm::EventSetup & c
tuple argc
Definition: dir2webdir.py:39
std::ostream& operator<< ( std::ostream &  out,
TriggerDiff  diff 
)

Definition at line 414 of file hltDiff.cc.

References TriggerDiff::count, TriggerDiff::format(), TriggerDiff::gained, TriggerDiff::internal, TriggerDiff::lost, and submitPVResolutionJobs::out.

414  {
415  out << std::setw(12) << diff.count << std::setw(12) << TriggerDiff::format(diff.gained, '+') << std::setw(12)
416  << TriggerDiff::format(diff.lost, '-') << std::setw(12) << TriggerDiff::format(diff.internal, '~');
417  return out;
418 }
unsigned int count
Definition: hltDiff.cc:388
unsigned int internal
Definition: hltDiff.cc:391
unsigned int lost
Definition: hltDiff.cc:390
static std::string format(unsigned int value, char sign= '+')
Definition: hltDiff.cc:393
unsigned int gained
Definition: hltDiff.cc:389
const char* path_state ( State  state)

Definition at line 250 of file hltDiff.cc.

References Invalid.

Referenced by HltDiff::compare(), and print_detailed_path_state().

250  {
251  static const char* message[] = {"not run", "accepted", "rejected", "exception", "prescaled", "invalid"};
252 
253  if (state > 0 and state < Invalid)
254  return message[state];
255  else
256  return message[Invalid];
257 }
State prescaled_state ( int  state,
int  path,
int  module,
HLTConfigInterface const &  config 
)
inline

Definition at line 259 of file hltDiff.cc.

References Fail, Prescaled, and HLTConfigInterface::prescaler().

Referenced by HltDiff::compare().

259  {
260  if (state == Fail and config.prescaler(path, module))
261  return Prescaled;
262  return (State)state;
263 }
Definition: hltDiff.cc:244
tuple config
parse the configuration file
tuple module
Definition: callgraph.py:69
void print_detailed_path_state ( std::ostream &  out,
State  state,
int  path,
int  module,
HLTConfigInterface const &  config 
)

Definition at line 286 of file hltDiff.cc.

References Fail, label, HLTConfigInterface::moduleLabel(), HLTConfigInterface::moduleType(), and path_state().

Referenced by HltDiff::compare().

286  {
287  auto const& label = config.moduleLabel(path, module);
288  auto const& type = config.moduleType(path, module);
289 
290  out << "'" << path_state(state) << "'";
291  if (state == Fail)
292  out << " by module " << module << " '" << label << "' [" << type << "]";
293  else if (state == Exception)
294  out << " at module " << module << " '" << label << "' [" << type << "]";
295 }
char const * label
Definition: hltDiff.cc:244
const char * path_state(State state)
Definition: hltDiff.cc:250
tuple config
parse the configuration file
tuple module
Definition: callgraph.py:69
void print_trigger_candidates ( std::ostream &  out,
trigger::TriggerEvent const &  summary,
edm::InputTag const &  filter 
)

Definition at line 297 of file hltDiff.cc.

References trigger::TriggerObject::eta(), trigger::TriggerEvent::filterIds(), trigger::TriggerEvent::filterIndex(), trigger::TriggerEvent::filterKeys(), trigger::TriggerEvent::getObjects(), mps_fire::i, trigger::TriggerObject::id(), submitPVResolutionJobs::key, trigger::TriggerObject::mass(), trigger::TriggerObject::phi(), trigger::TriggerObject::pt(), and trigger::TriggerEvent::sizeFilters().

Referenced by HltDiff::compare().

297  {
298  // find the index of the collection of trigger candidates corresponding to the filter
299  unsigned int index = summary.filterIndex(filter);
300 
301  if (index >= summary.sizeFilters()) {
302  // the collection of trigger candidates corresponding to the filter could not be found
303  out << " not found\n";
304  return;
305  }
306 
307  if (summary.filterKeys(index).empty()) {
308  // the collection of trigger candidates corresponding to the filter is empty
309  out << " none\n";
310  return;
311  }
312 
313  for (unsigned int i = 0; i < summary.filterKeys(index).size(); ++i) {
314  auto key = summary.filterKeys(index)[i];
315  auto id = summary.filterIds(index)[i];
316  trigger::TriggerObject const& candidate = summary.getObjects().at(key);
317  out << " "
318  << "filter id: " << id << ", "
319  << "object id: " << candidate.id() << ", "
320  << "pT: " << candidate.pt() << ", "
321  << "eta: " << candidate.eta() << ", "
322  << "phi: " << candidate.phi() << ", "
323  << "mass: " << candidate.mass() << "\n";
324  }
325 }
int id() const
getters
Definition: TriggerObject.h:51
float phi() const
Definition: TriggerObject.h:54
float eta() const
Definition: TriggerObject.h:53
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
tuple key
prepare the HTCondor submission files and eventually submit them
float mass() const
Definition: TriggerObject.h:55
void print_trigger_collection ( std::ostream &  out,
trigger::TriggerEvent const &  summary,
std::string const &  tag 
)

Definition at line 327 of file hltDiff.cc.

References SplitLinear::begin, trigger::TriggerEvent::collectionKey(), trigger::TriggerEvent::collectionTags(), dataset::end, trigger::TriggerObject::eta(), spr::find(), trigger::TriggerEvent::getObjects(), trigger::TriggerObject::id(), submitPVResolutionJobs::key, trigger::TriggerObject::mass(), trigger::TriggerObject::phi(), trigger::TriggerObject::pt(), and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by HltDiff::compare().

327  {
328  auto iterator = std::find(summary.collectionTags().begin(), summary.collectionTags().end(), tag);
329  if (iterator == summary.collectionTags().end()) {
330  // the collection of trigger candidates could not be found
331  out << " not found\n";
332  return;
333  }
334 
335  unsigned int index = iterator - summary.collectionTags().begin();
336  unsigned int begin = (index == 0) ? 0 : summary.collectionKey(index - 1);
337  unsigned int end = summary.collectionKey(index);
338 
339  if (end == begin) {
340  // the collection of trigger candidates is empty
341  out << " none\n";
342  return;
343  }
344 
345  for (unsigned int key = begin; key < end; ++key) {
346  trigger::TriggerObject const& candidate = summary.getObjects().at(key);
347  out << " "
348  << "object id: " << candidate.id() << ", "
349  << "pT: " << candidate.pt() << ", "
350  << "eta: " << candidate.eta() << ", "
351  << "phi: " << candidate.phi() << ", "
352  << "mass: " << candidate.mass() << "\n";
353  }
354 }
int id() const
getters
Definition: TriggerObject.h:51
float phi() const
Definition: TriggerObject.h:54
float eta() const
Definition: TriggerObject.h:53
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
tuple key
prepare the HTCondor submission files and eventually submit them
string end
Definition: dataset.py:937
float mass() const
Definition: TriggerObject.h:55
std::string strip_process_name ( std::string const &  s)

Definition at line 272 of file hltDiff.cc.

References submitPVResolutionJobs::count, dataset::end, and alignCSCRings::s.

Referenced by HltDiff::compare().

272  {
273  if (std::count(s.begin(), s.end(), ':') == 2) {
274  // remove the process name and the second ':' separator
275  size_t end = s.find_last_of(':');
276  if (end > 0 and s.at(end - 1) == ':')
277  // no instance name, remove also the first ':' separator
278  --end;
279  return s.substr(0, end);
280  } else {
281  // no process name, return the string unchanged
282  return s;
283  }
284 }
string end
Definition: dataset.py:937