LCOV - code coverage report
Current view: top level - proto - transfer_plugin_receiver.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 47 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 3 0

            Line data    Source code
       1              : #include "artdaq/TransferPlugins/TransferInterface.hh"
       2              : 
       3              : #include "artdaq-core/Data/Fragment.hh"
       4              : #include "artdaq-core/Utilities/ExceptionHandler.hh"
       5              : 
       6              : #include "cetlib/BasicPluginFactory.h"
       7              : #include "cetlib/filepath_maker.h"
       8              : #include "cetlib_except/exception.h"
       9              : #include "fhiclcpp/ParameterSet.h"
      10              : 
      11              : #include <boost/asio.hpp>
      12              : 
      13              : #include <iostream>
      14              : #include <limits>
      15              : #include <string>
      16              : 
      17              : // DUPLICATED CODE: also found in transfer_plugin_sender.cpp. Not as egregious as
      18              : // normal in that this function is unlikely to be changed, and this is
      19              : // a standalone app (not part of artdaq)
      20              : 
      21            0 : fhicl::ParameterSet ReadParameterSet(const std::string& fhicl_filename)
      22              : {
      23            0 :         if (std::getenv("FHICL_FILE_PATH") == nullptr)
      24              :         {
      25              :                 std::cerr
      26            0 :                     << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
      27            0 :                 setenv("FHICL_FILE_PATH", ".", 0);
      28              :         }
      29              : 
      30            0 :         cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
      31            0 :         auto pset = fhicl::ParameterSet::make(fhicl_filename, lookup_policy);
      32              : 
      33            0 :         return pset;
      34            0 : }
      35              : 
      36              : int do_check(const artdaq::Fragment& frag);
      37              : 
      38            0 : int main(int argc, char* argv[])
      39              : try
      40              : {
      41            0 :         if (argc != 2)
      42              :         {
      43            0 :                 std::cerr << "Usage: transfer_plugin_receiver <fhicl document>" << std::endl;
      44            0 :                 return 1;
      45              :         }
      46              : 
      47            0 :         auto fhicl_filename = boost::lexical_cast<std::string>(argv[1]);  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
      48              : 
      49            0 :         std::unique_ptr<artdaq::TransferInterface> transfer;
      50            0 :         auto pset = ReadParameterSet(fhicl_filename);
      51              : 
      52              :         try
      53              :         {
      54            0 :                 static cet::BasicPluginFactory bpf("transfer", "make");
      55              : 
      56              :                 transfer =
      57              :                     bpf.makePlugin<std::unique_ptr<artdaq::TransferInterface>,
      58              :                                    const fhicl::ParameterSet&,
      59            0 :                                    artdaq::TransferInterface::Role>(
      60            0 :                         pset.get<std::string>("transfer_plugin_type"),
      61              :                         pset,
      62            0 :                         artdaq::TransferInterface::Role::kReceive);
      63              :         }
      64            0 :         catch (...)
      65              :         {
      66            0 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no,
      67              :                                          "Error creating transfer plugin");
      68            0 :                 return 1;
      69            0 :         }
      70              : 
      71              :         while (true)
      72              :         {
      73            0 :                 artdaq::Fragment myfrag;
      74            0 :                 size_t timeout = 10000000;
      75              : 
      76            0 :                 auto retval = transfer->receiveFragment(myfrag, timeout);
      77              : 
      78            0 :                 if (retval >= artdaq::TransferInterface::RECV_SUCCESS)
      79              :                 {
      80            0 :                         std::cout << "Returned from call to transfer_->receiveFragmentFrom; fragment with seqID == " << myfrag.sequenceID() << ", fragID == " << myfrag.fragmentID() << " has size " << myfrag.sizeBytes() << " bytes" << std::endl;
      81              :                 }
      82              :                 else
      83              :                 {
      84            0 :                         std::cerr << "RECV_TIMEOUT received from call to transfer->receiveFragmentFrom" << std::endl;
      85            0 :                         continue;
      86              :                 }
      87              : 
      88            0 :                 if (do_check(myfrag) != 0)
      89              :                 {
      90            0 :                         std::cerr << "Error: do_check indicates fragment failed to transmit correctly" << std::endl;
      91              :                 }
      92              :                 else
      93              :                 {
      94            0 :                         std::cerr << "Success: do_check indicates fragment transmitted correctly" << std::endl;
      95              :                 }
      96            0 :         }
      97              : 
      98              :         return 0;
      99            0 : }
     100            0 : catch (...)
     101              : {
     102            0 :         return -1;
     103            0 : }
     104              : 
     105              : // JCF, Jun-22-2016
     106              : 
     107              : // do_check assumes std::iota was used to fill the sent fragment with
     108              : // monotonically incrementing 64-bit unsigned integers
     109              : 
     110            0 : int do_check(const artdaq::Fragment& frag)
     111              : {
     112            0 :         uint64_t variable_to_compare = 0;
     113              : 
     114            0 :         for (auto ptr_into_frag = reinterpret_cast<const uint64_t*>(frag.dataBeginBytes());  // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
     115            0 :              ptr_into_frag != reinterpret_cast<const uint64_t*>(frag.dataEndBytes());        // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
     116            0 :              ++ptr_into_frag, ++variable_to_compare)
     117              :         {
     118            0 :                 if (variable_to_compare != *ptr_into_frag)
     119              :                 {
     120            0 :                         std::cerr << "ERROR for fragment with sequence ID " << frag.sequenceID() << ", fragment ID " << frag.fragmentID() << ": expected ADC value of " << variable_to_compare << ", got " << *ptr_into_frag << std::endl;
     121            0 :                         return 1;
     122              :                 }
     123              :         }
     124              : 
     125            0 :         return 0;
     126              : }
        

Generated by: LCOV version 2.0-1