Go to the documentation of this file.00001 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00002 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00005
00006 #include <cstring>
00007 #include <iostream>
00008
00010
00011
00012
00013
00014
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 using namespace edm;
00053
00054
00055 namespace {
00056 class StandAloneScribe : public edm::service::AbstractMLscribe {
00057
00058 public:
00059 StandAloneScribe() {}
00060
00061
00062 virtual
00063 void runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand);
00064
00065 private:
00066 StandAloneScribe(const StandAloneScribe&);
00067
00068 const StandAloneScribe& operator=(const StandAloneScribe&);
00069
00070
00071
00072 };
00073
00074 void
00075 StandAloneScribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand) {
00076
00077 switch (opcode) {
00078 case edm::MessageLoggerQ::LOG_A_MESSAGE: {
00079 edm::ErrorObj * errorobj_p = static_cast<edm::ErrorObj *>(operand);
00080 if ( MessageLoggerQ::ignore
00081 (errorobj_p->xid().severity, errorobj_p->xid().id) ) {
00082 delete errorobj_p;
00083 break;
00084 }
00085 if (errorobj_p->is_verbatim()) {
00086 std::cerr<< errorobj_p->fullText() << std::endl;
00087 } else {
00088 std::cerr<< "%MSG" << errorobj_p->xid().severity.getSymbol()
00089 << " " << errorobj_p->xid().id << ": \n"
00090 << errorobj_p->fullText() << "\n"
00091 << "%MSG"
00092 << std::endl;
00093 }
00094 delete errorobj_p;
00095 break;
00096 }
00097 case edm::MessageLoggerQ::JOBREPORT:
00098 case edm::MessageLoggerQ::JOBMODE:
00099 case edm::MessageLoggerQ::GROUP_STATS:
00100 {
00101 std::string* string_p = static_cast<std::string*> (operand);
00102 delete string_p;
00103 break;
00104 }
00105 default:
00106 break;
00107 }
00108 }
00109
00110
00111 boost::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
00112 static boost::shared_ptr<StandAloneScribe>
00113 standAloneScribe_ptr( new StandAloneScribe );
00114 return standAloneScribe_ptr;
00115 }
00116
00117
00118 }
00119
00120 boost::shared_ptr<edm::service::AbstractMLscribe>
00121 MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
00122
00123
00124 MessageLoggerQ::MessageLoggerQ()
00125 { }
00126
00127
00128 MessageLoggerQ::~MessageLoggerQ()
00129 { }
00130
00131
00132 MessageLoggerQ *
00133 MessageLoggerQ::instance()
00134 {
00135 static MessageLoggerQ queue;
00136 return &queue;
00137 }
00138
00139 void
00140 MessageLoggerQ::setMLscribe_ptr
00141 (boost::shared_ptr<edm::service::AbstractMLscribe> m)
00142 {
00143 if (!m) {
00144 mlscribe_ptr = obtainStandAloneScribePtr();
00145 } else {
00146 mlscribe_ptr = m;
00147 }
00148 }
00149
00150 void
00151 MessageLoggerQ::simpleCommand(OpCode opcode, void * operand)
00152 {
00153 mlscribe_ptr->runCommand(opcode, operand);
00154 }
00155
00156 void
00157 MessageLoggerQ::handshakedCommand(
00158 OpCode opcode,
00159 void * operand,
00160 std::string const & commandMnemonic )
00161 {
00162 try {
00163 mlscribe_ptr->runCommand(opcode, operand);
00164 }
00165 catch(edm::Exception& ex)
00166 {
00167 ex << "\n The preceding exception was thrown in MessageLoggerScribe\n";
00168 ex << "and forwarded to the main thread from the Messages thread.";
00169 std::cerr << "exception from MessageLoggerQ::"
00170 << commandMnemonic << " - exception what() is \n"
00171 << ex.what();
00172
00173 throw ex;
00174 }
00175 }
00176
00177 void
00178 MessageLoggerQ::MLqEND()
00179 {
00180 simpleCommand (END_THREAD, (void *)0);
00181 }
00182
00183 void
00184 MessageLoggerQ::MLqSHT()
00185 {
00186 simpleCommand (SHUT_UP, (void *)0);
00187 }
00188
00189 void
00190 MessageLoggerQ::MLqLOG( ErrorObj * p )
00191 {
00192 simpleCommand (LOG_A_MESSAGE, static_cast<void *>(p));
00193 }
00194
00195
00196 void
00197 MessageLoggerQ::MLqCFG( ParameterSet * p )
00198 {
00199 handshakedCommand(CONFIGURE, p, "CFG" );
00200 }
00201
00202 void
00203 MessageLoggerQ::MLqEXT( service::NamedDestination* p )
00204 {
00205 simpleCommand (EXTERN_DEST, static_cast<void *>(p));
00206 }
00207
00208 void
00209 MessageLoggerQ::MLqSUM( )
00210 {
00211 simpleCommand (SUMMARIZE, 0);
00212 }
00213
00214 void
00215 MessageLoggerQ::MLqJOB( std::string * j )
00216 {
00217 simpleCommand (JOBREPORT, static_cast<void *>(j));
00218 }
00219
00220 void
00221 MessageLoggerQ::MLqMOD( std::string * jm )
00222 {
00223 simpleCommand (JOBMODE, static_cast<void *>(jm));
00224 }
00225
00226
00227 void
00228 MessageLoggerQ::MLqFLS( )
00229 {
00230
00231
00232
00233
00234 handshakedCommand(FLUSH_LOG_Q, 0, "FLS" );
00235 }
00236
00237 void
00238 MessageLoggerQ::MLqGRP( std::string * cat_p )
00239 {
00240 simpleCommand (GROUP_STATS, static_cast<void *>(cat_p));
00241 }
00242
00243 void
00244 MessageLoggerQ::MLqJRS( std::map<std::string, double> * sum_p )
00245 {
00246 handshakedCommand(FJR_SUMMARY, sum_p, "JRS" );
00247 }
00248
00249
00250 bool
00251 MessageLoggerQ::handshaked(MessageLoggerQ::OpCode const & op)
00252 {
00253 return ( (op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY) );
00254 }
00255
00256
00257 edm::ELseverityLevel MessageLoggerQ::threshold ("WARNING");
00258 std::set<std::string> MessageLoggerQ::squelchSet;
00259 void MessageLoggerQ::standAloneThreshold(std::string const & severity) {
00260 threshold = edm::ELseverityLevel(severity);
00261 }
00262 void MessageLoggerQ::squelch(std::string const & category) {
00263 squelchSet.insert(category);
00264 }
00265 bool MessageLoggerQ::ignore ( edm::ELseverityLevel const & severity,
00266 std::string const & category ) {
00267 if ( severity < threshold ) return true;
00268 if ( squelchSet.count(category) > 0 ) return true;
00269 return false;
00270 }