CMS 3D CMS Logo

MessageSender.cc
Go to the documentation of this file.
6 
7 #include <algorithm>
8 #include <cassert>
9 #include <vector>
10 #include <limits>
11 #include <atomic>
12 
13 #include <functional>
14 #include "tbb/concurrent_unordered_map.h"
15 
16 #define TRACE_DROP
17 #ifdef TRACE_DROP
18 #include <iostream>
19 #endif
20 
21 // Change log
22 //
23 // 1 mf 8/25/08 keeping the error summary information for
24 // LoggedErrorsSummary()
25 //
26 // 2 mf 11/2/10 Use new moduleContext method of MessageDrop:
27 // see MessageServer/src/MessageLogger.cc change 17.
28 //
29 
30 using namespace edm;
31 
32 namespace {
33  //Helper class used as 'key' to the thread safe map storing the
34  // per event log error and log warning messages
35  struct ErrorSummaryMapKey {
37  std::string module;
39 
40  bool operator<(ErrorSummaryMapKey const& iOther) const {
41  int comp = severity.getLevel() - iOther.severity.getLevel();
42  if (0 == comp) {
43  comp = category.compare(iOther.category);
44  if (comp == 0) {
45  comp = module.compare(iOther.module);
46  }
47  }
48  return comp < 0;
49  }
50 
51  bool operator==(ErrorSummaryMapKey const& iOther) const {
52  return ((iOther.category == category) and (iOther.module == module) and
53  (severity.getLevel() == iOther.severity.getLevel()));
54  }
55  size_t smallHash() const {
56  std::hash<std::string> h;
57 
58  return h(category + module + severity.getSymbol());
59  }
60 
61  struct key_hash {
62  std::size_t operator()(ErrorSummaryMapKey const& iKey) const { return iKey.smallHash(); }
63  };
64  };
65 
66  class AtomicUnsignedInt {
67  public:
68  AtomicUnsignedInt() : value_(0) {}
69  AtomicUnsignedInt(AtomicUnsignedInt const& r) : value_(r.value_.load(std::memory_order_acquire)) {}
70  std::atomic<unsigned int>& value() { return value_; }
71  std::atomic<unsigned int> const& value() const { return value_; }
72 
73  private:
74  std::atomic<unsigned int> value_;
75  };
76 
77 } // namespace
78 
79 CMS_THREAD_SAFE static std::atomic<bool> errorSummaryIsBeingKept{false};
80 //Each item in the vector is reserved for a different Stream
82  tbb::concurrent_unordered_map<ErrorSummaryMapKey, AtomicUnsignedInt, ErrorSummaryMapKey::key_hash>>
84 
85 MessageSender::MessageSender(ELseverityLevel const& sev, std::string_view id, bool verbatim, bool suppressed)
86  : errorobj_p(suppressed ? nullptr : new ErrorObj(sev, id, verbatim), ErrorObjDeleter()) {
87  //std::cout << "MessageSender ctor; new ErrorObj at: " << errorobj_p << '\n';
88 }
89 
90 // This destructor must not be permitted to throw. A
91 // boost::thread_resoruce_error is thrown at static destruction time,
92 // if the MessageLogger library is loaded -- even if it is not used.
94  if (errorObjPtr == nullptr) {
95  return;
96  }
97  try {
98  //std::cout << "MessageSender dtor; ErrorObj at: " << errorobj_p << '\n';
99 
100  // surrender ownership of our ErrorObj, transferring ownership
101  // (via the intermediate MessageLoggerQ) to the MessageLoggerScribe
102  // that will (a) route the message text to its destination(s)
103  // and will then (b) dispose of the ErrorObj
104 
106  if (drop) {
107  errorObjPtr->setModule(drop->moduleContext()); // change log
108  errorObjPtr->setContext(drop->runEvent);
109  }
110 #ifdef TRACE_DROP
111  if (!drop)
112  std::cerr << "MessageSender::~MessageSender() - Null drop pointer \n";
113 #endif
114  // change log 1
115  if (errorSummaryIsBeingKept.load(std::memory_order_acquire) && errorObjPtr->xid().severity >= ELwarning && drop &&
117  auto& errorSummaryMap = errorSummaryMaps[drop->streamID];
118 
119  ELextendedID const& xid = errorObjPtr->xid();
120  ErrorSummaryMapKey key{xid.id, xid.module, xid.severity};
121  auto i = errorSummaryMap.find(key);
122  if (i != errorSummaryMap.end()) {
123  i->second.value().fetch_add(1, std::memory_order_acq_rel); // same as ++errorSummaryMap[key]
124  } else {
125  errorSummaryMap[key].value().store(1, std::memory_order_release);
126  }
127  }
128 
129  MessageLoggerQ::MLqLOG(errorObjPtr);
130  } catch (...) {
131  // nothing to do
132 
133  // for test that removal of thread-involved static works,
134  // simply throw here, then run in trivial_main in totalview
135  // and Next or Step so that the exception would be detected.
136  // That test has been done 12/14/07.
137  }
138 }
140 
141 //The following functions are declared here rather than in
142 // LoggedErrorsSummary.cc because only MessageSender and these
143 // functions interact with the statics errorSummaryIsBeingKept and
144 // errorSummaryMaps. By putting them into the same .cc file the
145 // statics can be file scoped rather than class scoped and therefore
146 // better encapsulated.
147 namespace edm {
148 
150  bool ret = errorSummaryIsBeingKept.exchange(true, std::memory_order_acq_rel);
151  return ret;
152  }
153 
155  bool ret = errorSummaryIsBeingKept.exchange(false, std::memory_order_acq_rel);
156  return ret;
157  }
158 
159  bool FreshErrorsExist(unsigned int iStreamID) {
160  assert(iStreamID < errorSummaryMaps.size());
161  return !errorSummaryMaps[iStreamID].empty();
162  }
163 
164  std::vector<ErrorSummaryEntry> LoggedErrorsSummary(unsigned int iStreamID) {
165  assert(iStreamID < errorSummaryMaps.size());
166  auto const& errorSummaryMap = errorSummaryMaps[iStreamID];
167  std::vector<ErrorSummaryEntry> v;
168  auto end = errorSummaryMap.end();
169  for (auto i = errorSummaryMap.begin(); i != end; ++i) {
170  auto const& key = i->first;
171  ErrorSummaryEntry e{key.category, key.module, key.severity};
172 
173  e.count = i->second.value().load(std::memory_order_acquire);
174  v.push_back(e);
175  }
176  std::sort(v.begin(), v.end());
177  return v;
178  }
179 
180  void clearLoggedErrorsSummary(unsigned int iStreamID) {
181  assert(iStreamID < errorSummaryMaps.size());
182  errorSummaryMaps[iStreamID].clear();
183  }
184 
185  void setMaxLoggedErrorsSummaryIndicies(unsigned int iMax) { errorSummaryMaps.resize(iMax); }
186 
187  std::vector<ErrorSummaryEntry> LoggedErrorsOnlySummary(unsigned int iStreamID) { // ChangeLog 2
188  std::vector<ErrorSummaryEntry> v;
189  assert(iStreamID < errorSummaryMaps.size());
190  auto const& errorSummaryMap = errorSummaryMaps[iStreamID];
191  auto end = errorSummaryMap.end();
192  for (auto i = errorSummaryMap.begin(); i != end; ++i) {
193  auto const& key = i->first;
194  if (key.severity >= edm::ELerror) {
195  ErrorSummaryEntry e{key.category, key.module, key.severity};
196  e.count = i->second.value().load(std::memory_order_acquire);
197  v.push_back(e);
198  }
199  }
200  std::sort(v.begin(), v.end());
201  return v;
202  }
203 
204 } // end namespace edm
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
mps_fire.i
i
Definition: mps_fire.py:428
edm::ELextendedID::module
std::string module
Definition: ELextendedID.h:31
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edm::ErrorObj
Definition: ErrorObj.h:43
edm::ELextendedID
Definition: ELextendedID.h:25
edm::ELwarning
constexpr const ELseverityLevel ELwarning
Definition: ELseverityLevel.h:100
cms::cuda::assert
assert(be >=bs)
errorSummaryMaps
static std::vector< tbb::concurrent_unordered_map< ErrorSummaryMapKey, AtomicUnsignedInt, ErrorSummaryMapKey::key_hash > > errorSummaryMaps
Definition: MessageSender.cc:83
edm::MessageLoggerQ::MLqLOG
static void MLqLOG(ErrorObj *p)
Definition: MessageLoggerQ.cc:156
findQualityFiles.v
v
Definition: findQualityFiles.py:179
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
edm::ErrorSummaryEntry
Definition: ErrorSummaryEntry.h:37
edm::setMaxLoggedErrorsSummaryIndicies
void setMaxLoggedErrorsSummaryIndicies(unsigned int iMax)
Definition: MessageSender.cc:185
edm::DisableLoggedErrorsSummary
bool DisableLoggedErrorsSummary()
Definition: MessageSender.cc:154
edm::MessageSender::~MessageSender
~MessageSender()
Definition: MessageSender.cc:139
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::MessageSender::ErrorObjDeleter::operator()
void operator()(ErrorObj *errorObjPtr)
Definition: MessageSender.cc:93
edm::clearLoggedErrorsSummary
void clearLoggedErrorsSummary(unsigned int iStreamID)
Definition: MessageSender.cc:180
mps_fire.end
end
Definition: mps_fire.py:242
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
MessageLoggerQ.h
edm::MessageSender::ErrorObjDeleter
Definition: MessageSender.h:14
edm::ELerror
constexpr const ELseverityLevel ELerror
Definition: ELseverityLevel.h:102
ErrorSummaryEntry.h
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
MessageSender.h
edm::ErrorObj::xid
const ELextendedID & xid() const
Definition: ErrorObj.cc:142
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
errorSummaryIsBeingKept
static std::atomic< bool > errorSummaryIsBeingKept
Definition: MessageSender.cc:79
MessageDrop.h
edm::EnableLoggedErrorsSummary
bool EnableLoggedErrorsSummary()
Definition: MessageSender.cc:149
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::LoggedErrorsOnlySummary
std::vector< ErrorSummaryEntry > LoggedErrorsOnlySummary(unsigned int iStreamID)
Definition: MessageSender.cc:187
thread_safety_macros.h
edm::MessageDrop
Definition: MessageDrop.h:45
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::LoggedErrorsSummary
std::vector< ErrorSummaryEntry > LoggedErrorsSummary(unsigned int iStreamID)
Definition: MessageSender.cc:164
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::ErrorObj::setContext
virtual void setContext(std::string_view context)
Definition: ErrorObj.cc:175
edm::ELextendedID::id
std::string id
Definition: ELextendedID.h:29
edm::ELseverityLevel
Definition: ELseverityLevel.h:26
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
ErrorSummaryFilter_cfi.severity
severity
Definition: ErrorSummaryFilter_cfi.py:5
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::MessageDrop::instance
static MessageDrop * instance()
Definition: MessageDrop.cc:33
edm::MessageSender::MessageSender
MessageSender()=default
drop
const int drop
Definition: GenParticlePruner.cc:48
edm::FreshErrorsExist
bool FreshErrorsExist(unsigned int iStreamID)
Definition: MessageSender.cc:159
edm::ELextendedID::severity
ELseverityLevel severity
Definition: ELextendedID.h:30
edm::ErrorObj::setModule
virtual void setModule(std::string_view module)
Definition: ErrorObj.cc:173
crabWrapper.key
key
Definition: crabWrapper.py:19
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37