CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MessageLoggerScribe.h
Go to the documentation of this file.
1 #ifndef FWCore_MessageService_MessageLoggerScribe_h
2 #define FWCore_MessageService_MessageLoggerScribe_h
3 
5 
11 
13 
14 #include "boost/shared_ptr.hpp"
15 
16 #include <iosfwd>
17 #include <vector>
18 #include <map>
19 
20 #include <iostream>
21 
22 namespace edm {
23 namespace service {
24 
25 // ----------------------------------------------------------------------
26 //
27 // MessageLoggerScribe.h
28 //
29 // Changes:
30 //
31 // 1 - 2/6/07 mf
32 // Set up ability to get a remembered pointer to the ErrorLog of an
33 // instance of MessageLoggerScribe, from a non-member function, via
34 // getErrorLog_ptr(), and a corresponding routine to remember the pointer
35 // as setStaticErrorLog_ptr(). Needed if we decide to send an explicit
36 // message from the scribe.
37 //
38 // 2 - ?/?/? before 3/1/07 jm
39 // Modify parameter getting template so as not to catch tracked ones
40 // (that is, to crash if user mistakenly does not say untracked)
41 //
42 // 3 - 3/13/07 mf
43 // Added configure_ordinary_destinations, configure_fwkJobReports,
44 // and configure_statistics to allow these to be broken out of
45 // configure_errorlog.
46 //
47 // 4 - 3/26/07 mf
48 // Added configure_default_fwkJobReport, which implements the config
49 // originally placed in the .cfi file.
50 //
51 // 5 - 6/15/07 mf
52 // Accommodations for use of MessageLoggerDefault structure
53 //
54 // 6 - 7/24/07 mf
55 // Instace variable indicating that we really are logging what is sent.
56 // This is to be able to supress the <generator> info sent at exit by
57 // the JobReport, in the case where no .cfg file was given.
58 //
59 // 7 - 4/8/08 mf
60 // Modified getAparameter behavior when tracked parameter is found,
61 // for nicer output message.
62 //
63 // 8 - 6/19/08 mf
64 // triggerFJRmessageSummary
65 //
66 // 9 - 10/21/08 mf
67 // variables and routines in preparation for single-thread
68 //
69 // 10 - 10/22/08 mf
70 // derivation from AbstractMLscribe to allow for single-thread calling
71 // from MessageLoggerQ without introducing coupling to MessageService
72 //
73 // 11 - 5/26/09 mf
74 // restore getAparameter behavior to NOT throw for tracked, since
75 // now this will be caught when validating the PSet.
76 //
77 // 12 - 8/10/09 mf, cj
78 // member data to hold shared pointer to thread queue
79 //
80 // -----------------------------------------------------------------------
81 
82 class ThreadQueue;
83 class ErrorLog;
84 class ELadministrator;
85 
87 {
88 public:
89  // --- birth/death:
90 
91  // ChangeLog 12
93  explicit MessageLoggerScribe(boost::shared_ptr<ThreadQueue> queue);
94 
95  virtual ~MessageLoggerScribe();
96 
97  // --- receive and act on messages:
98  virtual
99  void run();
100  virtual // changelog 10
101  void runCommand(MessageLoggerQ::OpCode opcode, void * operand);
102  // changeLog 9
103 
104  // --- obtain a pointer to the errorlog
106 
107 private:
108  // --- convenience typedefs
109  typedef std::string String;
110  typedef std::vector<String> vString;
112 
113  // --- log one consumed message
114  void log(ErrorObj * errorobj_p);
115 
116  // --- cause statistics destinations to output
118  void triggerFJRmessageSummary(std::map<std::string, double> & sm);
119 
120  // --- handle details of configuring via a ParameterSet:
121  void configure_errorlog( );
122  void configure_fwkJobReports( ); // Change Log 3
123  void configure_ordinary_destinations( ); // Change Log 3
124  void configure_statistics( ); // Change Log 3
125  void configure_dest( ELdestControl & dest_ctrl
126  , String const & filename
127  );
128  void configure_default_fwkJobReport( ELdestControl & dest_ctrl); //ChangeLog 4
129  void configure_external_dests( );
130 
131 #define VALIDATE_ELSEWHERE // ChangeLog 11
132 
133 #ifdef OLDSTYLE
134  template <class T>
135  T getAparameter ( PSet const& p, std::string const & id, T const & def )
136  {
137  T t;
138  try {
139  t = p.template getUntrackedParameter<T>(id, def);
140  } catch (...) {
141  t = p.template getParameter<T>(id);
142  std::cerr << "Tracked parameter " << id
143  << " used in MessageLogger configuration.\n"
144  << "Use of tracked parameters for the message service "
145  << "is deprecated.\n"
146  << "The .cfg file should be modified to make this untracked.\n";
147  }
148  return t;
149  }
150 #else
151 #ifdef SIMPLESTYLE
152  template <class T>
153  T getAparameter ( PSet const& p, std::string const & id, T const & def )
154  {
155  T t;
156  t = p.template getUntrackedParameter<T>(id, def);
157  return t;
158  } // changelog 2
159 #else
160 #ifdef VALIDATE_ELSEWHERE
161  template <class T> // ChangeLog 11
162  T getAparameter ( PSet const& p, std::string const & id, T const & def )
163  {
164  T t = def;
165  try {
166  t = p.template getUntrackedParameter<T>(id, def);
167  } catch (...) {
168  try {
169  t = p.template getParameter<T>(id);
170  } catch (...) {
171  // Since PSetValidation will catch such errors, we simply proceed as
172  // best we can in case we are setting up the logger just to contain the
173  // validation-caught error messages.
174  }
175  }
176  return t;
177  }
178 #else // Do not tolerate errors
179  template <class T>
180  T getAparameter ( PSet const& p, std::string const & id, T const & def )
181  { // changelog 7
182  T t;
183  try {
184  t = p.template getUntrackedParameter<T>(id, def);
185  } catch (cms::Exception& e) {
186  try {
187  t = p.template getParameter<T>(id);
188  } catch (...) {
189  // if we get here, this was NOT a simple tracked parameter goof.
190  // we should just rethrow the ORIGINAL error
191  e.raise();
192  }
193  std::cerr << "Tracked parameter " << id
194  << " used in MessageLogger configuration.\n"
195  << "Use of tracked parameters for the message service "
196  << "is not allowed.\n"
197  << "The .cfg file should be modified to make this untracked.\n";
198  e.raise();
199  } catch (...) {
200  // This is not the usual tracked/untracked error; we can't add useful info
201  throw;
202  }
203  return t;
204  }
205 
206 #endif // VALIDATE_ELSEWHERE
207 #endif // SIMPLESTYLE
208 #endif // OLD_STYLE and the else Do not tolerate errors
209 
210 #ifdef REMOVE
211  template <class T>
212  T getCategoryDefault ( PSet * p,
213  std::string const & id,
214  std::string const & def )
215  {
216  T t;
217  t = p->template getUntrackedParameter<T>(id, def);
218  return t;
219  }
220 #endif
221 
222 
223  // --- other helpers
224  void parseCategories (std::string const & s, std::vector<std::string> & cats);
226 
227  // --- data:
230  boost::shared_ptr<ErrorLog> errorlog_p;
231  std::vector<boost::shared_ptr<std::ofstream> > file_ps;
233  boost::shared_ptr<PSet> job_pset_p;
234  std::vector<NamedDestination *> extern_dests;
235  std::map<String,std::ostream *> stream_ps;
236  std::vector<String> ordinary_destination_filenames;
237  std::vector<ELdestControl> statisticsDestControls;
238  std::vector<bool> statisticsResets;
239  std::string jobReportOption;
243  bool active;
244  bool singleThread; // changeLog 9
245  bool done; // changeLog 9
246  bool purge_mode; // changeLog 9
247  int count; // changeLog 9
248  boost::shared_ptr<ThreadQueue> m_queue; // changeLog 12
249 
250 }; // MessageLoggerScribe
251 
252 
253 } // end of namespace service
254 } // namespace edm
255 
256 
257 #endif // FWCore_MessageService_MessageLoggerScribe_h
virtual void runCommand(MessageLoggerQ::OpCode opcode, void *operand)
MessageLoggerScribe(boost::shared_ptr< ThreadQueue > queue)
— If queue is NULL, this sets singleThread true
void configure_default_fwkJobReport(ELdestControl &dest_ctrl)
boost::shared_ptr< ErrorLog > errorlog_p
void raise()
Definition: Exception.h:128
std::vector< boost::shared_ptr< std::ofstream > > file_ps
list queue
Definition: launcher.py:18
std::vector< String > ordinary_destination_filenames
std::vector< NamedDestination * > extern_dests
void configure_dest(ELdestControl &dest_ctrl, String const &filename)
void parseCategories(std::string const &s, std::vector< std::string > &cats)
boost::shared_ptr< ThreadQueue > m_queue
std::vector< ELdestControl > statisticsDestControls
boost::shared_ptr< PSet > job_pset_p
void triggerFJRmessageSummary(std::map< std::string, double > &sm)
tuple filename
Definition: lut2db_cfg.py:20
T getAparameter(PSet const &p, std::string const &id, T const &def)
std::map< String, std::ostream * > stream_ps
string s
Definition: asciidump.py:422
long double T
JetCorrectorParameters::Definitions def
Definition: classes.h:10
value_ptr< MessageLoggerDefaults > messageLoggerDefaults