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

            Line data    Source code
       1              : 
       2              : #include "ErrorHandler/MessageAnalyzer/ma_cell.h"
       3              : #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
       4              : 
       5              : #include <time.h>
       6              : 
       7              : using namespace novadaq::errorhandler;
       8              : 
       9            0 : ma_cell::ma_cell()
      10            0 :     : msgs()
      11            0 :     , on(false)
      12            0 :     , what_()
      13            0 :     , t_event(0)
      14              : {
      15            0 : }
      16              : 
      17            0 : ma_cell::~ma_cell()
      18              : {
      19            0 : }
      20              : 
      21            0 : bool ma_cell::hit(qt_mf_msg const& msg, boost::smatch const& w, ma_condition& cond, size_t s_idx, size_t t_idx)
      22              : {
      23              :         // regex groups
      24            0 :         what_ = w;
      25              : 
      26              :         // push new message
      27            0 :         time_t latest = msg.time().tv_sec;
      28            0 :         msgs.push_back(msg);
      29              : 
      30            0 :         if (on && cond.persistent())
      31              :         {
      32            0 :                 msgs.pop_front();
      33            0 :                 return false;
      34              :         }
      35              : 
      36              :         // pop expired messages ( >timespan )
      37            0 :         while (latest - msgs.front().time().tv_sec > cond.timespan())
      38            0 :                 msgs.pop_front();
      39              : 
      40              :         // pop excessive messages ( >count )
      41            0 :         while (msgs.size() > (size_t)cond.trigger_count())
      42            0 :                 msgs.pop_front();
      43              : 
      44              :         // determin the new state (on or off)
      45            0 :         bool new_state = false;
      46              : 
      47            0 :         if (msgs.size() == (size_t)cond.trigger_count())
      48              :         {
      49            0 :                 new_state = cond.at_least() ? true : false;
      50              : 
      51              :                 // lock
      52            0 :                 boost::mutex::scoped_lock lock(cond.timing_events().lock);
      53              : 
      54              :                 // schedule event
      55              :                 // t0 = events.front();
      56              :                 // schedule(t0 + ts + 1);
      57              : 
      58            0 :                 time_t t0 = msgs.front().time().tv_sec;
      59            0 :                 t_event = t0 + cond.timespan() + 1;
      60            0 :                 cond.timing_events().event_queue().push(ma_timing_event(t_event, cond, s_idx, t_idx));
      61            0 :         }
      62            0 :         else if (cond.at_most())
      63              :         {
      64              :                 // lock
      65            0 :                 boost::mutex::scoped_lock lock(cond.timing_events().lock);
      66              : 
      67              :                 // not reached the critical size
      68              :                 // for occur_at_least, do nothing.
      69              :                 // for occur_at_most, schedule an event to turn on the cell
      70              :                 // t0 = events.front();
      71              :                 // schedule(t0 + ts + 1);
      72              : 
      73            0 :                 time_t t0 = msgs.front().time().tv_sec;
      74            0 :                 t_event = t0 + cond.timespan() + 1;
      75            0 :                 cond.timing_events().event_queue().push(ma_timing_event(t_event, cond, s_idx, t_idx));
      76            0 :         }
      77              : 
      78              :         // no change in status
      79            0 :         if (new_state == on)
      80            0 :                 return false;
      81              : 
      82              :         // changed
      83            0 :         on = new_state;
      84            0 :         return true;
      85              : }
      86              : 
      87            0 : bool ma_cell::event(time_t t, ma_condition& cond)
      88              : {
      89              :         // not reached the event time, no flip
      90            0 :         if (t != t_event)
      91            0 :                 return false;
      92              : 
      93            0 :         bool new_status = cond.at_most() ? true : (cond.persistent() ? true : false);
      94              : 
      95              :         // not flipped
      96            0 :         if (new_status == on)
      97            0 :                 return false;
      98              : 
      99              :         // flipped
     100            0 :         on = new_status;
     101            0 :         return true;
     102              : }
     103              : 
     104            0 : void ma_cell::reset()
     105              : {
     106            0 :         on = false;
     107            0 :         t_event = 0;
     108            0 :         msgs.clear();
     109            0 : }
        

Generated by: LCOV version 2.0-1