$treeview $search $mathjax $extrastylesheet
artdaq_mfextensions
v1_03_03a
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "cetlib/PluginTypeDeducer.h" 00002 #include "cetlib/ProvideMakePluginMacros.h" 00003 #include "fhiclcpp/ParameterSet.h" 00004 00005 #include "cetlib/compiler_macros.h" 00006 #include "messagefacility/MessageService/ELdestination.h" 00007 #include "messagefacility/Utilities/ELseverityLevel.h" 00008 #include "messagefacility/Utilities/exception.h" 00009 00010 #define TRACE_NAME "MessageFacility" 00011 00012 #if GCC_VERSION >= 701000 || defined(__clang__) 00013 #pragma GCC diagnostic push 00014 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" 00015 #endif 00016 00017 #include "trace.h" 00018 00019 #if GCC_VERSION >= 701000 || defined(__clang__) 00020 #pragma GCC diagnostic pop 00021 #endif 00022 00023 namespace mfplugins { 00024 using mf::ELseverityLevel; 00025 using mf::ErrorObj; 00026 using mf::service::ELdestination; 00027 00031 class ELTRACE : public ELdestination { 00032 struct Config { 00033 fhicl::TableFragment<ELdestination::Config> elDestConfig; 00034 fhicl::Atom<size_t> lvls{fhicl::Name{"lvls"}, fhicl::Comment{"TRACE level mask for Slow output"}, 0}; 00035 fhicl::Atom<size_t> lvlm{fhicl::Name{"lvlm"}, fhicl::Comment{"TRACE level mask for Memory output"}, 0}; 00036 }; 00037 using Parameters = fhicl::WrappedTable<Config>; 00038 00039 public: 00044 ELTRACE(Parameters const& pset); 00045 00051 virtual void fillPrefix(std::ostringstream& o, const ErrorObj& e) override; 00052 00058 virtual void fillUsrMsg(std::ostringstream& o, const ErrorObj& e) override; 00059 00063 virtual void fillSuffix(std::ostringstream&, const ErrorObj&) override {} 00064 00070 virtual void routePayload(const std::ostringstream& o, const ErrorObj& e) override; 00071 }; 00072 00073 // END DECLARATION 00074 //====================================================================== 00075 // BEGIN IMPLEMENTATION 00076 00077 //====================================================================== 00078 // ELTRACE c'tor 00079 //====================================================================== 00080 ELTRACE::ELTRACE(Parameters const& pset) : ELdestination(pset().elDestConfig()) { 00081 size_t msk; 00082 00083 if (pset().lvls() != 0) { 00084 msk = pset().lvls(); 00085 TRACE_CNTL("lvlmskS", msk); // the S mask for TRACE_NAME 00086 } 00087 if (pset().lvlm() != 0) { 00088 msk = pset().lvlm(); 00089 TRACE_CNTL("lvlmskM", msk); // the M mask for TRACE_NAME 00090 } 00091 00092 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized."; 00093 } 00094 00095 //====================================================================== 00096 // Message prefix filler ( overriddes ELdestination::fillPrefix ) 00097 //====================================================================== 00098 void ELTRACE::fillPrefix(std::ostringstream& oss, const ErrorObj& msg) { 00099 const auto& xid = msg.xid(); 00100 00101 oss << xid.application() << ", "; // application 00102 oss << xid.id() << ": "; // category 00103 // oss << mf::MessageDrop::instance()->runEvent + ELstring(" "); // run/event no 00104 // oss << xid.module+ELstring(": "); // module name 00105 } 00106 00107 //====================================================================== 00108 // Message filler ( overriddes ELdestination::fillUsrMsg ) 00109 //====================================================================== 00110 void ELTRACE::fillUsrMsg(std::ostringstream& oss, const ErrorObj& msg) { 00111 std::ostringstream tmposs; 00112 ELdestination::fillUsrMsg(tmposs, msg); 00113 00114 // remove leading "\n" if present 00115 const std::string& usrMsg = !tmposs.str().compare(0, 1, "\n") ? tmposs.str().erase(0, 1) : tmposs.str(); 00116 00117 oss << usrMsg; 00118 } 00119 00120 //====================================================================== 00121 // Message router ( overriddes ELdestination::routePayload ) 00122 //====================================================================== 00123 void ELTRACE::routePayload(const std::ostringstream& oss, const ErrorObj& msg) { 00124 const auto& xid = msg.xid(); 00125 auto message = oss.str(); 00126 00127 auto level = xid.severity().getLevel(); 00128 auto lvlNum = 0; 00129 00130 switch (level) { 00131 case mf::ELseverityLevel::ELsev_success: 00132 case mf::ELseverityLevel::ELsev_zeroSeverity: 00133 case mf::ELseverityLevel::ELsev_unspecified: 00134 lvlNum = 3; 00135 break; 00136 00137 case mf::ELseverityLevel::ELsev_info: 00138 lvlNum = 2; 00139 break; 00140 00141 case mf::ELseverityLevel::ELsev_warning: 00142 lvlNum = 1; 00143 break; 00144 } 00145 TRACE(lvlNum, message); // this is the TRACE -- direct the message to memory and/or stdout 00146 } 00147 } // end namespace mfplugins 00148 00149 //====================================================================== 00150 // 00151 // makePlugin function 00152 // 00153 //====================================================================== 00154 00155 #ifndef EXTERN_C_FUNC_DECLARE_START 00156 #define EXTERN_C_FUNC_DECLARE_START extern "C" { 00157 #endif 00158 00159 EXTERN_C_FUNC_DECLARE_START 00160 auto makePlugin(const std::string&, const fhicl::ParameterSet& pset) { 00161 return std::make_unique<mfplugins::ELTRACE>(pset); 00162 } 00163 } 00164 00165 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)