LCOV - code coverage report
Current view: top level - include/Module/Probe - Probe.hxx (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 17 49 34.7 %
Date: 2024-06-12 12:04:18 Functions: 9 120 7.5 %

          Line data    Source code
       1             : #include <sstream>
       2             : 
       3             : #include "Module/Probe/Probe.hpp"
       4             : #include "Tools/Exception/exception.hpp"
       5             : 
       6             : namespace spu
       7             : {
       8             : namespace module
       9             : {
      10             : 
      11             : runtime::Task&
      12             : AProbe::operator[](const prb::tsk t)
      13             : {
      14             :     return Module::operator[]((int)t);
      15             : }
      16             : 
      17             : runtime::Socket&
      18             : AProbe::operator[](const prb::sck::probe s)
      19             : {
      20             :     assert((*this)[prb::tsk::probe].get_n_input_sockets() == 1);
      21             :     return Module::operator[]((int)prb::tsk::probe)[(int)s];
      22             : }
      23             : 
      24             : runtime::Socket&
      25             : AProbe::operator[](const prb::sck::probe_noin s)
      26             : {
      27             :     assert((*this)[prb::tsk::probe].get_n_input_sockets() == 0);
      28             :     return Module::operator[]((int)prb::tsk::probe)[(int)s];
      29             : }
      30             : 
      31             : runtime::Socket&
      32             : AProbe::operator[](const std::string& tsk_sck)
      33             : {
      34             :     return Module::operator[](tsk_sck);
      35             : }
      36             : 
      37             : template<typename T>
      38             : runtime::Task&
      39             : Probe<T>::operator[](const prb::tsk t)
      40             : {
      41             :     return Module::operator[]((int)t);
      42             : }
      43             : 
      44             : template<typename T>
      45             : runtime::Socket&
      46             : Probe<T>::operator[](const prb::sck::probe s)
      47             : {
      48             :     assert((*this)[prb::tsk::probe].get_n_input_sockets() == 1);
      49             :     return Module::operator[]((int)prb::tsk::probe)[(int)s];
      50             : }
      51             : 
      52             : template<typename T>
      53             : runtime::Socket&
      54             : Probe<T>::operator[](const prb::sck::probe_noin s)
      55             : {
      56             :     assert((*this)[prb::tsk::probe].get_n_input_sockets() == 0);
      57             :     return Module::operator[]((int)prb::tsk::probe)[(int)s];
      58             : }
      59             : 
      60             : template<typename T>
      61             : runtime::Socket&
      62             : Probe<T>::operator[](const std::string& tsk_sck)
      63             : {
      64             :     return Module::operator[](tsk_sck);
      65             : }
      66             : 
      67             : template<typename T>
      68         182 : Probe<T>::Probe(const size_t socket_size, const std::string& col_name)
      69             :   : AProbe()
      70         182 :   , socket_size(socket_size)
      71         182 :   , col_name(col_name)
      72             : {
      73         182 :     const std::string name = "Probe<" + col_name + ">";
      74         182 :     this->set_name(name);
      75         182 :     this->set_short_name(name);
      76             : 
      77         182 :     auto& p1 = this->create_task("probe");
      78         182 :     auto p1s_in = (socket_size > 0) ? (int)this->template create_socket_in<T>(p1, "in", this->socket_size) : (int)-1;
      79         182 :     this->create_codelet(p1,
      80        2021 :                          [p1s_in](Module& m, runtime::Task& t, const size_t frame_id) -> int
      81             :                          {
      82        1489 :                              auto& prb = static_cast<Probe<T>&>(m);
      83        1489 :                              const T* in = (p1s_in != -1) ? t[p1s_in].template get_dataptr<const T>() : nullptr;
      84        1489 :                              prb._probe(in, frame_id);
      85        1489 :                              return runtime::status_t::SUCCESS;
      86             :                          });
      87         182 : }
      88             : 
      89             : template<typename T>
      90             : void
      91           0 : Probe<T>::set_n_frames(const size_t n_frames)
      92             : {
      93           0 :     const size_t old_n_frames = this->get_n_frames();
      94           0 :     if (old_n_frames != n_frames)
      95             :     {
      96           0 :         Module::set_n_frames(n_frames);
      97           0 :         if (reporter != nullptr) reporter->set_n_frames(n_frames);
      98             :     }
      99           0 : }
     100             : 
     101             : template<typename T>
     102             : template<class AT>
     103             : void
     104             : Probe<T>::probe(const std::vector<T, AT>& in, const int frame_id, const bool managed_memory)
     105             : {
     106             :     if ((*this)[prb::tsk::probe].get_n_input_sockets() != 1)
     107             :     {
     108             :         std::stringstream message;
     109             :         message << "The number of input sockets has to be equal to 1 ('get_n_input_sockets()' = "
     110             :                 << (*this)[prb::tsk::probe].get_n_input_sockets() << ").";
     111             :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
     112             :     }
     113             : 
     114             :     (*this)[prb::sck::probe::in].bind(in);
     115             :     (*this)[prb::tsk::probe].exec(frame_id, managed_memory);
     116             : }
     117             : 
     118             : template<typename T>
     119             : void
     120             : Probe<T>::probe(const T* in, const int frame_id, const bool managed_memory)
     121             : {
     122             :     if ((*this)[prb::tsk::probe].get_n_input_sockets() != 1)
     123             :     {
     124             :         std::stringstream message;
     125             :         message << "The number of input sockets has to be equal to 1 ('get_n_input_sockets()' = "
     126             :                 << (*this)[prb::tsk::probe].get_n_input_sockets() << ").";
     127             :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
     128             :     }
     129             : 
     130             :     (*this)[prb::sck::probe::in].bind(in);
     131             :     (*this)[prb::tsk::probe].exec(frame_id, managed_memory);
     132             : }
     133             : 
     134             : template<typename T>
     135             : void
     136             : Probe<T>::probe(const int frame_id, const bool managed_memory)
     137             : {
     138             :     if ((*this)[prb::tsk::probe].get_n_input_sockets() != 0)
     139             :     {
     140             :         std::stringstream message;
     141             :         message << "The number of input sockets has to be equal to 0 ('get_n_input_sockets()' = "
     142             :                 << (*this)[prb::tsk::probe].get_n_input_sockets() << ").";
     143             :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
     144             :     }
     145             : 
     146             :     (*this)[prb::tsk::probe].exec(frame_id, managed_memory);
     147             : }
     148             : 
     149             : template<typename T>
     150             : void
     151           0 : Probe<T>::_probe(const T* in, const size_t frame_id)
     152             : {
     153           0 :     throw tools::unimplemented_error(__FILE__, __LINE__, __func__);
     154             : }
     155             : 
     156             : template<typename T>
     157             : void
     158           0 : Probe<T>::reset()
     159             : {
     160           0 : }
     161             : 
     162             : template<typename T>
     163             : void
     164           0 : Probe<T>::set_col_unit(const std::string& unit)
     165             : {
     166           0 :     this->check_reporter();
     167           0 :     this->reporter->set_col_unit(unit, *this);
     168           0 : }
     169             : 
     170             : template<typename T>
     171             : void
     172           0 : Probe<T>::set_col_buff_size(const size_t buffer_size)
     173             : {
     174           0 :     this->check_reporter();
     175           0 :     this->reporter->set_col_buff_size(buffer_size, *this);
     176           0 : }
     177             : 
     178             : template<typename T>
     179             : void
     180           0 : Probe<T>::set_col_fmtflags(const std::ios_base::fmtflags ff)
     181             : {
     182           0 :     this->check_reporter();
     183           0 :     this->reporter->set_col_fmtflags(ff, *this);
     184           0 : }
     185             : 
     186             : template<typename T>
     187             : void
     188           0 : Probe<T>::set_col_prec(const size_t precision)
     189             : {
     190           0 :     this->check_reporter();
     191           0 :     this->reporter->set_col_prec(precision, *this);
     192           0 : }
     193             : 
     194             : template<typename T>
     195             : void
     196           0 : Probe<T>::set_col_size(const size_t col_size)
     197             : {
     198           0 :     this->check_reporter();
     199           0 :     this->reporter->set_col_size(col_size, *this);
     200           0 : }
     201             : 
     202             : template<typename T>
     203             : const std::string&
     204           0 : Probe<T>::get_col_name() const
     205             : {
     206           0 :     return this->col_name;
     207             : }
     208             : 
     209             : template<typename T>
     210             : const size_t
     211          56 : Probe<T>::get_socket_size() const
     212             : {
     213          56 :     return this->socket_size;
     214             : }
     215             : 
     216             : }
     217             : }

Generated by: LCOV version 1.14