artdaq  v3_12_02
reconfigure_t.cc
1 #include "TRACE/tracemf.h"
2 #define TRACE_NAME "reconfigure_t"
3 #include "artdaq-core/Data/Fragment.hh"
4 
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/types/TableFragment.h"
12 
13 #include <cstddef>
14 #include <iostream>
15 #include <string>
16 #include <vector>
17 
18 using artdaq::FragmentPtrs;
21 using std::size_t;
22 
23 int main(int argc, char* argv[])
24 try
25 {
26  artdaq::configureMessageFacility("reconfigure_t");
27  struct Config
28  {
29  fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
30  fhicl::TableFragment<art::Config> art_config;
31  fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
32  };
33  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.");
34  int rc = -1;
35  try
36  {
37  size_t const NUM_FRAGS_PER_EVENT = 5;
38  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
39  size_t const NUM_EVENTS = 100;
40  // We may want to add ParameterSet parsing to this code, but right
41  // now this will do...
42  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
43  pset.put("run_number", RUN_ID);
44  pset.put("print_event_store_stats", true);
45  pset.put("max_event_size_bytes", 0x100000);
46  pset.put("buffer_count", 10);
47  pset.put("send_init_fragments", false);
48 
49  auto temp = pset.to_string() + " source.waiting_time: 10";
50  pset = fhicl::ParameterSet::make(temp);
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 = fhicl::ParameterSet::make(temp_config);
100  GenericFragmentSimulator sim2(sim_config2);
101  events->ReconfigureArt(sim_config2);
102  event_count = 0;
103  while (frags.clear(), event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
104  {
105  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
106  assert(frags.size() == NUM_FRAGS_PER_EVENT);
107  for (auto&& frag : frags)
108  {
109  assert(frag != nullptr);
110  bool sts = false;
111  auto loop_count = 0;
112  while (!sts)
113  {
114  artdaq::FragmentPtr tempFrag;
115  sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
116  if (!sts && event_count <= 10 && loop_count < 100)
117  {
118  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!";
119  exit(1);
120  }
121  frag = std::move(tempFrag);
122  if (!sts)
123  {
124  loop_count++;
125  usleep(10000);
126  }
127  }
128  }
129  }
130 
131  bool endSucceeded2 = events->endOfData();
132  if (endSucceeded2)
133  {
134  rc = 0;
135  }
136  else
137  {
138  rc = 16;
139  }
140  }
141  else
142  {
143  rc = 15;
144  }
145  }
146  catch (cet::exception& x)
147  {
148  std::cerr << *argv << " failure\n"
149  << x << std::endl;
150  rc = 1;
151  }
152  catch (std::string& x)
153  {
154  std::cerr << *argv << " failure\n"
155  << x << std::endl;
156  rc = 2;
157  }
158  catch (char const* x)
159  {
160  std::cerr << *argv << " failure\n"
161  << x << std::endl;
162  rc = 3;
163  }
164  return rc;
165 }
166 catch (...)
167 {
168  return -1;
169 }
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.