CMS 3D CMS Logo

MessageLoggerScribe.h

Go to the documentation of this file.
00001 #ifndef FWCore_MessageService_MessageLoggerScribe_h
00002 #define FWCore_MessageService_MessageLoggerScribe_h
00003 
00004 #include "FWCore/Utilities/interface/value_ptr.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006 
00007 #include "FWCore/MessageService/interface/ELdestControl.h"
00008 #include "FWCore/MessageService/interface/MsgContext.h"
00009 #include "FWCore/MessageService/interface/NamedDestination.h"
00010 #include "FWCore/MessageService/interface/MessageLoggerDefaults.h"
00011 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 
00014 #include <iosfwd>
00015 #include <vector>
00016 #include <map>
00017 
00018 #include <iostream>
00019 
00020 namespace edm {
00021 namespace service {       
00022 
00023 // ----------------------------------------------------------------------
00024 //
00025 // MessageLoggerScribe.h
00026 //
00027 // Changes:
00028 //
00029 //   1 - 2/6/07  mf     
00030 //      Set up ability to get a remembered pointer to the ErrorLog of an
00031 //      instance of MessageLoggerScribe, from a non-member function, via
00032 //      getErrorLog_ptr(), and a corresponding routine to remember the pointer
00033 //      as setStaticErrorLog_ptr().  Needed if we decide to send an explicit 
00034 //      message from the scribe.
00035 //
00036 //   2 - ?/?/? before 3/1/07 jm
00037 //       Modify parameter getting template so as not to catch tracked ones
00038 //       (that is, to crash if user mistakenly does not say untracked)
00039 //
00040 //   3 - 3/13/07 mf
00041 //       Added configure_ordinary_destinations, configure_fwkJobReports,
00042 //       and configure_statistics to allow these to be broken out of 
00043 //       configure_errorlog.    
00044 //
00045 //   4 - 3/26/07 mf
00046 //       Added configure_default_fwkJobReport, which implements the config
00047 //       originally placed in the .cfi file.
00048 //
00049 //   5 - 6/15/07 mf
00050 //       Accommodations for use of MessageLoggerDefault structure 
00051 //
00052 //   6 - 7/24/07 mf
00053 //       Instace variable indicating that we really are logging what is sent.
00054 //       This is to be able to supress the <generator> info sent at exit by
00055 //       the JobReport, in the case where no .cfg file was given.
00056 //
00057 //   7 - 4/8/08 mf
00058 //       Modified getAparameter behavior when tracked parameter is found,
00059 //       for nicer output message. 
00060 //
00061 //   8 - 6/19/08 mf
00062 //       triggerFJRmessageSummary
00063 //
00064 // -----------------------------------------------------------------------
00065 
00066 class MessageLoggerScribe
00067 {
00068 public:
00069   // ---  birth/death:
00070   MessageLoggerScribe();
00071   ~MessageLoggerScribe();
00072 
00073   // --- receive and act on messages:
00074   void  run();
00075 
00076   // --- obtain a pointer to the errorlog 
00077   static ErrorLog * getErrorLog_ptr() {return static_errorlog_p;}
00078   
00079 private:
00080   // --- convenience typedefs
00081   typedef std::string          String;
00082   typedef std::vector<String>  vString;
00083   typedef ParameterSet         PSet;
00084 
00085   // --- log one consumed message
00086   void log(ErrorObj * errorobj_p);
00087 
00088   // --- cause statistics destinations to output
00089   void triggerStatisticsSummaries();
00090   void triggerFJRmessageSummary(std::map<std::string, double> & sm);
00091   
00092   // --- handle details of configuring via a ParameterSet:
00093   void  configure_errorlog( );
00094   void  configure_fwkJobReports( );                             // Change Log 3
00095   void  configure_ordinary_destinations( );                     // Change Log 3
00096   void  configure_statistics( );                                // Change Log 3
00097   void  configure_dest( ELdestControl & dest_ctrl               
00098                       , String const &  filename
00099                       );
00100   void  configure_default_fwkJobReport( ELdestControl & dest_ctrl); //ChangeLog 4
00101   void  configure_external_dests( );
00102 
00103 #ifdef OLDSTYLE
00104   template <class T>
00105   T  getAparameter ( PSet * p, std::string const & id, T const & def ) 
00106   {
00107     T t;
00108     try { 
00109       t = p->template getUntrackedParameter<T>(id, def);
00110     } catch (...) {
00111       t = p->template getParameter<T>(id);
00112       std::cerr << "Tracked parameter " << id 
00113                 << " used in MessageLogger configuration.\n"
00114                 << "Use of tracked parameters for the message service "
00115                 << "is deprecated.\n"
00116                 << "The .cfg file should be modified to make this untracked.\n";
00117     }
00118     return t;
00119   }
00120 #else
00121 #ifdef SIMPLESTYLE
00122   template <class T>
00123   T  getAparameter ( PSet * p, std::string const & id, T const & def ) 
00124   {
00125     T t;
00126     t = p->template getUntrackedParameter<T>(id, def);
00127     return t;
00128   }                                                             // changelog 2
00129 #else
00130   template <class T>
00131   T  getAparameter ( PSet * p, std::string const & id, T const & def ) 
00132   {                                                             // changelog 7
00133     T t;
00134     try { 
00135       t = p->template getUntrackedParameter<T>(id, def);
00136     } catch (cms::Exception& e) {
00137       try {
00138         t = p->template getParameter<T>(id);
00139       } catch (...) {
00140         // if we get here, this was NOT a simple tracked parameter goof.
00141         // we should just rethrow the ORIGINAL error
00142         throw e;
00143       } 
00144       std::cerr << "Tracked parameter " << id 
00145                 << " used in MessageLogger configuration.\n"
00146                 << "Use of tracked parameters for the message service "
00147                 << "is not allowed.\n"
00148                 << "The .cfg file should be modified to make this untracked.\n";
00149       throw e;          
00150     } catch (...) {
00151       // This is not the usual tracked/untracked error; we can't add useful info
00152       throw;
00153     }
00154     return t;
00155   }
00156 
00157 
00158 
00159 #endif
00160 #endif
00161 
00162 #ifdef REMOVE
00163   template <class T>
00164   T  getCategoryDefault ( PSet * p, 
00165                           std::string const & id, 
00166                           std::string const & def  ) 
00167   {
00168     T t;
00169     t = p->template getUntrackedParameter<T>(id, def);
00170     return t;
00171   }                                                             
00172 #endif
00173 
00174 
00175   // --- other helpers
00176   void parseCategories (std::string const & s, std::vector<std::string> & cats);
00177   void setStaticErrorLog_ptr() {static_errorlog_p = errorlog_p;}
00178   
00179   // --- data:
00180   ELadministrator                   * admin_p;
00181   ELdestControl                       early_dest;
00182   ErrorLog                          * errorlog_p;
00183   std::vector<std::ofstream        *> file_ps;
00184   MsgContext                          msg_context;
00185   PSet *                              job_pset_p;
00186   std::vector<NamedDestination     *> extern_dests;
00187   std::map<String,std::ostream     *> stream_ps;
00188   std::vector<String>                 ordinary_destination_filenames;
00189   std::vector<ELdestControl>          statisticsDestControls;
00190   std::vector<bool>                   statisticsResets;
00191   std::string                         jobReportOption;
00192   static ErrorLog                   * static_errorlog_p;
00193   bool                                clean_slate_configuration;
00194   value_ptr<MessageLoggerDefaults>    messageLoggerDefaults;
00195   bool                                active;
00196     
00197 };  // MessageLoggerScribe
00198 
00199 
00200 }   // end of namespace service
00201 }  // namespace edm
00202 
00203 
00204 #endif  // FWCore_MessageService_MessageLoggerScribe_h

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