LCOV - code coverage report
Current view: top level - test/ArtModules - reconfigure_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 69.5 % 95 66
Test Date: 2026-10-29 00:35:58 Functions: 50.0 % 6 3

            Line data    Source code
       1              : #include "TRACE/tracemf.h"
       2              : #define TRACE_NAME "reconfigure_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/DAQrate/SharedMemoryEventManager.hh"
       8              : #include "artdaq/Generators/GenericFragmentSimulator.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            1 :         artdaq::configureMessageFacility("reconfigure_t");
      27              :         struct Config
      28              :         {
      29              :                 fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
      30              :                 fhicl::TableFragment<art::Config> art_config;
      31              :                 fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
      32              :         };
      33            3 :         auto pset = LoadParameterSet<Config>(argc, argv, "reconfigure_t", "reconfigure_t tests data from a GenericFragmentSimulator through art, then performs a reconfiguration and tests that the reconfiguration worked correctly.");
      34            1 :         int rc = -1;
      35              :         try
      36              :         {
      37            1 :                 size_t const NUM_FRAGS_PER_EVENT = 5;
      38            1 :                 SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
      39            1 :                 size_t const NUM_EVENTS = 100;
      40              :                 // We may want to add ParameterSet parsing to this code, but right
      41              :                 // now this will do...
      42            2 :                 pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
      43            1 :                 pset.put("run_number", RUN_ID);
      44            2 :                 pset.put("print_event_store_stats", true);
      45            2 :                 pset.put("max_event_size_bytes", 0x100000);
      46            2 :                 pset.put("buffer_count", 10);
      47            2 :                 pset.put("send_init_fragments", false);
      48              : 
      49            1 :                 auto temp = pset.to_string() + " source.waiting_time: 10";
      50            1 :                 pset = fhicl::ParameterSet::make(temp);
      51              :                 // Eventually, this test should make a mixed-up streams of
      52              :                 // Fragments; this has too clean a pattern to be an interesting
      53              :                 // test of the EventStore's ability to deal with multiple events
      54              :                 // simulatenously.
      55            1 :                 GenericFragmentSimulator sim(pset);
      56            1 :                 std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset));
      57            1 :                 if (!events->startRun(100))
      58              :                 {
      59            0 :                         TLOG(TLVL_ERROR) << "Failed to start run in SharedMemoryEventManager!";
      60            0 :                         return 4;
      61              :                 }
      62            1 :                 FragmentPtrs frags;
      63            1 :                 size_t event_count = 0;
      64          101 :                 while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
      65              :                 {
      66          300 :                         TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
      67          100 :                         assert(frags.size() == NUM_FRAGS_PER_EVENT);
      68          600 :                         for (auto&& frag : frags)
      69              :                         {
      70          500 :                                 assert(frag != nullptr);
      71              : 
      72          500 :                                 auto start_time = std::chrono::steady_clock::now();
      73          500 :                                 bool sts = false;
      74          500 :                                 auto loop_count = 0;
      75         1000 :                                 while (!sts)
      76              :                                 {
      77          500 :                                         artdaq::FragmentPtr tempFrag;
      78          500 :                                         sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
      79          500 :                                         if (!sts && event_count <= 10 && loop_count > 100)
      80              :                                         {
      81            0 :                                                 TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
      82            0 :                                                 events->endOfData();
      83            0 :                                                 exit(1);
      84              :                                         }
      85          500 :                                         frag = std::move(tempFrag);
      86          500 :                                         if (!sts)
      87              :                                         {
      88            0 :                                                 loop_count++;
      89            0 :                                                 usleep(10000);
      90              :                                         }
      91          500 :                                 }
      92              :                         }
      93              :                 }
      94              : 
      95            1 :                 std::cout << "Ending first run..." << std::endl;
      96            1 :                 bool endSucceeded = events->endOfData();
      97            1 :                 if (endSucceeded)
      98              :                 {
      99            1 :                         rc = 0;
     100              : 
     101            1 :                         size_t const NUM_EVENTS2 = 200;
     102            1 :                         auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
     103            1 :                         fhicl::ParameterSet sim_config2 = fhicl::ParameterSet::make(temp_config);
     104            1 :                         GenericFragmentSimulator sim2(sim_config2);
     105            1 :                         events->ReconfigureArt(sim_config2);
     106            1 :                         event_count = 0;
     107          201 :                         while (frags.clear(), event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
     108              :                         {
     109          600 :                                 TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
     110          200 :                                 assert(frags.size() == NUM_FRAGS_PER_EVENT);
     111         1200 :                                 for (auto&& frag : frags)
     112              :                                 {
     113         1000 :                                         assert(frag != nullptr);
     114         1000 :                                         bool sts = false;
     115         1000 :                                         auto loop_count = 0;
     116         2000 :                                         while (!sts)
     117              :                                         {
     118         1000 :                                                 artdaq::FragmentPtr tempFrag;
     119         1000 :                                                 sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
     120         1000 :                                                 if (!sts && event_count <= 10 && loop_count < 100)
     121              :                                                 {
     122            0 :                                                         TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!";
     123            0 :                                                         exit(1);
     124              :                                                 }
     125         1000 :                                                 frag = std::move(tempFrag);
     126         1000 :                                                 if (!sts)
     127              :                                                 {
     128            0 :                                                         loop_count++;
     129            0 :                                                         usleep(10000);
     130              :                                                 }
     131         1000 :                                         }
     132              :                                 }
     133              :                         }
     134              : 
     135            1 :                         bool endSucceeded2 = events->endOfData();
     136            1 :                         if (endSucceeded2)
     137              :                         {
     138            1 :                                 rc = 0;
     139              :                         }
     140              :                         else
     141              :                         {
     142            0 :                                 rc = 16;
     143              :                         }
     144            1 :                 }
     145              :                 else
     146              :                 {
     147            0 :                         rc = 15;
     148              :                 }
     149            1 :         }
     150            0 :         catch (cet::exception& x)
     151              :         {
     152            0 :                 std::cerr << *argv << " failure\n"
     153            0 :                           << x << std::endl;
     154            0 :                 rc = 1;
     155            0 :         }
     156            0 :         catch (std::string& x)
     157              :         {
     158              :                 std::cerr << *argv << " failure\n"
     159            0 :                           << x << std::endl;
     160            0 :                 rc = 2;
     161            0 :         }
     162            0 :         catch (char const* x)
     163              :         {
     164              :                 std::cerr << *argv << " failure\n"
     165            0 :                           << x << std::endl;
     166            0 :                 rc = 3;
     167            0 :         }
     168            1 :         return rc;
     169            1 : }
     170            0 : catch (...)
     171              : {
     172            0 :         return -1;
     173            0 : }
        

Generated by: LCOV version 2.0-1