1 #include "otsdaq-demo/Generators/DataGenReceiver.hh"
4 #include "artdaq-core/Utilities/SimpleLookupPolicy.h"
5 #include "artdaq/Application/GeneratorMacros.hh"
6 #include "cetlib/exception.h"
7 #include "fhiclcpp/ParameterSet.h"
8 #include "otsdaq-demo/Overlays/DataGenFragmentWriter.hh"
9 #include "otsdaq-demo/Overlays/FragmentType.hh"
18 ots::DataGenReceiver::DataGenReceiver(fhicl::ParameterSet
const& ps)
19 : WorkLoop(
"DataGenReceiver")
20 , DataConsumer(ps.get<std::string>(
"SupervisorApplicationUID",
"ARTDAQDataManager"),
21 ps.get<std::string>(
"BufferUID",
"ARTDAQBuffer"),
22 ps.get<std::string>(
"ProcessorUID",
"DataGenReceiver"),
24 , CommandableFragmentGenerator(ps)
25 , rawOutput_(ps.get<bool>(
"raw_output_enabled", false))
26 , rawPath_(ps.get<std::string>(
"raw_output_path",
"/tmp"))
27 , dataport_(ps.get<int>(
"port", 6343))
28 , ip_(ps.get<std::string>(
"ip",
"127.0.0.1"))
29 , expectedPacketNumber_(0)
30 , sendCommands_(ps.get<bool>(
"send_OtsUDP_commands", false))
31 , fragmentWindow_(ps.get<double>(
"fragment_time_window_ms", 1000))
32 , lastFrag_(std::chrono::high_resolution_clock::now())
34 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
35 mf::LogInfo(
"DataGenReceiver")
36 <<
"MY TRIGGER MODE IS: " << ps.get<std::string>(
"trigger_mode",
"UNDEFINED!!!");
37 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ <<
"registering to buffer!"
43 bool ots::DataGenReceiver::getNext_(artdaq::FragmentPtrs& output)
50 if(read<std::string, std::map<std::string, std::string>>(buffer_) < 0)
56 unsigned long long value;
57 memcpy((
void*)&value, (
void*)buffer_.substr(2).data(),
59 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::hex << value
60 << std::dec << std::endl;
67 void ots::DataGenReceiver::ProcessData_(artdaq::FragmentPtrs& frags)
69 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
70 unsigned long long value;
71 memcpy((
void*)&value, (
void*)buffer_.substr(2).data(),
73 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::hex << value << std::dec
80 metadata.address = 0xc0aabb11;
87 std::string outputPath = rawPath_ +
"/DataGenReceiver-" + ip_ +
":" +
88 std::to_string(dataport_) +
".bin";
91 output.open(outputPath, std::ios::out | std::ios::app | std::ios::binary);
94 mf::LogInfo(
"DataGenReceiver")
95 <<
"Starting DataGenReceiver Packet Processing Loop" << std::endl;
99 std::size_t initial_payload_size = 0;
101 frags.emplace_back(artdaq::Fragment::FragmentBytes(initial_payload_size,
104 ots::detail::FragmentType::DataGen,
111 thisFrag.resize(
sizeof(uint8_t) * 64050);
112 std::cout << __COUT_HDR_FL__ <<
"DJN2 after, datasizebytes=" << thisFrag.asksize()
116 memcpy(thisFrag.dataBegin(), (&buffer_[2]),
sizeof(DataGenFragment::DataBlob));
121 output.write(&buffer_[0],
sizeof(DataGenFragment::DataBlob));
124 mf::LogInfo(
"DataGenReceiver") <<
"Done with DataGenReceiver Packet "
125 "Processing Loop. Deleting PacketBuffers"
132 void ots::DataGenReceiver::start()
134 #pragma message "Using default implementation of DataGenReceiver::start_()"
138 void ots::DataGenReceiver::stop()
140 #pragma message "Using default implementation of DataGenReceiver::stop()"
144 void ots::DataGenReceiver::stopNoMutex(){
145 #pragma message "Using default implementation of DataGenReceiver::stopNoMutex()"