artdaq  v3_06_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/DAQdata/GenericFragmentSimulator.hh"
6 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
7 #include "cetlib_except/exception.h"
8 #include "fhiclcpp/make_ParameterSet.h"
9 #include "artdaq/Application/LoadParameterSet.hh"
10 
11 #include <cstddef>
12 #include <iostream>
13 #include <string>
14 #include <vector>
15 
16 using artdaq::FragmentPtrs;
19 using std::size_t;
20 
21 
22 int main(int argc, char* argv[])
23 {
24  struct Config {
25  fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
26  fhicl::TableFragment<art::Config> art_config;
27  fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
28  };
29  auto pset = LoadParameterSet<Config>(argc, argv, "daq_flow_t", "daq_flow_t tests data from a GenericFragmentSimulator through art");
30  int rc = -1;
31  try
32  {
33  size_t const NUM_FRAGS_PER_EVENT = 5;
34  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
35  size_t const NUM_EVENTS = 100;
36  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
37  pset.put("run_number", RUN_ID);
38  pset.put("print_event_store_stats", true);
39  pset.put("event_queue_wait_time", 10.0);
40  pset.put("max_event_size_bytes", 0x100000);
41  pset.put("buffer_count", 10);
42  pset.put("send_init_fragments", false);
43 
44  auto temp = pset.to_string() + " source.waiting_time: 10";
45  pset = fhicl::ParameterSet();
46  fhicl::make_ParameterSet(temp, pset);
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  GenericFragmentSimulator sim(pset);
52  SharedMemoryEventManager events(pset, pset);
53  events.startRun(RUN_ID);
54  FragmentPtrs frags;
55  size_t event_count = 0;
56  while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
57  {
58  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
59  assert(frags.size() == NUM_FRAGS_PER_EVENT);
60  for (auto&& frag : frags)
61  {
62  assert(frag != nullptr);
63 
64  auto start_time = std::chrono::steady_clock::now();
65  bool sts = false;
66  auto loop_count = 0;
67  while (!sts)
68  {
69  artdaq::FragmentPtr tempFrag;
70  sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
71  if (!sts && event_count <= 10 && loop_count > 100)
72  {
73  TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
74  events.endOfData();
75  exit(1);
76  }
77  frag = std::move(tempFrag);
78  if (!sts)
79  {
80  loop_count++;
81  usleep(10000);
82  }
83  }
84  }
85  }
86 
87  bool endSucceeded = events.endOfData();
88  if (endSucceeded)
89  {
90  rc = 0;
91  }
92  else
93  {
94  rc = 15;
95  }
96  }
97  catch (cet::exception& x)
98  {
99  std::cerr << argv[0] << " failure\n" << x << std::endl;
100  rc = 1;
101  }
102  catch (std::string& x)
103  {
104  std::cerr << argv[0] << " failure\n" << x << std::endl;
105  rc = 2;
106  }
107  catch (char const* x)
108  {
109  std::cerr << argv[0] << " failure\n" << x << std::endl;
110  rc = 3;
111  }
112  return rc;
113 }
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...