test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <cstring>
#include <unistd.h>
#include <getopt.h>
#include <math.h>
#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 286 of file hltDiff.cc.

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

Function Documentation

bool check_file ( std::string const &  file)

Definition at line 1161 of file hltDiff.cc.

References f.

Referenced by check_files().

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

Definition at line 1167 of file hltDiff.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, check_file(), and mergeVDriftHistosByStation::file.

Referenced by HltDiff::compare().

1167  {
1168  bool flag = true;
1169  for (auto const & file: files)
1170  if (not check_file(file)) {
1171  flag = false;
1172  std::cerr << "hltDiff: error: file " << file << " does not exist, or is not a regular file." << std::endl;
1173  }
1174  return flag;
1175 }
bool check_file(std::string const &file)
Definition: hltDiff.cc:1161
void error ( std::ostream &  out)

Definition at line 44 of file hltDiff.cc.

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

Definition at line 48 of file hltDiff.cc.

References relativeConstraints::error.

48  {
49  out << message << std::endl;
50  error(out);
51 }
void error ( std::ostream &  out,
const std::string &  message 
)

Definition at line 53 of file hltDiff.cc.

References relativeConstraints::error.

53  {
54  out << message << std::endl;
55  error(out);
56 }
const char* event_state ( bool  state)

Definition at line 134 of file hltDiff.cc.

Referenced by HltDiff::compare().

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

Definition at line 410 of file hltDiff.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, mps_alisetup::config, cmsRelvalreport::exit, edm::pset::Registry::getMapped(), getProcessNameFromBranch(), edm::pset::Registry::instance(), edm::ProcessConfiguration::parameterSetID(), and TrackValidation_cff::pset.

Referenced by HltDiff::compare().

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

Definition at line 404 of file hltDiff.cc.

References split.

Referenced by getHLTConfigData().

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

Definition at line 1523 of file hltDiff.cc.

References EnergyCorrector::c, ecal_dqm_sourceclient-live_cfg::cerr, HltDiff::compare(), HltDiff::debug, relativeConstraints::error, cmsRelvalreport::exit, HltDiff::file_check, runregparse::hlt, HltDiff::ignore_prescales, HltDiff::json_out, bookConverter::max, HltDiff::max_events, HltDiff::new_files, HltDiff::new_process, NULL, HltDiff::old_files, HltDiff::old_process, HltDiff::output_file, HltDiff::root_out, HltDiff::usage(), and HltDiff::verbose.

