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 // $Id: MessageDrop.cc,v 1.14 2011/10/13 22:40:28 wmtan Exp $
12 //
13 
14 // system include files
15 #include "boost/thread/tss.hpp"
16 #include <cstring>
17 
18 // 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 
53 bool MessageDrop::infoEnabled=true;
56 // The following are false at initialization (in case configure is not done)
57 // and are set true at the start of configure_ordinary_destinations,
58 // but are set false once a destination is thresholded to react to the
59 // corresponding severity:
60 bool MessageDrop::debugAlwaysSuppressed=false; // change log 2
61 bool MessageDrop::infoAlwaysSuppressed=false; // change log 2
62 bool MessageDrop::warningAlwaysSuppressed=false; // change log 2
63 
66 {
67  static boost::thread_specific_ptr<MessageDrop> drops;
68  MessageDrop* drop = drops.get();
69  if(drop==0) {
70  drops.reset(new MessageDrop);
71  drop=drops.get();
72  }
73  return drop;
74 }
75 
76 namespace edm {
77 namespace messagedrop {
78 
80  public:
81  virtual ~StringProducer() {}
82  virtual std::string theContext() const = 0;
83  virtual void snapshot() = 0;
84 };
85 
87 {
88  typedef std::map<const void*, std::string>::const_iterator NLMiter;
89  public:
91  : name_initial_value_ (" ") // change log 4
92  , label_initial_value_ (" ")
93  , name_ (&name_initial_value_)
94  , label_ (&label_initial_value_)
95  , phasePtr_ ("(Startup)")
96  , moduleID_ (0)
97  , cache_ ()
98  , nameLabelMap_ ()
99  , snapshot_name_ ()
100  , snapshot_label_ ()
101  , snapshot_phase_ () {
102  memset(snapshot_phase_, '\0', sizeof(snapshot_phase_));
103  }
104 
105  virtual std::string theContext() const {
106  if (cache_.empty()) {
107  if (moduleID_ != 0) {
108  NLMiter nameLableIter = nameLabelMap_.find(moduleID_);
109  if (nameLableIter != nameLabelMap_.end()) {
110  cache_.assign(nameLableIter->second);
111  cache_.append(phasePtr_);
112  return cache_;
113  }
114  }
115  cache_.assign(*name_);
116  cache_.append(":");
117  cache_.append(*label_);
118  nameLabelMap_[moduleID_] = cache_;
119  cache_.append(phasePtr_);
120  }
121  return cache_;
122  }
123  void set(std::string const & name,
124  std::string const & label,
125  const void * moduleID,
126  const char* phase) {
127  name_ = &name;
128  label_ = &label;
129  moduleID_ = moduleID;
130  phasePtr_ = phase;
131  cache_.clear();
132  }
133  virtual void snapshot() // change log 5
134  {
135  snapshot_name_ = *name_;
136  name_ = &snapshot_name_;
137  snapshot_label_ = *label_;
138  label_ = &snapshot_label_;
139  if ( snapshot_phase_ != phasePtr_ ) { // change log 6
140  std::strncpy (snapshot_phase_,phasePtr_,PHASE_MAX_LENGTH);
141  }
142  snapshot_phase_[PHASE_MAX_LENGTH] = 0;
143  phasePtr_ = snapshot_phase_;
144  }
145  private:
146  static const int PHASE_MAX_LENGTH = 32;
147  std::string const name_initial_value_;
148  std::string const label_initial_value_;
149  std::string const * name_;
150  std::string const * label_;
151  const char* phasePtr_;
152  const void * moduleID_;
153  mutable std::string cache_;
154  mutable std::map<const void*, std::string> nameLabelMap_;
155  std::string snapshot_name_;
156  std::string snapshot_label_;
157  char snapshot_phase_[PHASE_MAX_LENGTH+1];
158 };
159 
161  public:
163  : typePtr_("PathNotYetEstablished") // change log 4
164  , path_ (" ")
165  , cache_()
166  , snapshot_type_() {
167  memset(snapshot_type_, '\0', sizeof(snapshot_type_));
168  }
169  virtual std::string theContext() const {
170  if ( cache_.empty() ) {
171  cache_.assign(typePtr_);
172  cache_.append(path_);
173  }
174  return cache_;
175  }
176  void set(const char* type, std::string const & pathname) {
177  typePtr_ = type;
178  path_ = pathname;
179  cache_.clear();
180  }
181  virtual void snapshot() // change log 5
182  {
183  if ( snapshot_type_ != typePtr_ ) { // change log 6
184  std::strncpy (snapshot_type_,typePtr_,TYPE_MAX_LENGTH);
185  }
186  snapshot_type_[TYPE_MAX_LENGTH] = 0;
187  typePtr_ = snapshot_type_;
188  }
189  private:
190  static const int TYPE_MAX_LENGTH = 32;
191  const char* typePtr_;
192  std::string path_;
193  mutable std::string cache_;
194  char snapshot_type_[TYPE_MAX_LENGTH+1];
195 };
196 
198  public:
200  : singlet_("(NoModuleName)")
201  , snapshot_singlet_() {
202  memset(snapshot_singlet_, '\0', sizeof(snapshot_singlet_));
203  }
204  virtual std::string theContext() const {
205  return singlet_;
206  }
207  void set(const char * sing) {singlet_ = sing; }
208  virtual void snapshot()
209  {
210  if ( snapshot_singlet_ != singlet_ ) { // change log 6
211  std::strncpy (snapshot_singlet_,singlet_,SINGLET_MAX_LENGTH);
212  }
213  snapshot_singlet_[SINGLET_MAX_LENGTH] = 0;
214  singlet_ = snapshot_singlet_;
215  }
216  private:
217  static const int SINGLET_MAX_LENGTH = 32;
218  const char * singlet_;
219  char snapshot_singlet_[SINGLET_MAX_LENGTH+1];
220 };
221 
222 } // namespace messagedrop
223 
225  : moduleName ("")
226  , runEvent("pre-events")
227  , jobreport_name()
228  , jobMode("")
229  , spWithPhase(new messagedrop::StringProducerWithPhase)
230  , spPath (new messagedrop::StringProducerPath)
231  , spSinglet (new messagedrop::StringProducerSinglet)
232  , moduleNameProducer (spSinglet)
233 {
234 }
235 
237 {
238  delete spSinglet;
239  delete spPath;
240  delete spWithPhase;
241 }
242 
243 void MessageDrop::setModuleWithPhase(std::string const & name,
244  std::string const & label,
245  const void * moduleID,
246  const char* phase) {
247  spWithPhase->set(name, label, moduleID, phase);
249 }
250 
251 void MessageDrop::setPath(const char* type, std::string const & pathname) {
252  spPath->set(type, pathname);
254 }
255 
256 void MessageDrop::setSinglet(const char * sing) {
257  spSinglet->set(sing);
259 }
260 
262  return moduleNameProducer->theContext();
263 }
264 
267 }
268 
269 } // namespace edm
270 
271 
272 unsigned char MessageDrop::messageLoggerScribeIsRunning = 0;
type
Definition: HCALResponse.h:22
void set(const char *type, std::string const &pathname)
Definition: MessageDrop.cc:176
static bool warningEnabled
Definition: MessageDrop.h:107
void setModuleWithPhase(std::string const &name, std::string const &label, const void *moduleID, const char *phase)
Definition: MessageDrop.cc:243
virtual std::string theContext() const
Definition: MessageDrop.cc:204
static edm::Exception * ex_p
Definition: MessageDrop.h:110
static MessageDrop * instance()
Definition: MessageDrop.cc:65
static bool debugEnabled
Definition: MessageDrop.h:105
messagedrop::StringProducer const * moduleNameProducer
Definition: MessageDrop.h:118
void setSinglet(const char *sing)
Definition: MessageDrop.cc:256
static bool debugAlwaysSuppressed
Definition: MessageDrop.h:111
virtual std::string theContext() const
Definition: MessageDrop.cc:169
virtual std::string theContext() const
Definition: MessageDrop.cc:105
static bool infoEnabled
Definition: MessageDrop.h:106
void set(std::string const &name, std::string const &label, const void *moduleID, const char *phase)
Definition: MessageDrop.cc:123
std::string moduleContext()
Definition: MessageDrop.cc:261
const int drop
std::map< const void *, std::string > nameLabelMap_
Definition: MessageDrop.cc:154
static bool warningAlwaysSuppressed
Definition: MessageDrop.h:113
messagedrop::StringProducerSinglet * spSinglet
Definition: MessageDrop.h:117
static bool errorEnabled
Definition: MessageDrop.h:108
std::string & path_
messagedrop::StringProducerWithPhase * spWithPhase
Definition: MessageDrop.h:115
std::map< const void *, std::string >::const_iterator NLMiter
Definition: MessageDrop.cc:88
virtual std::string theContext() const =0
void setPath(const char *type, std::string const &pathname)
Definition: MessageDrop.cc:251
static bool infoAlwaysSuppressed
Definition: MessageDrop.h:112
messagedrop::StringProducerPath * spPath
Definition: MessageDrop.h:116