CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MessageLoggerScribe.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // MessageLoggerScribe.cc
4 //
5 // Changes:
6 //
7 // 1 - 3/22/06 mf - in configure_dest()
8 // Repaired the fact that destination limits for categories
9 // were not being effective:
10 // a) use values from the destination specific default PSet
11 // rather than the overall default PSet to set these
12 // b) when an explicit value has been set - either by overall default or
13 // by a destination specific default PSet - set that limit or
14 // timespan for that dest_ctrl via a "*" msgId.
15 //
16 // 2 - 3/22/06 mf - in configure_dest()
17 // Enabled the use of -1 in the .cfg file to mean infinite limit
18 // or timespan. This is done by:
19 // a) replacing the default value of -1 (by which we recognize
20 // never-specified values) by NO_VALUE_SET = -45654
21 // b) checking for values of -1 and substituting a very large integer
22 //
23 // 3 - 4/28/06 mf - in configure_dest()
24 // Mods to help deal with the fact that checking for an empty PSet is
25 // unwise when untracked parameters are involved: The PSet will appear
26 // to be empty and if skipped, will result in limits not being applied.
27 // a) Replaced default values directly in getAparameter with variables
28 // which can be examined all in one place.
29 // b) Carefully checked that we are never comparing to the empty PSet
30 //
31 // 4 - 4/28/06 mf - in configure_dest()
32 // If a destination name does not have an extension, append .log
33 // (or in the case of a FwkJobReport, .xml).
34 // [note for this change - the filename kept as an index to stream_ps
35 // can be kept as its original name; it is just a tool for assigning
36 // the right shared stream to statistics destinations]
37 //
38 // 5 - 4/28/06 mf - in configure_dest()
39 // Provision for an overall default affecting all categories, for
40 // example, establishing a limit for all a specific category for
41 // every destination.
42 //
43 // 6 - 5/18/06 mf - in configure_dest()
44 // Implement establishing intervals between reacting to message of
45 // some type.
46 //
47 // 7 - 5/24/06 mf - in configure_dest()
48 // Corrected algorithm for estabolishing limits and intervals, avoiding
49 // interference between setting the one and getting the default for the
50 // other.
51 //
52 // 8 - 5/31/06 wmtan - in configure_errorlog()
53 // The presence of the framework job report should not affect the output
54 // to the early destination (cerr).
55 //
56 // 9 - 6/6/06 mf - in configure_dest()
57 // Support for placeholder PSet without actually creating the destination.
58 // Useful in a .cfi file, in conjunction with potential replace commands.
59 //
60 // 10 - 6/6/06 mf - in configure_dest()
61 // Changed cfg keyword interval to reportEvery
62 //
63 // 11 - 6/12/06 mf - in configure_errorlog()
64 // Check for placeholder before attaching a destination that may not be
65 // wanted.
66 //
67 // 12 - 6/14/06 mf - in configure_external_dests()
68 // Clear the list of external dests needing configuration, if there
69 // is no configuration file available.
70 //
71 // 13 - 8/7/06 mf - in configure_external_dests()
72 // Undo change 12: the list of external dests needing configuration
73 // is left intact if there is no configuration file available, the
74 // assumption being that at some later time there will be a file and
75 // the message logger will be configured again.
76 //
77 // Note: The change made in (12) and un-done here was necessary to
78 // prevent segfault behavior when a job is done with external
79 // destinations and no .cfg file under some circumstances.
80 // D. Evans (who was being hit with that behavior due to an
81 // accidental .cfg omission) asserts (8/16) that running with
82 // no .cfg file is a sufficient anomoly that the current change
83 // is acceptable.
84 //
85 // 14 - 10/18/06 mf - in configure_error_log()
86 // Finer control of output file name for a given destination:
87 // Accept a parameter extension, to specify some extension other than
88 // .log without needing to place a dot in the Pset name. Also accept
89 // an explicit filename.
90 //
91 // 15 - 2/11/07 mf - at bottom
92 // Declared static_errorlog_p
93 //
94 // 16 - 3/13/07 mf - in configure_errorlog() and addition of 3 functions
95 // Break out the configuring of each type of destination, for sanity.
96 //
97 // 17 - 3/13/07 mf - in run(), at CONFIGURE case
98 // Use the handshake to make this synchronous, and pass any throw
99 // across to the other thread.
100 //
101 // 18 - 3/14/07 mf - in configure_ordinary_destinations() and 2 others
102 // Use actual filename in a master ostream_ps list, and behave correctly
103 // when duplicates are found (duplicate names both used leads to grim
104 // file behavior when one file is opened as two streams).
105 //
106 // 19 - 3/15/07 mf - in configure_fwkJobReports()
107 // "Deturdification" - default is to not produce a job reports; a
108 // command-line option lets you produce them.
109 //
110 // 20 - 3/15/07 mf - in configure_statistics() and configure_fwkJobReports()
111 // Handle the placeholder case
112 //
113 // 21 - 3/15/07 mf - run()
114 // Improve the behavior of catches of exceptions in non-synchronous
115 // command cases: Unless the ConfigurationHandshake is used, re-throw
116 // is not an option, but exit is also not very good.
117 //
118 // 22 - 4/18/07 mf - in configure_error_log and its called functions
119 // Allow for duplicate file names if configuration happens twice.
120 //
121 // 23 - 6/13/07 mf - in configure_statistics
122 // Repared error of calling "cerr" "err", which would cause appended
123 // statistics destinations going to cerr to instead come out in a file
124 // err.log
125 //
126 // 24 - 6/15/07 mf - in configure_errlog and its descendants
127 // Major mods to hardwire defaults taken from the .cfi file
128 // To allow flexibility, this depends on MessageLoggerDefaults.h
129 //
130 // 25 - 7/24/07 mf - in run()
131 // A command SHUT_UP to deactivate, and in the LOG_A_MESSGE case, response to
132 // that command. This allows supression of the generator info in case of a
133 // completely .cfg-less cmsRun command.
134 //
135 // 26 - 8/7/07 mf - in run()
136 // A command FLUSH_LOG_Q to consume the entire queue, processing each
137 // message. Actually, the key is that on the other side, it is used in
138 // a synchronous manner (like CONFIGURE) so as soon as one gets up to
139 // the flush command, the queue has in fact been flushed!
140 //
141 // 27 - 8/16/07 mf - in run()
142 // A command GROUP_STATS to add a category to a list which ELstatistics
143 // will use to avoid separate per-module statistics for that category.
144 //
145 // 28 - 6/18/08 mf - in CONFIGURE case and FLUSH_LOG_Q case
146 // Changed expectation of p from a ParameterSet* to a void*:
147 // static cast it to the needed ParameterSet*
148 //
149 // 29 - 6/19/08 mf - in run() and a new function triggerFJRmessageSummary()
150 // Implemented filling a map with summary info for the Job Report
151 //
152 // 30 - 6/20/08 mf - in run()
153 // Setting MessageLoggerScribeIsRunning
154 //
155 // 31 - 7/9/08 mf - in configure_ordinary_destinations()
156 // and configure_statistics()
157 // using hardwired default output filename if there is one
158 //
159 // 32 - 10/21/08 mf - in ctor and in run() and new runCommand()
160 // split up run() to have ability to implement single-thread
161 //
162 // 33 - 10/22/08 mf
163 // implementation of singleThread
164 //
165 // 34 - 5/13/09 mf
166 // Allowing threshold to be set for default destination in default PSet
167 //
168 // 35 - 5/29/09 mf
169 // Avoiding throw when duplicate destination names are used, to let the
170 // validation report that and abort instead.
171 //
172 // 36 - 8/10/09 mf, cdj
173 // Use ThreadQ in place of the singleton MessageLoggerQ to consume
174 //
175 // 37 - 9/24/10 mf
176 // Establish values of debugAlwaysSuppressed, infoAlwaysSuppressed
177 // and warningAlwaysSuppressed when setting up thresholds
178 //
179 // 38 - 9/29/10 mf, ql
180 // Limit and timespan shuold be translated from -1 input to
181 // 2000000000. This was being done in all cases except the
182 // severity limits; omission rectified.
183 //
184 // ----------------------------------------------------------------------
185 
194 
198 #include "FWCore/MessageLogger/interface/MessageDrop.h" // change log 37
199 #include "FWCore/MessageLogger/interface/ELseverityLevel.h" // change log 37
200 
203 
204 #include <algorithm>
205 #include <cassert>
206 #include <fstream>
207 #include <string>
208 #include <signal.h>
209 
210 using std::cerr;
211 
212 namespace edm {
213 namespace service {
214 
215 
216 MessageLoggerScribe::MessageLoggerScribe(boost::shared_ptr<ThreadQueue> queue)
217 : admin_p ( ELadministrator::instance() )
218 , early_dest( admin_p->attach(ELoutput(std::cerr, false)) )
219 , errorlog_p( new ErrorLog() )
220 , file_ps ( )
221 , job_pset_p( )
222 , extern_dests( )
223 , jobReportOption( )
224 , clean_slate_configuration( true )
225 , active( true )
226 , singleThread (queue.get() == 0) // changeLog 36
227 , done (false) // changeLog 32
228 , purge_mode (false) // changeLog 32
229 , count (false) // changeLog 32
230 , m_queue(queue) // changeLog 36
231 {
233 }
234 
236 {
237  admin_p->finish();
238  assert( extern_dests.empty() ); // nothing to do
239 }
240 
241 
242 void
244 {
245  MessageLoggerQ::OpCode opcode;
246  void * operand;
247 
249  MLSCRIBE_RUNNING_INDICATOR; // ChangeLog 30
250 // std::cerr << "MessageLoggerScribe::run(): \n";
251 // std::cerr << "messageLoggerScribeIsRunning = "
252 // << (int)MessageDrop::instance()->messageLoggerScribeIsRunning << "\n";
253 
254  do {
255  m_queue->consume(opcode, operand); // grab next work item from Q
256  // changeLog 36
257  runCommand (opcode, operand);
258  } while(! done);
259 
260 } // MessageLoggerScribe::run()
261 
262 void
264  MessageLoggerQ::OpCode opcode,
265  void * operand)
266 {
267  switch(opcode) { // interpret the work item
268  default: {
269  assert(false); // can't happen (we certainly hope!)
270  break;
271  }
273  assert( operand == 0 );
274  done = true;
276  (unsigned char) -1; // ChangeLog 30
277  break;
278  }
280  ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
281  try {
282  if(active && !purge_mode) log (errorobj_p);
283  }
284  catch(cms::Exception& e)
285  {
286  ++count;
287  std::cerr << "MessageLoggerScribe caught " << count
288  << " cms::Exceptions, text = \n"
289  << e.what() << "\n";
290 
291  if(count > 25)
292  {
293  cerr << "MessageLogger will no longer be processing "
294  << "messages due to errors (entering purge mode).\n";
295  purge_mode = true;
296  }
297  }
298  catch(...)
299  {
300  std::cerr << "MessageLoggerScribe caught an unknown exception and "
301  << "will no longer be processing "
302  << "messages. (entering purge mode)\n";
303  purge_mode = true;
304  }
305  delete errorobj_p; // dispose of the message text
306  break;
307  }
308  case MessageLoggerQ::CONFIGURE: { // changelog 17
309  if (singleThread) {
310  job_pset_p.reset(static_cast<ParameterSet *>(operand));
312  break;
313  } else {
314  ConfigurationHandshake * h_p =
315  static_cast<ConfigurationHandshake *>(operand);
316  job_pset_p.reset(static_cast<ParameterSet *>(h_p->p));
317  boost::mutex::scoped_lock sl(h_p->m); // get lock
318  try {
320  }
321  catch(edm::Exception& e)
322  {
324  if (!(*epp)) {
325  *epp = boost::shared_ptr<edm::Exception>(new edm::Exception(e));
326  } else {
328  (*ep) << "\n and another exception: \n" << e.what();
329  }
330  }
331  // Note - since the configuring code has not made a new copy of the
332  // job parameter set, we must not delete job_pset_p (in contrast to
333  // the case for errorobj_p). On the other hand, if we instantiate
334  // a new edm::Exception pointed to by *epp, it is the responsibility
335  // of the MessageLoggerQ to delete it.
336  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
337  // finally, release the scoped lock by letting it go out of scope
338  break;
339  }
340  }
342  try {
343  extern_dests.push_back( static_cast<NamedDestination *>(operand) );
345  }
346  catch(cms::Exception& e) // change log 21
347  {
348  std::cerr << "MessageLoggerScribe caught a cms::Exception "
349  << "during extern dest configuration:\n"
350  << e.what() << "\n"
351  << "This is a serious problem, and the extern dest "
352  << "will not be produced.\n"
353  << "However, the rest of the logger continues to run.\n";
354  }
355  catch(...) // change log 21
356  {
357  std::cerr << "MessageLoggerScribe caught unkonwn exception type\n"
358  << "during extern dest configuration. "
359  << "This is a serious problem, and the extern dest "
360  << "will not be produced.\n"
361  << "The rest of the logger will attempt to continue to run.\n";
362  }
363  break;
364  }
366  assert( operand == 0 );
367  try {
369  }
370  catch(cms::Exception& e)
371  {
372  std::cerr << "MessageLoggerScribe caught exception "
373  << "during summarize:\n"
374  << e.what() << "\n";
375  }
376  catch(...)
377  {
378  std::cerr << "MessageLoggerScribe caught unkonwn exception type "
379  << "during summarize. (Ignored)\n";
380  }
381  break;
382  }
383  case MessageLoggerQ::JOBREPORT: { // change log 19
384  std::string* jobReportOption_p =
385  static_cast<std::string*>(operand);
386  try {
387  jobReportOption = *jobReportOption_p;
388  }
389  catch(cms::Exception& e)
390  {
391  std::cerr << "MessageLoggerScribe caught a cms::Exception "
392  << "during processing of --jobReport option:\n"
393  << e.what() << "\n"
394  << "This likely will affect or prevent the job report.\n"
395  << "However, the rest of the logger continues to run.\n";
396  }
397  catch(...)
398  {
399  std::cerr << "MessageLoggerScribe caught unkonwn exception type\n"
400  << "during processing of --jobReport option.\n"
401  << "This likely will affect or prevent the job report.\n"
402  << "However, the rest of the logger continues to run.\n";
403  }
404  delete jobReportOption_p; // dispose of the message text
405  // which will have been new-ed
406  // in MessageLogger.cc (service version)
407  break;
408  }
409  case MessageLoggerQ::JOBMODE: { // change log 24
410  std::string* jobMode_p =
411  static_cast<std::string*>(operand);
412  JobMode jm = MessageLoggerDefaults::mode(*jobMode_p);
415  // Note - since messageLoggerDefaults is a value_ptr,
416  // there is no concern about deleting here.
417  delete jobMode_p; // dispose of the message text
418  // which will have been new-ed
419  // in MessageLogger.cc (service version)
420  break;
421  }
423  assert( operand == 0 );
424  active = false;
425  break;
426  }
427  case MessageLoggerQ::FLUSH_LOG_Q: { // changelog 26
428  if (singleThread) return;
429  ConfigurationHandshake * h_p =
430  static_cast<ConfigurationHandshake *>(operand);
431  job_pset_p.reset(static_cast<ParameterSet *>(h_p->p));
432  boost::mutex::scoped_lock sl(h_p->m); // get lock
433  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
434  // finally, release the scoped lock by letting it go out of scope
435  break;
436  }
437  case MessageLoggerQ::GROUP_STATS: { // change log 27
438  std::string* cat_p =
439  static_cast<std::string*>(operand);
441  delete cat_p; // dispose of the message text
442  break;
443  }
444  case MessageLoggerQ::FJR_SUMMARY: { // changelog 29
445  if (singleThread) {
446  std::map<std::string, double> * smp =
447  static_cast<std::map<std::string, double> *>(operand);
449  break;
450  } else {
451  ConfigurationHandshake * h_p =
452  static_cast<ConfigurationHandshake *>(operand);
453  boost::mutex::scoped_lock sl(h_p->m); // get lock
454  std::map<std::string, double> * smp =
455  static_cast<std::map<std::string, double> *>(h_p->p);
457  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
458  // finally, release the scoped lock by letting it go out of scope
459  break;
460  }
461  }
462  } // switch
463 
464 } // MessageLoggerScribe::runCommand(opcode, operand)
465 
466 void MessageLoggerScribe::log ( ErrorObj * errorobj_p ) {
469  MsgContext& mc = dynamic_cast<MsgContext&>(cs);
470  mc.setContext(errorobj_p->context());
471  std::vector<std::string> categories;
472  parseCategories(errorobj_p->xid().id, categories);
473  for (unsigned int icat = 0; icat < categories.size(); ++icat) {
474  errorobj_p->setID(categories[icat]);
475  (*errorlog_p)( *errorobj_p ); // route the message text
476  }
477 }
478 
479 void
481 {
482  vString empty_vString;
483  String empty_String;
484  PSet empty_PSet;
485 
486  // The following is present to test pre-configuration message handling:
487  String preconfiguration_message
488  = getAparameter<String>
489  (*job_pset_p, "generate_preconfiguration_message", empty_String);
490  if (preconfiguration_message != empty_String) {
491  // To test a preconfiguration message without first going thru the
492  // configuration we are about to do, we issue the message (so it sits
493  // on the queue), then copy the processing that the LOG_A_MESSAGE case
494  // does. We suppress the timestamp to allow for automated unit testing.
496  LogError ("preconfiguration") << preconfiguration_message;
497  if (!singleThread) {
498  MessageLoggerQ::OpCode opcode;
499  void * operand;
500  m_queue->consume(opcode, operand); // grab next work item from Q
501  assert (opcode == MessageLoggerQ::LOG_A_MESSAGE);
502  ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
503  log (errorobj_p);
504  delete errorobj_p; // dispose of the message text
505  }
506  }
507 
508  if ( !stream_ps.empty() ) {
509  LogWarning ("multiLogConfig")
510  << "The message logger has been configured multiple times";
511  clean_slate_configuration = false; // Change Log 22
512  }
513  configure_fwkJobReports(); // Change Log 16
514  configure_ordinary_destinations(); // Change Log 16
515  configure_statistics(); // Change Log 16
516 
518 
519 } // MessageLoggerScribe::configure_errorlog()
520 
521 
522 
523 
524 void
526  , String const & filename
527  )
528 {
529  static const int NO_VALUE_SET = -45654; // change log 2
530  vString empty_vString;
531  PSet empty_PSet;
532  String empty_String;
533 
534  // Defaults: // change log 3a
535  const std::string COMMON_DEFAULT_THRESHOLD = "INFO";
536  const int COMMON_DEFAULT_LIMIT = NO_VALUE_SET;
537  const int COMMON_DEFAULT_INTERVAL = NO_VALUE_SET; // change log 6
538  const int COMMON_DEFAULT_TIMESPAN = NO_VALUE_SET;
539 
540  char const* severity_array[] = {"WARNING", "INFO", "ERROR", "DEBUG"};
541  vString const severities(severity_array+0, severity_array+4);
542 
543  // grab list of categories
545  = getAparameter<vString>(*job_pset_p, "categories", empty_vString);
546 
547  // grab list of messageIDs -- these are a synonym for categories
548  // Note -- the use of messageIDs is deprecated in favor of categories
549  {
550  vString messageIDs
551  = getAparameter<vString>(*job_pset_p, "messageIDs", empty_vString);
552 
553  // combine the lists, not caring about possible duplicates (for now)
554  copy_all( messageIDs, std::back_inserter(categories) );
555  } // no longer need messageIDs
556 
557  // grab list of hardwired categories (hardcats) -- these are to be added
558  // to the list of categories -- change log 24
559  {
560  std::vector<std::string> hardcats = messageLoggerDefaults->categories;
561  // combine the lists, not caring about possible duplicates (for now)
562  copy_all( hardcats, std::back_inserter(categories) );
563  } // no longer need hardcats
564 
565  // grab default threshold common to all destinations
566  String default_threshold
567  = getAparameter<String>(*job_pset_p, "threshold", empty_String);
568  // change log 3a
569  // change log 24
570 
571  // grab default limit/interval/timespan common to all destinations/categories:
572  PSet default_pset
573  = getAparameter<PSet>(*job_pset_p, "default", empty_PSet);
574  int default_limit
575  = getAparameter<int>(default_pset, "limit", COMMON_DEFAULT_LIMIT);
576  int default_interval
577  = getAparameter<int>(default_pset, "reportEvery", COMMON_DEFAULT_INTERVAL);
578  // change log 6, 10
579  int default_timespan
580  = getAparameter<int>(default_pset, "timespan", COMMON_DEFAULT_TIMESPAN);
581  // change log 2a
582  // change log 3a
583  String default_pset_threshold
584  = getAparameter<String>(default_pset, "threshold", default_threshold);
585  // change log 34
586 
587  // grab all of this destination's parameters:
588  PSet dest_pset = getAparameter<PSet>(*job_pset_p, filename, empty_PSet);
589 
590  // See if this is just a placeholder // change log 9
591  bool is_placeholder
592  = getAparameter<bool>(dest_pset, "placeholder", false);
593  if (is_placeholder) return;
594 
595  // grab this destination's default limit/interval/timespan:
596  PSet dest_default_pset
597  = getAparameter<PSet>(dest_pset, "default", empty_PSet);
598  int dest_default_limit
599  = getAparameter<int>(dest_default_pset, "limit", default_limit);
600  int dest_default_interval
601  = getAparameter<int>(dest_default_pset, "reportEvery", default_interval);
602  // change log 6
603  int dest_default_timespan
604  = getAparameter<int>(dest_default_pset, "timespan", default_timespan);
605  // change log 1a
606  if ( dest_default_limit != NO_VALUE_SET ) {
607  if ( dest_default_limit < 0 ) dest_default_limit = 2000000000;
608  dest_ctrl.setLimit("*", dest_default_limit );
609  } // change log 1b, 2a, 2b
610  if ( dest_default_interval != NO_VALUE_SET ) { // change log 6
611  dest_ctrl.setInterval("*", dest_default_interval );
612  }
613  if ( dest_default_timespan != NO_VALUE_SET ) {
614  if ( dest_default_timespan < 0 ) dest_default_timespan = 2000000000;
615  dest_ctrl.setTimespan("*", dest_default_timespan );
616  } // change log 1b, 2a, 2b
617 
618  // establish this destination's threshold:
619  String dest_threshold
620  = getAparameter<String>(dest_pset, "threshold", default_threshold);
621  if (dest_threshold == empty_String) {
622  dest_threshold = default_threshold;
623  }
624  if (dest_threshold == empty_String) { // change log 34
625  dest_threshold = default_pset_threshold;
626  }
627  if (dest_threshold == empty_String) {
628  dest_threshold = messageLoggerDefaults->threshold(filename);
629  }
630  if (dest_threshold == empty_String) dest_threshold = COMMON_DEFAULT_THRESHOLD;
631  ELseverityLevel threshold_sev(dest_threshold);
632  dest_ctrl.setThreshold(threshold_sev);
633  // change log 37
634  if (threshold_sev <= ELseverityLevel::ELsev_success)
636  if (threshold_sev <= ELseverityLevel::ELsev_info)
638  if (threshold_sev <= ELseverityLevel::ELsev_warning)
640 
641  // establish this destination's limit/interval/timespan for each category:
642  for( vString::const_iterator id_it = categories.begin()
643  ; id_it != categories.end()
644  ; ++id_it
645  )
646  {
647  String msgID = *id_it;
648  PSet default_category_pset
649  = getAparameter<PSet>(default_pset, msgID, empty_PSet); // change log 5
650  PSet category_pset
651  = getAparameter<PSet>(dest_pset, msgID, default_category_pset);
652 
653  int category_default_limit
654  = getAparameter<int>(default_category_pset, "limit", NO_VALUE_SET);
655  int limit
656  = getAparameter<int>(category_pset, "limit", category_default_limit);
657  if (limit == NO_VALUE_SET) limit = dest_default_limit;
658  // change log 7
659  int category_default_interval
660  = getAparameter<int>(default_category_pset, "reportEvery", NO_VALUE_SET);
661  int interval
662  = getAparameter<int>(category_pset, "reportEvery",category_default_interval);
663  if (interval == NO_VALUE_SET) interval = dest_default_interval;
664  // change log 6 and then 7
665  int category_default_timespan
666  = getAparameter<int>(default_category_pset, "timespan", NO_VALUE_SET);
667  int timespan
668  = getAparameter<int>(category_pset, "timespan", category_default_timespan);
669  if (timespan == NO_VALUE_SET) timespan = dest_default_timespan;
670  // change log 7
671 
672  std::string category = msgID;
673  if ( limit == NO_VALUE_SET ) { // change log 24
674  limit = messageLoggerDefaults->limit(filename,category);
675  }
676  if ( interval == NO_VALUE_SET ) { // change log 24
677  interval = messageLoggerDefaults->reportEvery(filename,category);
678  }
679  if ( timespan == NO_VALUE_SET ) { // change log 24
680  timespan = messageLoggerDefaults->timespan(filename,category);
681  }
682 
683  if( limit != NO_VALUE_SET ) {
684  if ( limit < 0 ) limit = 2000000000;
685  dest_ctrl.setLimit(msgID, limit);
686  } // change log 2a, 2b
687  if( interval != NO_VALUE_SET ) {
688  dest_ctrl.setInterval(msgID, interval);
689  } // change log 6
690  if( timespan != NO_VALUE_SET ) {
691  if ( timespan < 0 ) timespan = 2000000000;
692  dest_ctrl.setTimespan(msgID, timespan);
693  } // change log 2a, 2b
694 
695  } // for
696 
697  // establish this destination's limit for each severity:
698  for( vString::const_iterator sev_it = severities.begin()
699  ; sev_it != severities.end()
700  ; ++sev_it
701  )
702  {
703  String sevID = *sev_it;
704  ELseverityLevel severity(sevID);
705  PSet default_sev_pset
706  = getAparameter<PSet>(default_pset, sevID, empty_PSet);
707  PSet sev_pset
708  = getAparameter<PSet>(dest_pset, sevID, default_sev_pset);
709  // change log 5
710  int limit = getAparameter<int>(sev_pset, "limit", NO_VALUE_SET);
711  if ( limit == NO_VALUE_SET ) { // change log 24
712  limit = messageLoggerDefaults->sev_limit(filename,sevID);
713  }
714  if( limit != NO_VALUE_SET ) {
715  if (limit < 0) limit = 2000000000; // change log 38
716  dest_ctrl.setLimit(severity, limit );
717  }
718  int interval = getAparameter<int>(sev_pset, "reportEvery", NO_VALUE_SET);
719  if ( interval == NO_VALUE_SET ) { // change log 24
720  interval = messageLoggerDefaults->sev_reportEvery(filename,sevID);
721  }
722  if( interval != NO_VALUE_SET ) dest_ctrl.setInterval(severity, interval);
723  // change log 2
724  int timespan = getAparameter<int>(sev_pset, "timespan", NO_VALUE_SET);
725  if ( timespan == NO_VALUE_SET ) { // change log 24
726  timespan = messageLoggerDefaults->sev_timespan(filename,sevID);
727  }
728  if( timespan != NO_VALUE_SET ) {
729  if (timespan < 0) timespan = 2000000000; // change log 38
730  dest_ctrl.setTimespan(severity, timespan );
731  }
732  } // for
733 
734  // establish this destination's linebreak policy:
735  bool noLineBreaks_default
736  = getAparameter<bool> (default_pset, "noLineBreaks", false);
737  // change log 5
738  bool noLineBreaks
739  = getAparameter<bool> (dest_pset, "noLineBreaks", noLineBreaks_default);
740  if (noLineBreaks) {
741  dest_ctrl.setLineLength(32000);
742  }
743  else {
744  int lenDef = 80;
745  int lineLen_default
746  = getAparameter<int> (default_pset, "lineLength", lenDef);
747  // change log 5
748  int lineLen = getAparameter<int> (dest_pset, "lineLength", lineLen_default);
749  if (lineLen != lenDef) {
750  dest_ctrl.setLineLength(lineLen);
751  }
752  }
753 
754  // if indicated, suppress time stamps in this destination's output
755  bool suppressTime_default
756  = getAparameter<bool> (default_pset, "noTimeStamps", false);
757  bool suppressTime
758  = getAparameter<bool> (dest_pset, "noTimeStamps", suppressTime_default);
759  if (suppressTime) {
760  dest_ctrl.suppressTime();
761  }
762 
763 } // MessageLoggerScribe::configure_dest()
764 
765 void
767  ( ELdestControl & dest_ctrl )
768 {
769 
770  dest_ctrl.setLimit("*", 0 );
771  String msgID = "FwkJob";
772  int FwkJob_limit = 10000000;
773  dest_ctrl.setLimit(msgID, FwkJob_limit);
774  dest_ctrl.setLineLength(32000);
775  dest_ctrl.suppressTime();
776 
777 } // MessageLoggerScribe::configure_default_fwkJobReport()
778 
779 
780 void
782 {
783  vString empty_vString;
784  String empty_String;
785  PSet empty_PSet;
786 
787  // decide whether to configure any job reports at all // Changelog 19
788  bool jobReportExists = false;
789  bool enableJobReports = false;
790  #ifdef DEFINE_THIS_TO_MAKE_REPORTS_THE_DEFAULT
791  enableJobReports = true;
792  #endif
793  if (jobReportOption != empty_String) enableJobReports = true;
794  if (jobReportOption == "~") enableJobReports = false; // --nojobReport
795  if (!enableJobReports) return;
796 
797  if ((jobReportOption != "*") && (jobReportOption != empty_String)) {
798  const std::string::size_type npos = std::string::npos;
799  if ( jobReportOption.find('.') == npos ) {
800  jobReportOption += ".xml";
801  }
802  }
803 
804  // grab list of fwkJobReports:
806  = getAparameter<vString>(*job_pset_p, "fwkJobReports", empty_vString);
807 
808  // Use the default list of fwkJobReports if and only if the grabbed list is
809  // empty // change log 24
810  if (fwkJobReports.empty()) {
811  fwkJobReports = messageLoggerDefaults->fwkJobReports;
812  }
813 
814  // establish each fwkJobReports destination:
815  for( vString::const_iterator it = fwkJobReports.begin()
816  ; it != fwkJobReports.end()
817  ; ++it
818  )
819  {
820  String filename = *it;
821  String psetname = filename;
822 
823  // check that this destination is not just a placeholder // change log 20
824  PSet fjr_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
825  bool is_placeholder
826  = getAparameter<bool>(fjr_pset, "placeholder", false);
827  if (is_placeholder) continue;
828 
829  // Modify the file name if extension or name is explicitly specified
830  // change log 14
831  String explicit_filename
832  = getAparameter<String>(fjr_pset, "filename", empty_String);
833  if (explicit_filename != empty_String) filename = explicit_filename;
834  String explicit_extension
835  = getAparameter<String>(fjr_pset, "extension", empty_String);
836  if (explicit_extension != empty_String) {
837  if (explicit_extension[0] == '.') {
838  filename += explicit_extension;
839  } else {
840  filename = filename + "." + explicit_extension;
841  }
842  }
843 
844  // Attach a default extension of .xml if there is no extension on a file
845  std::string actual_filename = filename; // change log 4
846  const std::string::size_type npos = std::string::npos;
847  if ( filename.find('.') == npos ) {
848  actual_filename += ".xml";
849  }
850 
851  // Check that this is not a duplicate name // change log 18
852  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
853  if (clean_slate_configuration) { // change log 22
855  <<"Duplicate name for a MessageLogger Framework Job Report Destination: "
856  << actual_filename
857  << "\n";
858  } else {
859  LogWarning("duplicateDestination")
860  <<"Duplicate name for a MessageLogger Framework Job Report Destination: "
861  << actual_filename
862  << "\n" << "Only original configuration instructions are used";
863  continue;
864  }
865  }
866 
867  jobReportExists = true; // Changelog 19
868  if ( actual_filename == jobReportOption ) jobReportOption = empty_String;
869 
870  boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
871  file_ps.push_back(os_sp);
872  ELdestControl dest_ctrl;
873  dest_ctrl = admin_p->attach( ELfwkJobReport(*os_sp) );
874  stream_ps[actual_filename] = os_sp.get();
875 
876  // now configure this destination:
877  configure_dest(dest_ctrl, psetname);
878 
879  } // for [it = fwkJobReports.begin() to end()]
880 
881  // Now possibly add the file specified by --jobReport // Changelog 19
882  if (jobReportOption==empty_String) return;
883  if (jobReportExists && ( jobReportOption=="*" )) return;
884  if (jobReportOption=="*") jobReportOption = "FrameworkJobReport.xml";
885  // Check that this report is not already on order -- here the duplicate
886  // name would not be a configuration error, but we shouldn't do it twice
887  std::string actual_filename = jobReportOption;
888  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) return;
889 
890  boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
891  file_ps.push_back(os_sp);
892  ELdestControl dest_ctrl;
893  dest_ctrl = admin_p->attach( ELfwkJobReport(*os_sp) );
894  stream_ps[actual_filename] = os_sp.get();
895 
896  // now configure this destination, in the jobreport default manner:
897  configure_default_fwkJobReport (dest_ctrl);
898 
899 }
900 
901 void
903 {
904  vString empty_vString;
905  String empty_String;
906  PSet empty_PSet;
907 
908  // Initialize unversal suppression variables
909  MessageDrop::debugAlwaysSuppressed=true; // change log 37
910  MessageDrop::infoAlwaysSuppressed=true; // change log 37
911  MessageDrop::warningAlwaysSuppressed=true; // change log 37
912 
913  // grab list of destinations:
915  = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
916 
917  // Use the default list of destinations if and only if the grabbed list is
918  // empty // change log 24
919  if (destinations.empty()) {
920  destinations = messageLoggerDefaults->destinations;
921  }
922 
923  // dial down the early destination if other dest's are supplied:
924  if( ! destinations.empty() )
926 
927  // establish each destination:
928  for( vString::const_iterator it = destinations.begin()
929  ; it != destinations.end()
930  ; ++it
931  )
932  {
933  String filename = *it;
934  String psetname = filename;
935 
936  // check that this destination is not just a placeholder // change log 11
937  PSet dest_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
938  bool is_placeholder
939  = getAparameter<bool>(dest_pset, "placeholder", false);
940  if (is_placeholder) continue;
941 
942  // Modify the file name if extension or name is explicitly specified
943  // change log 14
944 
945  // Although for an ordinary destination there is no output attribute
946  // for the cfg (you can use filename instead) we provide output() for
947  // uniformity with the statistics destinations. The "right way" to
948  // work this would have been to provide a filename() method, along with
949  // an extension() method. We recognize the potential name confusion here
950  // (filename(filename))!
951 
952  // Determine the destination file name to use if no explicit filename is
953  // supplied in the cfg.
954  String filename_default
955  = getAparameter<String>(dest_pset, "output", empty_String);
956  if ( filename_default == empty_String ) {
957  filename_default = messageLoggerDefaults->output(psetname); // change log 31
958  if (filename_default == empty_String) {
959  filename_default = filename;
960  }
961  }
962 
963  String explicit_filename
964  = getAparameter<String>(dest_pset, "filename", filename_default);
965  if (explicit_filename != empty_String) filename = explicit_filename;
966  String explicit_extension
967  = getAparameter<String>(dest_pset, "extension", empty_String);
968  if (explicit_extension != empty_String) {
969  if (explicit_extension[0] == '.') {
970  filename += explicit_extension;
971  } else {
972  filename = filename + "." + explicit_extension;
973  }
974  }
975 
976  // Attach a default extension of .log if there is no extension on a file
977  // change log 18 - this had been done in concert with attaching destination
978 
979  std::string actual_filename = filename; // change log 4
980  if ( (filename != "cout") && (filename != "cerr") ) {
981  const std::string::size_type npos = std::string::npos;
982  if ( filename.find('.') == npos ) {
983  actual_filename += ".log";
984  }
985  }
986 
987  // Check that this is not a duplicate name // change log 18
988  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
989  if (clean_slate_configuration) { // change log 22
990 // throw edm::Exception ( edm::errors::Configuration )
991  LogError("duplicateDestination") // change log 35
992  <<"Duplicate name for a MessageLogger Destination: "
993  << actual_filename
994  << "\n" << "Only the first configuration instructions are used";
995  continue;
996  } else {
997  LogWarning("duplicateDestination")
998  <<"Duplicate name for a MessageLogger Destination: "
999  << actual_filename
1000  << "\n" << "Only original configuration instructions are used";
1001  continue;
1002  }
1003  }
1004 
1005  ordinary_destination_filenames.push_back(actual_filename);
1006 
1007  // attach the current destination, keeping a control handle to it:
1008  ELdestControl dest_ctrl;
1009  if( actual_filename == "cout" ) {
1010  dest_ctrl = admin_p->attach( ELoutput(std::cout) );
1011  stream_ps["cout"] = &std::cout;
1012  }
1013  else if( actual_filename == "cerr" ) {
1015  dest_ctrl = early_dest;
1016  stream_ps["cerr"] = &std::cerr;
1017  }
1018  else {
1019  boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
1020  file_ps.push_back(os_sp);
1021  dest_ctrl = admin_p->attach( ELoutput(*os_sp) );
1022  stream_ps[actual_filename] = os_sp.get();
1023  }
1024  //(*errorlog_p)( ELinfo, "added_dest") << filename << endmsg;
1025 
1026  // now configure this destination:
1027  configure_dest(dest_ctrl, psetname);
1028 
1029  } // for [it = destinations.begin() to end()]
1030 
1031 } // configure_ordinary_destinations
1032 
1033 
1034 void
1036 {
1037  vString empty_vString;
1038  String empty_String;
1039  PSet empty_PSet;
1040 
1041  // grab list of statistics destinations:
1043  = getAparameter<vString>(*job_pset_p, "statistics", empty_vString);
1044 
1045  bool no_statistics_configured = statistics.empty(); // change log 24
1046 
1047  if ( no_statistics_configured ) {
1048  // Read the list of staistics destinations from hardwired defaults,
1049  // but only if there is also no list of ordinary destinations.
1050  // (If a cfg specifies destinations, and no statistics, assume that
1051  // is what the user wants.)
1053  = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
1054  if (destinations.empty()) {
1055  statistics = messageLoggerDefaults->statistics;
1056  no_statistics_configured = statistics.empty();
1057  }
1058  }
1059 
1060  // establish each statistics destination:
1061  for( vString::const_iterator it = statistics.begin()
1062  ; it != statistics.end()
1063  ; ++it
1064  )
1065  {
1066  String statname = *it;
1067  String psetname = statname;
1068 
1069  // check that this destination is not just a placeholder // change log 20
1070  PSet stat_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
1071  bool is_placeholder
1072  = getAparameter<bool>(stat_pset, "placeholder", false);
1073  if (is_placeholder) continue;
1074 
1075  // Determine the destination file name
1076  String filename
1077  = getAparameter<String>(stat_pset, "output", empty_String);
1078  if ( filename == empty_String ) {
1079  filename = messageLoggerDefaults->output(psetname); // change log 31
1080  if (filename == empty_String) {
1081  filename = statname;
1082  }
1083  }
1084 
1085  // Modify the file name if extension or name is explicitly specified
1086  // change log 14 -- probably suspenders and a belt, because ouput option
1087  // is present, but uniformity is nice.
1088 
1089  String explicit_filename
1090  = getAparameter<String>(stat_pset, "filename", filename);
1091  if (explicit_filename != empty_String) filename = explicit_filename;
1092  String explicit_extension
1093  = getAparameter<String>(stat_pset, "extension", empty_String);
1094  if (explicit_extension != empty_String) {
1095  if (explicit_extension[0] == '.') {
1096  filename += explicit_extension;
1097  } else {
1098  filename = filename + "." + explicit_extension;
1099  }
1100  }
1101 
1102  // Attach a default extension of .log if there is no extension on a file
1103  // change log 18 - this had been done in concert with attaching destination
1104 
1105  std::string actual_filename = filename; // change log 4
1106  if ( (filename != "cout") && (filename != "cerr") ) { // change log 23
1107  const std::string::size_type npos = std::string::npos;
1108  if ( filename.find('.') == npos ) {
1109  actual_filename += ".log";
1110  }
1111  }
1112 
1113  // Check that this is not a duplicate name -
1114  // unless it is an ordinary destination (which stats can share)
1115  if ( !search_all(ordinary_destination_filenames, actual_filename) ) {
1116  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
1117  if (clean_slate_configuration) { // change log 22
1119  <<"Duplicate name for a MessageLogger Statistics Destination: "
1120  << actual_filename
1121  << "\n";
1122  } else {
1123  LogWarning("duplicateDestination")
1124  <<"Duplicate name for a MessageLogger Statistics Destination: "
1125  << actual_filename
1126  << "\n" << "Only original configuration instructions are used";
1127  continue;
1128  }
1129  }
1130  }
1131 
1132  // create (if statistics file does not match any destination file name)
1133  // or note (if statistics file matches a destination file name) the ostream.
1134  // But if no statistics destinations were provided in the config, do not
1135  // create a new destination for this hardwired statistics - only act if
1136  // it is matches a destination. (shange log 24)
1137  bool statistics_destination_is_real = !no_statistics_configured;
1138  std::ostream* os_p;
1139  if ( stream_ps.find(actual_filename) == stream_ps.end() ) {
1140  if ( actual_filename == "cout" ) {
1141  os_p = &std::cout;
1142  } else if ( actual_filename == "cerr" ) {
1143  os_p = &std::cerr;
1144  } else {
1145  boost::shared_ptr<std::ofstream> os_sp(new std::ofstream(actual_filename.c_str()));
1146  file_ps.push_back(os_sp);
1147  os_p = os_sp.get();
1148  }
1149  stream_ps[actual_filename] = os_p;
1150  } else {
1151  statistics_destination_is_real = true; // change log 24
1152  os_p = stream_ps[actual_filename];
1153  }
1154 
1155  if (statistics_destination_is_real) { // change log 24
1156  // attach the statistics destination, keeping a control handle to it:
1157  ELdestControl dest_ctrl;
1158  dest_ctrl = admin_p->attach( ELstatistics(*os_p) );
1159  statisticsDestControls.push_back(dest_ctrl);
1160  bool reset = getAparameter<bool>(stat_pset, "reset", false);
1161  statisticsResets.push_back(reset);
1162 
1163  // now configure this destination:
1164  configure_dest(dest_ctrl, psetname);
1165 
1166  // and suppress the desire to do an extra termination summary just because
1167  // of end-of-job info messages
1168  dest_ctrl.noTerminationSummary();
1169  }
1170 
1171  } // for [it = statistics.begin() to end()]
1172 
1173 } // configure_statistics
1174 
1175 void
1177 {
1178  if( ! job_pset_p )
1179  {
1180 // extern_dests.clear();
1181 // change log 12, removed by change log 13
1182  return;
1183  }
1184 
1185  for( std::vector<NamedDestination*>::const_iterator it = extern_dests.begin()
1186  ; it != extern_dests.end()
1187  ; ++it
1188  )
1189  {
1190  ELdestination * dest_p = (*it)->dest_p().get();
1191  ELdestControl dest_ctrl = admin_p->attach( *dest_p );
1192 
1193  // configure the newly-attached destination:
1194  configure_dest( dest_ctrl, (*it)->name() );
1195  delete *it; // dispose of our (copy of the) NamedDestination
1196  }
1197  extern_dests.clear();
1198 
1199 } // MessageLoggerScribe::configure_external_dests
1200 
1201 void
1203  std::vector<std::string> & cats)
1204 {
1205  const std::string::size_type npos = std::string::npos;
1207  while ( i != npos ) {
1208  std::string::size_type j = s.find('|',i);
1209  cats.push_back (s.substr(i,j-i));
1210  i = j;
1211  while ( (i != npos) && (s[i] == '|') ) ++i;
1212  // the above handles cases of || and also | at end of string
1213  }
1214  // Note: This algorithm assigns, as desired, one null category if it
1215  // encounters an empty categories string
1216 }
1217 
1218 void
1220  assert (statisticsDestControls.size() == statisticsResets.size());
1221  for (unsigned int i = 0; i != statisticsDestControls.size(); ++i) {
1222  statisticsDestControls[i].summary( );
1223  if (statisticsResets[i]) statisticsDestControls[i].wipe( );
1224  }
1225 }
1226 
1227 void
1229  triggerFJRmessageSummary(std::map<std::string, double> & sm) // ChangeLog 29
1230 {
1231  if (statisticsDestControls.empty()) {
1232  sm["NoStatisticsDestinationsConfigured"] = 0.0;
1233  } else {
1234  statisticsDestControls[0].summaryForJobReport(sm);
1235  }
1236 }
1237 
1239 
1240 
1241 } // end of namespace service
1242 } // end of namespace edm
1243 
virtual char const * what() const
Definition: Exception.cc:141
const ELcontextSupplier & getContextSupplier() const
static unsigned char messageLoggerScribeIsRunning
Definition: MessageDrop.h:109
int i
Definition: DBlmapReader.cc:9
virtual void runCommand(MessageLoggerQ::OpCode opcode, void *operand)
virtual ELdestControl & setLimit(const ELstring &s, int n)
auto_ptr< ClusterSequence > cs
MessageLoggerScribe(boost::shared_ptr< ThreadQueue > queue)
— If queue is NULL, this sets singleThread true
void configure_default_fwkJobReport(ELdestControl &dest_ctrl)
void setContext(const std::string &c)
Definition: MsgContext.h:19
virtual ELdestControl & setThreshold(const ELseverityLevel &sv)
tuple interval
Definition: MergeJob_cfg.py:20
static PFTauRenderPlugin instance
static MessageDrop * instance()
Definition: MessageDrop.cc:65
virtual ELdestControl & setTimespan(const ELstring &s, int n)
std::vector< boost::shared_ptr< std::ofstream > > file_ps
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
uint16_t size_type
static const unsigned char MLSCRIBE_RUNNING_INDICATOR
Definition: MessageDrop.h:121
boost::shared_ptr< edm::Exception > Pointer_to_new_exception_on_heap
std::vector< String > ordinary_destination_filenames
static bool debugAlwaysSuppressed
Definition: MessageDrop.h:111
virtual int setLineLength(int len)
const ELextendedID & xid() const
Definition: ErrorObj.cc:146
edm::Place_for_passing_exception_ptr epp
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
boost::shared_ptr< Pointer_to_new_exception_on_heap > Place_for_passing_exception_ptr
std::vector< NamedDestination * > extern_dests
int j
Definition: DBlmapReader.cc:9
void configure_dest(ELdestControl &dest_ctrl, String const &filename)
static void noteGroupedCategory(std::string const &cat)
void parseCategories(std::string const &s, std::vector< std::string > &cats)
virtual void noTerminationSummary()
boost::shared_ptr< ThreadQueue > m_queue
static bool warningAlwaysSuppressed
Definition: MessageDrop.h:113
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:181
std::vector< ELdestControl > statisticsDestControls
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:46
static edm::JobMode mode(std::string const &jm)
void setContextSupplier(const ELcontextSupplier &supplier)
boost::shared_ptr< PSet > job_pset_p
virtual ELdestControl & setInterval(const ELstring &s, int interval)
JobMode
Definition: JobMode.h:15
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
void triggerFJRmessageSummary(std::map< std::string, double > &sm)
tuple filename
Definition: lut2db_cfg.py:20
tuple destinations
Definition: gather_cfg.py:120
std::map< String, std::ostream * > stream_ps
tuple cout
Definition: gather_cfg.py:121
ELdestControl attach(const ELdestination &sink)
static bool infoAlwaysSuppressed
Definition: MessageDrop.h:112
void reset(double vett[256])
Definition: TPedValues.cc:11
T get(const Candidate &c)
Definition: component.h:56
ELstring context() const
Definition: ErrorObj.cc:153
value_ptr< MessageLoggerDefaults > messageLoggerDefaults