LCOV - code coverage report
Current view: top level - test/ArtModules - daq_flow_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 66.7 % 66 44
Test Date: 2025-09-04 00:45:34 Functions: 66.7 % 3 2

            Line data    Source code
       1              : #include "TRACE/tracemf.h"
       2              : #define TRACE_NAME "daq_flow_t"
       3              : #include "artdaq-core/Data/Fragment.hh"
       4              : 
       5              : #include "artdaq/Application/LoadParameterSet.hh"
       6              : #include "artdaq/ArtModules/detail/ArtConfig.hh"
       7              : #include "artdaq/DAQdata/GenericFragmentSimulator.hh"
       8              : #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
       9              : #include "cetlib_except/exception.h"
      10              : #include "fhiclcpp/ParameterSet.h"
      11              : #include "fhiclcpp/types/TableFragment.h"
      12              : 
      13              : #include <cstddef>
      14              : #include <iostream>
      15              : #include <string>
      16              : #include <vector>
      17              : 
      18              : using artdaq::FragmentPtrs;
      19              : using artdaq::GenericFragmentSimulator;
      20              : using artdaq::SharedMemoryEventManager;
      21              : using std::size_t;
      22              : 
      23            1 : int main(int argc, char* argv[])
      24              : try
      25              : {
      26              :         struct Config
      27              :         {
      28              :                 fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
      29              :                 fhicl::TableFragment<art::Config> art_config;
      30              :                 fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
      31              :         };
      32            3 :         auto pset = LoadParameterSet<Config>(argc, argv, "daq_flow_t", "daq_flow_t tests data from a GenericFragmentSimulator through art");
      33            1 :         int rc = -1;
      34              :         try
      35              :         {
      36            1 :                 size_t const NUM_FRAGS_PER_EVENT = 5;
      37            1 :                 SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
      38            1 :                 size_t const NUM_EVENTS = 100;
      39            2 :                 pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
      40            1 :                 pset.put("run_number", RUN_ID);
      41            2 :                 pset.put("print_event_store_stats", true);
      42            2 :                 pset.put("event_queue_wait_time", 10.0);
      43            2 :                 pset.put("max_event_size_bytes", 0x100000);
      44            2 :                 pset.put("buffer_count", 10);
      45            2 :                 pset.put("send_init_fragments", false);
      46              : 
      47            1 :                 auto temp = pset.to_string() + " source.waiting_time: 10";
      48            1 :                 pset = fhicl::ParameterSet::make(temp);
      49              :                 // Eventually, this test should make a mixed-up streams of
      50              :                 // Fragments; this has too clean a pattern to be an interesting
      51              :                 // test of the EventStore's ability to deal with multiple events
      52              :                 // simulatenously.
      53              : 
      54            1 :                 if (metricMan)
      55              :                 {
      56            3 :                         metricMan->initialize(pset.get<fhicl::ParameterSet>("metrics", fhicl::ParameterSet()), app_name);
      57            1 :                         metricMan->do_start();
      58              :                 }
      59              : 
      60            1 :                 GenericFragmentSimulator sim(pset);
      61            1 :                 SharedMemoryEventManager events(pset, pset);
      62            1 :                 events.startRun(RUN_ID);
      63            1 :                 FragmentPtrs frags;
      64            1 :                 size_t event_count = 0;
      65          101 :                 while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
      66              :                 {
      67          300 :                         TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
      68          100 :                         assert(frags.size() == NUM_FRAGS_PER_EVENT);
      69          600 :                         for (auto&& frag : frags)
      70              :                         {
      71          500 :                                 assert(frag != nullptr);
      72              : 
      73          500 :                                 auto start_time = std::chrono::steady_clock::now();
      74          500 :                                 bool sts = false;
      75          500 :                                 auto loop_count = 0;
      76         1000 :                                 while (!sts)
      77              :                                 {
      78          500 :                                         artdaq::FragmentPtr tempFrag;
      79          500 :                                         sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
      80          500 :                                         if (!sts && event_count <= 10 && loop_count > 100)
      81              :                                         {
      82            0 :                                                 TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
      83            0 :                                                 events.endOfData();
      84            0 :                                                 exit(1);
      85              :                                         }
      86          500 :                                         frag = std::move(tempFrag);
      87          500 :                                         if (!sts)
      88              :                                         {
      89            0 :                                                 loop_count++;
      90            0 :                                                 usleep(10000);
      91              :                                         }
      92          500 :                                 }
      93              :                         }
      94              :                 }
      95              : 
      96            1 :                 bool endSucceeded = events.endOfData();
      97            1 :                 if (endSucceeded)
      98              :                 {
      99            1 :                         rc = 0;
     100              :                 }
     101              :                 else
     102              :                 {
     103            0 :                         rc = 15;
     104              :                 }
     105            1 :         }
     106            0 :         catch (cet::exception& x)
     107              :         {
     108            0 :                 std::cerr << *argv << " failure\n"
     109            0 :                           << x << std::endl;
     110            0 :                 rc = 1;
     111            0 :         }
     112            0 :         catch (std::string& x)
     113              :         {
     114              :                 std::cerr << *argv << " failure\n"
     115            0 :                           << x << std::endl;
     116            0 :                 rc = 2;
     117            0 :         }
     118            0 :         catch (char const* x)
     119              :         {
     120              :                 std::cerr << *argv << " failure\n"
     121            0 :                           << x << std::endl;
     122            0 :                 rc = 3;
     123            0 :         }
     124            1 :         return rc;
     125            1 : }
     126            0 : catch (...)
     127              : {
     128            0 :         return -1;
     129            0 : }
        

Generated by: LCOV version 2.0-1