$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #define TRACE_NAME "reconfigure_t" 00002 00003 #include "art/Framework/Art/artapp.h" 00004 #include "artdaq-core/Data/Fragment.hh" 00005 #include "artdaq/DAQdata/GenericFragmentSimulator.hh" 00006 #include "artdaq/DAQrate/SharedMemoryEventManager.hh" 00007 #include "cetlib_except/exception.h" 00008 #include "fhiclcpp/ParameterSet.h" 00009 #include "fhiclcpp/make_ParameterSet.h" 00010 #include "artdaq/Application/LoadParameterSet.hh" 00011 00012 #include <cstddef> 00013 #include <iostream> 00014 #include <string> 00015 #include <vector> 00016 00017 using artdaq::SharedMemoryEventManager; 00018 using artdaq::FragmentPtrs; 00019 using artdaq::GenericFragmentSimulator; 00020 using fhicl::ParameterSet; 00021 using std::size_t; 00022 00023 00024 int main(int argc, char* argv[]) 00025 { 00026 artdaq::configureMessageFacility("reconfigure_t"); 00027 struct Config 00028 { 00029 fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config; 00030 fhicl::TableFragment<art::Config> art_config; 00031 fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config; 00032 }; 00033 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."); 00034 int rc = -1; 00035 try 00036 { 00037 size_t const NUM_FRAGS_PER_EVENT = 5; 00038 SharedMemoryEventManager::run_id_t const RUN_ID = 2112; 00039 size_t const NUM_EVENTS = 100; 00040 // We may want to add ParameterSet parsing to this code, but right 00041 // now this will do... 00042 pset.put("expected_fragments_per_event", NUM_FRAGS_PER_EVENT); 00043 pset.put("run_number", RUN_ID); 00044 pset.put("print_event_store_stats", true); 00045 pset.put("max_event_size_bytes", 0x100000); 00046 pset.put("buffer_count",10); 00047 pset.put("send_init_fragments", false); 00048 00049 auto temp = pset.to_string() + " source.waiting_time: 10"; 00050 pset = fhicl::ParameterSet(); 00051 fhicl::make_ParameterSet(temp, pset); 00052 // Eventually, this test should make a mixed-up streams of 00053 // Fragments; this has too clean a pattern to be an interesting 00054 // test of the EventStore's ability to deal with multiple events 00055 // simulatenously. 00056 GenericFragmentSimulator sim(pset); 00057 std::unique_ptr<SharedMemoryEventManager> events(new SharedMemoryEventManager(pset, pset)); 00058 events->startRun(100); 00059 FragmentPtrs frags; 00060 size_t event_count = 0; 00061 while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags)) 00062 { 00063 TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size(); 00064 assert(frags.size() == NUM_FRAGS_PER_EVENT); 00065 for (auto&& frag : frags) 00066 { 00067 assert(frag != nullptr); 00068 00069 auto start_time = std::chrono::steady_clock::now(); 00070 bool sts = false; 00071 auto loop_count = 0; 00072 while (!sts) 00073 { 00074 artdaq::FragmentPtr tempFrag; 00075 sts = events->AddFragment(std::move(frag), 1000000, tempFrag); 00076 if (!sts && event_count <= 10 && loop_count > 100) 00077 { 00078 TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!"; 00079 events->endOfData(); 00080 exit(1); 00081 } 00082 frag = std::move(tempFrag); 00083 if (!sts) 00084 { 00085 loop_count++; 00086 usleep(10000); 00087 } 00088 } 00089 } 00090 } 00091 00092 std::cout << "Ending first run..." << std::endl; 00093 bool endSucceeded = events->endOfData(); 00094 if (endSucceeded) 00095 { 00096 rc = 0; 00097 00098 size_t const NUM_EVENTS2 = 200; 00099 auto temp_config = pset.to_string() + " source.waiting_time: 10 physics.analyzers.frags.num_events_expected: " + std::to_string(NUM_EVENTS2); 00100 fhicl::ParameterSet sim_config2; 00101 fhicl::make_ParameterSet(temp_config, sim_config2); 00102 GenericFragmentSimulator sim2(sim_config2); 00103 events->ReconfigureArt(sim_config2); 00104 event_count = 0; 00105 while (frags.clear() , event_count++ < NUM_EVENTS2 && sim2.getNext(frags)) 00106 { 00107 TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size(); 00108 assert(frags.size() == NUM_FRAGS_PER_EVENT); 00109 for (auto&& frag : frags) 00110 { 00111 assert(frag != nullptr); 00112 bool sts = false; 00113 auto loop_count = 0; 00114 while (!sts) 00115 { 00116 artdaq::FragmentPtr tempFrag; 00117 sts = events->AddFragment(std::move(frag), 1000000, tempFrag); 00118 if (!sts && event_count <= 10 && loop_count < 100) 00119 { 00120 TLOG(TLVL_ERROR) << "Fragment was not added after 1s. Check art thread status!"; 00121 exit(1); 00122 } 00123 frag = std::move(tempFrag); 00124 if (!sts) 00125 { 00126 loop_count++; 00127 usleep(10000); 00128 } 00129 } 00130 } 00131 } 00132 00133 bool endSucceeded2 = events->endOfData(); 00134 if (endSucceeded2) 00135 { 00136 rc = 0; 00137 } 00138 else 00139 { 00140 rc = 16; 00141 } 00142 } 00143 else 00144 { 00145 rc = 15; 00146 } 00147 } 00148 catch (cet::exception& x) 00149 { 00150 std::cerr << argv[0] << " failure\n" << x << std::endl; 00151 rc = 1; 00152 } 00153 catch (std::string& x) 00154 { 00155 std::cerr << argv[0] << " failure\n" << x << std::endl; 00156 rc = 2; 00157 } 00158 catch (char const* x) 00159 { 00160 std::cerr << argv[0] << " failure\n" << x << std::endl; 00161 rc = 3; 00162 } 00163 return rc; 00164 }