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