artdaq_mfextensions  v1_06_02
ma_function_count.cpp
1 
2 #include "ErrorHandler/MessageAnalyzer/ma_function_count.h"
3 #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
4 #include "ErrorHandler/MessageAnalyzer/ma_participants.h"
5 
6 #include <boost/algorithm/string.hpp>
7 
8 using namespace novadaq::errorhandler;
9 
10 REG_MA_FUNCTION(count, ma_func_count)
11 
12 bool ma_func_count::parse_arguments(anys_t const& args)
13 {
14  // override 1: int count(cond)
15  if (args.empty())
16  {
17  count_type = NONE;
18  return true;
19  }
20 
21  // override 2: double count(cond, 'type')
22  // return the absolute value of count(cond) in the given type
23  // type = 'SOURCE'
24  // type = 'TARGET'
25  // type = 'MESSAGE'
26  std::string type = boost::any_cast<std::string>(args[0]);
27  boost::to_upper(type);
28 
29  if (type == "SOURCE")
30  count_type = SOURCE;
31  else if (type == "TARGET")
32  count_type = TARGET;
33  else if (type == "MESSAGE")
34  count_type = NONE;
35  else
36  return false;
37 
38  return true;
39 }
40 
41 boost::any
42 ma_func_count::evaluate(ma_condition const& cond, ma_cond_domain dom)
43 {
44  // get triggering count from hitmap of the condition with give domain
45  int count = cond.get_alarm_count(dom, count_type);
46 
47  TLOG(TLVL_DEBUG) << "count = " << count;
48 
49  return boost::any(count);
50 }