CMS 3D CMS Logo

MessageDrop.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MessageLogger
4 // Class : MessageDrop
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: M. Fischler and Jim Kowalkowsi
10 // Created: Tues Feb 14 16:38:19 CST 2006
11 //
12 
13 // system include files
14 #include <cstring>
15 #include <limits>
16 
17 // user include files
19 
20 // Change Log
21 //
22 // 1 12/13/07 mf the static drops had been file-global level; moved it
23 // into the instance() method to cure a 24-byte memory
24 // leak reported by valgrind. Suggested by MP.
25 //
26 // 2 9/23/10 mf Variables supporting situations where no thresholds are
27 // low enough to react to LogDebug (or info, or warning)
28 //
29 // 3 11/2/10 mf, crj Prepare moduleContext method:
30 // see MessageServer/src/MessageLogger.cc change 17.
31 // Change is extensive, involving StringProducer and
32 // its derivative classes.
33 //
34 // 4 11/29/10 mf Intitalize all local string-holders in the various
35 // string producers.
36 //
37 // 5 mf 11/30/10 Snapshot method to prepare for invalidation of the
38 // pointers used to hold module context. Supports
39 // surviving throws that cause objects to go out of scope.
40 //
41 // 6 mf 12/7/10 Fix in snapshot method to avoid strncpy from
42 // a string to the identical address, which valgrind
43 // reports as an overlap problem.
44 //
45 // 7 fwyzard 7/6/11 Add support for discarding LogError-level messages
46 // on a per-module basis (needed at HLT)
47 
48 using namespace edm;
49 
50 // The following are false at initialization (in case configure is not done)
51 // and are set true at the start of configure_ordinary_destinations,
52 // but are set false once a destination is thresholded to react to the
53 // corresponding severity:
54 bool MessageDrop::debugAlwaysSuppressed = false; // change log 2
55 bool MessageDrop::infoAlwaysSuppressed = false; // change log 2
56 bool MessageDrop::warningAlwaysSuppressed = false; // change log 2
58 
60  thread_local static MessageDrop s_drop{};
61  return &s_drop;
62 }
63 namespace {
64  const std::string kBlankString{" "};
65 }
66 
67 namespace edm {
68  namespace messagedrop {
69 
71  public:
72  virtual ~StringProducer() {}
73  virtual std::string theContext() const = 0;
74  };
75 
77  public:
79  : name_(&kBlankString),
80  label_(&kBlankString),
81  phasePtr_("(Startup)"),
82  moduleID_(std::numeric_limits<unsigned int>::max()),
83  cache_(),
84  idLabelMap_() {}
85 
86  std::string theContext() const override {
87  if (cache_.empty()) {
88  if (moduleID_ != std::numeric_limits<unsigned int>::max()) {
89  auto nameLableIter = idLabelMap_.find(moduleID_);
90  if (nameLableIter != idLabelMap_.end()) {
91  cache_.assign(nameLableIter->second);
92  cache_.append(phasePtr_);
93  return cache_;
94  }
95  }
96  cache_.assign(*name_);
97  cache_.append(":");
98  cache_.append(*label_);
99  idLabelMap_[moduleID_] = cache_;
100  cache_.append(phasePtr_);
101  }
102  return cache_;
103  }
104  void set(std::string const& name, std::string const& label, unsigned int moduleID, const char* phase) {
105  name_ = &name;
106  label_ = &label;
107  moduleID_ = moduleID;
108  phasePtr_ = phase;
109  cache_.clear();
110  }
111 
112  private:
115  const char* phasePtr_;
116  unsigned int moduleID_;
118  mutable std::map<unsigned int, std::string> idLabelMap_;
119  };
120 
122  public:
124  : typePtr_("PathNotYetEstablished") // change log 4
125  ,
126  path_(" "),
127  cache_() {}
128  std::string theContext() const override {
129  if (cache_.empty()) {
130  cache_.assign(typePtr_);
131  cache_.append(path_);
132  }
133  return cache_;
134  }
135  void set(const char* type, std::string const& pathname) {
136  typePtr_ = type;
137  path_ = pathname;
138  cache_.clear();
139  }
140 
141  private:
142  const char* typePtr_;
145  };
146 
148  public:
149  StringProducerSinglet() : singlet_("(NoModuleName)") {}
150  std::string theContext() const override { return singlet_; }
151  void set(const char* sing) { singlet_ = sing; }
152 
153  private:
154  const char* singlet_;
155  };
156 
157  } // namespace messagedrop
158 
160  : runEvent("pre-events"),
161  streamID(std::numeric_limits<unsigned int>::max()),
163  infoEnabled(true),
166  spWithPhase(new messagedrop::StringProducerWithPhase),
167  spPath(new messagedrop::StringProducerPath),
168  spSinglet(new messagedrop::StringProducerSinglet),
170 
172  delete spSinglet.get();
173  delete spPath.get();
174  delete spWithPhase.get();
175  }
176 
178  std::string const& label,
179  unsigned int moduleID,
180  const char* phase) {
181  spWithPhase->set(name, label, moduleID, phase);
183  }
184 
185  void MessageDrop::setPath(const char* type, std::string const& pathname) {
186  spPath->set(type, pathname);
188  }
189 
190  void MessageDrop::setSinglet(const char* sing) {
191  spSinglet->set(sing);
193  }
194 
197 } // namespace edm
198 
type
Definition: HCALResponse.h:21
static unsigned char messageLoggerScribeIsRunning
Definition: MessageDrop.h:109
std::string theContext() const override
Definition: MessageDrop.cc:128
std::map< unsigned int, std::string > idLabelMap_
Definition: MessageDrop.cc:118
void setModuleWithPhase(std::string const &name, std::string const &label, unsigned int moduleID, const char *phase)
Definition: MessageDrop.cc:177
static MessageDrop * instance()
Definition: MessageDrop.cc:59
static std::string jobMode
Definition: MessageDrop.h:108
messagedrop::StringProducer const * moduleNameProducer
Definition: MessageDrop.h:117
void setSinglet(const char *sing)
Definition: MessageDrop.cc:190
static bool debugAlwaysSuppressed
Definition: MessageDrop.h:110
char const * label
edm::propagate_const< messagedrop::StringProducerWithPhase * > spWithPhase
Definition: MessageDrop.h:114
edm::propagate_const< messagedrop::StringProducerSinglet * > spSinglet
Definition: MessageDrop.h:116
unsigned int streamID
Definition: MessageDrop.h:102
std::string theContext() const override
Definition: MessageDrop.cc:86
std::string moduleContext()
Definition: MessageDrop.cc:195
element_type const * get() const
std::string theContext() const override
Definition: MessageDrop.cc:150
static bool warningAlwaysSuppressed
Definition: MessageDrop.h:112
edm::propagate_const< messagedrop::StringProducerPath * > spPath
Definition: MessageDrop.h:115
std::string & path_
HLT enums.
std::string_view runEvent
Definition: MessageDrop.h:101
void setPath(const char *type, std::string const &pathname)
Definition: MessageDrop.cc:185
static bool infoAlwaysSuppressed
Definition: MessageDrop.h:111
virtual std::string theContext() const =0
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118