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