artdaq  v3_11_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-utilities/Plugins/MakeParameterSet.hh"
6 #include "artdaq/Application/LoadParameterSet.hh"
7 #include "artdaq/ArtModules/detail/ArtConfig.hh"
8 #include "artdaq/DAQdata/GenericFragmentSimulator.hh"
9 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
10 #include "cetlib_except/exception.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[]) try
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 = artdaq::make_pset(temp);
47  // Eventually, this test should make a mixed-up streams of
48  // Fragments; this has too clean a pattern to be an interesting
49  // test of the EventStore's ability to deal with multiple events
50  // simulatenously.
51 
52  if (metricMan)
53  {
54  metricMan->initialize(pset.get<fhicl::ParameterSet>("metrics", fhicl::ParameterSet()), app_name);
55  metricMan->do_start();
56  }
57 
58  GenericFragmentSimulator sim(pset);
59  SharedMemoryEventManager events(pset, pset);
60  events.startRun(RUN_ID);
61  FragmentPtrs frags;
62  size_t event_count = 0;
63  while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
64  {
65  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
66  assert(frags.size() == NUM_FRAGS_PER_EVENT);
67  for (auto&& frag : frags)
68  {
69  assert(frag != nullptr);
70 
71  auto start_time = std::chrono::steady_clock::now();
72  bool sts = false;
73  auto loop_count = 0;
74  while (!sts)
75  {
76  artdaq::FragmentPtr tempFrag;
77  sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
78  if (!sts && event_count <= 10 && loop_count > 100)
79  {
80  TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
81  events.endOfData();
82  exit(1);
83  }
84  frag = std::move(tempFrag);
85  if (!sts)
86  {
87  loop_count++;
88  usleep(10000);
89  }
90  }
91  }
92  }
93 
94  bool endSucceeded = events.endOfData();
95  if (endSucceeded)
96  {
97  rc = 0;
98  }
99  else
100  {
101  rc = 15;
102  }
103  }
104  catch (cet::exception& x)
105  {
106  std::cerr << *argv << " failure\n"
107  << x << std::endl;
108  rc = 1;
109  }
110  catch (std::string& x)
111  {
112  std::cerr << *argv << " failure\n"
113  << x << std::endl;
114  rc = 2;
115  }
116  catch (char const* x)
117  {
118  std::cerr << *argv << " failure\n"
119  << x << std::endl;
120  rc = 3;
121  }
122  return rc;
123 }
124 catch (...)
125 {
126  return -1;
127 }
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.