artdaq  v3_09_01
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 try
24 {
25  struct Config
26  {
27  fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
28  fhicl::TableFragment<art::Config> art_config;
29  fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
30  };
31  auto pset = LoadParameterSet<Config>(argc, argv, "daq_flow_t", "daq_flow_t tests data from a GenericFragmentSimulator through art");
32  int rc = -1;
33  try
34  {
35  size_t const NUM_FRAGS_PER_EVENT = 5;
36  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
37  size_t const NUM_EVENTS = 100;
38  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
39  pset.put("run_number", RUN_ID);
40  pset.put("print_event_store_stats", true);
41  pset.put("event_queue_wait_time", 10.0);
42  pset.put("max_event_size_bytes", 0x100000);
43  pset.put("buffer_count", 10);
44  pset.put("send_init_fragments", false);
45 
46  auto temp = pset.to_string() + " source.waiting_time: 10";
47  pset = fhicl::ParameterSet();
48  fhicl::make_ParameterSet(temp, pset);
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  if (metricMan)
55  {
56  metricMan->initialize(pset.get<fhicl::ParameterSet>("metrics", fhicl::ParameterSet()), app_name);
57  metricMan->do_start();
58  }
59 
60  GenericFragmentSimulator sim(pset);
61  SharedMemoryEventManager events(pset, pset);
62  events.startRun(RUN_ID);
63  FragmentPtrs frags;
64  size_t event_count = 0;
65  while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
66  {
67  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
68  assert(frags.size() == NUM_FRAGS_PER_EVENT);
69  for (auto&& frag : frags)
70  {
71  assert(frag != nullptr);
72 
73  auto start_time = std::chrono::steady_clock::now();
74  bool sts = false;
75  auto loop_count = 0;
76  while (!sts)
77  {
78  artdaq::FragmentPtr tempFrag;
79  sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
80  if (!sts && event_count <= 10 && loop_count > 100)
81  {
82  TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
83  events.endOfData();
84  exit(1);
85  }
86  frag = std::move(tempFrag);
87  if (!sts)
88  {
89  loop_count++;
90  usleep(10000);
91  }
92  }
93  }
94  }
95 
96  bool endSucceeded = events.endOfData();
97  if (endSucceeded)
98  {
99  rc = 0;
100  }
101  else
102  {
103  rc = 15;
104  }
105  }
106  catch (cet::exception& x)
107  {
108  std::cerr << *argv << " failure\n"
109  << x << std::endl;
110  rc = 1;
111  }
112  catch (std::string& x)
113  {
114  std::cerr << *argv << " failure\n"
115  << x << std::endl;
116  rc = 2;
117  }
118  catch (char const* x)
119  {
120  std::cerr << *argv << " failure\n"
121  << x << std::endl;
122  rc = 3;
123  }
124  return rc;
125 }
126 catch (...)
127 {
128  return -1;
129 }
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.