CMS 3D CMS Logo

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 <boost/filesystem.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 288 of file hltDiff.cc.

288  {
293  Prescaled,
294  Invalid
295 };
not [yet] run
Definition: HLTenums.h:18
Definition: hltDiff.cc:290
reject
Definition: HLTenums.h:20
accept
Definition: HLTenums.h:19
Definition: hltDiff.cc:291

Function Documentation

bool check_file ( std::string const &  file)

Definition at line 1210 of file hltDiff.cc.

References f.

Referenced by check_files().

1210  {
1211  std::unique_ptr<TFile> f(TFile::Open(file.c_str()));
1212  return (f and not f->IsZombie());
1213 }
double f[11][100]
bool check_files ( std::vector< std::string > const &  files)

Definition at line 1216 of file hltDiff.cc.

References MessageLogger_cfi::cerr, check_file(), FrontierConditions_GlobalTag_cff::file, and RemoveAddSevLevel::flag.

Referenced by HltDiff::compare().

1216  {
1217  bool flag = true;
1218  for (auto const & file: files)
1219  if (not check_file(file)) {
1220  flag = false;
1221  std::cerr << "hltDiff: error: file " << file << " does not exist, or is not a regular file." << std::endl;
1222  }
1223  return flag;
1224 }
bool check_file(std::string const &file)
Definition: hltDiff.cc:1210
void error ( std::ostream &  out)

Definition at line 45 of file hltDiff.cc.

Referenced by error(), and main().

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

Definition at line 49 of file hltDiff.cc.

References error().

49  {
50  out << message << std::endl;
51  error(out);
52 }
void error(std::ostream &out)
Definition: hltDiff.cc:45
void error ( std::ostream &  out,
const std::string &  message 
)

Definition at line 54 of file hltDiff.cc.

References error().

54  {
55  out << message << std::endl;
56  error(out);
57 }
void error(std::ostream &out)
Definition: hltDiff.cc:45
const char* event_state ( bool  state)

Definition at line 136 of file hltDiff.cc.

Referenced by HltDiff::compare().

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

Definition at line 412 of file hltDiff.cc.

References MicroEventContent_cff::branch, MessageLogger_cfi::cerr, looper::config, cmsRelvalreport::exit, edm::pset::Registry::getMapped(), getProcessNameFromBranch(), edm::pset::Registry::instance(), edm::ProcessConfiguration::parameterSetID(), and muonDTDigis_cfi::pset.

Referenced by HltDiff::compare().

412  {
413  auto const & history = event.processHistory();
414  if (process.empty()) {
415  // determine the process name from the most recent "TriggerResults" object
416  auto const & branch = event.getBranchNameFor( edm::Wrapper<edm::TriggerResults>::typeInfo(), "TriggerResults", "", process.c_str() );
418  }
419 
421  if (not history.getConfigurationForProcess(process, config)) {
422  std::cerr << "error: the process " << process << " is not in the Process History" << std::endl;
423  exit(1);
424  }
426  if (pset == nullptr) {
427  std::cerr << "error: the configuration for the process " << process << " is not available in the Provenance" << std::endl;
428  exit(1);
429  }
430  return std::make_unique<HLTConfigDataEx>(HLTConfigData(pset));
431 }
config
Definition: looper.py:287
ParameterSetID const & parameterSetID() const
std::string getProcessNameFromBranch(std::string const &branch)
Definition: hltDiff.cc:406
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:19
static Registry * instance()
Definition: Registry.cc:13
std::string getProcessNameFromBranch ( std::string const &  branch)

Definition at line 406 of file hltDiff.cc.

References split.

Referenced by getHLTConfigData().

406  {
407  std::vector<boost::iterator_range<std::string::const_iterator>> tokens;
408  boost::split(tokens, branch, boost::is_any_of("_."), boost::token_compress_off);
409  return boost::copy_range<std::string>(tokens[3]);
410 }
double split
Definition: MVATrainer.cc:139
int main ( int  argc,
char **  argv 
)

Definition at line 1596 of file hltDiff.cc.

References EnergyCorrector::c, MessageLogger_cfi::cerr, error(), cmsRelvalreport::exit, ValidationMatrix::hlt, SiStripPI::max, and TSGForRoadSearch_cfi::option.

