Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-03 01:06:15

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     char const* actionName(ActionCodes code) {
0012       static constexpr std::array<char const*, LastCode> tab = []() constexpr {
0013         std::array<char const*, LastCode> table{};
0014         table[IgnoreCompletely] = "IgnoreCompletely";
0015         table[Rethrow] = "Rethrow";
0016         table[SkipEvent] = "SkipEvent";
0017         table[FailPath] = "FailPath";
0018         return table;
0019       }
0020       ();
0021       return static_cast<unsigned int>(code) < tab.size() ? tab[code] : "UnknownAction";
0022     }
0023   }  // namespace exception_actions
0024 
0025   ExceptionToActionTable::ExceptionToActionTable() : map_() { addDefaults(); }
0026 
0027   namespace {
0028     inline void install(exception_actions::ActionCodes code,
0029                         ExceptionToActionTable::ActionMap& out,
0030                         ParameterSet const& pset) {
0031       typedef std::vector<std::string> vstring;
0032 
0033       // we cannot have parameters in the main process section so look
0034       // for an untracked (optional) ParameterSet called "options" for
0035       // now.  Notice that all exceptions (most actally) throw
0036       // edm::Exception with the configuration category.  This
0037       // category should probably be more specific or a derived
0038       // exception type should be used so the catch can be more
0039       // specific.
0040 
0041       //    cerr << pset.toString() << std::endl;
0042 
0043       ParameterSet const& opts = pset.getUntrackedParameterSet("options");
0044       //cerr << "looking for " << actionName(code) << std::endl;
0045       for (auto const& v : opts.getUntrackedParameter<std::vector<std::string>>(actionName(code))) {
0046         out[v] = code;
0047       }
0048     }
0049   }  // namespace
0050 
0051   ExceptionToActionTable::ExceptionToActionTable(ParameterSet const& pset) : map_() {
0052     addDefaults();
0053 
0054     install(exception_actions::SkipEvent, map_, pset);
0055     install(exception_actions::Rethrow, map_, pset);
0056     install(exception_actions::IgnoreCompletely, map_, pset);
0057     install(exception_actions::FailPath, map_, pset);
0058   }
0059 
0060   void ExceptionToActionTable::addDefaults() {
0061     // populate defaults that are not 'Rethrow'
0062     // (There are none as of CMSSW_3_4_X.)
0063     // 'Rethrow' is the default default.
0064     if (2 <= debugit()) {
0065       ActionMap::const_iterator ib(map_.begin()), ie(map_.end());
0066       for (; ib != ie; ++ib) {
0067         std::cerr << ib->first << ',' << ib->second << '\n';
0068       }
0069       std::cerr << std::endl;
0070     }
0071   }
0072 
0073   ExceptionToActionTable::~ExceptionToActionTable() {}
0074 
0075   void ExceptionToActionTable::add(std::string const& category, exception_actions::ActionCodes code) {
0076     map_[category] = code;
0077   }
0078 
0079   exception_actions::ActionCodes ExceptionToActionTable::find(std::string const& category) const {
0080     ActionMap::const_iterator i(map_.find(category));
0081     return i != map_.end() ? i->second : exception_actions::Rethrow;
0082   }
0083 
0084 }  // namespace edm