CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FWCore/Framework/src/Actions.cc

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_[FailPath] = "FailPath";
00019         }
00020 
00021         typedef std::vector<char const*> Table;
00022         Table table_;
00023       };      
00024     }
00025 
00026     char const* actionName(ActionCodes code) {
00027       static ActionNames tab;
00028       return static_cast<unsigned int>(code) < tab.table_.size() ?  tab.table_[code] : "UnknownAction";
00029     }
00030   }
00031 
00032   ActionTable::ActionTable() : map_() {
00033     addDefaults();
00034   }
00035 
00036   namespace {
00037     inline void install(actions::ActionCodes code,
00038                         ActionTable::ActionMap& out,
00039                         ParameterSet const& pset) {
00040       using boost::lambda::_1;
00041       using boost::lambda::var;
00042       typedef std::vector<std::string> vstring;
00043 
00044       // we cannot have parameters in the main process section so look
00045       // for an untracked (optional) ParameterSet called "options" for
00046       // now.  Notice that all exceptions (most actally) throw
00047       // edm::Exception with the configuration category.  This
00048       // category should probably be more specific or a derived
00049       // exception type should be used so the catch can be more
00050       // specific.
00051 
00052 //      cerr << pset.toString() << std::endl;
00053 
00054       ParameterSet defopts;
00055       ParameterSet const& opts = pset.getUntrackedParameterSet("options", defopts);
00056       //cerr << "looking for " << actionName(code) << std::endl;
00057       vstring v = opts.getUntrackedParameter(actionName(code),vstring());
00058       for_all(v, var(out)[_1] = code);      
00059 
00060     }  
00061   }
00062 
00063   ActionTable::ActionTable(ParameterSet const& pset) : map_() {
00064     addDefaults();
00065 
00066     install(actions::SkipEvent, map_, pset);
00067     install(actions::Rethrow, map_, pset);
00068     install(actions::IgnoreCompletely, map_, pset);
00069     install(actions::FailPath, map_, pset);
00070   }
00071 
00072   void ActionTable::addDefaults() {
00073     using namespace boost::lambda;
00074     // populate defaults that are not 'Rethrow'
00075     // (There are none as of CMSSW_3_4_X.)
00076     // 'Rethrow' is the default default.
00077     if(2 <= debugit()) {
00078         ActionMap::const_iterator ib(map_.begin()),ie(map_.end());
00079         for(;ib != ie; ++ib) {
00080           std::cerr << ib->first << ',' << ib->second << '\n';
00081         }
00082         std::cerr << std::endl;
00083     }
00084   }
00085 
00086   ActionTable::~ActionTable() {
00087   }
00088 
00089   void ActionTable::add(std::string const& category, actions::ActionCodes code) {
00090     map_[category] = code;
00091   }
00092 
00093   actions::ActionCodes ActionTable::find(std::string const& category) const {
00094     ActionMap::const_iterator i(map_.find(category));
00095     return i != map_.end() ? i->second : actions::Rethrow;
00096   }
00097 
00098 }