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