artdaq_mfextensions  v1_06_02
ma_function_is_syncd.cpp
1 
2 #include "ErrorHandler/MessageAnalyzer/ma_function_is_syncd.h"
3 #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
4 
5 #include <boost/lexical_cast.hpp>
6 
7 using namespace novadaq::errorhandler;
8 
9 // class registeration
10 REG_MA_FUNCTION(is_syncd /*function name*/, ma_func_is_syncd /*class name*/)
11 
12 bool ma_func_is_syncd::grouped_alarm()
13 {
14  return false;
15 }
16 
17 boost::any
18 ma_func_is_syncd::evaluate(ma_condition const& cond, ma_cond_domain)
19 {
20  std::string time_str = cond.get_msg_group(1);
21  std::string source = cond.get_msg_source();
22 
23  uint64_t time = 0;
24 
25  try
26  {
27  time = boost::lexical_cast<uint64_t>(time_str);
28  }
29  catch (boost::bad_lexical_cast&)
30  {
31  return boost::any(true);
32  }
33 
34  //std::map<std::string, uint64_t>::const_iterator it = sync_time.find(source);
35 
36  if (sync_time.empty() || sync_time.find(source) != sync_time.end())
37  {
38  // a new round if the table is empty, or the key already exists
39  sync_time.clear();
40  min = time;
41  max = time;
42 
43  sync_time.insert(std::make_pair(source, time));
44  return boost::any(false);
45  }
46  else
47  {
48  // check if in-sync
49  sync_time.insert(std::make_pair(source, time));
50 
51  if (time < min) min = time;
52  if (time > max) max = time;
53 
54  if (max - min > 5)
55  return boost::any(true);
56  else
57  return boost::any(false);
58  }
59 }