artdaq  v3_01_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  auto pset = LoadParameterSet(argc, argv);
25  int rc = -1;
26  try
27  {
28  size_t const NUM_FRAGS_PER_EVENT = 5;
29  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
30  size_t const NUM_EVENTS = 100;
31  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
32  pset.put("run_number", RUN_ID);
33  pset.put("print_event_store_stats", true);
34  pset.put("event_queue_wait_time", 10.0);
35  pset.put("max_event_size_bytes", 0x100000);
36  pset.put("buffer_count", 10);
37  pset.put("send_init_fragments", false);
38 
39  auto temp = pset.to_string() + " source.waiting_time: 10";
40  pset = fhicl::ParameterSet();
41  fhicl::make_ParameterSet(temp, pset);
42  // Eventually, this test should make a mixed-up streams of
43  // Fragments; this has too clean a pattern to be an interesting
44  // test of the EventStore's ability to deal with multiple events
45  // simulatenously.
46  GenericFragmentSimulator sim(pset);
47  SharedMemoryEventManager events(pset, pset);
48  events.startRun(RUN_ID);
49  FragmentPtrs frags;
50  size_t event_count = 0;
51  while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
52  {
53  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size() ;
54  assert(frags.size() == NUM_FRAGS_PER_EVENT);
55  for (auto&& frag : frags)
56  {
57  assert(frag != nullptr);
58  artdaq::FragmentPtr tempFrag;
59  auto sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
60  if (!sts)
61  {
62  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!" ;
63  exit(1);
64  }
65  }
66  }
67 
68  bool endSucceeded = events.endOfData();
69  if (endSucceeded)
70  {
71  rc = 0;
72  }
73  else
74  {
75  rc = 15;
76  }
77  }
78  catch (cet::exception& x)
79  {
80  std::cerr << argv[0] << " failure\n" << x << std::endl;
81  rc = 1;
82  }
83  catch (std::string& x)
84  {
85  std::cerr << argv[0] << " failure\n" << x << std::endl;
86  rc = 2;
87  }
88  catch (char const* x)
89  {
90  std::cerr << argv[0] << " failure\n" << x << std::endl;
91  rc = 3;
92  }
93  return rc;
94 }
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...