1596  {
1597  // options
1598  const char optstring[] = "dfo:O:n:N:m:pcjrF:v::hq";
1599  const option longopts[] = {
1600  option{ "debug", no_argument, nullptr, 'd' },
1601  option{ "file-check", no_argument, nullptr, 'f' },
1602  option{ "old-files", required_argument, nullptr, 'o' },
1603  option{ "old-process", required_argument, nullptr, 'O' },
1604  option{ "new-files", required_argument, nullptr, 'n' },
1605  option{ "new-process", required_argument, nullptr, 'N' },
1606  option{ "max-events", required_argument, nullptr, 'm' },
1607  option{ "prescales", no_argument, nullptr, 'p' },
1608  option{ "csv-output", optional_argument, nullptr, 'c' },
1609  option{ "json-output", optional_argument, nullptr, 'j' },
1610  option{ "root-output", optional_argument, nullptr, 'r' },
1611  option{ "output-file", optional_argument, nullptr, 'F' },
1612  option{ "verbose", optional_argument, nullptr, 'v' },
1613  option{ "help", no_argument, nullptr, 'h' },
1614  option{ "quiet", no_argument, nullptr, 'q' },
1615  };
1616 
1617  // Creating an HltDiff object with the default configuration
1618  auto hlt = new HltDiff();
1619 
1620  // parse the command line options
1621  int c = -1;
1622  while ((c = getopt_long(argc, argv, optstring, longopts, nullptr)) != -1) {
1623  switch (c) {
1624  case 'd':
1625  hlt->debug = true;
1626  break;
1627 
1628  case 'f':
1629  hlt->file_check = true;
1630  break;
1631 
1632  case 'o':
1633  hlt->old_files.emplace_back(optarg);
1634  while (optind < argc) {
1635  if (argv[optind][0] == '-')
1636  break;
1637  hlt->old_files.emplace_back(argv[optind]);
1638  ++optind;
1639  }
1640  break;
1641 
1642  case 'O':
1643  hlt->old_process = optarg;
1644  break;
1645 
1646  case 'n':
1647  hlt->new_files.emplace_back(optarg);
1648  while (optind < argc) {
1649  if (argv[optind][0] == '-')
1650  break;
1651  hlt->new_files.emplace_back(argv[optind]);
1652  ++optind;
1653  }
1654  break;
1655 
1656  case 'N':
1657  hlt->new_process = optarg;
1658  break;
1659 
1660  case 'm':
1661  hlt->max_events = atoi(optarg);
1662  break;
1663 
1664  case 'p':
1665  hlt->ignore_prescales = false;
1666  break;
1667 
1668  case 'c':
1669  hlt->csv_out = true;
1670  break;
1671 
1672  case 'j':
1673  hlt->json_out = true;
1674  break;
1675 
1676  case 'r':
1677  hlt->root_out = true;
1678  break;
1679 
1680  case 'F':
1681  hlt->output_file = optarg;
1682  break;
1683 
1684  case 'v':
1685  hlt->verbose = 1;
1686  if (optarg) {
1687  hlt->verbose = std::max(1, atoi(optarg));
1688  } else if (!optarg && nullptr != argv[optind] && '-' != argv[optind][0]) {
1689  // workaround for a bug in getopt which doesn't allow space before optional arguments
1690  const char *tmp_optarg = argv[optind++];
1691  hlt->verbose = std::max(1, atoi(tmp_optarg));
1692  }
1693  break;
1694 
1695  case 'h':
1696  hlt->usage(std::cerr);
1697  exit(0);
1698  break;
1699 
1700  case 'q':
1701  hlt->quiet = true;
1702  break;
1703 
1704  default:
1705  error(std::cerr);
1706  exit(1);
1707  break;
1708  }
1709  }
1710 
1711  if (hlt->old_files.empty()) {
1712  error(std::cerr, "hltDiff: please specify the 'old' file(s)");
1713  exit(1);
1714  }
1715  if (hlt->new_files.empty()) {
1716  error(std::cerr, "hltDiff: please specify the 'new' file(s)");
1717  exit(1);
1718  }
1719 
1720  hlt->compare();
1721 
1722  return 0;
1723 }
void error(std::ostream &out)
Definition: hltDiff.cc:45
std::ostream& operator<< ( std::ostream &  out,
TriggerDiff  diff 
)

Definition at line 466 of file hltDiff.cc.

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

466  {
467  out << std::setw(12) << diff.count
468  << std::setw(12) << TriggerDiff::format(diff.gained, '+')
469  << std::setw(12) << TriggerDiff::format(diff.lost, '-')
470  << std::setw(12) << TriggerDiff::format(diff.internal, '~');
471  return out;
472 }
unsigned int count
Definition: hltDiff.cc:437
unsigned int internal
Definition: hltDiff.cc:440
unsigned int lost
Definition: hltDiff.cc:439
static std::string format(unsigned int value, char sign= '+')
Definition: hltDiff.cc:443
unsigned int gained
Definition: hltDiff.cc:438
const char* path_state ( State  state)

Definition at line 297 of file hltDiff.cc.

References Invalid, and python.rootplot.argparse::message.

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

297  {
298  static const char * message[] = { "not run", "accepted", "rejected", "exception", "prescaled", "invalid" };
299 
300  if (state > 0 and state < Invalid)
301  return message[state];
302  else
303  return message[Invalid];
304 }
State prescaled_state ( int  state,
int  path,
int  module,
HLTConfigInterface const &  config 
)
inline

