8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "canvas/Utilities/Exception.h"
14 #include "artdaq-core/Data/Fragment.hh"
15 #include "artdaq-ots/Overlays/UDPFragment.hh"
16 #include "otsdaq/Macros/CoutMacros.h"
18 #include <arpa/inet.h>
35 explicit UDPDump(fhicl::ParameterSet
const& pset);
38 virtual void analyze(art::Event
const& evt);
41 std::string raw_data_label_;
42 std::string frag_type_;
43 unsigned int num_bytes_to_show_;
46 ots::UDPDump::UDPDump(fhicl::ParameterSet
const& pset)
48 , raw_data_label_(pset.get<std::string>(
"raw_data_label"))
49 , frag_type_(pset.get<std::string>(
"frag_type"))
50 , num_bytes_to_show_(pset.get<int>(
"num_bytes"))
54 ots::UDPDump::~UDPDump() {}
56 void ots::UDPDump::analyze(art::Event
const& evt)
58 art::EventNumber_t eventNumber = evt.event();
66 art::Handle<artdaq::Fragments> raw;
67 evt.getByLabel(raw_data_label_, frag_type_, raw);
71 std::cout << __COUT_HDR_FL__ <<
"######################################################################" << std::endl;
73 std::cout << __COUT_HDR_FL__ << std::dec <<
"Run " << evt.run() <<
", subrun " << evt.subRun() <<
", event " << eventNumber <<
" has " << raw->size()
74 <<
" fragment(s) of type " << frag_type_ << std::endl;
76 for(
size_t idx = 0; idx < raw->size(); ++idx)
78 const auto& frag((*raw)[idx]);
82 std::cout << __COUT_HDR_FL__ <<
"UDP fragment " << frag.fragmentID() <<
" has total byte count = " << bb.udp_data_words() << std::endl;
84 if(frag.hasMetadata())
86 std::cout << __COUT_HDR_FL__ <<
"Fragment metadata: " << std::endl;
89 char buf[
sizeof(in_addr)];
90 struct sockaddr_in addr;
91 addr.sin_addr.s_addr = md->address;
92 inet_ntop(AF_INET, &(addr.sin_addr), buf, INET_ADDRSTRLEN);
94 std::cout << __COUT_HDR_FL__ <<
"Board port number = " << ((int)md->port) <<
", address = " << std::string(buf) << std::endl;
97 int type = bb.hdr_data_type();
98 if(type == 0 || type > 2)
100 auto it = bb.dataBegin();
101 std::cout << __COUT_HDR_FL__ << std::hex <<
"0x" << (int)*it << std::endl;
104 for(; it != bb.dataEnd(); ++it)
106 std::cout << __COUT_HDR_FL__ <<
", " << std::hex <<
"0x" << (int)*it << std::endl;
111 std::string output = std::string((
const char*)bb.dataBegin());
112 std::cout << __COUT_HDR_FL__ << output << std::endl;
118 std::cout << __COUT_HDR_FL__ << std::dec <<
"Run " << evt.run() <<
", subrun " << evt.subRun() <<
", event " << eventNumber <<
" has zero"
119 <<
" UDP fragments." << std::endl;