Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:11

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