artdaq  v3_06_02
reconfigure_t.cc
1 #define TRACE_NAME "reconfigure_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/DAQdata/GenericFragmentSimulator.hh"
7 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
8 #include "cetlib_except/exception.h"
9 #include "fhiclcpp/ParameterSet.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 fhicl::ParameterSet;
21 using std::size_t;
22 
23 int main(int argc, char* argv[])
24 {
25  artdaq::configureMessageFacility("reconfigure_t");
26  struct Config
27  {
28  fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
29  fhicl::TableFragment<art::Config> art_config;
30  fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
31  };
32  auto pset = LoadParameterSet<Config>(argc, argv, "reconfigure_t", "reconfigure_t tests data from a GenericFragmentSimulator through art, then performs a reconfiguration and tests that the reconfiguration worked correctly.");
33  int rc = -1;
34  try
35  {
36  size_t const NUM_FRAGS_PER_EVENT = 5;
37  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
38  size_t const NUM_EVENTS = 100;
39  // We may want to add ParameterSet parsing to this code, but right
40  // now this will do...
41  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
42  pset.put("run_number", RUN_ID);
43  pset.put("print_event_store_stats", true);
44  pset.put("max_event_size_bytes", 0x100000);
45  pset.put("buffer_count", 10);
46  pset.put("send_init_fragments", false);
47 
48  auto temp = pset.to_string() + " source.waiting_time: 10";
49  pset = fhicl::ParameterSet();
50  fhicl::make_ParameterSet(temp, pset);
51  // Eventually, this test should make a mixed-up streams of
52  // Fragments; this has too clean a pattern to be an interesting
53  // test of the EventStore's ability to deal with multiple events
54  // simulatenously.
55  GenericFragmentSimulator sim(pset);
56  std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset));
57  events->startRun(100);
58  FragmentPtrs frags;
59  size_t event_count = 0;
60  while (frags.clear(), event_count++ < NUM_EVENTS && sim.getNext(frags))
61  {
62  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
63  assert(frags.size() == NUM_FRAGS_PER_EVENT);
64  for (auto&& frag : frags)
65  {
66  assert(frag != nullptr);
67 
68  auto start_time = std::chrono::steady_clock::now();
69  bool sts = false;
70  auto loop_count = 0;
71  while (!sts)
72  {
73  artdaq::FragmentPtr tempFrag;
74  sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
75  if (!sts && event_count <= 10 && loop_count > 100)
76  {
77  TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
78  events->endOfData();
79  exit(1);
80  }
81  frag = std::move(tempFrag);
82  if (!sts)
83  {
84  loop_count++;
85  usleep(10000);
86  }
87  }
88  }
89  }
90 
91  std::cout << "Ending first run..." << std::endl;
92  bool endSucceeded = events->endOfData();
93  if (endSucceeded)
94  {
95  rc = 0;
96 
97  size_t const NUM_EVENTS2 = 200;
98  auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
99  fhicl::ParameterSet sim_config2;
100  fhicl::make_ParameterSet(temp_config, sim_config2);
101  GenericFragmentSimulator sim2(sim_config2);
102  events->ReconfigureArt(sim_config2);
103  event_count = 0;
104  while (frags.clear(), event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
105  {
106  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
107  assert(frags.size() == NUM_FRAGS_PER_EVENT);
108  for (auto&& frag : frags)
109  {
110  assert(frag != nullptr);
111  bool sts = false;
112  auto loop_count = 0;
113  while (!sts)
114  {
115  artdaq::FragmentPtr tempFrag;
116  sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
117  if (!sts && event_count <= 10 && loop_count < 100)
118  {
119  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!";
120  exit(1);
121  }
122  frag = std::move(tempFrag);
123  if (!sts)
124  {
125  loop_count++;
126  usleep(10000);
127  }
128  }
129  }
130  }
131 
132  bool endSucceeded2 = events->endOfData();
133  if (endSucceeded2)
134  {
135  rc = 0;
136  }
137  else
138  {
139  rc = 16;
140  }
141  }
142  else
143  {
144  rc = 15;
145  }
146  }
147  catch (cet::exception& x)
148  {
149  std::cerr << argv[0] << " failure\n"
150  << x << std::endl;
151  rc = 1;
152  }
153  catch (std::string& x)
154  {
155  std::cerr << argv[0] << " failure\n"
156  << x << std::endl;
157  rc = 2;
158  }
159  catch (char const* x)
160  {
161  std::cerr << argv[0] << " failure\n"
162  << x << std::endl;
163  rc = 3;
164  }
165  return rc;
166 }
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...