artdaq_mfextensions  v1_05_00
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
13  ma_func_is_syncd::grouped_alarm( )
14 {
15  return false;
16 }
17 
18 boost::any
19  ma_func_is_syncd::evaluate( ma_condition const & cond
20  , ma_cond_domain )
21 {
22  std::string time_str = cond.get_msg_group(1);
23  std::string source = cond.get_msg_source();
24 
25  uint64_t time = 0;
26 
27  try
28  {
29  time = boost::lexical_cast<uint64_t>(time_str);
30  }
31  catch( boost::bad_lexical_cast & )
32  {
33  return boost::any(true);
34  }
35 
36  //std::map<std::string, uint64_t>::const_iterator it = sync_time.find(source);
37 
38  if( sync_time.empty() || sync_time.find(source)!=sync_time.end() )
39  {
40  // a new round if the table is empty, or the key already exists
41  sync_time.clear();
42  min = time;
43  max = time;
44 
45  sync_time.insert(std::make_pair(source, time));
46  return boost::any(false);
47  }
48  else
49  {
50  // check if in-sync
51  sync_time.insert(std::make_pair(source, time));
52 
53  if( time<min ) min = time;
54  if( time>max ) max = time;
55 
56  if( max-min > 5 ) return boost::any(true);
57  else return boost::any(false);
58  }
59 
60 }
61 
62