00001
00002
00003
00004
00005
00007
00008 #include "art/Framework/Core/EDAnalyzer.h"
00009 #include "art/Framework/Core/ModuleMacros.h"
00010 #include "art/Framework/Principal/Event.h"
00011 #include "art/Framework/Principal/Handle.h"
00012 #include "canvas/Utilities/Exception.h"
00013
00014 #include "artdaq-ots/Overlays/UDPFragment.hh"
00015 #include "artdaq-core/Data/Fragment.hh"
00016 #include "otsdaq-core/Macros/CoutMacros.h"
00017
00018 #include <algorithm>
00019 #include <cassert>
00020 #include <cmath>
00021 #include <fstream>
00022 #include <iomanip>
00023 #include <vector>
00024 #include <iostream>
00025 #include <arpa/inet.h>
00026
00027 namespace ots {
00028 class UDPDump;
00029 }
00030
00031 class ots::UDPDump : public art::EDAnalyzer {
00032 public:
00033 explicit UDPDump(fhicl::ParameterSet const & pset);
00034 virtual ~UDPDump();
00035
00036 virtual void analyze(art::Event const & evt);
00037
00038 private:
00039 std::string raw_data_label_;
00040 std::string frag_type_;
00041 unsigned int num_bytes_to_show_;
00042 };
00043
00044
00045 ots::UDPDump::UDPDump(fhicl::ParameterSet const & pset)
00046 : EDAnalyzer(pset),
00047 raw_data_label_(pset.get<std::string>("raw_data_label")),
00048 frag_type_(pset.get<std::string>("frag_type")),
00049 num_bytes_to_show_(pset.get<int>("num_bytes"))
00050 {
00051 }
00052
00053 ots::UDPDump::~UDPDump()
00054 {
00055 }
00056
00057 void ots::UDPDump::analyze(art::Event const & evt)
00058 {
00059 art::EventNumber_t eventNumber = evt.event();
00060
00061
00062
00063
00064
00065
00066
00067 art::Handle<artdaq::Fragments> raw;
00068 evt.getByLabel(raw_data_label_, frag_type_, raw);
00069
00070 if (raw.isValid()) {
00071 std::cout << __COUT_HDR_FL__ << "######################################################################" << std::endl;
00072
00073 std::cout << __COUT_HDR_FL__ << std::dec << "Run " << evt.run() << ", subrun " << evt.subRun()
00074 << ", event " << eventNumber << " has " << raw->size()
00075 << " fragment(s) of type " << frag_type_ << std::endl;
00076
00077 for (size_t idx = 0; idx < raw->size(); ++idx) {
00078 const auto& frag((*raw)[idx]);
00079
00080 ots::UDPFragment bb(frag);
00081
00082
00083 std::cout << __COUT_HDR_FL__ << "UDP fragment " << frag.fragmentID() << " has total byte count = "
00084 << bb.udp_data_words() << std::endl;
00085
00086
00087 if (frag.hasMetadata()) {
00088
00089 std::cout << __COUT_HDR_FL__ << "Fragment metadata: " << std::endl;
00090 ots::UDPFragment::Metadata const* md =
00091 frag.metadata<ots::UDPFragment::Metadata>();
00092
00093 char buf[sizeof(in_addr)];
00094 struct sockaddr_in addr;
00095 addr.sin_addr.s_addr = md->address;
00096 inet_ntop(AF_INET, &(addr.sin_addr), buf, INET_ADDRSTRLEN);
00097
00098 std::cout << __COUT_HDR_FL__ << "Board port number = "
00099 << ((int)md->port) << ", address = "
00100 << std::string(buf)
00101 << std::endl;
00102
00103 }
00104
00105 int type = bb.hdr_data_type();
00106 if(type == 0 || type > 2)
00107 {
00108 auto it = bb.dataBegin();
00109 std::cout << __COUT_HDR_FL__ << std::hex << "0x" << (int)*it << std::endl;
00110 ++it;
00111
00112 for(; it !=bb.dataEnd(); ++it)
00113 {
00114 std::cout << __COUT_HDR_FL__ << ", " << std::hex << "0x" << (int)*it << std::endl;
00115 }
00116
00117 }
00118 else
00119 {
00120 std::string output = std::string((const char *)bb.dataBegin());
00121 std::cout << __COUT_HDR_FL__ << output << std::endl;
00122 }
00123 }
00124 }
00125 else {
00126 std::cout << __COUT_HDR_FL__ << std::dec << "Run " << evt.run() << ", subrun " << evt.subRun()
00127 << ", event " << eventNumber << " has zero"
00128 << " UDP fragments." << std::endl;
00129 }
00130
00131
00132 }
00133
00134 DEFINE_ART_MODULE(ots::UDPDump)