artdaq_mfextensions  v1_06_02
ma_function_countpercent.cpp
1 
2 #include "ErrorHandler/MessageAnalyzer/ma_function_countpercent.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_percent, ma_func_count_percent)
11 
12 bool ma_func_count_percent::parse_arguments(anys_t const& args)
13 {
14  if (args.empty() || args.size() < 2)
15  return false;
16 
17  // double count_percent(cond, 'type', 'group')
18  // return the ratio of count(cond, 'type') to the # participant in 'group'
19  // type = 'SOURCE'
20  // type = 'TARGET'
21  // group : arbitary string
22 
23  std::string type = boost::any_cast<std::string>(args[0]);
24  boost::to_upper(type);
25 
26  if (type == "SOURCE")
27  count_type = SOURCE;
28  else if (type == "TARGET")
29  count_type = TARGET;
30  else
31  return false;
32 
33  group = boost::any_cast<std::string>(args[1]);
34 
35  return true;
36 }
37 
38 boost::any
39 ma_func_count_percent::evaluate(ma_condition const& cond, ma_cond_domain dom)
40 {
41  // get triggering count from hitmap of the condition with give domain
42  int count = cond.get_alarm_count(dom, count_type);
43  int total = ma_participants::instance().get_group_participant_count(group);
44 
45  TLOG(TLVL_DEBUG) << "count = " << count << ", participants = " << total;
46 
47  return boost::any((double)count / total);
48 }