diff --git a/HLTrigger/Tools/bin/BuildFile.xml b/HLTrigger/Tools/bin/BuildFile.xml index 342f6db9bf983..9fd426691f8d6 100644 --- a/HLTrigger/Tools/bin/BuildFile.xml +++ b/HLTrigger/Tools/bin/BuildFile.xml @@ -15,6 +15,7 @@ + diff --git a/HLTrigger/Tools/bin/hltDiff.cc b/HLTrigger/Tools/bin/hltDiff.cc index c3b39373e2f71..f6ec50efeaf54 100644 --- a/HLTrigger/Tools/bin/hltDiff.cc +++ b/HLTrigger/Tools/bin/hltDiff.cc @@ -16,6 +16,7 @@ #include #include +#include #include "FWCore/Common/interface/TriggerNames.h" #include "FWCore/Utilities/interface/InputTag.h" @@ -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 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 const & old_files, std::string const & old_process, std::vector const & new_files, std::string const & new_process, unsigned int max_events, bool ignore_prescales, int verbose) { - std::shared_ptr old_events = std::make_shared(old_files); + std::shared_ptr old_events; std::shared_ptr new_events; + if (check_files(old_files)) + old_events = std::make_shared(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(new_files); + else + return; std::unique_ptr old_config_data; std::unique_ptr new_config_data; @@ -629,10 +668,14 @@ void compare(std::vector 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; + } }