00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 #include "FWCore/MessageService/interface/MessageLoggerScribe.h"
00187 #include "FWCore/MessageService/interface/ELadministrator.h"
00188 #include "FWCore/MessageService/interface/ELoutput.h"
00189 #include "FWCore/MessageService/interface/ELstatistics.h"
00190 #include "FWCore/MessageService/interface/ELfwkJobReport.h"
00191 #include "FWCore/MessageService/interface/ErrorLog.h"
00192 #include "FWCore/MessageService/interface/NamedDestination.h"
00193 #include "FWCore/MessageService/interface/ThreadQueue.h"
00194
00195 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00196 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00197 #include "FWCore/MessageLogger/interface/ConfigurationHandshake.h"
00198 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00199 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00200
00201 #include "FWCore/Utilities/interface/EDMException.h"
00202 #include "FWCore/Utilities/interface/Algorithms.h"
00203
00204 #include <algorithm>
00205 #include <cassert>
00206 #include <fstream>
00207 #include <string>
00208 #include <signal.h>
00209
00210 using std::cerr;
00211
00212 namespace edm {
00213 namespace service {
00214
00215
00216 MessageLoggerScribe::MessageLoggerScribe(boost::shared_ptr<ThreadQueue> queue)
00217 : admin_p ( ELadministrator::instance() )
00218 , early_dest( admin_p->attach(ELoutput(std::cerr, false)) )
00219 , errorlog_p( new ErrorLog() )
00220 , file_ps ( )
00221 , job_pset_p( )
00222 , extern_dests( )
00223 , jobReportOption( )
00224 , clean_slate_configuration( true )
00225 , active( true )
00226 , singleThread (queue.get() == 0)
00227 , done (false)
00228 , purge_mode (false)
00229 , count (false)
00230 , m_queue(queue)
00231 {
00232 admin_p->setContextSupplier(msg_context);
00233 }
00234
00235 MessageLoggerScribe::~MessageLoggerScribe()
00236 {
00237 admin_p->finish();
00238 assert( extern_dests.empty() );
00239 }
00240
00241
00242 void
00243 MessageLoggerScribe::run()
00244 {
00245 MessageLoggerQ::OpCode opcode;
00246 void * operand;
00247
00248 MessageDrop::instance()->messageLoggerScribeIsRunning =
00249 MLSCRIBE_RUNNING_INDICATOR;
00250
00251
00252
00253
00254 do {
00255 m_queue->consume(opcode, operand);
00256
00257 runCommand (opcode, operand);
00258 } while(! done);
00259
00260 }
00261
00262 void
00263 MessageLoggerScribe::runCommand(
00264 MessageLoggerQ::OpCode opcode,
00265 void * operand)
00266 {
00267 switch(opcode) {
00268 default: {
00269 assert(false);
00270 break;
00271 }
00272 case MessageLoggerQ::END_THREAD: {
00273 assert( operand == 0 );
00274 done = true;
00275 MessageDrop::instance()->messageLoggerScribeIsRunning =
00276 (unsigned char) -1;
00277 break;
00278 }
00279 case MessageLoggerQ::LOG_A_MESSAGE: {
00280 ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
00281 try {
00282 if(active && !purge_mode) log (errorobj_p);
00283 }
00284 catch(cms::Exception& e)
00285 {
00286 ++count;
00287 std::cerr << "MessageLoggerScribe caught " << count
00288 << " cms::Exceptions, text = \n"
00289 << e.what() << "\n";
00290
00291 if(count > 25)
00292 {
00293 cerr << "MessageLogger will no longer be processing "
00294 << "messages due to errors (entering purge mode).\n";
00295 purge_mode = true;
00296 }
00297 }
00298 catch(...)
00299 {
00300 std::cerr << "MessageLoggerScribe caught an unknown exception and "
00301 << "will no longer be processing "
00302 << "messages. (entering purge mode)\n";
00303 purge_mode = true;
00304 }
00305 delete errorobj_p;
00306 break;
00307 }
00308 case MessageLoggerQ::CONFIGURE: {
00309 if (singleThread) {
00310 job_pset_p.reset(static_cast<ParameterSet *>(operand));
00311 configure_errorlog();
00312 break;
00313 } else {
00314 ConfigurationHandshake * h_p =
00315 static_cast<ConfigurationHandshake *>(operand);
00316 job_pset_p.reset(static_cast<ParameterSet *>(h_p->p));
00317 boost::mutex::scoped_lock sl(h_p->m);
00318 try {
00319 configure_errorlog();
00320 }
00321 catch(edm::Exception& e)
00322 {
00323 Place_for_passing_exception_ptr epp = h_p->epp;
00324 if (!(*epp)) {
00325 *epp = boost::shared_ptr<edm::Exception>(new edm::Exception(e));
00326 } else {
00327 Pointer_to_new_exception_on_heap ep = *epp;
00328 (*ep) << "\n and another exception: \n" << e.what();
00329 }
00330 }
00331
00332
00333
00334
00335
00336 h_p->c.notify_all();
00337
00338 break;
00339 }
00340 }
00341 case MessageLoggerQ::EXTERN_DEST: {
00342 try {
00343 extern_dests.push_back( static_cast<NamedDestination *>(operand) );
00344 configure_external_dests();
00345 }
00346 catch(cms::Exception& e)
00347 {
00348 std::cerr << "MessageLoggerScribe caught a cms::Exception "
00349 << "during extern dest configuration:\n"
00350 << e.what() << "\n"
00351 << "This is a serious problem, and the extern dest "
00352 << "will not be produced.\n"
00353 << "However, the rest of the logger continues to run.\n";
00354 }
00355 catch(...)
00356 {
00357 std::cerr << "MessageLoggerScribe caught unkonwn exception type\n"
00358 << "during extern dest configuration. "
00359 << "This is a serious problem, and the extern dest "
00360 << "will not be produced.\n"
00361 << "The rest of the logger will attempt to continue to run.\n";
00362 }
00363 break;
00364 }
00365 case MessageLoggerQ::SUMMARIZE: {
00366 assert( operand == 0 );
00367 try {
00368 triggerStatisticsSummaries();
00369 }
00370 catch(cms::Exception& e)
00371 {
00372 std::cerr << "MessageLoggerScribe caught exception "
00373 << "during summarize:\n"
00374 << e.what() << "\n";
00375 }
00376 catch(...)
00377 {
00378 std::cerr << "MessageLoggerScribe caught unkonwn exception type "
00379 << "during summarize. (Ignored)\n";
00380 }
00381 break;
00382 }
00383 case MessageLoggerQ::JOBREPORT: {
00384 std::string* jobReportOption_p =
00385 static_cast<std::string*>(operand);
00386 try {
00387 jobReportOption = *jobReportOption_p;
00388 }
00389 catch(cms::Exception& e)
00390 {
00391 std::cerr << "MessageLoggerScribe caught a cms::Exception "
00392 << "during processing of --jobReport option:\n"
00393 << e.what() << "\n"
00394 << "This likely will affect or prevent the job report.\n"
00395 << "However, the rest of the logger continues to run.\n";
00396 }
00397 catch(...)
00398 {
00399 std::cerr << "MessageLoggerScribe caught unkonwn exception type\n"
00400 << "during processing of --jobReport option.\n"
00401 << "This likely will affect or prevent the job report.\n"
00402 << "However, the rest of the logger continues to run.\n";
00403 }
00404 delete jobReportOption_p;
00405
00406
00407 break;
00408 }
00409 case MessageLoggerQ::JOBMODE: {
00410 std::string* jobMode_p =
00411 static_cast<std::string*>(operand);
00412 JobMode jm = MessageLoggerDefaults::mode(*jobMode_p);
00413 messageLoggerDefaults =
00414 value_ptr<MessageLoggerDefaults>(new MessageLoggerDefaults(jm));
00415
00416
00417 delete jobMode_p;
00418
00419
00420 break;
00421 }
00422 case MessageLoggerQ::SHUT_UP: {
00423 assert( operand == 0 );
00424 active = false;
00425 break;
00426 }
00427 case MessageLoggerQ::FLUSH_LOG_Q: {
00428 if (singleThread) return;
00429 ConfigurationHandshake * h_p =
00430 static_cast<ConfigurationHandshake *>(operand);
00431 job_pset_p.reset(static_cast<ParameterSet *>(h_p->p));
00432 boost::mutex::scoped_lock sl(h_p->m);
00433 h_p->c.notify_all();
00434
00435 break;
00436 }
00437 case MessageLoggerQ::GROUP_STATS: {
00438 std::string* cat_p =
00439 static_cast<std::string*>(operand);
00440 ELstatistics::noteGroupedCategory(*cat_p);
00441 delete cat_p;
00442 break;
00443 }
00444 case MessageLoggerQ::FJR_SUMMARY: {
00445 if (singleThread) {
00446 std::map<std::string, double> * smp =
00447 static_cast<std::map<std::string, double> *>(operand);
00448 triggerFJRmessageSummary(*smp);
00449 break;
00450 } else {
00451 ConfigurationHandshake * h_p =
00452 static_cast<ConfigurationHandshake *>(operand);
00453 boost::mutex::scoped_lock sl(h_p->m);
00454 std::map<std::string, double> * smp =
00455 static_cast<std::map<std::string, double> *>(h_p->p);
00456 triggerFJRmessageSummary(*smp);
00457 h_p->c.notify_all();
00458
00459 break;
00460 }
00461 }
00462 }
00463
00464 }
00465
00466 void MessageLoggerScribe::log ( ErrorObj * errorobj_p ) {
00467 ELcontextSupplier& cs =
00468 const_cast<ELcontextSupplier&>(admin_p->getContextSupplier());
00469 MsgContext& mc = dynamic_cast<MsgContext&>(cs);
00470 mc.setContext(errorobj_p->context());
00471 std::vector<std::string> categories;
00472 parseCategories(errorobj_p->xid().id, categories);
00473 for (unsigned int icat = 0; icat < categories.size(); ++icat) {
00474 errorobj_p->setID(categories[icat]);
00475 (*errorlog_p)( *errorobj_p );
00476 }
00477 }
00478
00479 void
00480 MessageLoggerScribe::configure_errorlog()
00481 {
00482 vString empty_vString;
00483 String empty_String;
00484 PSet empty_PSet;
00485
00486
00487 String preconfiguration_message
00488 = getAparameter<String>
00489 (*job_pset_p, "generate_preconfiguration_message", empty_String);
00490 if (preconfiguration_message != empty_String) {
00491
00492
00493
00494
00495 early_dest.suppressTime();
00496 LogError ("preconfiguration") << preconfiguration_message;
00497 if (!singleThread) {
00498 MessageLoggerQ::OpCode opcode;
00499 void * operand;
00500 m_queue->consume(opcode, operand);
00501 assert (opcode == MessageLoggerQ::LOG_A_MESSAGE);
00502 ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
00503 log (errorobj_p);
00504 delete errorobj_p;
00505 }
00506 }
00507
00508 if ( !stream_ps.empty() ) {
00509 LogWarning ("multiLogConfig")
00510 << "The message logger has been configured multiple times";
00511 clean_slate_configuration = false;
00512 }
00513 configure_fwkJobReports();
00514 configure_ordinary_destinations();
00515 configure_statistics();
00516
00517 configure_external_dests();
00518
00519 }
00520
00521
00522
00523
00524 void
00525 MessageLoggerScribe::configure_dest( ELdestControl & dest_ctrl
00526 , String const & filename
00527 )
00528 {
00529 static const int NO_VALUE_SET = -45654;
00530 vString empty_vString;
00531 PSet empty_PSet;
00532 String empty_String;
00533
00534
00535 const std::string COMMON_DEFAULT_THRESHOLD = "INFO";
00536 const int COMMON_DEFAULT_LIMIT = NO_VALUE_SET;
00537 const int COMMON_DEFAULT_INTERVAL = NO_VALUE_SET;
00538 const int COMMON_DEFAULT_TIMESPAN = NO_VALUE_SET;
00539
00540 char const* severity_array[] = {"WARNING", "INFO", "ERROR", "DEBUG"};
00541 vString const severities(severity_array+0, severity_array+4);
00542
00543
00544 vString categories
00545 = getAparameter<vString>(*job_pset_p, "categories", empty_vString);
00546
00547
00548
00549 {
00550 vString messageIDs
00551 = getAparameter<vString>(*job_pset_p, "messageIDs", empty_vString);
00552
00553
00554 copy_all( messageIDs, std::back_inserter(categories) );
00555 }
00556
00557
00558
00559 {
00560 std::vector<std::string> hardcats = messageLoggerDefaults->categories;
00561
00562 copy_all( hardcats, std::back_inserter(categories) );
00563 }
00564
00565
00566 String default_threshold
00567 = getAparameter<String>(*job_pset_p, "threshold", empty_String);
00568
00569
00570
00571
00572 PSet default_pset
00573 = getAparameter<PSet>(*job_pset_p, "default", empty_PSet);
00574 int default_limit
00575 = getAparameter<int>(default_pset, "limit", COMMON_DEFAULT_LIMIT);
00576 int default_interval
00577 = getAparameter<int>(default_pset, "reportEvery", COMMON_DEFAULT_INTERVAL);
00578
00579 int default_timespan
00580 = getAparameter<int>(default_pset, "timespan", COMMON_DEFAULT_TIMESPAN);
00581
00582
00583 String default_pset_threshold
00584 = getAparameter<String>(default_pset, "threshold", default_threshold);
00585
00586
00587
00588 PSet dest_pset = getAparameter<PSet>(*job_pset_p, filename, empty_PSet);
00589
00590
00591 bool is_placeholder
00592 = getAparameter<bool>(dest_pset, "placeholder", false);
00593 if (is_placeholder) return;
00594
00595
00596 PSet dest_default_pset
00597 = getAparameter<PSet>(dest_pset, "default", empty_PSet);
00598 int dest_default_limit
00599 = getAparameter<int>(dest_default_pset, "limit", default_limit);
00600 int dest_default_interval
00601 = getAparameter<int>(dest_default_pset, "reportEvery", default_interval);
00602
00603 int dest_default_timespan
00604 = getAparameter<int>(dest_default_pset, "timespan", default_timespan);
00605
00606 if ( dest_default_limit != NO_VALUE_SET ) {
00607 if ( dest_default_limit < 0 ) dest_default_limit = 2000000000;
00608 dest_ctrl.setLimit("*", dest_default_limit );
00609 }
00610 if ( dest_default_interval != NO_VALUE_SET ) {
00611 dest_ctrl.setInterval("*", dest_default_interval );
00612 }
00613 if ( dest_default_timespan != NO_VALUE_SET ) {
00614 if ( dest_default_timespan < 0 ) dest_default_timespan = 2000000000;
00615 dest_ctrl.setTimespan("*", dest_default_timespan );
00616 }
00617
00618
00619 String dest_threshold
00620 = getAparameter<String>(dest_pset, "threshold", default_threshold);
00621 if (dest_threshold == empty_String) {
00622 dest_threshold = default_threshold;
00623 }
00624 if (dest_threshold == empty_String) {
00625 dest_threshold = default_pset_threshold;
00626 }
00627 if (dest_threshold == empty_String) {
00628 dest_threshold = messageLoggerDefaults->threshold(filename);
00629 }
00630 if (dest_threshold == empty_String) dest_threshold = COMMON_DEFAULT_THRESHOLD;
00631 ELseverityLevel threshold_sev(dest_threshold);
00632 dest_ctrl.setThreshold(threshold_sev);
00633
00634 if (threshold_sev <= ELseverityLevel::ELsev_success)
00635 { edm::MessageDrop::debugAlwaysSuppressed = false; }
00636 if (threshold_sev <= ELseverityLevel::ELsev_info)
00637 { edm::MessageDrop::infoAlwaysSuppressed = false; }
00638 if (threshold_sev <= ELseverityLevel::ELsev_warning)
00639 { edm::MessageDrop::warningAlwaysSuppressed = false; }
00640
00641
00642 for( vString::const_iterator id_it = categories.begin()
00643 ; id_it != categories.end()
00644 ; ++id_it
00645 )
00646 {
00647 String msgID = *id_it;
00648 PSet default_category_pset
00649 = getAparameter<PSet>(default_pset, msgID, empty_PSet);
00650 PSet category_pset
00651 = getAparameter<PSet>(dest_pset, msgID, default_category_pset);
00652
00653 int category_default_limit
00654 = getAparameter<int>(default_category_pset, "limit", NO_VALUE_SET);
00655 int limit
00656 = getAparameter<int>(category_pset, "limit", category_default_limit);
00657 if (limit == NO_VALUE_SET) limit = dest_default_limit;
00658
00659 int category_default_interval
00660 = getAparameter<int>(default_category_pset, "reportEvery", NO_VALUE_SET);
00661 int interval
00662 = getAparameter<int>(category_pset, "reportEvery",category_default_interval);
00663 if (interval == NO_VALUE_SET) interval = dest_default_interval;
00664
00665 int category_default_timespan
00666 = getAparameter<int>(default_category_pset, "timespan", NO_VALUE_SET);
00667 int timespan
00668 = getAparameter<int>(category_pset, "timespan", category_default_timespan);
00669 if (timespan == NO_VALUE_SET) timespan = dest_default_timespan;
00670
00671
00672 std::string category = msgID;
00673 if ( limit == NO_VALUE_SET ) {
00674 limit = messageLoggerDefaults->limit(filename,category);
00675 }
00676 if ( interval == NO_VALUE_SET ) {
00677 interval = messageLoggerDefaults->reportEvery(filename,category);
00678 }
00679 if ( timespan == NO_VALUE_SET ) {
00680 timespan = messageLoggerDefaults->timespan(filename,category);
00681 }
00682
00683 if( limit != NO_VALUE_SET ) {
00684 if ( limit < 0 ) limit = 2000000000;
00685 dest_ctrl.setLimit(msgID, limit);
00686 }
00687 if( interval != NO_VALUE_SET ) {
00688 dest_ctrl.setInterval(msgID, interval);
00689 }
00690 if( timespan != NO_VALUE_SET ) {
00691 if ( timespan < 0 ) timespan = 2000000000;
00692 dest_ctrl.setTimespan(msgID, timespan);
00693 }
00694
00695 }
00696
00697
00698 for( vString::const_iterator sev_it = severities.begin()
00699 ; sev_it != severities.end()
00700 ; ++sev_it
00701 )
00702 {
00703 String sevID = *sev_it;
00704 ELseverityLevel severity(sevID);
00705 PSet default_sev_pset
00706 = getAparameter<PSet>(default_pset, sevID, empty_PSet);
00707 PSet sev_pset
00708 = getAparameter<PSet>(dest_pset, sevID, default_sev_pset);
00709
00710 int limit = getAparameter<int>(sev_pset, "limit", NO_VALUE_SET);
00711 if ( limit == NO_VALUE_SET ) {
00712 limit = messageLoggerDefaults->sev_limit(filename,sevID);
00713 }
00714 if( limit != NO_VALUE_SET ) {
00715 if (limit < 0) limit = 2000000000;
00716 dest_ctrl.setLimit(severity, limit );
00717 }
00718 int interval = getAparameter<int>(sev_pset, "reportEvery", NO_VALUE_SET);
00719 if ( interval == NO_VALUE_SET ) {
00720 interval = messageLoggerDefaults->sev_reportEvery(filename,sevID);
00721 }
00722 if( interval != NO_VALUE_SET ) dest_ctrl.setInterval(severity, interval);
00723
00724 int timespan = getAparameter<int>(sev_pset, "timespan", NO_VALUE_SET);
00725 if ( timespan == NO_VALUE_SET ) {
00726 timespan = messageLoggerDefaults->sev_timespan(filename,sevID);
00727 }
00728 if( timespan != NO_VALUE_SET ) {
00729 if (timespan < 0) timespan = 2000000000;
00730 dest_ctrl.setTimespan(severity, timespan );
00731 }
00732 }
00733
00734
00735 bool noLineBreaks_default
00736 = getAparameter<bool> (default_pset, "noLineBreaks", false);
00737
00738 bool noLineBreaks
00739 = getAparameter<bool> (dest_pset, "noLineBreaks", noLineBreaks_default);
00740 if (noLineBreaks) {
00741 dest_ctrl.setLineLength(32000);
00742 }
00743 else {
00744 int lenDef = 80;
00745 int lineLen_default
00746 = getAparameter<int> (default_pset, "lineLength", lenDef);
00747
00748 int lineLen = getAparameter<int> (dest_pset, "lineLength", lineLen_default);
00749 if (lineLen != lenDef) {
00750 dest_ctrl.setLineLength(lineLen);
00751 }
00752 }
00753
00754
00755 bool suppressTime_default
00756 = getAparameter<bool> (default_pset, "noTimeStamps", false);
00757 bool suppressTime
00758 = getAparameter<bool> (dest_pset, "noTimeStamps", suppressTime_default);
00759 if (suppressTime) {
00760 dest_ctrl.suppressTime();
00761 }
00762
00763 }
00764
00765 void
00766 MessageLoggerScribe::configure_default_fwkJobReport
00767 ( ELdestControl & dest_ctrl )
00768 {
00769
00770 dest_ctrl.setLimit("*", 0 );
00771 String msgID = "FwkJob";
00772 int FwkJob_limit = 10000000;
00773 dest_ctrl.setLimit(msgID, FwkJob_limit);
00774 dest_ctrl.setLineLength(32000);
00775 dest_ctrl.suppressTime();
00776
00777 }
00778
00779
00780 void
00781 MessageLoggerScribe::configure_fwkJobReports()
00782 {
00783 vString empty_vString;
00784 String empty_String;
00785 PSet empty_PSet;
00786
00787
00788 bool jobReportExists = false;
00789 bool enableJobReports = false;
00790 #ifdef DEFINE_THIS_TO_MAKE_REPORTS_THE_DEFAULT
00791 enableJobReports = true;
00792 #endif
00793 if (jobReportOption != empty_String) enableJobReports = true;
00794 if (jobReportOption == "~") enableJobReports = false;
00795 if (!enableJobReports) return;
00796
00797 if ((jobReportOption != "*") && (jobReportOption != empty_String)) {
00798 const std::string::size_type npos = std::string::npos;
00799 if ( jobReportOption.find('.') == npos ) {
00800 jobReportOption += ".xml";
00801 }
00802 }
00803
00804
00805 vString fwkJobReports
00806 = getAparameter<vString>(*job_pset_p, "fwkJobReports", empty_vString);
00807
00808
00809
00810 if (fwkJobReports.empty()) {
00811 fwkJobReports = messageLoggerDefaults->fwkJobReports;
00812 }
00813
00814
00815 for( vString::const_iterator it = fwkJobReports.begin()
00816 ; it != fwkJobReports.end()
00817 ; ++it
00818 )
00819 {
00820 String filename = *it;
00821 String psetname = filename;
00822
00823
00824 PSet fjr_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
00825 bool is_placeholder
00826 = getAparameter<bool>(fjr_pset, "placeholder", false);
00827 if (is_placeholder) continue;
00828
00829
00830
00831 String explicit_filename
00832 = getAparameter<String>(fjr_pset, "filename", empty_String);
00833 if (explicit_filename != empty_String) filename = explicit_filename;
00834 String explicit_extension
00835 = getAparameter<String>(fjr_pset, "extension", empty_String);
00836 if (explicit_extension != empty_String) {
00837 if (explicit_extension[0] == '.') {
00838 filename += explicit_extension;
00839 } else {
00840 filename = filename + "." + explicit_extension;
00841 }
00842 }
00843
00844
00845 std::string actual_filename = filename;
00846 const std::string::size_type npos = std::string::npos;
00847 if ( filename.find('.') == npos ) {
00848 actual_filename += ".xml";
00849 }
00850
00851
00852 if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
00853 if (clean_slate_configuration) {
00854 throw edm::Exception ( edm::errors::Configuration )
00855 <<"Duplicate name for a MessageLogger Framework Job Report Destination: "
00856 << actual_filename
00857 << "\n";
00858 } else {
00859 LogWarning("duplicateDestination")
00860 <<"Duplicate name for a MessageLogger Framework Job Report Destination: "
00861 << actual_filename
00862 << "\n" << "Only original configuration instructions are used";
00863 continue;
00864 }
00865 }
00866
00867 jobReportExists = true;
00868 if ( actual_filename == jobReportOption ) jobReportOption = empty_String;
00869
00870 boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
00871 file_ps.push_back(os_sp);
00872 ELdestControl dest_ctrl;
00873 dest_ctrl = admin_p->attach( ELfwkJobReport(*os_sp) );
00874 stream_ps[actual_filename] = os_sp.get();
00875
00876
00877 configure_dest(dest_ctrl, psetname);
00878
00879 }
00880
00881
00882 if (jobReportOption==empty_String) return;
00883 if (jobReportExists && ( jobReportOption=="*" )) return;
00884 if (jobReportOption=="*") jobReportOption = "FrameworkJobReport.xml";
00885
00886
00887 std::string actual_filename = jobReportOption;
00888 if ( stream_ps.find(actual_filename)!=stream_ps.end() ) return;
00889
00890 boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
00891 file_ps.push_back(os_sp);
00892 ELdestControl dest_ctrl;
00893 dest_ctrl = admin_p->attach( ELfwkJobReport(*os_sp) );
00894 stream_ps[actual_filename] = os_sp.get();
00895
00896
00897 configure_default_fwkJobReport (dest_ctrl);
00898
00899 }
00900
00901 void
00902 MessageLoggerScribe::configure_ordinary_destinations()
00903 {
00904 vString empty_vString;
00905 String empty_String;
00906 PSet empty_PSet;
00907
00908
00909 MessageDrop::debugAlwaysSuppressed=true;
00910 MessageDrop::infoAlwaysSuppressed=true;
00911 MessageDrop::warningAlwaysSuppressed=true;
00912
00913
00914 vString destinations
00915 = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
00916
00917
00918
00919 if (destinations.empty()) {
00920 destinations = messageLoggerDefaults->destinations;
00921 }
00922
00923
00924 if( ! destinations.empty() )
00925 early_dest.setThreshold(ELhighestSeverity);
00926
00927
00928 for( vString::const_iterator it = destinations.begin()
00929 ; it != destinations.end()
00930 ; ++it
00931 )
00932 {
00933 String filename = *it;
00934 String psetname = filename;
00935
00936
00937 PSet dest_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
00938 bool is_placeholder
00939 = getAparameter<bool>(dest_pset, "placeholder", false);
00940 if (is_placeholder) continue;
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954 String filename_default
00955 = getAparameter<String>(dest_pset, "output", empty_String);
00956 if ( filename_default == empty_String ) {
00957 filename_default = messageLoggerDefaults->output(psetname);
00958 if (filename_default == empty_String) {
00959 filename_default = filename;
00960 }
00961 }
00962
00963 String explicit_filename
00964 = getAparameter<String>(dest_pset, "filename", filename_default);
00965 if (explicit_filename != empty_String) filename = explicit_filename;
00966 String explicit_extension
00967 = getAparameter<String>(dest_pset, "extension", empty_String);
00968 if (explicit_extension != empty_String) {
00969 if (explicit_extension[0] == '.') {
00970 filename += explicit_extension;
00971 } else {
00972 filename = filename + "." + explicit_extension;
00973 }
00974 }
00975
00976
00977
00978
00979 std::string actual_filename = filename;
00980 if ( (filename != "cout") && (filename != "cerr") ) {
00981 const std::string::size_type npos = std::string::npos;
00982 if ( filename.find('.') == npos ) {
00983 actual_filename += ".log";
00984 }
00985 }
00986
00987
00988 if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
00989 if (clean_slate_configuration) {
00990
00991 LogError("duplicateDestination")
00992 <<"Duplicate name for a MessageLogger Destination: "
00993 << actual_filename
00994 << "\n" << "Only the first configuration instructions are used";
00995 continue;
00996 } else {
00997 LogWarning("duplicateDestination")
00998 <<"Duplicate name for a MessageLogger Destination: "
00999 << actual_filename
01000 << "\n" << "Only original configuration instructions are used";
01001 continue;
01002 }
01003 }
01004
01005 ordinary_destination_filenames.push_back(actual_filename);
01006
01007
01008 ELdestControl dest_ctrl;
01009 if( actual_filename == "cout" ) {
01010 dest_ctrl = admin_p->attach( ELoutput(std::cout) );
01011 stream_ps["cout"] = &std::cout;
01012 }
01013 else if( actual_filename == "cerr" ) {
01014 early_dest.setThreshold(ELzeroSeverity);
01015 dest_ctrl = early_dest;
01016 stream_ps["cerr"] = &std::cerr;
01017 }
01018 else {
01019 boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
01020 file_ps.push_back(os_sp);
01021 dest_ctrl = admin_p->attach( ELoutput(*os_sp) );
01022 stream_ps[actual_filename] = os_sp.get();
01023 }
01024
01025
01026
01027 configure_dest(dest_ctrl, psetname);
01028
01029 }
01030
01031 }
01032
01033
01034 void
01035 MessageLoggerScribe::configure_statistics()
01036 {
01037 vString empty_vString;
01038 String empty_String;
01039 PSet empty_PSet;
01040
01041
01042 vString statistics
01043 = getAparameter<vString>(*job_pset_p, "statistics", empty_vString);
01044
01045 bool no_statistics_configured = statistics.empty();
01046
01047 if ( no_statistics_configured ) {
01048
01049
01050
01051
01052 vString destinations
01053 = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
01054 if (destinations.empty()) {
01055 statistics = messageLoggerDefaults->statistics;
01056 no_statistics_configured = statistics.empty();
01057 }
01058 }
01059
01060
01061 for( vString::const_iterator it = statistics.begin()
01062 ; it != statistics.end()
01063 ; ++it
01064 )
01065 {
01066 String statname = *it;
01067 String psetname = statname;
01068
01069
01070 PSet stat_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
01071 bool is_placeholder
01072 = getAparameter<bool>(stat_pset, "placeholder", false);
01073 if (is_placeholder) continue;
01074
01075
01076 String filename
01077 = getAparameter<String>(stat_pset, "output", empty_String);
01078 if ( filename == empty_String ) {
01079 filename = messageLoggerDefaults->output(psetname);
01080 if (filename == empty_String) {
01081 filename = statname;
01082 }
01083 }
01084
01085
01086
01087
01088
01089 String explicit_filename
01090 = getAparameter<String>(stat_pset, "filename", filename);
01091 if (explicit_filename != empty_String) filename = explicit_filename;
01092 String explicit_extension
01093 = getAparameter<String>(stat_pset, "extension", empty_String);
01094 if (explicit_extension != empty_String) {
01095 if (explicit_extension[0] == '.') {
01096 filename += explicit_extension;
01097 } else {
01098 filename = filename + "." + explicit_extension;
01099 }
01100 }
01101
01102
01103
01104
01105 std::string actual_filename = filename;
01106 if ( (filename != "cout") && (filename != "cerr") ) {
01107 const std::string::size_type npos = std::string::npos;
01108 if ( filename.find('.') == npos ) {
01109 actual_filename += ".log";
01110 }
01111 }
01112
01113
01114
01115 if ( !search_all(ordinary_destination_filenames, actual_filename) ) {
01116 if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
01117 if (clean_slate_configuration) {
01118 throw edm::Exception ( edm::errors::Configuration )
01119 <<"Duplicate name for a MessageLogger Statistics Destination: "
01120 << actual_filename
01121 << "\n";
01122 } else {
01123 LogWarning("duplicateDestination")
01124 <<"Duplicate name for a MessageLogger Statistics Destination: "
01125 << actual_filename
01126 << "\n" << "Only original configuration instructions are used";
01127 continue;
01128 }
01129 }
01130 }
01131
01132
01133
01134
01135
01136
01137 bool statistics_destination_is_real = !no_statistics_configured;
01138 std::ostream* os_p;
01139 if ( stream_ps.find(actual_filename) == stream_ps.end() ) {
01140 if ( actual_filename == "cout" ) {
01141 os_p = &std::cout;
01142 } else if ( actual_filename == "cerr" ) {
01143 os_p = &std::cerr;
01144 } else {
01145 boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
01146 file_ps.push_back(os_sp);
01147 os_p = os_sp.get();
01148 }
01149 stream_ps[actual_filename] = os_p;
01150 } else {
01151 statistics_destination_is_real = true;
01152 os_p = stream_ps[actual_filename];
01153 }
01154
01155 if (statistics_destination_is_real) {
01156
01157 ELdestControl dest_ctrl;
01158 dest_ctrl = admin_p->attach( ELstatistics(*os_p) );
01159 statisticsDestControls.push_back(dest_ctrl);
01160 bool reset = getAparameter<bool>(stat_pset, "reset", false);
01161 statisticsResets.push_back(reset);
01162
01163
01164 configure_dest(dest_ctrl, psetname);
01165
01166
01167
01168 dest_ctrl.noTerminationSummary();
01169 }
01170
01171 }
01172
01173 }
01174
01175 void
01176 MessageLoggerScribe::configure_external_dests()
01177 {
01178 if( ! job_pset_p )
01179 {
01180
01181
01182 return;
01183 }
01184
01185 for( std::vector<NamedDestination*>::const_iterator it = extern_dests.begin()
01186 ; it != extern_dests.end()
01187 ; ++it
01188 )
01189 {
01190 ELdestination * dest_p = (*it)->dest_p().get();
01191 ELdestControl dest_ctrl = admin_p->attach( *dest_p );
01192
01193
01194 configure_dest( dest_ctrl, (*it)->name() );
01195 delete *it;
01196 }
01197 extern_dests.clear();
01198
01199 }
01200
01201 void
01202 MessageLoggerScribe::parseCategories (std::string const & s,
01203 std::vector<std::string> & cats)
01204 {
01205 const std::string::size_type npos = std::string::npos;
01206 std::string::size_type i = 0;
01207 while ( i != npos ) {
01208 std::string::size_type j = s.find('|',i);
01209 cats.push_back (s.substr(i,j-i));
01210 i = j;
01211 while ( (i != npos) && (s[i] == '|') ) ++i;
01212
01213 }
01214
01215
01216 }
01217
01218 void
01219 MessageLoggerScribe::triggerStatisticsSummaries() {
01220 assert (statisticsDestControls.size() == statisticsResets.size());
01221 for (unsigned int i = 0; i != statisticsDestControls.size(); ++i) {
01222 statisticsDestControls[i].summary( );
01223 if (statisticsResets[i]) statisticsDestControls[i].wipe( );
01224 }
01225 }
01226
01227 void
01228 MessageLoggerScribe::
01229 triggerFJRmessageSummary(std::map<std::string, double> & sm)
01230 {
01231 if (statisticsDestControls.empty()) {
01232 sm["NoStatisticsDestinationsConfigured"] = 0.0;
01233 } else {
01234 statisticsDestControls[0].summaryForJobReport(sm);
01235 }
01236 }
01237
01238 ErrorLog * MessageLoggerScribe::static_errorlog_p;
01239
01240
01241 }
01242 }
01243