00001 #define TRACE_NAME "daq_flow_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/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::FragmentPtrs;
00017 using artdaq::GenericFragmentSimulator;
00018 using artdaq::SharedMemoryEventManager;
00019 using std::size_t;
00020
00021
00022 int main(int argc, char* argv[])
00023 {
00024 struct Config {
00025 fhicl::TableFragment<artdaq::SharedMemoryEventManager::Config> shmem_config;
00026 fhicl::TableFragment<art::Config> art_config;
00027 fhicl::TableFragment<artdaq::GenericFragmentSimulator::Config> frag_gen_config;
00028 };
00029 auto pset = LoadParameterSet<Config>(argc, argv, "daq_flow_t", "daq_flow_t tests data from a GenericFragmentSimulator through art");
00030 int rc = -1;
00031 try
00032 {
00033 size_t const NUM_FRAGS_PER_EVENT = 5;
00034 SharedMemoryEventManager::run_id_t const RUN_ID = 2112;
00035 size_t const NUM_EVENTS = 100;
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("event_queue_wait_time", 10.0);
00040 pset.put("max_event_size_bytes", 0x100000);
00041 pset.put("buffer_count", 10);
00042 pset.put("send_init_fragments", false);
00043
00044 auto temp = pset.to_string() + " source.waiting_time: 10";
00045 pset = fhicl::ParameterSet();
00046 fhicl::make_ParameterSet(temp, pset);
00047
00048
00049
00050
00051 GenericFragmentSimulator sim(pset);
00052 SharedMemoryEventManager events(pset, pset);
00053 events.startRun(RUN_ID);
00054 FragmentPtrs frags;
00055 size_t event_count = 0;
00056 while (frags.clear() , event_count++ < NUM_EVENTS && sim.getNext(frags))
00057 {
00058 TLOG(TLVL_DEBUG) << "Number of fragments: " << frags.size();
00059 assert(frags.size() == NUM_FRAGS_PER_EVENT);
00060 for (auto&& frag : frags)
00061 {
00062 assert(frag != nullptr);
00063
00064 auto start_time = std::chrono::steady_clock::now();
00065 bool sts = false;
00066 auto loop_count = 0;
00067 while (!sts)
00068 {
00069 artdaq::FragmentPtr tempFrag;
00070 sts = events.AddFragment(std::move(frag), 1000000, tempFrag);
00071 if (!sts && event_count <= 10 && loop_count > 100)
00072 {
00073 TLOG(TLVL_ERROR) << "Fragment was not added after " << artdaq::TimeUtils::GetElapsedTime(start_time) << " s. Check art thread status!";
00074 events.endOfData();
00075 exit(1);
00076 }
00077 frag = std::move(tempFrag);
00078 if (!sts)
00079 {
00080 loop_count++;
00081 usleep(10000);
00082 }
00083 }
00084 }
00085 }
00086
00087 bool endSucceeded = events.endOfData();
00088 if (endSucceeded)
00089 {
00090 rc = 0;
00091 }
00092 else
00093 {
00094 rc = 15;
00095 }
00096 }
00097 catch (cet::exception& x)
00098 {
00099 std::cerr << argv[0] << " failure\n" << x << std::endl;
00100 rc = 1;
00101 }
00102 catch (std::string& x)
00103 {
00104 std::cerr << argv[0] << " failure\n" << x << std::endl;
00105 rc = 2;
00106 }
00107 catch (char const* x)
00108 {
00109 std::cerr << argv[0] << " failure\n" << x << std::endl;
00110 rc = 3;
00111 }
00112 return rc;
00113 }