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 <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

◆ State

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

Definition at line 241 of file hltDiff.cc.

241  {
246  Prescaled,
247  Invalid
248 };
not [yet] run
Definition: HLTenums.h:17
Definition: hltDiff.cc:243
reject
Definition: HLTenums.h:19
accept
Definition: HLTenums.h:18
Definition: hltDiff.cc:244

Function Documentation

◆ check_file()

bool check_file ( std::string const &  file)

Definition at line 1224 of file hltDiff.cc.

References f, and geometryDiff::file.

Referenced by check_files().

1224  {
1225  std::unique_ptr<TFile> f(TFile::Open(file.c_str()));
1226  return (f and not f->IsZombie());
1227 }
double f[11][100]

◆ check_files()

bool check_files ( std::vector< std::string > const &  files)

Definition at line 1229 of file hltDiff.cc.

References DMR_cfg::cerr, check_file(), geometryDiff::file, submitPVResolutionJobs::files, and RemoveAddSevLevel::flag.

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

◆ error() [1/3]

void error ( std::ostream &  out)

Definition at line 43 of file hltDiff.cc.

References MillePedeFileConverter_cfg::out.

Referenced by error(), and main().

43 { out << "Try 'hltDiff --help' for more information" << std::endl; }

◆ error() [2/3]

void error ( std::ostream &  out,
const char *  message 
)

Definition at line 45 of file hltDiff.cc.

References error(), and MillePedeFileConverter_cfg::out.

45  {
46  out << message << std::endl;
47  error(out);
48 }
void error(std::ostream &out)
Definition: hltDiff.cc:43

◆ error() [3/3]

void error ( std::ostream &  out,
const std::string &  message 
)

Definition at line 50 of file hltDiff.cc.

References error(), and MillePedeFileConverter_cfg::out.

50  {
51  out << message << std::endl;
52  error(out);
53 }
void error(std::ostream &out)
Definition: hltDiff.cc:43

◆ event_state()

const char* event_state ( bool  state)

Definition at line 113 of file hltDiff.cc.

Referenced by HltDiff::compare().

113 { return state ? "accepted" : "rejected"; }

◆ getHLTConfigData()

std::unique_ptr<HLTConfigDataEx> getHLTConfigData ( fwlite::EventBase const &  event,
std::string  process 
)

Definition at line 362 of file hltDiff.cc.

References MicroEventContent_cff::branch, DMR_cfg::cerr, DiMuonV_cfg::config, beamvalidation::exit(), edm::pset::Registry::getMapped(), getProcessNameFromBranch(), edm::pset::Registry::instance(), LaserDQM_cfg::process, and muonDTDigis_cfi::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 }
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
Definition: config.py:1
std::string getProcessNameFromBranch(std::string const &branch)
Definition: hltDiff.cc:356
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
static Registry * instance()
Definition: Registry.cc:12
def exit(msg="")

◆ getProcessNameFromBranch()

std::string getProcessNameFromBranch ( std::string const &  branch)

Definition at line 356 of file hltDiff.cc.

References MicroEventContent_cff::branch, and 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 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1628 of file hltDiff.cc.

References dir2webdir::argc, GCPpyPlots::argv, HltBtagPostValidation_cff::c, DMR_cfg::cerr, error(), beamvalidation::exit(), ValidationMatrix::hlt, SiStripPI::max, and fileinputsource_cfi::option.

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 }
void error(std::ostream &out)
Definition: hltDiff.cc:43
def exit(msg="")

◆ operator<<()

std::ostream& operator<< ( std::ostream &  out,
TriggerDiff  diff 
)

Definition at line 414 of file hltDiff.cc.

References change_name::diff, TriggerDiff::format(), and MillePedeFileConverter_cfg::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 }
static std::string format(unsigned int value, char sign='+')
Definition: hltDiff.cc:393

◆ path_state()

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 }

◆ prescaled_state()

State prescaled_state ( int  state,
int  path,
int  module,
HLTConfigInterface const &  config 
)
inline

Definition at line 259 of file hltDiff.cc.

References Fail, castor_dqm_sourceclient_file_cfg::path, and Prescaled.

Referenced by HltDiff::compare().

259  {
260  if (state == Fail and config.prescaler(path, module))
261  return Prescaled;
262  return (State)state;
263 }
Definition: config.py:1
Definition: hltDiff.cc:244

◆ print_detailed_path_state()

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, MillePedeFileConverter_cfg::out, castor_dqm_sourceclient_file_cfg::path, 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 }
Definition: config.py:1
char const * label
Definition: hltDiff.cc:244
const char * path_state(State state)
Definition: hltDiff.cc:250

◆ print_trigger_candidates()

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(), ALCARECOTkAlBeamHalo_cff::filter, mps_fire::i, trigger::TriggerObject::id(), submitPVResolutionJobs::key, trigger::TriggerObject::mass(), MillePedeFileConverter_cfg::out, trigger::TriggerObject::phi(), trigger::TriggerObject::pt(), and edmLumisInFiles::summary.

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 }
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
int id() const
getters
Definition: TriggerObject.h:51
key
prepare the HTCondor submission files and eventually submit them

◆ print_trigger_collection()

void print_trigger_collection ( std::ostream &  out,
trigger::TriggerEvent const &  summary,
std::string const &  tag 
)

Definition at line 327 of file hltDiff.cc.

References mps_fire::end, trigger::TriggerObject::eta(), spr::find(), trigger::TriggerObject::id(), submitPVResolutionJobs::key, trigger::TriggerObject::mass(), MillePedeFileConverter_cfg::out, trigger::TriggerObject::phi(), trigger::TriggerObject::pt(), edmLumisInFiles::summary, and makeGlobalPositionRcd_cfg::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 }
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
int id() const
getters
Definition: TriggerObject.h:51
key
prepare the HTCondor submission files and eventually submit them

◆ strip_process_name()

std::string strip_process_name ( std::string const &  s)

Definition at line 272 of file hltDiff.cc.

References submitPVResolutionJobs::count, mps_fire::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 }