LCOV - code coverage report
Current view: top level - test/ArtModules - reconfigure_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 71.0 % 93 66
Test Date: 2025-09-04 00:45:34 Functions: 60.0 % 5 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/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            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 :                 events->startRun(100);
      58            1 :                 FragmentPtrs frags;
      59            1 :                 size_t event_count = 0;
      60          101 :                 while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
      61              :                 {
      62          300 :                         TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
      63          100 :                         assert(frags.size() == NUM_FRAGS_PER_EVENT);
      64          600 :                         for (auto&& frag : frags)
      65              :                         {
      66          500 :                                 assert(frag != nullptr);
      67              : 
      68          500 :                                 auto start_time = std::chrono::steady_clock::now();
      69          500 :                                 bool sts = false;
      70          500 :                                 auto loop_count = 0;
      71         1000 :                                 while (!sts)
      72              :                                 {
      73          500 :                                         artdaq::FragmentPtr tempFrag;
      74          500 :                                         sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
      75          500 :                                         if (!sts && event_count <= 10 && loop_count > 100)
      76              :                                         {
      77            0 :                                                 TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
      78            0 :                                                 events->endOfData();
      79            0 :                                                 exit(1);
      80              :                                         }
      81          500 :                                         frag = std::move(tempFrag);
      82          500 :                                         if (!sts)
      83              :                                         {
      84            0 :                                                 loop_count++;
      85            0 :                                                 usleep(10000);
      86              :                                         }
      87          500 :                                 }
      88              :                         }
      89              :                 }
      90              : 
      91            1 :                 std::cout << "Ending first run..." << std::endl;
      92            1 :                 bool endSucceeded = events->endOfData();
      93            1 :                 if (endSucceeded)
      94              :                 {
      95            1 :                         rc = 0;
      96              : 
      97            1 :                         size_t const NUM_EVENTS2 = 200;
      98            1 :                         auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
      99            1 :                         fhicl::ParameterSet sim_config2 = fhicl::ParameterSet::make(temp_config);
     100            1 :                         GenericFragmentSimulator sim2(sim_config2);
     101            1 :                         events->ReconfigureArt(sim_config2);
     102            1 :                         event_count = 0;
     103          201 :                         while (frags.clear(), event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
     104              :                         {
     105          600 :                                 TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
     106          200 :                                 assert(frags.size() == NUM_FRAGS_PER_EVENT);
     107         1200 :                                 for (auto&& frag : frags)
     108              :                                 {
     109         1000 :                                         assert(frag != nullptr);
     110         1000 :                                         bool sts = false;
     111         1000 :                                         auto loop_count = 0;
     112         2000 :                                         while (!sts)
     113              :                                         {
     114         1000 :                                                 artdaq::FragmentPtr tempFrag;
     115         1000 :                                                 sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
     116         1000 :                                                 if (!sts && event_count <= 10 && loop_count < 100)
     117              :                                                 {
     118            0 :                                                         TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!";
     119            0 :                                                         exit(1);
     120              :                                                 }
     121         1000 :                                                 frag = std::move(tempFrag);
     122         1000 :                                                 if (!sts)
     123              :                                                 {
     124            0 :                                                         loop_count++;
     125            0 :                                                         usleep(10000);
     126              :                                                 }
     127         1000 :                                         }
     128              :                                 }
     129              :                         }
     130              : 
     131            1 :                         bool endSucceeded2 = events->endOfData();
     132            1 :                         if (endSucceeded2)
     133              :                         {
     134            1 :                                 rc = 0;
     135              :                         }
     136              :                         else
     137              :                         {
     138            0 :                                 rc = 16;
     139              :                         }
     140            1 :                 }
     141              :                 else
     142              :                 {
     143            0 :                         rc = 15;
     144              :                 }
     145            1 :         }
     146            0 :         catch (cet::exception& x)
     147              :         {
     148            0 :                 std::cerr << *argv << " failure\n"
     149            0 :                           << x << std::endl;
     150            0 :                 rc = 1;
     151            0 :         }
     152            0 :         catch (std::string& x)
     153              :         {
     154              :                 std::cerr << *argv << " failure\n"
     155            0 :                           << x << std::endl;
     156            0 :                 rc = 2;
     157            0 :         }
     158            0 :         catch (char const* x)
     159              :         {
     160              :                 std::cerr << *argv << " failure\n"
     161            0 :                           << x << std::endl;
     162            0 :                 rc = 3;
     163            0 :         }
     164            1 :         return rc;
     165            1 : }
     166            0 : catch (...)
     167              : {
     168            0 :         return -1;
     169            0 : }
        

Generated by: LCOV version 2.0-1