Skip to content

Commit

Permalink
move prescaler logic into CategoryEntry, and add summary informations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Bocci committed Nov 10, 2009
1 parent c55cc70 commit 7839e2f
Showing 1 changed file with 59 additions and 21 deletions.
80 changes: 59 additions & 21 deletions HLTrigger/special/src/HLTLogMonitorFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//
// Original Author: Andrea Bocci
// Created: Thu Nov 5 15:16:46 CET 2009
// $Id: HLTLogMonitorFilter.cc,v 1.1 2009/11/09 00:01:23 fwyzard Exp $
// $Id: HLTLogMonitorFilter.cc,v 1.1 2009/11/09 14:04:30 fwyzard Exp $
//


Expand Down Expand Up @@ -44,19 +44,39 @@ class HLTLogMonitorFilter : public HLTFilter {
uint32_t threshold; // configurable threshold, after which messages in this Category start to be logarithmically prescaled
uint32_t prescale; // current prescale for this Category
uint64_t counter; // number of events that fired this Category
uint64_t accepted; // number of events acepted for this Category

CategoryEntry(uint32_t t = 0) :
threshold(t), // default-constructed entries have the threshold set to 0, which means the associated category is disabled
threshold(t), // default-constructed entries have the threshold set to 0, which means the associated Category is disabled
prescale(1),
counter(0)
counter(0),
accepted(0)
{ }

bool accept() {
++counter;

// fail if the prescaler is disabled (threshold == 0), or if the counter is not a multiple of the prescale
if ((threshold == 0) or (counter % prescale))
return false;

// quasi-logarithmic increase in the prescale factor (should be safe even if threshold is 1)
if (counter == prescale * threshold)
prescale *= threshold;

++accepted;
return true;
}
};

// ---------- private methods -----------------------

/// EDFilter accept method
virtual bool filter(edm::Event&, const edm::EventSetup &);

/// EDFilter endJob method
virtual void endJob(void);

/// check if the requested category has a valid entry
bool knownCategory(const std::string & category);

Expand All @@ -66,18 +86,25 @@ class HLTLogMonitorFilter : public HLTFilter {
/// return the entry for requested category, if it exists, or create a new one with the default threshold value
CategoryEntry & getCategory(const std::string & category);

/// summarize to LogInfo
void summary(void);


// ---------- member data ---------------------------
uint32_t m_prescale; // default threshold, after which messages in each Category start to be logarithmically prescaled
uint32_t m_prescale; // default threshold, after which messages in each Category start to be logarithmically prescaled
std::map<std::string, CategoryEntry> m_data; // map each category name to its prescale data
};


// system include files
#include <iostream>
#include <iomanip>
#include <boost/foreach.hpp>
#include <boost/range.hpp>
#include <boost/algorithm/string.hpp>

// user include files
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/MessageLogger/interface/LoggedErrorsSummary.h"

//
Expand Down Expand Up @@ -108,8 +135,7 @@ HLTLogMonitorFilter::~HLTLogMonitorFilter()
//

// ------------ method called on each new Event ------------
bool
HLTLogMonitorFilter::filter(edm::Event & event, const edm::EventSetup & setup) {
bool HLTLogMonitorFilter::filter(edm::Event & event, const edm::EventSetup & setup) {
// no LogErrors or LogWarnings, skip processing and reject the event
if (not edm::FreshErrorsExist())
return false;
Expand All @@ -129,26 +155,19 @@ HLTLogMonitorFilter::filter(edm::Event & event, const edm::EventSetup & setup) {
// FIXME: this can be avoided if the m_data map is keyed on boost::sub_range<std::string>
category.assign(i->begin(), i->end());

// access the message category, or create a new one as needed
CategoryEntry & data = getCategory(category);
++data.counter;

// if this category is disabled (scale == 0), skip this event
// if the counter is not a multiple of the prescale, skip the event
if ((data.prescale == 0) or (data.counter % data.prescale))
continue;

// quasi-logarithmic increase in the prescale factor (should be safe even if threshold is 1)
if (data.counter == data.prescale * data.threshold)
data.prescale *= data.threshold;

accept = true;
// access the message category, or create a new one as needed, and check the prescale
if (getCategory(category).accept())
accept = true;
}
}

return accept;
}

// ------------ method called at the end of the Job ---------
void HLTLogMonitorFilter::endJob(void) {
summary();
}

/// check if the requested category has a valid entry
bool HLTLogMonitorFilter::knownCategory(const std::string & category) {
return (m_data.find( category ) != m_data.end());
Expand All @@ -173,6 +192,25 @@ HLTLogMonitorFilter::CategoryEntry & HLTLogMonitorFilter::getCategory(const std:
return m_data.insert( std::make_pair(category, CategoryEntry(m_prescale)) ).first->second;
}

/// summarize to LogInfo
void HLTLogMonitorFilter::summary(void) {
edm::LogVerbatim("Report") << "HLTLogMonitorFilter Summary:\n"
<< std::setw(-48) << "Category"
<< std::setw(8) << "Events"
<< std::setw(8) << "Accept"
<< std::setw(8) << "Thresh."
<< std::setw(8) << "Final prescale"
<< std::endl;
typedef std::map<std::string, HLTLogMonitorFilter::CategoryEntry>::value_type Entry;
BOOST_FOREACH(const Entry & entry, m_data) {
edm::LogVerbatim("Report") << std::setw(-48) << entry.first
<< std::setw(8) << entry.second.counter
<< std::setw(8) << entry.second.accepted
<< std::setw(8) << entry.second.threshold
<< std::setw(8) << entry.second.prescale
<< std::endl;
}
}

// define as a framework plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down

0 comments on commit 7839e2f

Please sign in to comment.