1523  {
1524  // options
1525  const char optstring[] = "dfo:O:n:N:m:pjrF:v::h";
1526  const option longopts[] = {
1527  option{ "debug", no_argument, nullptr, 'd' },
1528  option{ "file-check", no_argument, nullptr, 'f' },
1529  option{ "old-files", required_argument, nullptr, 'o' },
1530  option{ "old-process", required_argument, nullptr, 'O' },
1531  option{ "new-files", required_argument, nullptr, 'n' },
1532  option{ "new-process", required_argument, nullptr, 'N' },
1533  option{ "max-events", required_argument, nullptr, 'm' },
1534  option{ "prescales", no_argument, nullptr, 'p' },
1535  option{ "json-output", optional_argument, nullptr, 'j' },
1536  option{ "root-output", optional_argument, nullptr, 'r' },
1537  option{ "output-file", optional_argument, nullptr, 'F' },
1538  option{ "verbose", optional_argument, nullptr, 'v' },
1539  option{ "help", no_argument, nullptr, 'h' },
1540  };
1541 
1542  // Creating an HltDiff object with the default configuration
1543  HltDiff* hlt = new HltDiff();
1544 
1545  // parse the command line options
1546  int c = -1;
1547  while ((c = getopt_long(argc, argv, optstring, longopts, nullptr)) != -1) {
1548  switch (c) {
1549  case 'd':
1550  hlt->debug = true;
1551  break;
1552 
1553  case 'f':
1554  hlt->file_check = true;
1555  break;
1556 
1557  case 'o':
1558  hlt->old_files.emplace_back(optarg);
1559  while (optind < argc) {
1560  if (argv[optind][0] == '-')
1561  break;
1562  hlt->old_files.emplace_back(argv[optind]);
1563  ++optind;
1564  }
1565  break;
1566 
1567  case 'O':
1568  hlt->old_process = optarg;
1569  break;
1570 
1571  case 'n':
1572  hlt->new_files.emplace_back(optarg);
1573  while (optind < argc) {
1574  if (argv[optind][0] == '-')
1575  break;
1576  hlt->new_files.emplace_back(argv[optind]);
1577  ++optind;
1578  }
1579  break;
1580 
1581  case 'N':
1582  hlt->new_process = optarg;
1583  break;
1584 
1585  case 'm':
1586  hlt->max_events = atoi(optarg);
1587  break;
1588 
1589  case 'p':
1590  hlt->ignore_prescales = false;
1591  break;
1592 
1593  case 'j':
1594  hlt->json_out = true;
1595  break;
1596 
1597  case 'r':
1598  hlt->root_out = true;
1599  break;
1600 
1601  case 'F':
1602  hlt->output_file = optarg;
1603  break;
1604 
1605  case 'v':
1606  hlt->verbose = 1;
1607  if (optarg) {
1608  hlt->verbose = std::max(1, atoi(optarg));
1609  } else if (!optarg && NULL != argv[optind] && '-' != argv[optind][0]) {
1610  // workaround for a bug in getopt which doesn't allow space before optional arguments
1611  const char *tmp_optarg = argv[optind++];
1612  hlt->verbose = std::max(1, atoi(tmp_optarg));
1613  }
1614  break;
1615 
1616  case 'h':
1617  hlt->usage(std::cerr);
1618  exit(0);
1619  break;
1620 
1621  default:
1622  error(std::cerr);
1623  exit(1);
1624  break;
1625  }
1626  }
1627 
1628  if (hlt->old_files.empty()) {
1629  error(std::cerr, "hltDiff: please specify the 'old' file(s)");
1630  exit(1);
1631  }
1632  if (hlt->new_files.empty()) {
1633  error(std::cerr, "hltDiff: please specify the 'new' file(s)");
1634  exit(1);
1635  }
1636 
1637  hlt->compare();
1638 
1639  return 0;
1640 }
bool debug
Definition: hltDiff.cc:1191
bool root_out
Definition: hltDiff.cc:1188
bool file_check
Definition: hltDiff.cc:1190
unsigned int verbose
Definition: hltDiff.cc:1192
#define NULL
Definition: scimark2.h:8
std::vector< std::string > old_files
Definition: hltDiff.cc:1181
std::string output_file
Definition: hltDiff.cc:1189
std::vector< std::string > new_files
Definition: hltDiff.cc:1183
bool ignore_prescales
Definition: hltDiff.cc:1186
bool json_out
Definition: hltDiff.cc:1187
void compare() const
Definition: hltDiff.cc:1208
tuple argc
Definition: dir2webdir.py:38
unsigned int max_events
Definition: hltDiff.cc:1185
std::string new_process
Definition: hltDiff.cc:1184
std::string old_process
Definition: hltDiff.cc:1182
void usage(std::ostream &out) const
Definition: hltDiff.cc:1462
std::ostream& operator<< ( std::ostream &  out,
TriggerDiff  diff 
)

Definition at line 460 of file hltDiff.cc.

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

460  {
461  out << std::setw(12) << diff.count
462  << std::setw(12) << TriggerDiff::format(diff.gained, '+')
463  << std::setw(12) << TriggerDiff::format(diff.lost, '-')
464  << std::setw(12) << TriggerDiff::format(diff.internal, '~');
465  return out;
466 }
unsigned int count
Definition: hltDiff.cc:435
unsigned int internal
Definition: hltDiff.cc:438
unsigned int lost
Definition: hltDiff.cc:437
static std::string format(unsigned int value, char sign= '+')
Definition: hltDiff.cc:441
unsigned int gained
Definition: hltDiff.cc:436
const char* path_state ( State  state)

Definition at line 295 of file hltDiff.cc.

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

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

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

Definition at line 305 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 333 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 344 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

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

Referenced by HltDiff::compare().

374  {
375  auto iterator = std::find(summary.collectionTags().begin(), summary.collectionTags().end(), tag);
376  if (iterator == summary.collectionTags().end()) {
377  // the collection of trigger candidates could not be found
378  out << " not found\n";
379  return;
380  }
381 
382  unsigned int index = iterator - summary.collectionTags().begin();
383  unsigned int begin = (index == 0) ? 0 : summary.collectionKey(index - 1);
384  unsigned int end = summary.collectionKey(index);
385 
386  if (end == begin) {
387  // the collection of trigger candidates is empty
388  out << " none\n";
389  return;
390  }
391 
392  for (unsigned int key = begin; key < end; ++key) {
393  trigger::TriggerObject const & candidate = summary.getObjects().at(key);
394  out << " "
395  << "object id: " << candidate.id() << ", "
396  << "pT: " << candidate.pt() << ", "
397  << "eta: " << candidate.eta() << ", "
398  << "phi: " << candidate.phi() << ", "
399  << "mass: " << candidate.mass() << "\n";
400  }
401 }
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
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#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 318 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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