CMS 3D CMS Logo

Classes | Enumerations | Functions
hltDiff.cc File Reference
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <iomanip>
#include <memory>
#include <algorithm>
#include <cstring>
#include <unistd.h>
#include <getopt.h>
#include <cstdio>
#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 {
  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
Ready 
Pass 
Fail 
Exception 
Prescaled 
Invalid 

Definition at line 287 of file hltDiff.cc.

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

Function Documentation

bool check_file ( std::string const &  file)

Definition at line 1209 of file hltDiff.cc.

References f.

Referenced by check_files().

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

Definition at line 1215 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

1215  {
1216  bool flag = true;
1217  for (auto const & file: files)
1218  if (not check_file(file)) {
1219  flag = false;
1220  std::cerr << "hltDiff: error: file " << file << " does not exist, or is not a regular file." << std::endl;
1221  }
1222  return flag;
1223 }
bool check_file(std::string const &file)
Definition: hltDiff.cc:1209
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 135 of file hltDiff.cc.

Referenced by HltDiff::compare().

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

Definition at line 411 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 405 of file hltDiff.cc.

References split.

Referenced by getHLTConfigData().

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

Definition at line 1595 of file hltDiff.cc.

References EnergyCorrector::c, MessageLogger_cfi::cerr, HltDiff::compare(), HltDiff::csv_out, HltDiff::debug, error(), cmsRelvalreport::exit, HltDiff::file_check, HltDiff::ignore_prescales, HltDiff::json_out, hpstanc_transforms::max, HltDiff::max_events, HltDiff::new_files, HltDiff::new_process, NULL, HltDiff::old_files, HltDiff::old_process, TSGForRoadSearch_cfi::option, HltDiff::output_file, HltDiff::quiet, HltDiff::root_out, HltDiff::usage(), and HltDiff::verbose.

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

Definition at line 465 of file hltDiff.cc.

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

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

Definition at line 296 of file hltDiff.cc.

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

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

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

Definition at line 306 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 334 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 345 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

345  {
346  // find the index of the collection of trigger candidates corresponding to the filter
347  unsigned int index = summary.filterIndex(filter);
348 
349  if (index >= summary.sizeFilters()) {
350  // the collection of trigger candidates corresponding to the filter could not be found
351  out << " not found\n";
352  return;
353  }
354 
355  if (summary.filterKeys(index).empty()) {
356  // the collection of trigger candidates corresponding to the filter is empty
357  out << " none\n";
358  return;
359  }
360 
361  for (unsigned int i = 0; i < summary.filterKeys(index).size(); ++i) {
362  auto key = summary.filterKeys(index)[i];
363  auto id = summary.filterIds(index)[i];
364  trigger::TriggerObject const & candidate = summary.getObjects().at(key);
365  out << " "
366  << "filter id: " << id << ", "
367  << "object id: " << candidate.id() << ", "
368  << "pT: " << candidate.pt() << ", "
369  << "eta: " << candidate.eta() << ", "
370  << "phi: " << candidate.phi() << ", "
371  << "mass: " << candidate.mass() << "\n";
372  }
373 }
int i
Definition: DBlmapReader.cc:9
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 375 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

375  {
376  auto iterator = std::find(summary.collectionTags().begin(), summary.collectionTags().end(), tag);
377  if (iterator == summary.collectionTags().end()) {
378  // the collection of trigger candidates could not be found
379  out << " not found\n";
380  return;
381  }
382 
383  unsigned int index = iterator - summary.collectionTags().begin();
384  unsigned int begin = (index == 0) ? 0 : summary.collectionKey(index - 1);
385  unsigned int end = summary.collectionKey(index);
386 
387  if (end == begin) {
388  // the collection of trigger candidates is empty
389  out << " none\n";
390  return;
391  }
392 
393  for (unsigned int key = begin; key < end; ++key) {
394  trigger::TriggerObject const & candidate = summary.getObjects().at(key);
395  out << " "
396  << "object id: " << candidate.id() << ", "
397  << "pT: " << candidate.pt() << ", "
398  << "eta: " << candidate.eta() << ", "
399  << "phi: " << candidate.phi() << ", "
400  << "mass: " << candidate.mass() << "\n";
401  }
402 }
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:7
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
float mass() const
Definition: TriggerObject.h:59
std::string strip_process_name ( std::string const &  s)

Definition at line 319 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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