CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/FWCore/MessageService/interface/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 
00006 #include "FWCore/MessageService/interface/ELdestControl.h"
00007 #include "FWCore/MessageService/interface/MsgContext.h"
00008 #include "FWCore/MessageService/interface/MessageLoggerDefaults.h"
00009 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00010 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
00011 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 
00014 #include "boost/shared_ptr.hpp"
00015 
00016 #include <iosfwd>
00017 #include <vector>
00018 #include <map>
00019 
00020 #include <iostream>
00021 
00022 namespace edm {
00023 namespace service {       
00024 
00025 // ----------------------------------------------------------------------
00026 //
00027 // MessageLoggerScribe.h
00028 //
00029 // Changes:
00030 //
00031 //   1 - 2/6/07  mf     
00032 //      Set up ability to get a remembered pointer to the ErrorLog of an
00033 //      instance of MessageLoggerScribe, from a non-member function, via
00034 //      getErrorLog_ptr(), and a corresponding routine to remember the pointer
00035 //      as setStaticErrorLog_ptr().  Needed if we decide to send an explicit 
00036 //      message from the scribe.
00037 //
00038 //   2 - ?/?/? before 3/1/07 jm
00039 //       Modify parameter getting template so as not to catch tracked ones
00040 //       (that is, to crash if user mistakenly does not say untracked)
00041 //
00042 //   3 - 3/13/07 mf
00043 //       Added configure_ordinary_destinations, configure_fwkJobReports,
00044 //       and configure_statistics to allow these to be broken out of 
00045 //       configure_errorlog.    
00046 //
00047 //   4 - 3/26/07 mf
00048 //       Added configure_default_fwkJobReport, which implements the config
00049 //       originally placed in the .cfi file.
00050 //
00051 //   5 - 6/15/07 mf
00052 //       Accommodations for use of MessageLoggerDefault structure 
00053 //
00054 //   6 - 7/24/07 mf
00055 //       Instace variable indicating that we really are logging what is sent.
00056 //       This is to be able to supress the <generator> info sent at exit by
00057 //       the JobReport, in the case where no .cfg file was given.
00058 //
00059 //   7 - 4/8/08 mf
00060 //       Modified getAparameter behavior when tracked parameter is found,
00061 //       for nicer output message. 
00062 //
00063 //   8 - 6/19/08 mf
00064 //       triggerFJRmessageSummary
00065 //
00066 //   9 - 10/21/08 mf
00067 //       variables and routines in preparation for single-thread
00068 //
00069 //  10 - 10/22/08 mf
00070 //       derivation from AbstractMLscribe to allow for single-thread calling
00071 //       from MessageLoggerQ without introducing coupling to MessageService
00072 //
00073 //  11 - 5/26/09 mf
00074 //       restore getAparameter behavior to NOT throw for tracked, since
00075 //       now this will be caught when validating the PSet.
00076 //
00077 //  12 - 8/10/09 mf, cj
00078 //       member data  to hold shared pointer to thread queue
00079 //
00080 // -----------------------------------------------------------------------
00081 
00082 class ThreadQueue;
00083 class ErrorLog;
00084 class ELadministrator;
00085 
00086 class MessageLoggerScribe : public AbstractMLscribe
00087 {
00088 public:
00089   // ---  birth/death:
00090   
00091   // ChangeLog 12
00093   explicit MessageLoggerScribe(boost::shared_ptr<ThreadQueue> queue);
00094   
00095   virtual ~MessageLoggerScribe();
00096 
00097   // --- receive and act on messages:
00098   virtual
00099   void  run();
00100   virtual                                                       // changelog 10
00101   void  runCommand(MessageLoggerQ::OpCode  opcode, void * operand);
00102                                                                 // changeLog 9
00103 
00104   // --- obtain a pointer to the errorlog 
00105   static ErrorLog * getErrorLog_ptr() {return static_errorlog_p;}
00106   
00107 private:
00108   // --- convenience typedefs
00109   typedef std::string          String;
00110   typedef std::vector<String>  vString;
00111   typedef ParameterSet         PSet;
00112 
00113   // --- log one consumed message
00114   void log(ErrorObj * errorobj_p);
00115 
00116   // --- cause statistics destinations to output
00117   void triggerStatisticsSummaries();
00118   void triggerFJRmessageSummary(std::map<std::string, double> & sm);
00119   
00120   // --- handle details of configuring via a ParameterSet:
00121   void  configure_errorlog( );
00122   void  configure_fwkJobReports( );                             // Change Log 3
00123   void  configure_ordinary_destinations( );                     // Change Log 3
00124   void  configure_statistics( );                                // Change Log 3
00125   void  configure_dest( ELdestControl & dest_ctrl               
00126                       , String const &  filename
00127                       );
00128   void  configure_default_fwkJobReport( ELdestControl & dest_ctrl); //ChangeLog 4
00129   void  configure_external_dests( );
00130 
00131 #define VALIDATE_ELSEWHERE                                      // ChangeLog 11
00132 
00133 #ifdef OLDSTYLE
00134   template <class T>
00135   T getAparameter ( PSet const& p, std::string const & id, T const & def ) 
00136   {
00137     T t;
00138     try { 
00139       t = p.template getUntrackedParameter<T>(id, def);
00140     } catch (...) {
00141       t = p.template getParameter<T>(id);
00142       std::cerr << "Tracked parameter " << id 
00143                 << " used in MessageLogger configuration.\n"
00144                 << "Use of tracked parameters for the message service "
00145                 << "is deprecated.\n"
00146                 << "The .cfg file should be modified to make this untracked.\n";
00147     }
00148     return t;
00149   }
00150 #else
00151 #ifdef SIMPLESTYLE
00152   template <class T>
00153   T getAparameter ( PSet const& p, std::string const & id, T const & def ) 
00154   {
00155     T t;
00156     t = p.template getUntrackedParameter<T>(id, def);
00157     return t;
00158   }                                                             // changelog 2
00159 #else
00160 #ifdef VALIDATE_ELSEWHERE
00161   template <class T>                                            // ChangeLog 11
00162   T getAparameter ( PSet const& p, std::string const & id, T const & def ) 
00163   {
00164     T t = def;
00165     try { 
00166       t = p.template getUntrackedParameter<T>(id, def);
00167     } catch (...) {
00168       try {
00169         t = p.template getParameter<T>(id);
00170       } catch (...) {
00171         // Since PSetValidation will catch such errors, we simply proceed as
00172         // best we can in case we are setting up the logger just to contain the 
00173         // validation-caught error messages. 
00174       }
00175     }
00176     return t;
00177   }
00178 #else  // Do not tolerate errors
00179   template <class T>
00180   T  getAparameter ( PSet const& p, std::string const & id, T const & def ) 
00181   {                                                             // changelog 7
00182     T t;
00183     try { 
00184       t = p.template getUntrackedParameter<T>(id, def);
00185     } catch (cms::Exception& e) {
00186       try {
00187         t = p.template getParameter<T>(id);
00188       } catch (...) {
00189         // if we get here, this was NOT a simple tracked parameter goof.
00190         // we should just rethrow the ORIGINAL error
00191         e.raise();
00192       } 
00193       std::cerr << "Tracked parameter " << id 
00194                 << " used in MessageLogger configuration.\n"
00195                 << "Use of tracked parameters for the message service "
00196                 << "is not allowed.\n"
00197                 << "The .cfg file should be modified to make this untracked.\n";
00198       e.raise();                
00199     } catch (...) {
00200       // This is not the usual tracked/untracked error; we can't add useful info
00201       throw;
00202     }
00203     return t;
00204      }
00205 
00206 #endif // VALIDATE_ELSEWHERE
00207 #endif // SIMPLESTYLE
00208 #endif // OLD_STYLE and the else Do not tolerate errors
00209 
00210 #ifdef REMOVE
00211   template <class T>
00212   T  getCategoryDefault ( PSet * p, 
00213                           std::string const & id, 
00214                           std::string const & def  ) 
00215   {
00216     T t;
00217     t = p->template getUntrackedParameter<T>(id, def);
00218     return t;
00219   }                                                             
00220 #endif
00221 
00222 
00223   // --- other helpers
00224   void parseCategories (std::string const & s, std::vector<std::string> & cats);
00225   void setStaticErrorLog_ptr() {static_errorlog_p = errorlog_p.get();}
00226   
00227   // --- data:
00228   ELadministrator                   * admin_p;
00229   ELdestControl                       early_dest;
00230   boost::shared_ptr<ErrorLog>         errorlog_p;
00231   std::vector<boost::shared_ptr<std::ofstream> > file_ps;
00232   MsgContext                          msg_context;
00233   boost::shared_ptr<PSet>             job_pset_p;
00234   std::vector<NamedDestination     *> extern_dests;
00235   std::map<String,std::ostream     *> stream_ps;
00236   std::vector<String>                 ordinary_destination_filenames;
00237   std::vector<ELdestControl>          statisticsDestControls;
00238   std::vector<bool>                   statisticsResets;
00239   std::string                         jobReportOption;
00240   static ErrorLog                   * static_errorlog_p;
00241   bool                                clean_slate_configuration;
00242   value_ptr<MessageLoggerDefaults>    messageLoggerDefaults;
00243   bool                                active;
00244   bool                                singleThread;             // changeLog 9
00245   bool                                done;                     // changeLog 9
00246   bool                                purge_mode;               // changeLog 9
00247   int                                 count;                    // changeLog 9
00248   boost::shared_ptr<ThreadQueue>      m_queue;                  // changeLog 12
00249       
00250 };  // MessageLoggerScribe
00251 
00252 
00253 }   // end of namespace service
00254 }  // namespace edm
00255 
00256 
00257 #endif  // FWCore_MessageService_MessageLoggerScribe_h