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