artdaq  v3_05_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/DAQdata/GenericFragmentSimulator.hh"
6 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
7 #include "cetlib_except/exception.h"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "fhiclcpp/make_ParameterSet.h"
10 #include "artdaq/Application/LoadParameterSet.hh"
11 
12 #include <cstddef>
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 
18 using artdaq::FragmentPtrs;
20 using fhicl::ParameterSet;
21 using std::size_t;
22 
23 
24 int main(int argc, char* argv[])
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();
51  fhicl::make_ParameterSet(temp, pset);
52  // Eventually, this test should make a mixed-up streams of
53  // Fragments; this has too clean a pattern to be an interesting
54  // test of the EventStore's ability to deal with multiple events
55  // simulatenously.
56  GenericFragmentSimulator sim(pset);
57  std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset));
58  events->startRun(100);
59  FragmentPtrs frags;
60  size_t event_count = 0;
61  while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
62  {
63  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
64  assert(frags.size() == NUM_FRAGS_PER_EVENT);
65  for (auto&& frag : frags)
66  {
67  assert(frag != nullptr);
68 
69  auto start_time = std::chrono::steady_clock::now();
70  bool sts = false;
71  auto loop_count = 0;
72  while (!sts)
73  {
74  artdaq::FragmentPtr tempFrag;
75  sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
76  if (!sts && event_count <= 10 && loop_count > 100)
77  {
78  TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
79  events->endOfData();
80  exit(1);
81  }
82  frag = std::move(tempFrag);
83  if (!sts)
84  {
85  loop_count++;
86  usleep(10000);
87  }
88  }
89  }
90  }
91 
92  std::cout << "Ending first run..." << std::endl;
93  bool endSucceeded = events->endOfData();
94  if (endSucceeded)
95  {
96  rc = 0;
97 
98  size_t const NUM_EVENTS2 = 200;
99  auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
100  fhicl::ParameterSet sim_config2;
101  fhicl::make_ParameterSet(temp_config, sim_config2);
102  GenericFragmentSimulator sim2(sim_config2);
103  events->ReconfigureArt(sim_config2);
104  event_count = 0;
105  while (frags.clear() , event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
106  {
107  TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
108  assert(frags.size() == NUM_FRAGS_PER_EVENT);
109  for (auto&& frag : frags)
110  {
111  assert(frag != nullptr);
112  bool sts = false;
113  auto loop_count = 0;
114  while (!sts)
115  {
116  artdaq::FragmentPtr tempFrag;
117  sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
118  if (!sts && event_count <= 10 && loop_count < 100)
119  {
120  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!";
121  exit(1);
122  }
123  frag = std::move(tempFrag);
124  if (!sts)
125  {
126  loop_count++;
127  usleep(10000);
128  }
129  }
130  }
131  }
132 
133  bool endSucceeded2 = events->endOfData();
134  if (endSucceeded2)
135  {
136  rc = 0;
137  }
138  else
139  {
140  rc = 16;
141  }
142  }
143  else
144  {
145  rc = 15;
146  }
147  }
148  catch (cet::exception& x)
149  {
150  std::cerr << argv[0] << " failure\n" << x << std::endl;
151  rc = 1;
152  }
153  catch (std::string& x)
154  {
155  std::cerr << argv[0] << " failure\n" << x << std::endl;
156  rc = 2;
157  }
158  catch (char const* x)
159  {
160  std::cerr << argv[0] << " failure\n" << x << std::endl;
161  rc = 3;
162  }
163  return rc;
164 }
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...