File indexing completed on 2021-02-14 13:27:56
0001
0002 #include "FWCore/Framework/interface/ExceptionActions.h"
0003 #include "FWCore/Utilities/interface/DebugMacros.h"
0004 #include "FWCore/Utilities/interface/Algorithms.h"
0005
0006 #include <vector>
0007 #include <iostream>
0008
0009 namespace edm {
0010 namespace exception_actions {
0011 namespace {
0012 struct ActionNames {
0013 ActionNames() : table_(LastCode + 1) {
0014 table_[IgnoreCompletely] = "IgnoreCompletely";
0015 table_[Rethrow] = "Rethrow";
0016 table_[SkipEvent] = "SkipEvent";
0017 table_[FailPath] = "FailPath";
0018 }
0019
0020 typedef std::vector<char const*> Table;
0021 Table table_;
0022 };
0023 }
0024
0025 char const* actionName(ActionCodes code) {
0026 static ActionNames tab;
0027 return static_cast<unsigned int>(code) < tab.table_.size() ? tab.table_[code] : "UnknownAction";
0028 }
0029 }
0030
0031 ExceptionToActionTable::ExceptionToActionTable() : map_() { addDefaults(); }
0032
0033 namespace {
0034 inline void install(exception_actions::ActionCodes code,
0035 ExceptionToActionTable::ActionMap& out,
0036 ParameterSet const& pset) {
0037 typedef std::vector<std::string> vstring;
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 ParameterSet const& opts = pset.getUntrackedParameterSet("options");
0050
0051 for (auto const& v : opts.getUntrackedParameter<std::vector<std::string>>(actionName(code))) {
0052 out[v] = code;
0053 }
0054 }
0055 }
0056
0057 ExceptionToActionTable::ExceptionToActionTable(ParameterSet const& pset) : map_() {
0058 addDefaults();
0059
0060 install(exception_actions::SkipEvent, map_, pset);
0061 install(exception_actions::Rethrow, map_, pset);
0062 install(exception_actions::IgnoreCompletely, map_, pset);
0063 install(exception_actions::FailPath, map_, pset);
0064 }
0065
0066 void ExceptionToActionTable::addDefaults() {
0067
0068
0069
0070 if (2 <= debugit()) {
0071 ActionMap::const_iterator ib(map_.begin()), ie(map_.end());
0072 for (; ib != ie; ++ib) {
0073 std::cerr << ib->first << ',' << ib->second << '\n';
0074 }
0075 std::cerr << std::endl;
0076 }
0077 }
0078
0079 ExceptionToActionTable::~ExceptionToActionTable() {}
0080
0081 void ExceptionToActionTable::add(std::string const& category, exception_actions::ActionCodes code) {
0082 map_[category] = code;
0083 }
0084
0085 exception_actions::ActionCodes ExceptionToActionTable::find(std::string const& category) const {
0086 ActionMap::const_iterator i(map_.find(category));
0087 return i != map_.end() ? i->second : exception_actions::Rethrow;
0088 }
0089
0090 }