Definition at line 307 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

307  {
308  if (state == Fail and config.prescaler(path, module))
309  return Prescaled;
310  return (State) state;
311 }
Definition: config.py:1
Definition: hltDiff.cc:291
Definition: vlib.h:208
void print_detailed_path_state ( std::ostream &  out,
State  state,
int  path,
int  module,
HLTConfigInterface const &  config 
)

Definition at line 335 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

335  {
336  auto const & label = config.moduleLabel(path, module);
337  auto const & type = config.moduleType(path, module);
338 
339  out << "'" << path_state(state) << "'";
340  if (state == Fail)
341  out << " by module " << module << " '" << label << "' [" << type << "]";
342  else if (state == Exception)
343  out << " at module " << module << " '" << label << "' [" << type << "]";
344 }
type
Definition: HCALResponse.h:21
Definition: config.py:1
Definition: hltDiff.cc:291
const char * path_state(State state)
Definition: hltDiff.cc:297
Definition: vlib.h:208
void print_trigger_candidates ( std::ostream &  out,
trigger::TriggerEvent const &  summary,
edm::InputTag const &  filter 
)

Definition at line 346 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(), crabWrapper::key, trigger::TriggerObject::mass(), trigger::TriggerObject::phi(), trigger::TriggerObject::pt(), and trigger::TriggerEvent::sizeFilters().

Referenced by HltDiff::compare().

346  {
347  // find the index of the collection of trigger candidates corresponding to the filter
348  unsigned int index = summary.filterIndex(filter);
349 
350  if (index >= summary.sizeFilters()) {
351  // the collection of trigger candidates corresponding to the filter could not be found
352  out << " not found\n";
353  return;
354  }
355 
356  if (summary.filterKeys(index).empty()) {
357  // the collection of trigger candidates corresponding to the filter is empty
358  out << " none\n";
359  return;
360  }
361 
362  for (unsigned int i = 0; i < summary.filterKeys(index).size(); ++i) {
363  auto key = summary.filterKeys(index)[i];
364  auto id = summary.filterIds(index)[i];
365  trigger::TriggerObject const & candidate = summary.getObjects().at(key);
366  out << " "
367  << "filter id: " << id << ", "
368  << "object id: " << candidate.id() << ", "
369  << "pT: " << candidate.pt() << ", "
370  << "eta: " << candidate.eta() << ", "
371  << "phi: " << candidate.phi() << ", "
372  << "mass: " << candidate.mass() << "\n";
373  }
374 }
int id() const
getters
Definition: TriggerObject.h:55
float phi() const
Definition: TriggerObject.h:58
float eta() const
Definition: TriggerObject.h:57
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
float mass() const
Definition: TriggerObject.h:59
void print_trigger_collection ( std::ostream &  out,
trigger::TriggerEvent const &  summary,
std::string const &  tag 
)

Definition at line 376 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

376  {
377  auto iterator = std::find(summary.collectionTags().begin(), summary.collectionTags().end(), tag);
378  if (iterator == summary.collectionTags().end()) {
379  // the collection of trigger candidates could not be found
380  out << " not found\n";
381  return;
382  }
383 
384  unsigned int index = iterator - summary.collectionTags().begin();
385  unsigned int begin = (index == 0) ? 0 : summary.collectionKey(index - 1);
386  unsigned int end = summary.collectionKey(index);
387 
388  if (end == begin) {
389  // the collection of trigger candidates is empty
390  out << " none\n";
391  return;
392  }
393 
394  for (unsigned int key = begin; key < end; ++key) {
395  trigger::TriggerObject const & candidate = summary.getObjects().at(key);
396  out << " "
397  << "object id: " << candidate.id() << ", "
398  << "pT: " << candidate.pt() << ", "
399  << "eta: " << candidate.eta() << ", "
400  << "phi: " << candidate.phi() << ", "
401  << "mass: " << candidate.mass() << "\n";
402  }
403 }
int id() const
getters
Definition: TriggerObject.h:55
float phi() const
Definition: TriggerObject.h:58
float eta() const
Definition: TriggerObject.h:57
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
float mass() const
Definition: TriggerObject.h:59
std::string strip_process_name ( std::string const &  s)

Definition at line 320 of file hltDiff.cc.

References KineDebug3::count(), end, and alignCSCRings::s.

Referenced by HltDiff::compare().

320  {
321  if (std::count(s.begin(), s.end(), ':') == 2) {
322  // remove the process name and the second ':' separator
323  size_t end = s.find_last_of(':');
324  if (end > 0 and s.at(end-1) == ':')
325  // no instance name, remove also the first ':' separator
326  --end;
327  return s.substr(0, end);
328  } else {
329  // no process name, return the string unchanged
330  return s;
331  }
332 }
#define end
Definition: vmac.h:39