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