artdaq  v3_01_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  auto pset = LoadParameterSet(argc, argv);
28  int rc = -1;
29  try
30  {
31  size_t const NUM_FRAGS_PER_EVENT = 5;
32  SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
33  size_t const NUM_EVENTS = 100;
34  // We may want to add ParameterSet parsing to this code, but right
35  // now this will do...
36  pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
37  pset.put("run_number", RUN_ID);
38  pset.put("print_event_store_stats", true);
39  pset.put("max_event_size_bytes", 0x100000);
40  pset.put("buffer_count",10);
41 
42  auto temp = pset.to_string() + " source.waiting_time: 10";
43  pset = fhicl::ParameterSet();
44  fhicl::make_ParameterSet(temp, pset);
45  // Eventually, this test should make a mixed-up streams of
46  // Fragments; this has too clean a pattern to be an interesting
47  // test of the EventStore's ability to deal with multiple events
48  // simulatenously.
49  GenericFragmentSimulator sim(pset);
50  std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset));
51  events->startRun(100);
52  FragmentPtrs frags;
53  size_t event_count = 0;
54  while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
55  {
56  LOG_DEBUG("main") << "Number of fragments: " << frags.size() << '\n';
57  assert(frags.size() == NUM_FRAGS_PER_EVENT);
58  for (auto&& frag : frags)
59  {
60  assert(frag != nullptr);
61  artdaq::FragmentPtr tempFrag;
62  auto sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
63  if (!sts)
64  {
65  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!" ;
66  exit(1);
67  }
68  }
69  }
70 
71  std::cout << "Ending first run..." << std::endl;
72  bool endSucceeded = events->endOfData();
73  if (endSucceeded)
74  {
75  rc = 0;
76 
77  size_t const NUM_EVENTS2 = 200;
78  auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
79  fhicl::ParameterSet sim_config2;
80  fhicl::make_ParameterSet(temp_config, sim_config2);
81  GenericFragmentSimulator sim2(sim_config2);
82  events->ReconfigureArt(sim_config2);
83  event_count = 0;
84  while (frags.clear() , event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
85  {
86  LOG_DEBUG("main") << "Number of fragments: " << frags.size() << '\n';
87  assert(frags.size() == NUM_FRAGS_PER_EVENT);
88  for (auto&& frag : frags)
89  {
90  assert(frag != nullptr);
91  artdaq::FragmentPtr tempFrag;
92  auto sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
93  if (!sts)
94  {
95  TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!" ;
96  exit(1);
97  }
98  }
99  }
100 
101  bool endSucceeded2 = events->endOfData();
102  if (endSucceeded2)
103  {
104  rc = 0;
105  }
106  else
107  {
108  rc = 16;
109  }
110  }
111  else
112  {
113  rc = 15;
114  }
115  }
116  catch (cet::exception& x)
117  {
118  std::cerr << argv[0] << " failure\n" << x << std::endl;
119  rc = 1;
120  }
121  catch (std::string& x)
122  {
123  std::cerr << argv[0] << " failure\n" << x << std::endl;
124  rc = 2;
125  }
126  catch (char const* x)
127  {
128  std::cerr << argv[0] << " failure\n" << x << std::endl;
129  rc = 3;
130  }
131  return rc;
132 }
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...