LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-mfextensions/ErrorHandler/MessageAnalyzer - ma_boolean_cond.cpp (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 77 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 7 0

            Line data    Source code
       1              : 
       2              : #include "ErrorHandler/MessageAnalyzer/ma_boolean_cond.h"
       3              : #include "ErrorHandler/MessageAnalyzer/ma_boolean_expr.h"
       4              : 
       5              : using namespace novadaq::errorhandler;
       6              : 
       7              : template<typename T>
       8            0 : bool compare(compare_op_t op, T v, T rhv)
       9              : {
      10            0 :         switch (op)
      11              :         {
      12            0 :                 case CO_L:
      13            0 :                         return (v < rhv);
      14            0 :                 case CO_LE:
      15            0 :                         return (v <= rhv);
      16            0 :                 case CO_E:
      17            0 :                         return (v == rhv);
      18            0 :                 case CO_NE:
      19            0 :                         return (v != rhv);
      20            0 :                 case CO_GE:
      21            0 :                         return (v >= rhv);
      22            0 :                 case CO_G:
      23            0 :                         return (v > rhv);
      24            0 :                 default:
      25            0 :                         return false;
      26              :         }
      27              : }
      28              : 
      29              : typedef std::vector<boost::any> anys_t;
      30              : 
      31            0 : void ma_boolean_cond::insert_ext_func(cond_idx_t ci, arg_t arg, anys_t const& func_args, std::string const& function)
      32              : {
      33            0 :         cond_arg.first = ci;
      34            0 :         cond_arg.second = arg;
      35            0 :         cond_type = FUNCTION;
      36            0 :         ext_func.reset(ma_function_factory::create_instance(function));
      37              : 
      38            0 :         if (!ext_func->parse_arguments(func_args))
      39            0 :                 throw std::runtime_error("arguments rejected by " + function);
      40            0 : }
      41              : 
      42            0 : void ma_boolean_cond::reset()
      43              : {
      44            0 :         if (cond_type == EXPR)
      45              :         {
      46              :                 // expression must not be null
      47            0 :                 assert(expr.get() != NULL);
      48            0 :                 return expr->reset();
      49              :         }
      50              : 
      51            0 :         if (cond_type == COND)
      52              :         {
      53            0 :                 return;
      54              :         }
      55              : 
      56            0 :         if (cond_type >= FUNCTION)
      57              :         {
      58              :                 // custom function must not be null
      59            0 :                 assert(ext_func.get() != NULL);
      60              : 
      61            0 :                 return ext_func->reset();
      62              :         }
      63              : 
      64            0 :         throw std::runtime_error("ma_boolean_cond::reset(): unknow cond_type");
      65              : }
      66              : 
      67            0 : bool ma_boolean_cond::evaluate(ma_domain& value, ma_domain& alarm, ma_domain const& domain) const
      68              : {
      69            0 :         if (cond_type == EXPR)
      70              :         {
      71              :                 // expression must not be null
      72            0 :                 assert(expr.get() != NULL);
      73              : 
      74              :                 // evaluate from the expr
      75            0 :                 return expr->evaluate(value, alarm, domain);
      76              :         }
      77              : 
      78            0 :         if (cond_type == COND)
      79              :         {
      80            0 :                 cond_idx_t cond_idx = cond_arg.first;
      81              : 
      82              :                 // condition ptr must not be null
      83            0 :                 assert(cond_idx.first != NULL);
      84              : 
      85              :                 // update alarm
      86            0 :                 if (domain_is_null(alarm[cond_idx.second]))
      87            0 :                         alarm[cond_idx.second] = value[cond_idx.second];
      88              : 
      89              :                 // get status from hitmap of the condition
      90            0 :                 return cond_idx.first->get_status(value[cond_idx.second]);
      91              :         }
      92              : 
      93            0 :         if (cond_type >= FUNCTION)
      94              :         {
      95            0 :                 cond_idx_t cond_idx = cond_arg.first;
      96              : 
      97              :                 // condition ptr must not be null
      98            0 :                 assert(cond_idx.first != NULL);
      99              : 
     100              :                 // custom function must not be null
     101            0 :                 assert(ext_func.get() != NULL);
     102              : 
     103              :                 // update alarm
     104            0 :                 if (ext_func->grouped_alarm())
     105              :                 {
     106            0 :                         alarm[cond_idx.second] = domain[cond_idx.second];
     107              :                 }
     108              :                 else
     109              :                 {
     110            0 :                         alarm[cond_idx.second] =
     111            0 :                             ma_cond_domain(cond_idx.first->find_source(cond_idx.first->get_msg_source()), cond_idx.first->find_target(cond_idx.first->get_qt_mf_msgarget()));
     112              :                 }
     113              : 
     114              :                 // evaluate
     115            0 :                 boost::any v = ext_func->evaluate(*(cond_idx.first), domain[cond_idx.second]);
     116              :                 double d;
     117              :                 bool b;
     118            0 :                 std::string s;
     119              : 
     120            0 :                 switch (cond_type)
     121              :                 {
     122            0 :                         case FUNCTION:
     123            0 :                                 b = boost::any_cast<bool>(v);
     124            0 :                                 return b;
     125              : 
     126            0 :                         case FUNCTION_BOOL:
     127            0 :                                 b = boost::any_cast<bool>(v);
     128            0 :                                 return compare(op, b, rhv_b);
     129              : 
     130            0 :                         case FUNCTION_STRING:
     131            0 :                                 s = boost::any_cast<std::string>(v);
     132            0 :                                 return compare(op, s, rhv_s);
     133              : 
     134            0 :                         case FUNCTION_DOUBLE:
     135            0 :                                 if (v.type() == typeid(int))
     136            0 :                                         d = boost::any_cast<int>(v);
     137              :                                 else
     138            0 :                                         d = boost::any_cast<double>(v);
     139            0 :                                 return compare(op, d, rhv_d);
     140              : 
     141            0 :                         default:
     142            0 :                                 break;
     143              :                 }
     144            0 :         }
     145              : 
     146            0 :         throw std::runtime_error("ma_boolean_cond::evaluate(): unknow cond_type");
     147              : }
     148              : 
     149            0 : void ma_boolean_cond::insert_expr(ma_boolean_expr const& b_expr)
     150              : {
     151            0 :         expr.reset(new ma_boolean_expr(b_expr));
     152            0 :         cond_type = EXPR;
     153            0 : }
        

Generated by: LCOV version 2.0-1