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/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 : 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 : auto started = events.startRun(RUN_ID);
63 1 : if (!started)
64 : {
65 0 : TLOG(TLVL_ERROR) << "Failed to start run in SharedMemoryEventManager!";
66 0 : return 4;
67 : }
68 1 : FragmentPtrs frags;
69 1 : size_t event_count = 0;
70 101 : while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
71 : {
72 300 : TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
73 100 : assert(frags.size() == NUM_FRAGS_PER_EVENT);
74 600 : for (auto&& frag : frags)
75 : {
76 500 : assert(frag != nullptr);
77 :
78 500 : auto start_time = std::chrono::steady_clock::now();
79 500 : bool sts = false;
80 500 : auto loop_count = 0;
81 1004 : while (!sts)
82 : {
83 504 : artdaq::FragmentPtr tempFrag;
84 504 : sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
85 504 : if (!sts && event_count <= 10 && loop_count > 100)
86 : {
87 0 : TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
88 0 : events.endOfData();
89 0 : exit(1);
90 : }
91 504 : frag = std::move(tempFrag);
92 504 : if (!sts)
93 : {
94 4 : loop_count++;
95 4 : usleep(10000);
96 : }
97 504 : }
98 : }
99 : }
100 :
101 1 : bool endSucceeded = events.endOfData();
102 1 : if (endSucceeded)
103 : {
104 1 : rc = 0;
105 : }
106 : else
107 : {
108 0 : rc = 15;
109 : }
110 1 : }
111 0 : catch (cet::exception& x)
112 : {
113 0 : std::cerr << *argv << " failure\n"
114 0 : << x << std::endl;
115 0 : rc = 1;
116 0 : }
117 0 : catch (std::string& x)
118 : {
119 : std::cerr << *argv << " failure\n"
120 0 : << x << std::endl;
121 0 : rc = 2;
122 0 : }
123 0 : catch (char const* x)
124 : {
125 : std::cerr << *argv << " failure\n"
126 0 : << x << std::endl;
127 0 : rc = 3;
128 0 : }
129 1 : return rc;
130 1 : }
131 0 : catch (...)
132 : {
133 0 : return -1;
134 0 : }
|