MessageDrop.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
4 #include "cetlib/exempt_ptr.h"
7 
8 #include <limits>
9 #include <map>
10 #include <memory>
11 #include <string>
12 
13 using namespace std;
14 using namespace std::string_literals;
15 
16 namespace mf {
17 
18  bool MessageDrop::debugAlwaysSuppressed{false};
19 
20  bool MessageDrop::infoAlwaysSuppressed{false};
21 
22  bool MessageDrop::warningAlwaysSuppressed{false};
23 
24  string MessageDrop::jobMode{};
25 
26  unsigned char MessageDrop::messageLoggerScribeIsRunning = 0;
27 
29 
30  private: // TYPES
31  using id_label_map_t = map<module_id_t, string>;
32 
33  public:
34  virtual string
35  theContext() const override
36  {
37  if (cache_.empty()) {
38  if (moduleID_ != numeric_limits<module_id_t>::max()) {
39  auto nameLableIter = idLabelMap_.find(moduleID_);
40  if (nameLableIter != idLabelMap_.end()) {
41  cache_.assign(nameLableIter->second);
42  cache_.append(phase_);
43  return cache_;
44  }
45  }
46  cache_.assign(name_);
47  cache_.append(":");
48  cache_.append(label_);
49  idLabelMap_[moduleID_] = cache_;
50  if (!phase_.empty()) {
51  cache_.append(phase_);
52  }
53  }
54  return cache_;
55  }
56 
57  void
58  set(string const& name,
59  string const& label,
60  module_id_t moduleID,
61  string const& phase)
62  {
63  name_ = name;
64  label_ = label;
65  moduleID_ = moduleID;
66  phase_ = "@"s + phase;
67  cache_.clear();
68  }
69 
70  private:
71  string phase_{"@Early"s};
72 
73  string name_{};
74 
75  string label_{};
76 
77  module_id_t moduleID_{};
78 
79  mutable string cache_{};
80 
81  mutable id_label_map_t idLabelMap_{};
82  };
83 
85 
86  public:
87  virtual string
88  theContext() const override
89  {
90  if (cache_.empty()) {
91  cache_.assign(phase_);
92  cache_.append(" ");
93  cache_.append(path_);
94  }
95  return cache_;
96  }
97 
98  void
99  set(string const& phase, string const& path)
100  {
101  phase_ = phase;
102  path_ = path;
103  cache_.clear();
104  }
105 
106  private:
107  string phase_{"(NoPath)"};
108 
109  string path_{};
110 
111  mutable string cache_;
112  };
113 
115 
116  public:
117  virtual string
118  theContext() const override
119  {
120  return singlet_;
121  }
122 
123  void
124  set(string const& singlet)
125  {
126  singlet_ = singlet;
127  }
128 
129  private:
130  string singlet_{"Early"};
131  };
132 
133  MessageDrop::~MessageDrop() {}
134 
135  MessageDrop::MessageDrop()
136  : messageStreamID(numeric_limits<unsigned int>::max())
137  , spWithPhase_(new MessageDrop::StringProducerWithPhase)
138  , spPath_(new MessageDrop::StringProducerPath)
139  , spSinglet_(new MessageDrop::StringProducerSinglet)
140  , moduleNameProducer_(spSinglet_.get())
141  {}
142 
143  MessageDrop*
145  {
146  thread_local static MessageDrop s_drop;
147  return &s_drop;
148  }
149 
150  void
152  string const& label,
153  module_id_t moduleID,
154  string const& phase)
155  {
156  spWithPhase_->set(name, label, moduleID, phase);
158  }
159 
160  void
161  MessageDrop::setPath(string const& phase, string const& path)
162  {
163  spPath_->set(phase, path);
165  }
166 
167  void
168  MessageDrop::setSinglet(string const& singlet)
169  {
170  spSinglet_->set(singlet);
172  }
173 
174  string
176  {
177  return moduleNameProducer_->theContext();
178  }
179 
180  void
182  {
183  setSinglet(""s);
184  }
185 
186 } // namespace mf
constexpr std::tuple_element_t< I, art::AssnsNode< L, R, D > > & get(art::AssnsNode< L, R, D > &t) noexcept
Definition: ProxyBase.h:5014
cet::propagate_const< std::unique_ptr< StringProducerWithPhase > > spWithPhase_
Definition: MessageDrop.h:84
virtual string theContext() const override
Definition: MessageDrop.cc:35
unsigned int module_id_t
Definition: MessageDrop.h:17
map< module_id_t, string > id_label_map_t
Definition: MessageDrop.cc:31
std::string moduleContext() const
Definition: MessageDrop.cc:175
STL namespace.
cet::propagate_const< std::unique_ptr< StringProducerSinglet > > spSinglet_
Definition: MessageDrop.h:88
void setPath(std::string const &path, std::string const &phase)
Definition: MessageDrop.cc:161
cet::exempt_ptr< StringProducer > moduleNameProducer_
Definition: MessageDrop.h:90
virtual string theContext() const override
Definition: MessageDrop.cc:118
void setModuleWithPhase(std::string const &name, std::string const &label, module_id_t moduleID, std::string const &phase)
Definition: MessageDrop.cc:151
void setSinglet(std::string const &singlet)
Definition: MessageDrop.cc:168
virtual string theContext() const override
Definition: MessageDrop.cc:88
static const double s
Definition: Units.h:99
static MessageDrop * instance()
Definition: MessageDrop.cc:144
cet::propagate_const< std::unique_ptr< StringProducerPath > > spPath_
Definition: MessageDrop.h:86