Go to the documentation of this file.00001
00002 #include "FWCore/Framework/interface/Actions.h"
00003 #include "FWCore/Utilities/interface/DebugMacros.h"
00004 #include "FWCore/Utilities/interface/Algorithms.h"
00005 #include "boost/lambda/lambda.hpp"
00006
00007 #include <vector>
00008 #include <iostream>
00009
00010 namespace edm {
00011 namespace actions {
00012 namespace {
00013 struct ActionNames {
00014 ActionNames():table_(LastCode + 1) {
00015 table_[IgnoreCompletely] = "IgnoreCompletely";
00016 table_[Rethrow] = "Rethrow";
00017 table_[SkipEvent] = "SkipEvent";
00018 table_[FailModule] = "FailModule";
00019 table_[FailPath] = "FailPath";
00020 }
00021
00022 typedef std::vector<char const*> Table;
00023 Table table_;
00024 };
00025 }
00026
00027 char const* actionName(ActionCodes code) {
00028 static ActionNames tab;
00029 return static_cast<unsigned int>(code) < tab.table_.size() ? tab.table_[code] : "UnknownAction";
00030 }
00031 }
00032
00033 ActionTable::ActionTable() : map_() {
00034 addDefaults();
00035 }
00036
00037 namespace {
00038 inline void install(actions::ActionCodes code,
00039 ActionTable::ActionMap& out,
00040 ParameterSet const& pset) {
00041 using boost::lambda::_1;
00042 using boost::lambda::var;
00043 typedef std::vector<std::string> vstring;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 ParameterSet defopts;
00056 ParameterSet const& opts = pset.getUntrackedParameterSet("options", defopts);
00057
00058 vstring v = opts.getUntrackedParameter(actionName(code),vstring());
00059 for_all(v, var(out)[_1] = code);
00060
00061 }
00062 }
00063
00064 ActionTable::ActionTable(ParameterSet const& pset) : map_() {
00065 addDefaults();
00066
00067 install(actions::SkipEvent, map_, pset);
00068 install(actions::Rethrow, map_, pset);
00069 install(actions::IgnoreCompletely, map_, pset);
00070 install(actions::FailModule, map_, pset);
00071 install(actions::FailPath, map_, pset);
00072 }
00073
00074 void ActionTable::addDefaults() {
00075 using namespace boost::lambda;
00076
00077
00078
00079 if(2 <= debugit()) {
00080 ActionMap::const_iterator ib(map_.begin()),ie(map_.end());
00081 for(;ib != ie; ++ib) {
00082 std::cerr << ib->first << ',' << ib->second << '\n';
00083 }
00084 std::cerr << std::endl;
00085 }
00086 }
00087
00088 ActionTable::~ActionTable() {
00089 }
00090
00091 void ActionTable::add(std::string const& category, actions::ActionCodes code) {
00092 map_[category] = code;
00093 }
00094
00095 actions::ActionCodes ActionTable::find(std::string const& category) const {
00096 ActionMap::const_iterator i(map_.find(category));
00097 return i != map_.end() ? i->second : actions::Rethrow;
00098 }
00099
00100 }