File indexing completed on 2024-04-06 12:12:44
0001 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
0002 #include "FWCore/MessageLogger/interface/ErrorObj.h"
0003 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
0004 #include "FWCore/Utilities/interface/EDMException.h"
0005 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0006
0007 #include <cstring>
0008 #include <iostream>
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 using namespace edm;
0054
0055
0056 namespace {
0057 class StandAloneScribe : public edm::service::AbstractMLscribe {
0058 public:
0059 StandAloneScribe() {}
0060
0061 StandAloneScribe(const StandAloneScribe &) = delete;
0062
0063 const StandAloneScribe &operator=(const StandAloneScribe &) = delete;
0064
0065
0066
0067 void runCommand(edm::MessageLoggerQ::OpCode opcode, void *operand) override;
0068
0069 private:
0070
0071 };
0072
0073 void StandAloneScribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void *operand) {
0074
0075 switch (opcode) {
0076 case edm::MessageLoggerQ::LOG_A_MESSAGE: {
0077 edm::ErrorObj *errorobj_p = static_cast<edm::ErrorObj *>(operand);
0078 if (MessageLoggerQ::ignore
0079 (errorobj_p->xid().severity, errorobj_p->xid().id)) {
0080 delete errorobj_p;
0081 break;
0082 }
0083 if (errorobj_p->is_verbatim()) {
0084 std::cerr << errorobj_p->fullText() << std::endl;
0085 } else {
0086 std::cerr << "%MSG" << errorobj_p->xid().severity.getSymbol() << " " << errorobj_p->xid().id << ": \n"
0087 << errorobj_p->fullText() << "\n"
0088 << "%MSG" << std::endl;
0089 }
0090 delete errorobj_p;
0091 break;
0092 }
0093 case edm::MessageLoggerQ::JOBMODE:
0094 case edm::MessageLoggerQ::GROUP_STATS: {
0095 std::string *string_p = static_cast<std::string *>(operand);
0096 delete string_p;
0097 break;
0098 }
0099 default:
0100 break;
0101 }
0102 }
0103
0104
0105 std::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
0106 static auto standAloneScribe_ptr = std::make_shared<StandAloneScribe>();
0107 return standAloneScribe_ptr;
0108 }
0109
0110 }
0111
0112 std::shared_ptr<edm::service::AbstractMLscribe> MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
0113
0114
0115 MessageLoggerQ::MessageLoggerQ() {}
0116
0117 MessageLoggerQ::~MessageLoggerQ() {}
0118
0119 MessageLoggerQ *MessageLoggerQ::instance() {
0120 CMS_THREAD_SAFE static MessageLoggerQ queue;
0121 return &queue;
0122 }
0123
0124 void MessageLoggerQ::setMLscribe_ptr(std::shared_ptr<edm::service::AbstractMLscribe> m)
0125 {
0126 if (!m) {
0127 mlscribe_ptr = obtainStandAloneScribePtr();
0128 } else {
0129 mlscribe_ptr = m;
0130 }
0131 }
0132
0133 void MessageLoggerQ::simpleCommand(OpCode opcode, void *operand)
0134 {
0135 mlscribe_ptr->runCommand(opcode, operand);
0136 }
0137
0138 void MessageLoggerQ::handshakedCommand(OpCode opcode,
0139 void *operand,
0140 std::string const &commandMnemonic) {
0141 try {
0142 mlscribe_ptr->runCommand(opcode, operand);
0143 } catch (edm::Exception &ex) {
0144 ex << "\n The preceding exception was thrown in MessageLoggerScribe\n";
0145 ex << "and forwarded to the main thread from the Messages thread.";
0146 std::cerr << "exception from MessageLoggerQ::" << commandMnemonic << " - exception what() is \n" << ex.what();
0147
0148 throw ex;
0149 }
0150 }
0151
0152 void MessageLoggerQ::MLqEND() { simpleCommand(END_THREAD, (void *)nullptr); }
0153
0154 void MessageLoggerQ::MLqSHT() { simpleCommand(SHUT_UP, (void *)nullptr); }
0155
0156 void MessageLoggerQ::MLqLOG(ErrorObj *p) {
0157 simpleCommand(LOG_A_MESSAGE, static_cast<void *>(p));
0158 }
0159
0160 void MessageLoggerQ::MLqCFG(ParameterSet *p) { handshakedCommand(CONFIGURE, p, "CFG"); }
0161
0162 void MessageLoggerQ::MLqSUM() { simpleCommand(SUMMARIZE, nullptr); }
0163
0164 void MessageLoggerQ::MLqMOD(std::string *jm) {
0165 simpleCommand(JOBMODE, static_cast<void *>(jm));
0166 }
0167
0168 void MessageLoggerQ::MLqFLS()
0169 {
0170
0171
0172
0173
0174 handshakedCommand(FLUSH_LOG_Q, nullptr, "FLS");
0175 }
0176
0177 void MessageLoggerQ::MLqGRP(std::string *cat_p)
0178 {
0179 simpleCommand(GROUP_STATS, static_cast<void *>(cat_p));
0180 }
0181
0182 void MessageLoggerQ::MLqJRS(std::map<std::string, double> *sum_p) {
0183 handshakedCommand(FJR_SUMMARY, sum_p, "JRS");
0184 }
0185
0186 bool MessageLoggerQ::handshaked(MessageLoggerQ::OpCode const &op)
0187 {
0188 return ((op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY));
0189 }
0190
0191
0192 edm::messagelogger::ELseverityLevel MessageLoggerQ::threshold(edm::messagelogger::ELseverityLevel::ELsev_warning);
0193 std::set<std::string> MessageLoggerQ::squelchSet;
0194 void MessageLoggerQ::standAloneThreshold(edm::messagelogger::ELseverityLevel const &severity) { threshold = severity; }
0195 void MessageLoggerQ::squelch(std::string const &category) { squelchSet.insert(category); }
0196 bool MessageLoggerQ::ignore(edm::messagelogger::ELseverityLevel const &severity, std::string const &category) {
0197 if (severity < threshold)
0198 return true;
0199 if (squelchSet.count(category) > 0)
0200 return true;
0201 return false;
0202 }