Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hltDiff: add protections against missing or empty input files #11640

Merged
merged 2 commits into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HLTrigger/Tools/bin/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<bin name="hltDiff" file="hltDiff.cc">
<use name="jemalloc"/>
<use name="boost"/>
<use name="boost_filesystem"/>
<use name="FWCore/Common"/>
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
Expand Down
55 changes: 49 additions & 6 deletions HLTrigger/Tools/bin/hltDiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <getopt.h>

#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>

#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/Utilities/interface/InputTag.h"
Expand Down Expand Up @@ -471,17 +472,55 @@ std::ostream & operator<<(std::ostream & out, TriggerDiff diff) {
}


bool check_file(std::string const & file) {
boost::filesystem::path p(file);

// check if the file exists
if (not boost::filesystem::exists(p))
return false;

// resolve the file name to canonical form
p = boost::filesystem::canonical(p);
if (not boost::filesystem::exists(p))
return false;

// check for a regular file
if (not boost::filesystem::is_regular_file(p))
return false;

return true;
}


bool check_files(std::vector<std::string> const & files) {
bool flag = true;
for (auto const & file: files)
if (not check_file(file)) {
flag = false;
std::cerr << "hltDiff: error: file " << file << " does not exist, or is not a regular file." << std::endl;
}
return flag;
}


void compare(std::vector<std::string> const & old_files, std::string const & old_process,
std::vector<std::string> const & new_files, std::string const & new_process,
unsigned int max_events, bool ignore_prescales, int verbose) {

std::shared_ptr<fwlite::ChainEvent> old_events = std::make_shared<fwlite::ChainEvent>(old_files);
std::shared_ptr<fwlite::ChainEvent> old_events;
std::shared_ptr<fwlite::ChainEvent> new_events;

if (check_files(old_files))
old_events = std::make_shared<fwlite::ChainEvent>(old_files);
else
return;

if (new_files.size() == 1 and new_files[0] == "-")
new_events = old_events;
else
else if (check_files(new_files))
new_events = std::make_shared<fwlite::ChainEvent>(new_files);
else
return;

std::unique_ptr<HLTConfigDataEx> old_config_data;
std::unique_ptr<HLTConfigDataEx> new_config_data;
Expand Down Expand Up @@ -629,10 +668,14 @@ void compare(std::vector<std::string> const & old_files, std::string const & old
break;
}

std::cout << "Found " << affected << " events out of " << counter << " with differences:\n" << std::endl;
std::cout << std::setw(12) << "Events" << std::setw(12) << "Accepted" << std::setw(12) << "Gained" << std::setw(12) << "Lost" << std::setw(12) << "Other" << " " << "Trigger" << std::endl;
for (unsigned int p = 0; p < old_config->size(); ++p)
std::cout << std::setw(12) << counter << differences[p] << " " << old_config->triggerName(p) << std::endl;
if (not counter) {
std::cout << "There are no common events between the old and new files." << std::endl;
} else {
std::cout << "Found " << affected << " events out of " << counter << " with differences:\n" << std::endl;
std::cout << std::setw(12) << "Events" << std::setw(12) << "Accepted" << std::setw(12) << "Gained" << std::setw(12) << "Lost" << std::setw(12) << "Other" << " " << "Trigger" << std::endl;
for (unsigned int p = 0; p < old_config->size(); ++p)
std::cout << std::setw(12) << counter << differences[p] << " " << old_config->triggerName(p) << std::endl;
}
}


Expand Down