CMS 3D CMS Logo

MessageLogger.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Services
00004 // Class  :     MessageLogger
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  W. Brown, M. Fischler
00010 //         Created:  Fri Nov 11 16:42:39 CST 2005
00011 // $Id: MessageLogger.cc,v 1.27 2008/06/24 20:31:40 fischler Exp $
00012 //
00013 // Change log
00014 //
00015 // 1  mf  5/12/06       In ctor, MessageDrop::debugEnabled is set to a
00016 //                      sensible value in case action happens before modules
00017 //                      are entered.  If any modules enable debugs, such
00018 //                      LogDebug messages are not immediately discarded
00019 //                      (though they might be filtered at the server side).
00020 //
00021 // 2  mf  5/27/06       In preEventProcessing, change the syntax for 
00022 //                      runEvent from 1/23 to Run: 1 Event: 23
00023 //
00024 // 3 mf   6/27/06       PreModuleCOnstruction and PreSourceCOnstruction get
00025 //                      correct module name
00026 //
00027 // 4 mf   6/27/06       Between events the run/event is previous one
00028 //
00029 // 5  mf  3/30/07       Support for --jobreport option
00030 //
00031 // 6 mf   6/6/07        Remove the catches for forgiveness of tracked
00032 //                      parameters 
00033 //
00034 // 7 mf   6/19/07       Support for --jobreport option
00035 //
00036 // 8 wmtan 6/25/07      Enable suppression for sources, just as for modules
00037 //
00038 // 9 mf   7/25/07       Modify names of the MessageLoggerQ methods, eg MLqLOG
00039 //
00040 //10 mf   6/18/07       Insert into the PostEndJob a possible SummarizeInJobReport
00041 
00042 // system include files
00043 // user include files
00044 
00045 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00046 
00047 #include "FWCore/MessageService/interface/MessageLogger.h"
00048 
00049 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00050 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00051 
00052 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00053 
00054 #include "FWCore/MessageLogger/interface/JobReport.h"
00055 #include "FWCore/ServiceRegistry/interface/Service.h"
00056 
00057 #include <sstream>
00058 #include <string>
00059 #include <map>
00060 
00061 static const std::string kPostModule("PostModule");
00062 static const std::string kSource("main_input:source");
00063 
00064 using namespace edm;
00065 using namespace edm::service;
00066 
00067 namespace edm {
00068 namespace service {
00069 
00070 bool edm::service::MessageLogger::anyDebugEnabled_     = false;
00071 bool edm::service::MessageLogger::everyDebugEnabled_   = false;
00072 bool edm::service::MessageLogger::fjrSummaryRequested_ = false;
00073   
00074 //
00075 // constructors and destructor
00076 //
00077 edm::service::MessageLogger::
00078 MessageLogger( ParameterSet const & iPS
00079              , ActivityRegistry   & iRegistry
00080                             )
00081         : curr_module_("BeginningJob")
00082         , debugEnabled_(false)
00083 {
00084   // decide whether a summary should be placed in job report
00085   fjrSummaryRequested_ = 
00086         iPS.getUntrackedParameter<bool>("messageSummaryToJobReport", false);
00087 
00088   typedef std::vector<std::string>  vString;
00089    vString  empty_vString;
00090   
00091   // grab list of debug-enabled modules
00092   vString  debugModules;
00093   debugModules = 
00094         iPS.getUntrackedParameter<vString>("debugModules", empty_vString);
00095 
00096   // grab lists of suppressLEVEL modules
00097   vString suppressDebug;
00098   suppressDebug = 
00099         iPS.getUntrackedParameter<vString>("suppressDebug", empty_vString);
00100 
00101   vString suppressInfo;
00102   suppressInfo = 
00103         iPS.getUntrackedParameter<vString>("suppressInfo", empty_vString);
00104 
00105   vString suppressWarning;
00106   suppressWarning = 
00107         iPS.getUntrackedParameter<vString>("suppressWarning", empty_vString);
00108 
00109   // Use these lists to prepare a map to use in tracking suppression 
00110 
00111 // Do suppressDebug first and suppressWarning last to get proper order
00112   for( vString::const_iterator it  = suppressDebug.begin();
00113                                it != suppressDebug.end(); ++it ) {
00114     suppression_levels_[*it] = ELseverityLevel::ELsev_success;
00115   }
00116   
00117   for( vString::const_iterator it  = suppressInfo.begin();
00118                                it != suppressInfo.end(); ++it ) {
00119     suppression_levels_[*it] = ELseverityLevel::ELsev_info;
00120   }
00121   
00122   for( vString::const_iterator it  = suppressWarning.begin();
00123                                it != suppressWarning.end(); ++it ) {
00124     suppression_levels_[*it] = ELseverityLevel::ELsev_warning;
00125   }
00126   
00127   // set up for tracking whether current module is debug-enabled 
00128   // (and info-enabled and warning-enabled)
00129   if ( debugModules.empty()) {
00130     MessageDrop::instance()->debugEnabled = false;      // change log 2
00131   } else {
00132     anyDebugEnabled_ = true;
00133     MessageDrop::instance()->debugEnabled = true;
00134     // this will be over-ridden when specific modules are entered
00135   }
00136 
00137   if ( debugModules.empty()) anyDebugEnabled_ = true;
00138   for( vString::const_iterator it  = debugModules.begin();
00139                                it != debugModules.end(); ++it ) {
00140     if (*it == "*") { 
00141         everyDebugEnabled_ = true;
00142       } else {
00143         debugEnabledModules_.insert(*it); 
00144       }
00145   }
00146 
00147                                                                 // change log 5
00148   std::string jr_name = edm::MessageDrop::instance()->jobreport_name; 
00149   if (!jr_name.empty()) {                       
00150     std::string * jr_name_p = new std::string(jr_name);
00151     MessageLoggerQ::MLqJOB( jr_name_p );                        // change log 8
00152   }
00153   
00154                                                                 // change log 7
00155   std::string jm = edm::MessageDrop::instance()->jobMode; 
00156   std::string * jm_p = new std::string(jm);
00157   MessageLoggerQ::MLqMOD( jm_p );                               // change log 8
00158   
00159   MessageLoggerQ::MLqCFG( new ParameterSet(iPS) );              // change log 8
00160 
00161   iRegistry.watchPostBeginJob(this,&MessageLogger::postBeginJob);
00162   iRegistry.watchPostEndJob(this,&MessageLogger::postEndJob);
00163 
00164   iRegistry.watchPreModuleConstruction(this,&MessageLogger::preModuleConstruction);
00165   iRegistry.watchPostModuleConstruction(this,&MessageLogger::postModuleConstruction);
00166                                                                 // change log 3
00167 
00168   iRegistry.watchPreSourceConstruction(this,&MessageLogger::preSourceConstruction);
00169   iRegistry.watchPostSourceConstruction(this,&MessageLogger::postSourceConstruction);
00170                                                                 // change log 3
00171 
00172   iRegistry.watchPreProcessEvent(this,&MessageLogger::preEventProcessing);
00173   iRegistry.watchPostProcessEvent(this,&MessageLogger::postEventProcessing);
00174 
00175   iRegistry.watchPreModule(this,&MessageLogger::preModule);
00176   iRegistry.watchPostModule(this,&MessageLogger::postModule);
00177 
00178   iRegistry.watchPreSource(this,&MessageLogger::preSource);
00179   iRegistry.watchPostSource(this,&MessageLogger::postSource);
00180                                                                 // change log 3
00181 }
00182 
00183 // edm::service::
00184 // MessageLogger::MessageLogger(const MessageLogger& rhs)
00185 // {
00186 //    // do actual copying here;
00187 // }
00188 
00189 // edm::service::
00190 // MessageLogger::~MessageLogger()
00191 //{
00192 //}
00193 
00194 //
00195 // assignment operators
00196 //
00197 // const // edm::service::MessageLogger& MessageLogger::operator=(const MessageLogger& rhs)
00198 // {
00199 //   //An exception safe implementation is
00200 //   MessageLogger temp(rhs);
00201 //   swap(rhs);
00202 //
00203 //   return *this;
00204 // }
00205 
00206 //
00207 // member functions
00208 //
00209 
00210 void
00211 MessageLogger::postBeginJob()
00212 {
00213   MessageDrop::instance()->runEvent = "BeforeEvents";  
00214   MessageDrop::instance()->moduleName = "";  
00215 }
00216 
00217 void
00218 MessageLogger::postEndJob()
00219 {
00220   SummarizeInJobReport();     // Put summary info into Job Rep  // change log 10
00221   MessageLoggerQ::MLqSUM ( ); // trigger summary info.          // change log 8
00222 }
00223 
00224 void
00225 MessageLogger::preEventProcessing( const edm::EventID& iID
00226                                  , const edm::Timestamp& iTime
00227                                  )
00228 {
00229   std::ostringstream ost;
00230   curr_event_ = iID;
00231   ost << "Run: " << curr_event_.run() 
00232       << " Event: " << curr_event_.event();                     // change log 2
00233   edm::MessageDrop::instance()->runEvent = ost.str();  
00234 }
00235 void
00236 MessageLogger::postEventProcessing(const Event&, const EventSetup&)
00237 {
00238   // MessageDrop::instance()->runEvent = "BetweenEvents";       // change log 4
00239 }
00240 
00241 void
00242 MessageLogger::preSourceConstruction(const ModuleDescription& desc)
00243 {
00244   curr_module_ = desc.moduleName_;
00245   curr_module_ += ":";
00246   curr_module_ += desc.moduleLabel_;
00247   MessageDrop::instance()->moduleName = curr_module_ + "{*ctor*}";  
00248   if (!anyDebugEnabled_) {
00249     MessageDrop::instance()->debugEnabled = false;
00250   } else if (everyDebugEnabled_) {
00251     MessageDrop::instance()->debugEnabled = true;
00252   } else {
00253     MessageDrop::instance()->debugEnabled = 
00254                         debugEnabledModules_.count(desc.moduleLabel_);
00255   }
00256 }
00257 
00258 void
00259 MessageLogger::preSource()
00260 {
00261   MessageDrop* messageDrop = MessageDrop::instance();
00262   curr_module_ = kSource;
00263   //curr_module_ += ":";
00264   //curr_module_ += "source";
00265   messageDrop->moduleName = curr_module_;  
00266   if (!anyDebugEnabled_) {
00267     messageDrop->debugEnabled = false;
00268   } else if (everyDebugEnabled_) {
00269     messageDrop->debugEnabled = true;
00270   } else {
00271     messageDrop->debugEnabled = 
00272                 debugEnabledModules_.count("source");
00273   }
00274   std::map<const std::string,ELseverityLevel>::const_iterator it =
00275        suppression_levels_.find("source");
00276   if ( it != suppression_levels_.end() ) {
00277     messageDrop->debugEnabled  = messageDrop->debugEnabled
00278                                            && (it->second < ELseverityLevel::ELsev_success );
00279     messageDrop->infoEnabled    = (it->second < ELseverityLevel::ELsev_info );
00280     messageDrop->warningEnabled = (it->second < ELseverityLevel::ELsev_warning );
00281   } else {
00282     messageDrop->infoEnabled    = true;
00283     messageDrop->warningEnabled = true;
00284   }
00285 
00286 }
00287 
00288 
00289 void
00290 MessageLogger::preModuleConstruction(const ModuleDescription& desc)
00291 {
00292   // LogInfo("preModule") << "Module:" << desc.moduleLabel();
00293   curr_module_ = desc.moduleName_;
00294   curr_module_ += ":";
00295   curr_module_ += desc.moduleLabel_;
00296   
00297   MessageDrop::instance()->moduleName = curr_module_ + "{ctor}";  
00298   if (!anyDebugEnabled_) {
00299     MessageDrop::instance()->debugEnabled = false;
00300   } else if (everyDebugEnabled_) {
00301     MessageDrop::instance()->debugEnabled = true;
00302   } else {
00303     MessageDrop::instance()->debugEnabled = 
00304                         debugEnabledModules_.count(desc.moduleLabel_);
00305   }
00306 }
00307 
00308 void
00309 MessageLogger::preModule(const ModuleDescription& desc)
00310 {
00311   // LogInfo("preModule") << "Module:" << desc.moduleLabel();
00312   //cache the value to improve performance based on profiling studies
00313   MessageDrop* messageDrop = MessageDrop::instance();
00314   std::map<const ModuleDescription*,std::string>::const_iterator itFind = descToCalcName_.find(&desc);
00315   if ( itFind == descToCalcName_.end()) {
00316     curr_module_ = desc.moduleName_;
00317     curr_module_ += ":";
00318     curr_module_ += desc.moduleLabel_;
00319     //cache this value to improve performance based on profiling studies
00320     descToCalcName_[&desc]=curr_module_;
00321     messageDrop->moduleName = curr_module_;  
00322   } else {
00323     messageDrop->moduleName = itFind->second;
00324   }
00325 
00326   if (!anyDebugEnabled_) {
00327     messageDrop->debugEnabled = false;
00328   } else if (everyDebugEnabled_) {
00329     messageDrop->debugEnabled = true;
00330   } else {
00331     messageDrop->debugEnabled = 
00332                         debugEnabledModules_.count(desc.moduleLabel_);
00333   }
00334 
00335   std::map<const std::string,ELseverityLevel>::const_iterator it =
00336        suppression_levels_.find(desc.moduleLabel_);
00337   if ( it != suppression_levels_.end() ) {
00338     messageDrop->debugEnabled  = messageDrop->debugEnabled 
00339                                            && (it->second < ELseverityLevel::ELsev_success );
00340     messageDrop->infoEnabled    = (it->second < ELseverityLevel::ELsev_info );
00341     messageDrop->warningEnabled = (it->second < ELseverityLevel::ELsev_warning );
00342   } else {
00343     messageDrop->infoEnabled    = true;
00344     messageDrop->warningEnabled = true;
00345   }
00346 }
00347 
00348 void
00349 MessageLogger::postSourceConstruction(const ModuleDescription& iDescription)
00350 {
00351   // LogInfo("postModule") << "Module:" << iDescription.moduleLabel_
00352   //                      << " finished";
00353   curr_module_ = "AfterSourceConstruction";
00354   MessageDrop::instance()->moduleName = curr_module_;  
00355 }
00356 
00357 void
00358 MessageLogger::postModuleConstruction(const ModuleDescription& iDescription)
00359 {
00360   // LogInfo("postModule") << "Module:" << iDescription.moduleLabel_
00361   //                      << " finished";
00362   curr_module_ = "AfterModuleConstruction";
00363   MessageDrop::instance()->moduleName = curr_module_;  
00364 }
00365 
00366 void
00367 MessageLogger::postSource()
00368 {
00369   // LogInfo("postModule") << "Module:" << iDescription.moduleLabel_
00370   //                      << " finished";
00371   curr_module_ = "PostSource";
00372   MessageDrop::instance()->moduleName = curr_module_;  
00373 }
00374 
00375 void
00376 MessageLogger::postModule(const ModuleDescription& iDescription)
00377 {
00378   // LogInfo("postModule") << "Module:" << iDescription.moduleLabel_
00379   //                      << " finished";
00380   //curr_module_ = kPostModule;
00381   //MessageDrop::instance()->moduleName = curr_module_;  
00382   MessageDrop::instance()->moduleName = kPostModule;
00383 }
00384 
00385 void
00386 MessageLogger::SummarizeInJobReport() {
00387   if ( fjrSummaryRequested_ ) { 
00388     std::map<std::string, double> * smp = new std::map<std::string, double> ();
00389     MessageLoggerQ::MLqJRS ( smp );
00390     Service<JobReport> reportSvc;
00391     reportSvc->reportMessageInfo(*smp);
00392     delete smp;
00393   } 
00394 }
00395 
00396 } // end of namespace service  
00397 } // end of namespace edm  

Generated on Tue Jun 9 17:36:17 2009 for CMSSW by  doxygen 1.5.4