Back to home page

Project CMSSW displayed by LXR

 
 

    


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     }  // namespace
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   }  // namespace exception_actions
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       // we cannot have parameters in the main process section so look
0040       // for an untracked (optional) ParameterSet called "options" for
0041       // now.  Notice that all exceptions (most actally) throw
0042       // edm::Exception with the configuration category.  This
0043       // category should probably be more specific or a derived
0044       // exception type should be used so the catch can be more
0045       // specific.
0046 
0047       //    cerr << pset.toString() << std::endl;
0048 
0049       ParameterSet const& opts = pset.getUntrackedParameterSet("options");
0050       //cerr << "looking for " << actionName(code) << std::endl;
0051       for (auto const& v : opts.getUntrackedParameter<std::vector<std::string>>(actionName(code))) {
0052         out[v] = code;
0053       }
0054     }
0055   }  // namespace
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     // populate defaults that are not 'Rethrow'
0068     // (There are none as of CMSSW_3_4_X.)
0069     // 'Rethrow' is the default default.
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 }  // namespace edm