00001 #include "art/Framework/Art/artapp.h"
00002 #include "artdaq-core/Data/Fragment.hh"
00003 #include "artdaq/DAQdata/GenericFragmentSimulator.hh"
00004 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
00005 #include "artdaq/Application/MPI2/MPISentry.hh"
00006 #include "cetlib/exception.h"
00007 #include "fhiclcpp/ParameterSet.h"
00008 #include "fhiclcpp/make_ParameterSet.h"
00009 #include "artdaq/Application/LoadParameterSet.hh"
00010
00011 #include <cstddef>
00012 #include <iostream>
00013 #include <string>
00014 #include <vector>
00015
00016 using artdaq::SharedMemoryEventManager;
00017 using artdaq::FragmentPtrs;
00018 using artdaq::GenericFragmentSimulator;
00019 using fhicl::ParameterSet;
00020 using std::size_t;
00021
00022
00023 int main(int argc, char* argv[])
00024 {
00025 artdaq::configureMessageFacility("reconfigure_t");
00026 auto pset = LoadParameterSet(argc, argv);
00027 artdaq::MPISentry mpiSentry(&argc, &argv);
00028 int rc = -1;
00029 try
00030 {
00031 size_t const NUM_FRAGS_PER_EVENT = 5;
00032 SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
00033 size_t const NUM_EVENTS = 100;
00034
00035
00036 pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT);
00037 pset.put("run_number", RUN_ID);
00038 pset.put("print_event_store_stats", true);
00039 pset.put("max_event_size_bytes", 0x100000);
00040 pset.put("buffer_count",10);
00041
00042 auto temp = pset.to_string() + " source.waiting_time: 10";
00043 pset = fhicl::ParameterSet();
00044 fhicl::make_ParameterSet(temp, pset);
00045
00046
00047
00048
00049 GenericFragmentSimulator sim(pset);
00050 std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset));
00051 events->startRun(100);
00052 FragmentPtrs frags;
00053 size_t event_count = 0;
00054 while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
00055 {
00056 LOG_DEBUG("main") << "Number of fragments: " << frags.size() << '\n';
00057 assert(frags.size() == NUM_FRAGS_PER_EVENT);
00058 for (auto&& frag : frags)
00059 {
00060 assert(frag != nullptr);
00061 artdaq::FragmentPtr tempFrag;
00062 auto sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
00063 if (!sts)
00064 {
00065 TLOG_ERROR("reconfigure_t") << "Fragment was not added after 1s. Check art thread status!" << TLOG_ENDL;
00066 exit(1);
00067 }
00068 }
00069 }
00070
00071 std::cout << "Ending first run..." << std::endl;
00072 bool endSucceeded = events->endOfData();
00073 if (endSucceeded)
00074 {
00075 rc = 0;
00076
00077 size_t const NUM_EVENTS2 = 200;
00078 auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2);
00079 fhicl::ParameterSet sim_config2;
00080 fhicl::make_ParameterSet(temp_config, sim_config2);
00081 GenericFragmentSimulator sim2(sim_config2);
00082 events->ReconfigureArt(sim_config2);
00083 event_count = 0;
00084 while (frags.clear() , event_count++ < NUM_EVENTS2 && sim2.getNext(frags))
00085 {
00086 LOG_DEBUG("main") << "Number of fragments: " << frags.size() << '\n';
00087 assert(frags.size() == NUM_FRAGS_PER_EVENT);
00088 for (auto&& frag : frags)
00089 {
00090 assert(frag != nullptr);
00091 artdaq::FragmentPtr tempFrag;
00092 auto sts = events->AddFragment(std::move(frag), 1000000, tempFrag);
00093 if (!sts)
00094 {
00095 TLOG_ERROR("reconfigure_t") << "Fragment was not added after 1s. Check art thread status!" << TLOG_ENDL;
00096 exit(1);
00097 }
00098 }
00099 }
00100
00101 bool endSucceeded2 = events->endOfData();
00102 if (endSucceeded2)
00103 {
00104 rc = 0;
00105 }
00106 else
00107 {
00108 rc = 16;
00109 }
00110 }
00111 else
00112 {
00113 rc = 15;
00114 }
00115 }
00116 catch (cet::exception& x)
00117 {
00118 std::cerr << argv[0] << " failure\n" << x << std::endl;
00119 rc = 1;
00120 }
00121 catch (std::string& x)
00122 {
00123 std::cerr << argv[0] << " failure\n" << x << std::endl;
00124 rc = 2;
00125 }
00126 catch (char const* x)
00127 {
00128 std::cerr << argv[0] << " failure\n" << x << std::endl;
00129 rc = 3;
00130 }
00131 return rc;
00132 }