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