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