CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
61 {
62  thread_local static MessageDrop s_drop{};
63  return &s_drop;
64 }
65 namespace {
66  const std::string kBlankString{" "};
67 }
68 
69 namespace edm {
70 namespace messagedrop {
71 
73  public:
74  virtual ~StringProducer() {}
75  virtual std::string theContext() const = 0;
76 };
77 
79 {
80  public:
82  : name_ (&kBlankString)
83  , label_ (&kBlankString)
84  , phasePtr_ ("(Startup)")
85  , moduleID_ (std::numeric_limits<unsigned int>::max())
86  , cache_ ()
87  , idLabelMap_ ()
88  {
89  }
90 
91  virtual std::string theContext() const override {
92  if (cache_.empty()) {
93  if (moduleID_ != std::numeric_limits<unsigned int>::max()) {
94  auto nameLableIter = idLabelMap_.find(moduleID_);
95  if (nameLableIter != idLabelMap_.end()) {
96  cache_.assign(nameLableIter->second);
97  cache_.append(phasePtr_);
98  return cache_;
99  }
100  }
101  cache_.assign(*name_);
102  cache_.append(":");
103  cache_.append(*label_);
104  idLabelMap_[moduleID_] = cache_;
105  cache_.append(phasePtr_);
106  }
107  return cache_;
108  }
109  void set(std::string const & name,
110  std::string const & label,
111  unsigned int moduleID,
112  const char* phase) {
113  name_ = &name;
114  label_ = &label;
115  moduleID_ = moduleID;
116  phasePtr_ = phase;
117  cache_.clear();
118  }
119  private:
122  const char* phasePtr_;
123  unsigned int moduleID_;
125  mutable std::map<unsigned int, std::string> idLabelMap_;
126 };
127 
129  public:
131  : typePtr_("PathNotYetEstablished") // change log 4
132  , path_ (" ")
133  , cache_()
134  {
135  }
136  virtual std::string theContext() const override {
137  if ( cache_.empty() ) {
138  cache_.assign(typePtr_);
139  cache_.append(path_);
140  }
141  return cache_;
142  }
143  void set(const char* type, std::string const & pathname) {
144  typePtr_ = type;
145  path_ = pathname;
146  cache_.clear();
147  }
148  private:
149  const char* typePtr_;
152 };
153 
155  public:
157  : singlet_("(NoModuleName)")
158  {
159  }
160  virtual std::string theContext() const override {
161  return singlet_;
162  }
163  void set(const char * sing) {singlet_ = sing; }
164  private:
165  const char * singlet_;
166 };
167 
168 } // namespace messagedrop
169 
171  : runEvent("pre-events")
172  , streamID(std::numeric_limits<unsigned int>::max())
173  , debugEnabled(true)
174  , infoEnabled(true)
175  , warningEnabled(true)
176  , errorEnabled(true)
177  , spWithPhase(new messagedrop::StringProducerWithPhase)
178  , spPath (new messagedrop::StringProducerPath)
179  , spSinglet (new messagedrop::StringProducerSinglet)
180  , moduleNameProducer (spSinglet)
181 {
182 }
183 
185 {
186  delete spSinglet;
187  delete spPath;
188  delete spWithPhase;
189 }
190 
192  std::string const & label,
193  unsigned int moduleID,
194  const char* phase) {
195  spWithPhase->set(name, label, moduleID, phase);
197 }
198 
199 void MessageDrop::setPath(const char* type, std::string const & pathname) {
200  spPath->set(type, pathname);
202 }
203 
204 void MessageDrop::setSinglet(const char * sing) {
205  spSinglet->set(sing);
207 }
208 
210  return moduleNameProducer->theContext();
211 }
213  setSinglet("");
214 }
215 } // namespace edm
216 
217 
218 unsigned char MessageDrop::messageLoggerScribeIsRunning = 0;
type
Definition: HCALResponse.h:21
void set(std::string const &name, std::string const &label, unsigned int moduleID, const char *phase)
Definition: MessageDrop.cc:109
void set(const char *type, std::string const &pathname)
Definition: MessageDrop.cc:143
std::map< unsigned int, std::string > idLabelMap_
Definition: MessageDrop.cc:125
void setModuleWithPhase(std::string const &name, std::string const &label, unsigned int moduleID, const char *phase)
Definition: MessageDrop.cc:191
static MessageDrop * instance()
Definition: MessageDrop.cc:60
static std::string jobMode
Definition: MessageDrop.h:109
messagedrop::StringProducer const * moduleNameProducer
Definition: MessageDrop.h:118
void setSinglet(const char *sing)
Definition: MessageDrop.cc:204
static bool debugAlwaysSuppressed
Definition: MessageDrop.h:111
virtual std::string theContext() const override
Definition: MessageDrop.cc:136
virtual std::string theContext() const override
Definition: MessageDrop.cc:91
std::string moduleContext()
Definition: MessageDrop.cc:209
static bool warningAlwaysSuppressed
Definition: MessageDrop.h:113
messagedrop::StringProducerSinglet * spSinglet
Definition: MessageDrop.h:117
virtual std::string theContext() const override
Definition: MessageDrop.cc:160
std::string & path_
messagedrop::StringProducerWithPhase * spWithPhase
Definition: MessageDrop.h:115
virtual std::string theContext() const =0
void setPath(const char *type, std::string const &pathname)
Definition: MessageDrop.cc:199
static bool infoAlwaysSuppressed
Definition: MessageDrop.h:112
messagedrop::StringProducerPath * spPath
Definition: MessageDrop.h:116
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:137