CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTLogMonitorFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTLogMonitorFilter
4 // Class: HLTLogMonitorFilter
5 //
13 //
14 // Original Author: Andrea Bocci
15 // Created: Thu Nov 5 15:16:46 CET 2009
16 //
17 
18 
19 // system include files
20 #include <stdint.h>
21 #include <map>
22 
23 // user include files
32 
33 //
34 // class declaration
35 //
36 
38 public:
39  explicit HLTLogMonitorFilter(const edm::ParameterSet &);
41 
42  struct CategoryEntry {
43  uint32_t threshold; // configurable threshold, after which messages in this Category start to be logarithmically prescaled
44  uint32_t prescale; // current prescale for this Category
45  uint64_t counter; // number of events that fired this Category
46  uint64_t accepted; // number of events acepted for this Category
47  bool done; // track if this Category has already been seen in the current event
48 
49  CategoryEntry(uint32_t t = 0) :
50  threshold(t), // default-constructed entries have the threshold set to 0, which means the associated Category is disabled
51  prescale(1),
52  counter(0),
53  accepted(0),
54  done(false)
55  { }
56 
57  bool accept() {
58  if (not done) {
59  done = true;
60  ++counter;
61  }
62 
63  // fail if the prescaler is disabled (threshold == 0), or if the counter is not a multiple of the prescale
64  if ((threshold == 0) or (counter % prescale))
65  return false;
66 
67  // quasi-logarithmic increase in the prescale factor (should be safe even if threshold is 1)
68  if (counter == prescale * threshold)
69  prescale *= threshold;
70 
71  ++accepted;
72  return true;
73  }
74 
75  };
76 
77  typedef std::map<std::string, CategoryEntry> CategoryMap;
78 
79  // ---------- private methods -----------------------
80 
82  virtual bool filter(edm::Event&, const edm::EventSetup &) override;
83 
85  virtual void beginJob(void) override;
86 
88  virtual void endJob(void) override;
89 
91  bool knownCategory(const std::string & category);
92 
95 
98 
100  void summary(void);
101 
102 
103  // ---------- member data ---------------------------
104  uint32_t m_prescale; // default threshold, after which messages in each Category start to be logarithmically prescaled
105  CategoryMap m_data; // map each category name to its prescale data
106 };
107 
108 
109 // system include files
110 #include <sstream>
111 #include <iomanip>
112 #include <memory>
113 #include <boost/foreach.hpp>
114 #include <boost/range.hpp>
115 #include <boost/algorithm/string.hpp>
116 
117 // user include files
120 
121 //
122 // constructors and destructor
123 //
125  m_prescale(),
126  m_data()
127 {
128  m_prescale = config.getParameter<uint32_t>("default_threshold");
129 
130  typedef std::vector<edm::ParameterSet> VPSet;
131  const VPSet & categories = config.getParameter<VPSet>("categories");
132  for (VPSet::const_iterator category = categories.begin(); category != categories.end(); ++category) {
133  const std::string & name = category->getParameter<std::string>("name");
134  uint32_t threshold = category->getParameter<uint32_t>("threshold");
135  addCategory(name, threshold);
136  }
137 
138  produces<std::vector<edm::ErrorSummaryEntry> >();
139 }
140 
142 {
143 }
144 
145 //
146 // member functions
147 //
148 
149 // ------------ method called on each new Event ------------
151  // no LogErrors or LogWarnings, skip processing and reject the event
152  if (not edm::FreshErrorsExist(event.streamID().value()))
153  return false;
154 
155  // clear "done" flag in all Categories
156  BOOST_FOREACH(CategoryMap::value_type & entry, m_data)
157  entry.second.done = false;
158 
159  // look at the LogErrors and LogWarnings, and accept the event if at least one is under threshold or matches the prescale
160  bool accept = false;
162 
163  std::vector<edm::ErrorSummaryEntry> errorSummary{ edm::LoggedErrorsSummary(event.streamID().value()) };
164  for( auto const& entry : errorSummary ) {
165  // split the message category
166  typedef boost::split_iterator<std::string::const_iterator> splitter;
167  for (splitter i = boost::make_split_iterator(entry.category, boost::first_finder("|", boost::is_equal()));
168  i != splitter();
169  ++i)
170  {
171  // extract the substring corresponding to the split_iterator
172  // FIXME: this can be avoided if the m_data map is keyed on boost::sub_range<std::string>
173  category.assign(i->begin(), i->end());
174 
175  // access the message category, or create a new one as needed, and check the prescale
176  if (getCategory(category).accept())
177  accept = true;
178  }
179  }
180 
181  // harvest the errors, but only if the filter will accept the event
182  std::auto_ptr<std::vector<edm::ErrorSummaryEntry> > errors(new std::vector<edm::ErrorSummaryEntry>());
183  if (accept) {
184  errors->swap(errorSummary);
185  }
186  event.put(errors);
187 
188  return accept;
189 }
190 
191 // ------------ method called at the end of the Job ---------
194 }
195 // ------------ method called at the end of the Job ---------
198  summary();
199 }
200 
203  return (m_data.find( category ) != m_data.end());
204 }
205 
208  // check after inserting, as either the new CategoryEntry is needed, or an error condition is raised
209  std::pair<CategoryMap::iterator, bool> result = m_data.insert( std::make_pair(category, CategoryEntry(threshold)) );
210  if (not result.second)
211  throw cms::Exception("Configuration") << "Duplicate entry for category " << category;
212  return result.first->second;
213 }
214 
217  // check before inserting, to avoid the construction of a CategoryEntry object
218  CategoryMap::iterator i = m_data.find(category);
219  if (i != m_data.end())
220  return i->second;
221  else
222  return m_data.insert( std::make_pair(category, CategoryEntry(m_prescale)) ).first->second;
223 }
224 
227  std::stringstream out;
228  out << "Log-Report ---------- HLTLogMonitorFilter Summary ------------\n"
229  << "Log-Report Threshold Prescale Issued Accepted Rejected Category\n";
230  BOOST_FOREACH(const CategoryMap::value_type & entry, m_data) {
231  out << "Log-Report "
232  << std::right
233  << std::setw(10) << entry.second.threshold << ' '
234  << std::setw(10) << entry.second.prescale << ' '
235  << std::setw(10) << entry.second.counter << ' '
236  << std::setw(10) << entry.second.accepted << ' '
237  << std::setw(10) << (entry.second.counter - entry.second.accepted) << ' '
238  << std::left << entry.first << '\n';
239  }
240  edm::LogVerbatim("Report") << out.str();
241 }
242 
243 // define as a framework plug-in
T getParameter(std::string const &) const
CategoryEntry & getCategory(const std::string &category)
return the entry for requested category, if it exists, or create a new one with the default threshold...
int i
Definition: DBlmapReader.cc:9
CategoryEntry & addCategory(const std::string &category, uint32_t threshold)
create a new entry for the given category, with the given threshold value
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool EnableLoggedErrorsSummary()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool knownCategory(const std::string &category)
check if the requested category has a valid entry
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:24
bool FreshErrorsExist(unsigned int iStreamID)
bool DisableLoggedErrorsSummary()
def splitter
Definition: confdb.py:11
virtual void endJob(void) override
EDFilter endJob method.
tuple result
Definition: query.py:137
std::map< std::string, CategoryEntry > CategoryMap
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Container::value_type value_type
tuple out
Definition: dbtoconf.py:99
unsigned int value() const
Definition: StreamID.h:46
unsigned long long uint64_t
Definition: Time.h:15
StreamID streamID() const
Definition: Event.h:79
std::vector< ErrorSummaryEntry > LoggedErrorsSummary(unsigned int iStreamID)
HLTLogMonitorFilter(const edm::ParameterSet &)
volatile std::atomic< bool > shutdown_flag false
virtual void beginJob(void) override
EDFilter beginJob method.
virtual bool filter(edm::Event &, const edm::EventSetup &) override
EDFilter accept method.
void summary(void)
summarize to LogInfo
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")