CMS 3D CMS Logo

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 
191 
195 #include "FWCore/MessageLogger/interface/MessageDrop.h" // change log 37
196 #include "FWCore/MessageLogger/interface/ELseverityLevel.h" // change log 37
197 
200 
201 #include <algorithm>
202 #include <cassert>
203 #include <fstream>
204 #include <string>
205 #include <csignal>
206 
207 using std::cerr;
208 
209 namespace edm {
210 namespace service {
211 
212 
213 MessageLoggerScribe::MessageLoggerScribe(std::shared_ptr<ThreadQueue> queue)
214 : admin_p ( new ELadministrator() )
215 , early_dest( admin_p->attach(std::make_shared<ELoutput>(std::cerr, false)) )
216 , file_ps ( )
217 , job_pset_p( )
218 , clean_slate_configuration( true )
219 , active( true )
220 , singleThread (queue.get() == nullptr) // changeLog 36
221 , done (false) // changeLog 32
222 , purge_mode (false) // changeLog 32
223 , count (false) // changeLog 32
224 , m_queue(queue) // changeLog 36
225 {
226 }
227 
229 {
230  admin_p->finish();
231 }
232 
233 
234 void
236 {
237  MessageLoggerQ::OpCode opcode;
238  void * operand;
239 
241  MLSCRIBE_RUNNING_INDICATOR; // ChangeLog 30
242 // std::cerr << "MessageLoggerScribe::run(): \n";
243 // std::cerr << "messageLoggerScribeIsRunning = "
244 // << (int)MessageDrop::instance()->messageLoggerScribeIsRunning << "\n";
245 
246  do {
247  m_queue->consume(opcode, operand); // grab next work item from Q
248  // changeLog 36
249  runCommand (opcode, operand);
250  } while(! done);
251 
252 } // MessageLoggerScribe::run()
253 
254 void
256  MessageLoggerQ::OpCode opcode,
257  void * operand)
258 {
259  switch(opcode) { // interpret the work item
260  default: {
261  assert(false); // can't happen (we certainly hope!)
262  break;
263  }
265  assert( operand == nullptr );
266  done = true;
268  (unsigned char) -1; // ChangeLog 30
269  break;
270  }
272  ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
273  try {
274  if(active && !purge_mode) log (errorobj_p);
275  }
276  catch(cms::Exception& e)
277  {
278  ++count;
279  std::cerr << "MessageLoggerScribe caught " << count
280  << " cms::Exceptions, text = \n"
281  << e.what() << "\n";
282 
283  if(count > 25)
284  {
285  cerr << "MessageLogger will no longer be processing "
286  << "messages due to errors (entering purge mode).\n";
287  purge_mode = true;
288  }
289  }
290  catch(...)
291  {
292  std::cerr << "MessageLoggerScribe caught an unknown exception and "
293  << "will no longer be processing "
294  << "messages. (entering purge mode)\n";
295  purge_mode = true;
296  }
297  delete errorobj_p; // dispose of the message text
298  break;
299  }
300  case MessageLoggerQ::CONFIGURE: { // changelog 17
301  if (singleThread) {
302  job_pset_p = std::shared_ptr<PSet>(static_cast<PSet*>(operand)); // propagate_const<T> has no reset() function
304  break;
305  } else {
306  ConfigurationHandshake * h_p =
307  static_cast<ConfigurationHandshake *>(operand);
308  job_pset_p = std::shared_ptr<PSet>(static_cast<PSet*>(h_p->p)); // propagate_const<T> has no reset() function
309  std::lock_guard<std::mutex> sl(h_p->m); // get lock
310  try {
312  }
313  catch(edm::Exception& e)
314  {
316  if (!(*epp)) {
317  *epp = std::make_shared<edm::Exception>(e);
318  } else {
320  (*ep) << "\n and another exception: \n" << e.what();
321  }
322  }
323  // Note - since the configuring code has not made a new copy of the
324  // job parameter set, we must not delete job_pset_p (in contrast to
325  // the case for errorobj_p). On the other hand, if we instantiate
326  // a new edm::Exception pointed to by *epp, it is the responsibility
327  // of the MessageLoggerQ to delete it.
328  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
329  // finally, release the scoped lock by letting it go out of scope
330  break;
331  }
332  }
334  assert( operand == nullptr );
335  try {
337  }
338  catch(cms::Exception& e)
339  {
340  std::cerr << "MessageLoggerScribe caught exception "
341  << "during summarize:\n"
342  << e.what() << "\n";
343  }
344  catch(...)
345  {
346  std::cerr << "MessageLoggerScribe caught unkonwn exception type "
347  << "during summarize. (Ignored)\n";
348  }
349  break;
350  }
351  case MessageLoggerQ::JOBMODE: { // change log 24
352  std::string* jobMode_p =
353  static_cast<std::string*>(operand);
354  JobMode jm = MessageLoggerDefaults::mode(*jobMode_p);
357  // Note - since messageLoggerDefaults is a value_ptr,
358  // there is no concern about deleting here.
359  delete jobMode_p; // dispose of the message text
360  // which will have been new-ed
361  // in MessageLogger.cc (service version)
362  break;
363  }
365  assert( operand == nullptr );
366  active = false;
367  break;
368  }
369  case MessageLoggerQ::FLUSH_LOG_Q: { // changelog 26
370  if (singleThread) return;
371  ConfigurationHandshake * h_p =
372  static_cast<ConfigurationHandshake *>(operand);
373  job_pset_p = std::shared_ptr<PSet>(static_cast<PSet*>(h_p->p)); // propagate_const<T> has no reset() function
374  std::lock_guard<std::mutex> sl(h_p->m); // get lock
375  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
376  // finally, release the scoped lock by letting it go out of scope
377  break;
378  }
379  case MessageLoggerQ::GROUP_STATS: { // change log 27
380  std::string* cat_p =
381  static_cast<std::string*>(operand);
383  delete cat_p; // dispose of the message text
384  break;
385  }
386  case MessageLoggerQ::FJR_SUMMARY: { // changelog 29
387  if (singleThread) {
388  std::map<std::string, double> * smp =
389  static_cast<std::map<std::string, double> *>(operand);
391  break;
392  } else {
393  ConfigurationHandshake * h_p =
394  static_cast<ConfigurationHandshake *>(operand);
395  std::lock_guard<std::mutex> sl(h_p->m); // get lock
396  std::map<std::string, double> * smp =
397  static_cast<std::map<std::string, double> *>(h_p->p);
399  h_p->c.notify_all(); // Signal to MessageLoggerQ that we are done
400  // finally, release the scoped lock by letting it go out of scope
401  break;
402  }
403  }
404  } // switch
405 
406 } // MessageLoggerScribe::runCommand(opcode, operand)
407 
408 void MessageLoggerScribe::log ( ErrorObj * errorobj_p ) {
409  std::vector<std::string> categories;
410  parseCategories(errorobj_p->xid().id, categories);
411  for (unsigned int icat = 0; icat < categories.size(); ++icat) {
412  errorobj_p->setID(categories[icat]);
413  admin_p->log( *errorobj_p ); // route the message text
414  }
415 }
416 
417 void
419 {
420  vString empty_vString;
421  String empty_String;
422  PSet empty_PSet;
423 
424  // The following is present to test pre-configuration message handling:
425  String preconfiguration_message
426  = getAparameter<String>
427  (*job_pset_p, "generate_preconfiguration_message", empty_String);
428  if (preconfiguration_message != empty_String) {
429  // To test a preconfiguration message without first going thru the
430  // configuration we are about to do, we issue the message (so it sits
431  // on the queue), then copy the processing that the LOG_A_MESSAGE case
432  // does. We suppress the timestamp to allow for automated unit testing.
433  early_dest->suppressTime();
434  LogError ("preconfiguration") << preconfiguration_message;
435  if (!singleThread) {
436  MessageLoggerQ::OpCode opcode;
437  void * operand;
438  m_queue->consume(opcode, operand); // grab next work item from Q
439  assert (opcode == MessageLoggerQ::LOG_A_MESSAGE);
440  ErrorObj * errorobj_p = static_cast<ErrorObj *>(operand);
441  log (errorobj_p);
442  delete errorobj_p; // dispose of the message text
443  }
444  }
445 
446  if ( !stream_ps.empty() ) {
447  LogWarning ("multiLogConfig")
448  << "The message logger has been configured multiple times";
449  clean_slate_configuration = false; // Change Log 22
450  }
451  configure_ordinary_destinations(); // Change Log 16
452  configure_statistics(); // Change Log 16
453 } // MessageLoggerScribe::configure_errorlog()
454 
455 
456 
457 
458 void
459  MessageLoggerScribe::configure_dest( std::shared_ptr<ELdestination> dest_ctrl
460  , String const & filename
461  )
462 {
463  static const int NO_VALUE_SET = -45654; // change log 2
464  vString empty_vString;
465  PSet empty_PSet;
466  String empty_String;
467 
468  // Defaults: // change log 3a
469  const std::string COMMON_DEFAULT_THRESHOLD = "INFO";
470  const int COMMON_DEFAULT_LIMIT = NO_VALUE_SET;
471  const int COMMON_DEFAULT_INTERVAL = NO_VALUE_SET; // change log 6
472  const int COMMON_DEFAULT_TIMESPAN = NO_VALUE_SET;
473 
474  char const* severity_array[] = {"WARNING", "INFO", "ERROR", "DEBUG"};
475  vString const severities(severity_array+0, severity_array+4);
476 
477  // grab list of categories
479  = getAparameter<vString>(*job_pset_p, "categories", empty_vString);
480 
481  // grab list of messageIDs -- these are a synonym for categories
482  // Note -- the use of messageIDs is deprecated in favor of categories
483  {
484  vString messageIDs
485  = getAparameter<vString>(*job_pset_p, "messageIDs", empty_vString);
486 
487  // combine the lists, not caring about possible duplicates (for now)
488  copy_all( messageIDs, std::back_inserter(categories) );
489  } // no longer need messageIDs
490 
491  // grab list of hardwired categories (hardcats) -- these are to be added
492  // to the list of categories -- change log 24
493  {
494  std::vector<std::string> hardcats = messageLoggerDefaults->categories;
495  // combine the lists, not caring about possible duplicates (for now)
496  copy_all( hardcats, std::back_inserter(categories) );
497  } // no longer need hardcats
498 
499  // grab default threshold common to all destinations
500  String default_threshold
501  = getAparameter<String>(*job_pset_p, "threshold", empty_String);
502  // change log 3a
503  // change log 24
504 
505  // grab default limit/interval/timespan common to all destinations/categories:
506  PSet default_pset
507  = getAparameter<PSet>(*job_pset_p, "default", empty_PSet);
508  int default_limit
509  = getAparameter<int>(default_pset, "limit", COMMON_DEFAULT_LIMIT);
510  int default_interval
511  = getAparameter<int>(default_pset, "reportEvery", COMMON_DEFAULT_INTERVAL);
512  // change log 6, 10
513  int default_timespan
514  = getAparameter<int>(default_pset, "timespan", COMMON_DEFAULT_TIMESPAN);
515  // change log 2a
516  // change log 3a
517  String default_pset_threshold
518  = getAparameter<String>(default_pset, "threshold", default_threshold);
519  // change log 34
520 
521  // grab all of this destination's parameters:
522  PSet dest_pset = getAparameter<PSet>(*job_pset_p, filename, empty_PSet);
523 
524  // See if this is just a placeholder // change log 9
525  bool is_placeholder
526  = getAparameter<bool>(dest_pset, "placeholder", false);
527  if (is_placeholder) return;
528 
529  // grab this destination's default limit/interval/timespan:
530  PSet dest_default_pset
531  = getAparameter<PSet>(dest_pset, "default", empty_PSet);
532  int dest_default_limit
533  = getAparameter<int>(dest_default_pset, "limit", default_limit);
534  int dest_default_interval
535  = getAparameter<int>(dest_default_pset, "reportEvery", default_interval);
536  // change log 6
537  int dest_default_timespan
538  = getAparameter<int>(dest_default_pset, "timespan", default_timespan);
539  // change log 1a
540  if ( dest_default_limit != NO_VALUE_SET ) {
541  if ( dest_default_limit < 0 ) dest_default_limit = 2000000000;
542  dest_ctrl->setLimit("*", dest_default_limit );
543  } // change log 1b, 2a, 2b
544  if ( dest_default_interval != NO_VALUE_SET ) { // change log 6
545  dest_ctrl->setInterval("*", dest_default_interval );
546  }
547  if ( dest_default_timespan != NO_VALUE_SET ) {
548  if ( dest_default_timespan < 0 ) dest_default_timespan = 2000000000;
549  dest_ctrl->setTimespan("*", dest_default_timespan );
550  } // change log 1b, 2a, 2b
551 
552  // establish this destination's threshold:
553  String dest_threshold
554  = getAparameter<String>(dest_pset, "threshold", default_threshold);
555  if (dest_threshold == empty_String) {
556  dest_threshold = default_threshold;
557  }
558  if (dest_threshold == empty_String) { // change log 34
559  dest_threshold = default_pset_threshold;
560  }
561  if (dest_threshold == empty_String) {
562  dest_threshold = messageLoggerDefaults->threshold(filename);
563  }
564  if (dest_threshold == empty_String) dest_threshold = COMMON_DEFAULT_THRESHOLD;
565  ELseverityLevel threshold_sev(dest_threshold);
566  dest_ctrl->setThreshold(threshold_sev);
567  // change log 37
568  if (threshold_sev <= ELseverityLevel::ELsev_success)
570  if (threshold_sev <= ELseverityLevel::ELsev_info)
572  if (threshold_sev <= ELseverityLevel::ELsev_warning)
574 
575  // establish this destination's limit/interval/timespan for each category:
576  for( vString::const_iterator id_it = categories.begin()
577  ; id_it != categories.end()
578  ; ++id_it
579  )
580  {
581  String msgID = *id_it;
582  PSet default_category_pset
583  = getAparameter<PSet>(default_pset, msgID, empty_PSet); // change log 5
584  PSet category_pset
585  = getAparameter<PSet>(dest_pset, msgID, default_category_pset);
586 
587  int category_default_limit
588  = getAparameter<int>(default_category_pset, "limit", NO_VALUE_SET);
589  int limit
590  = getAparameter<int>(category_pset, "limit", category_default_limit);
591  if (limit == NO_VALUE_SET) limit = dest_default_limit;
592  // change log 7
593  int category_default_interval
594  = getAparameter<int>(default_category_pset, "reportEvery", NO_VALUE_SET);
595  int interval
596  = getAparameter<int>(category_pset, "reportEvery",category_default_interval);
597  if (interval == NO_VALUE_SET) interval = dest_default_interval;
598  // change log 6 and then 7
599  int category_default_timespan
600  = getAparameter<int>(default_category_pset, "timespan", NO_VALUE_SET);
601  int timespan
602  = getAparameter<int>(category_pset, "timespan", category_default_timespan);
603  if (timespan == NO_VALUE_SET) timespan = dest_default_timespan;
604  // change log 7
605 
606  const std::string& category = msgID;
607  if ( limit == NO_VALUE_SET ) { // change log 24
608  limit = messageLoggerDefaults->limit(filename,category);
609  }
610  if ( interval == NO_VALUE_SET ) { // change log 24
611  interval = messageLoggerDefaults->reportEvery(filename,category);
612  }
613  if ( timespan == NO_VALUE_SET ) { // change log 24
614  timespan = messageLoggerDefaults->timespan(filename,category);
615  }
616 
617  if( limit != NO_VALUE_SET ) {
618  if ( limit < 0 ) limit = 2000000000;
619  dest_ctrl->setLimit(msgID, limit);
620  } // change log 2a, 2b
621  if( interval != NO_VALUE_SET ) {
622  dest_ctrl->setInterval(msgID, interval);
623  } // change log 6
624  if( timespan != NO_VALUE_SET ) {
625  if ( timespan < 0 ) timespan = 2000000000;
626  dest_ctrl->setTimespan(msgID, timespan);
627  } // change log 2a, 2b
628 
629  } // for
630 
631  // establish this destination's limit for each severity:
632  for( vString::const_iterator sev_it = severities.begin()
633  ; sev_it != severities.end()
634  ; ++sev_it
635  )
636  {
637  String sevID = *sev_it;
638  ELseverityLevel severity(sevID);
639  PSet default_sev_pset
640  = getAparameter<PSet>(default_pset, sevID, empty_PSet);
641  PSet sev_pset
642  = getAparameter<PSet>(dest_pset, sevID, default_sev_pset);
643  // change log 5
644  int limit = getAparameter<int>(sev_pset, "limit", NO_VALUE_SET);
645  if ( limit == NO_VALUE_SET ) { // change log 24
646  limit = messageLoggerDefaults->sev_limit(filename,sevID);
647  }
648  if( limit != NO_VALUE_SET ) {
649  if (limit < 0) limit = 2000000000; // change log 38
650  dest_ctrl->setLimit(severity, limit );
651  }
652  int interval = getAparameter<int>(sev_pset, "reportEvery", NO_VALUE_SET);
653  if ( interval == NO_VALUE_SET ) { // change log 24
654  interval = messageLoggerDefaults->sev_reportEvery(filename,sevID);
655  }
656  if( interval != NO_VALUE_SET ) dest_ctrl->setInterval(severity, interval);
657  // change log 2
658  int timespan = getAparameter<int>(sev_pset, "timespan", NO_VALUE_SET);
659  if ( timespan == NO_VALUE_SET ) { // change log 24
660  timespan = messageLoggerDefaults->sev_timespan(filename,sevID);
661  }
662  if( timespan != NO_VALUE_SET ) {
663  if (timespan < 0) timespan = 2000000000; // change log 38
664  dest_ctrl->setTimespan(severity, timespan );
665  }
666  } // for
667 
668  // establish this destination's linebreak policy:
669  bool noLineBreaks_default
670  = getAparameter<bool> (default_pset, "noLineBreaks", false);
671  // change log 5
672  bool noLineBreaks
673  = getAparameter<bool> (dest_pset, "noLineBreaks", noLineBreaks_default);
674  if (noLineBreaks) {
675  dest_ctrl->setLineLength(32000);
676  }
677  else {
678  int lenDef = 80;
679  int lineLen_default
680  = getAparameter<int> (default_pset, "lineLength", lenDef);
681  // change log 5
682  int lineLen = getAparameter<int> (dest_pset, "lineLength", lineLen_default);
683  if (lineLen != lenDef) {
684  dest_ctrl->setLineLength(lineLen);
685  }
686  }
687 
688  // if indicated, suppress time stamps in this destination's output
689  bool suppressTime_default
690  = getAparameter<bool> (default_pset, "noTimeStamps", false);
691  bool suppressTime
692  = getAparameter<bool> (dest_pset, "noTimeStamps", suppressTime_default);
693  if (suppressTime) {
694  dest_ctrl->suppressTime();
695  }
696 
697 } // MessageLoggerScribe::configure_dest()
698 
699 void
701 {
702  vString empty_vString;
703  String empty_String;
704  PSet empty_PSet;
705 
706  // Initialize unversal suppression variables
707  MessageDrop::debugAlwaysSuppressed=true; // change log 37
708  MessageDrop::infoAlwaysSuppressed=true; // change log 37
709  MessageDrop::warningAlwaysSuppressed=true; // change log 37
710 
711  // grab list of destinations:
713  = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
714 
715  // Use the default list of destinations if and only if the grabbed list is
716  // empty // change log 24
717  if (destinations.empty()) {
718  destinations = messageLoggerDefaults->destinations;
719  }
720 
721  // dial down the early destination if other dest's are supplied:
722  if( ! destinations.empty() )
723  early_dest->setThreshold(ELhighestSeverity);
724 
725  // establish each destination:
726  for( vString::const_iterator it = destinations.begin()
727  ; it != destinations.end()
728  ; ++it
729  )
730  {
731  String filename = *it;
732  String psetname = filename;
733 
734  // check that this destination is not just a placeholder // change log 11
735  PSet dest_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
736  bool is_placeholder
737  = getAparameter<bool>(dest_pset, "placeholder", false);
738  if (is_placeholder) continue;
739 
740  // Modify the file name if extension or name is explicitly specified
741  // change log 14
742 
743  // Although for an ordinary destination there is no output attribute
744  // for the cfg (you can use filename instead) we provide output() for
745  // uniformity with the statistics destinations. The "right way" to
746  // work this would have been to provide a filename() method, along with
747  // an extension() method. We recognize the potential name confusion here
748  // (filename(filename))!
749 
750  // Determine the destination file name to use if no explicit filename is
751  // supplied in the cfg.
752  String filename_default
753  = getAparameter<String>(dest_pset, "output", empty_String);
754  if ( filename_default == empty_String ) {
755  filename_default = messageLoggerDefaults->output(psetname); // change log 31
756  if (filename_default == empty_String) {
757  filename_default = filename;
758  }
759  }
760 
761  String explicit_filename
762  = getAparameter<String>(dest_pset, "filename", filename_default);
763  if (explicit_filename != empty_String) filename = explicit_filename;
764  String explicit_extension
765  = getAparameter<String>(dest_pset, "extension", empty_String);
766  if (explicit_extension != empty_String) {
767  if (explicit_extension[0] == '.') {
768  filename += explicit_extension;
769  } else {
770  filename = filename + "." + explicit_extension;
771  }
772  }
773 
774  // Attach a default extension of .log if there is no extension on a file
775  // change log 18 - this had been done in concert with attaching destination
776 
777  std::string actual_filename = filename; // change log 4
778  if ( (filename != "cout") && (filename != "cerr") ) {
779  const std::string::size_type npos = std::string::npos;
780  if ( filename.find('.') == npos ) {
781  actual_filename += ".log";
782  }
783  }
784 
785  // Check that this is not a duplicate name // change log 18
786  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
787  if (clean_slate_configuration) { // change log 22
788 // throw edm::Exception ( edm::errors::Configuration )
789  LogError("duplicateDestination") // change log 35
790  <<"Duplicate name for a MessageLogger Destination: "
791  << actual_filename
792  << "\n" << "Only the first configuration instructions are used";
793  continue;
794  } else {
795  LogWarning("duplicateDestination")
796  <<"Duplicate name for a MessageLogger Destination: "
797  << actual_filename
798  << "\n" << "Only original configuration instructions are used";
799  continue;
800  }
801  }
802 
803  ordinary_destination_filenames.push_back(actual_filename);
804 
805  // attach the current destination, keeping a control handle to it:
806  std::shared_ptr<ELdestination> dest_ctrl;
807  if( actual_filename == "cout" ) {
808  dest_ctrl = std::make_shared<ELoutput>(std::cout);
809  admin_p->attach( dest_ctrl );
810  stream_ps["cout"] = &std::cout;
811  }
812  else if( actual_filename == "cerr" ) {
813  early_dest->setThreshold(ELzeroSeverity);
814  dest_ctrl = early_dest;
815  stream_ps["cerr"] = &std::cerr;
816  }
817  else {
818  auto os_sp = std::make_shared<std::ofstream>(actual_filename.c_str());
819  file_ps.push_back(os_sp);
820  dest_ctrl = std::make_shared<ELoutput>(*os_sp);
821  admin_p->attach( dest_ctrl );
822  stream_ps[actual_filename] = os_sp.get();
823  }
824 
825  // now configure this destination:
826  configure_dest(dest_ctrl, psetname);
827 
828  } // for [it = destinations.begin() to end()]
829 
830 } // configure_ordinary_destinations
831 
832 
833 void
835 {
836  vString empty_vString;
837  String empty_String;
838  PSet empty_PSet;
839 
840  // grab list of statistics destinations:
842  = getAparameter<vString>(*job_pset_p, "statistics", empty_vString);
843 
844  bool no_statistics_configured = statistics.empty(); // change log 24
845 
846  if ( no_statistics_configured ) {
847  // Read the list of staistics destinations from hardwired defaults,
848  // but only if there is also no list of ordinary destinations.
849  // (If a cfg specifies destinations, and no statistics, assume that
850  // is what the user wants.)
852  = getAparameter<vString>(*job_pset_p, "destinations", empty_vString);
853  if (destinations.empty()) {
854  statistics = messageLoggerDefaults->statistics;
855  no_statistics_configured = statistics.empty();
856  }
857  }
858 
859  // establish each statistics destination:
860  for( vString::const_iterator it = statistics.begin()
861  ; it != statistics.end()
862  ; ++it
863  )
864  {
865  String statname = *it;
866  const String& psetname = statname;
867 
868  // check that this destination is not just a placeholder // change log 20
869  PSet stat_pset = getAparameter<PSet>(*job_pset_p, psetname, empty_PSet);
870  bool is_placeholder
871  = getAparameter<bool>(stat_pset, "placeholder", false);
872  if (is_placeholder) continue;
873 
874  // Determine the destination file name
876  = getAparameter<String>(stat_pset, "output", empty_String);
877  if ( filename == empty_String ) {
878  filename = messageLoggerDefaults->output(psetname); // change log 31
879  if (filename == empty_String) {
880  filename = statname;
881  }
882  }
883 
884  // Modify the file name if extension or name is explicitly specified
885  // change log 14 -- probably suspenders and a belt, because ouput option
886  // is present, but uniformity is nice.
887 
888  String explicit_filename
889  = getAparameter<String>(stat_pset, "filename", filename);
890  if (explicit_filename != empty_String) filename = explicit_filename;
891  String explicit_extension
892  = getAparameter<String>(stat_pset, "extension", empty_String);
893  if (explicit_extension != empty_String) {
894  if (explicit_extension[0] == '.') {
895  filename += explicit_extension;
896  } else {
897  filename = filename + "." + explicit_extension;
898  }
899  }
900 
901  // Attach a default extension of .log if there is no extension on a file
902  // change log 18 - this had been done in concert with attaching destination
903 
904  std::string actual_filename = filename; // change log 4
905  if ( (filename != "cout") && (filename != "cerr") ) { // change log 23
906  const std::string::size_type npos = std::string::npos;
907  if ( filename.find('.') == npos ) {
908  actual_filename += ".log";
909  }
910  }
911 
912  // Check that this is not a duplicate name -
913  // unless it is an ordinary destination (which stats can share)
914  if ( !search_all(ordinary_destination_filenames, actual_filename) ) {
915  if ( stream_ps.find(actual_filename)!=stream_ps.end() ) {
916  if (clean_slate_configuration) { // change log 22
918  <<"Duplicate name for a MessageLogger Statistics Destination: "
919  << actual_filename
920  << "\n";
921  } else {
922  LogWarning("duplicateDestination")
923  <<"Duplicate name for a MessageLogger Statistics Destination: "
924  << actual_filename
925  << "\n" << "Only original configuration instructions are used";
926  continue;
927  }
928  }
929  }
930 
931  // create (if statistics file does not match any destination file name)
932  // or note (if statistics file matches a destination file name) the ostream.
933  // But if no statistics destinations were provided in the config, do not
934  // create a new destination for this hardwired statistics - only act if
935  // it is matches a destination. (shange log 24)
936  bool statistics_destination_is_real = !no_statistics_configured;
937  std::ostream* os_p;
938  if ( stream_ps.find(actual_filename) == stream_ps.end() ) {
939  if ( actual_filename == "cout" ) {
940  os_p = &std::cout;
941  } else if ( actual_filename == "cerr" ) {
942  os_p = &std::cerr;
943  } else {
944  auto os_sp = std::make_shared<std::ofstream>(actual_filename.c_str());
945  file_ps.push_back(os_sp);
946  os_p = os_sp.get();
947  }
948  stream_ps[actual_filename] = os_p;
949  } else {
950  statistics_destination_is_real = true; // change log 24
951  os_p = stream_ps[actual_filename];
952  }
953 
954  if (statistics_destination_is_real) { // change log 24
955  // attach the statistics destination, keeping a control handle to it:
956  auto stat = std::make_shared<ELstatistics>(*os_p);
957  admin_p->attach( stat );
958  statisticsDestControls.push_back(stat);
959  bool reset = getAparameter<bool>(stat_pset, "reset", false);
960  statisticsResets.push_back(reset);
961 
962  // now configure this destination:
963  configure_dest(stat, psetname);
964 
965  // and suppress the desire to do an extra termination summary just because
966  // of end-of-job info messages
967  stat->noTerminationSummary();
968  }
969 
970  } // for [it = statistics.begin() to end()]
971 
972 } // configure_statistics
973 
974 void
976  std::vector<std::string> & cats)
977 {
978  const std::string::size_type npos = std::string::npos;
980  while ( i != npos ) {
981  std::string::size_type j = s.find('|',i);
982  cats.push_back (s.substr(i,j-i));
983  i = j;
984  while ( (i != npos) && (s[i] == '|') ) ++i;
985  // the above handles cases of || and also | at end of string
986  }
987  // Note: This algorithm assigns, as desired, one null category if it
988  // encounters an empty categories string
989 }
990 
991 void
993  assert (statisticsDestControls.size() == statisticsResets.size());
994  for (unsigned int i = 0; i != statisticsDestControls.size(); ++i) {
995  statisticsDestControls[i]->summary( 0 );
996  if (statisticsResets[i]) statisticsDestControls[i]->wipe( );
997  }
998 }
999 
1000 void
1002  triggerFJRmessageSummary(std::map<std::string, double> & sm) // ChangeLog 29
1003 {
1004  if (statisticsDestControls.empty()) {
1005  sm["NoStatisticsDestinationsConfigured"] = 0.0;
1006  } else {
1007  statisticsDestControls[0]->summaryForJobReport(sm);
1008  }
1009 }
1010 
1011 
1012 
1013 } // end of namespace service
1014 } // end of namespace edm
1015 
static unsigned char messageLoggerScribeIsRunning
Definition: MessageDrop.h:111
std::map< String, edm::propagate_const< std::ostream * > > stream_ps
static MessageDrop * instance()
Definition: MessageDrop.cc:60
char const * what() const override
Definition: Exception.cc:141
#define nullptr
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
uint16_t size_type
static const unsigned char MLSCRIBE_RUNNING_INDICATOR
Definition: MessageDrop.h:122
std::vector< String > ordinary_destination_filenames
static bool debugAlwaysSuppressed
Definition: MessageDrop.h:112
void runCommand(MessageLoggerQ::OpCode opcode, void *operand) override
edm::propagate_const< std::shared_ptr< ELadministrator > > admin_p
const ELextendedID & xid() const
Definition: ErrorObj.cc:148
edm::Place_for_passing_exception_ptr epp
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
void configure_dest(std::shared_ptr< ELdestination > dest_ctrl, String const &filename)
T const & get(Event const &event, InputTag const &tag)
Definition: Event.h:690
std::vector< std::shared_ptr< ELstatistics > > statisticsDestControls
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > file_ps
std::shared_ptr< ELdestination > early_dest
static void noteGroupedCategory(std::string const &cat)
void parseCategories(std::string const &s, std::vector< std::string > &cats)
static bool warningAlwaysSuppressed
Definition: MessageDrop.h:114
edm::propagate_const< std::shared_ptr< PSet > > job_pset_p
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:183
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:46
static edm::JobMode mode(std::string const &jm)
MessageLoggerScribe(std::shared_ptr< ThreadQueue > queue)
— If queue is NULL, this sets singleThread true
HLT enums.
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)
edm::propagate_const< std::shared_ptr< ThreadQueue > > m_queue
static bool infoAlwaysSuppressed
Definition: MessageDrop.h:113
void reset(double vett[256])
Definition: TPedValues.cc:11
std::shared_ptr< Pointer_to_new_exception_on_heap > Place_for_passing_exception_ptr
value_ptr< MessageLoggerDefaults > messageLoggerDefaults
std::shared_ptr< edm::Exception > Pointer_to_new_exception_on_heap