Line data Source code
1 : ////////////////////////////////////////////////////////////////////////
2 : /// Class: UDPDump
3 : /// Module Type: analyzer
4 : /// File: UDPDump_module.cc
5 : /// Description: Prints out information about each event.
6 : ////////////////////////////////////////////////////////////////////////
7 :
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"
13 :
14 : #include "artdaq-core/Data/Fragment.hh"
15 : #include "artdaq-ots/Overlays/UDPFragment.hh"
16 : #include "otsdaq/Macros/CoutMacros.h"
17 :
18 : #include <arpa/inet.h>
19 : #include <algorithm>
20 : #include <cassert>
21 : #include <cmath>
22 : #include <fstream>
23 : #include <iomanip>
24 : #include <iostream>
25 : #include <vector>
26 :
27 : namespace ots
28 : {
29 : class UDPDump;
30 : }
31 :
32 : class ots::UDPDump : public art::EDAnalyzer
33 : {
34 : public:
35 : explicit UDPDump(fhicl::ParameterSet const& pset);
36 : virtual ~UDPDump();
37 :
38 : virtual void analyze(art::Event const& evt);
39 :
40 : private:
41 : std::string raw_data_label_;
42 : std::string frag_type_;
43 : unsigned int num_bytes_to_show_;
44 : };
45 :
46 0 : ots::UDPDump::UDPDump(fhicl::ParameterSet const& pset)
47 : : EDAnalyzer(pset)
48 0 : , raw_data_label_(pset.get<std::string>("raw_data_label"))
49 0 : , frag_type_(pset.get<std::string>("frag_type"))
50 0 : , num_bytes_to_show_(pset.get<int>("num_bytes"))
51 : {
52 0 : }
53 :
54 0 : ots::UDPDump::~UDPDump() {}
55 :
56 0 : void ots::UDPDump::analyze(art::Event const& evt)
57 : {
58 0 : art::EventNumber_t eventNumber = evt.event();
59 :
60 : // ***********************
61 : // *** Toy Fragments ***
62 : // ***********************
63 :
64 : // look for raw UDP data
65 :
66 0 : art::Handle<artdaq::Fragments> raw;
67 0 : evt.getByLabel(raw_data_label_, frag_type_, raw);
68 :
69 0 : if(raw.isValid())
70 : {
71 : std::cout
72 0 : << __COUT_HDR_FL__
73 0 : << "######################################################################"
74 0 : << std::endl;
75 :
76 0 : std::cout << __COUT_HDR_FL__ << std::dec << "Run " << evt.run() << ", subrun "
77 0 : << evt.subRun() << ", event " << eventNumber << " has " << raw->size()
78 0 : << " fragment(s) of type " << frag_type_ << std::endl;
79 :
80 0 : for(size_t idx = 0; idx < raw->size(); ++idx)
81 : {
82 0 : const auto& frag((*raw)[idx]);
83 :
84 0 : ots::UDPFragment bb(frag);
85 :
86 0 : std::cout << __COUT_HDR_FL__ << "UDP fragment " << frag.fragmentID()
87 0 : << " has total byte count = " << bb.udp_data_words() << std::endl;
88 :
89 0 : if(frag.hasMetadata())
90 : {
91 0 : std::cout << __COUT_HDR_FL__ << "Fragment metadata: " << std::endl;
92 : ots::UDPFragment::Metadata const* md =
93 0 : frag.metadata<ots::UDPFragment::Metadata>();
94 :
95 : char buf[sizeof(in_addr)];
96 : struct sockaddr_in addr;
97 0 : addr.sin_addr.s_addr = md->address;
98 0 : inet_ntop(AF_INET, &(addr.sin_addr), buf, INET_ADDRSTRLEN);
99 :
100 0 : std::cout << __COUT_HDR_FL__ << "Board port number = " << ((int)md->port)
101 0 : << ", address = " << std::string(buf) << std::endl;
102 : }
103 :
104 0 : int type = bb.hdr_data_type();
105 0 : if(type == 0 || type > 2)
106 : {
107 0 : auto it = bb.dataBegin();
108 0 : std::cout << __COUT_HDR_FL__ << std::hex << "0x" << (int)*it << std::endl;
109 0 : ++it;
110 :
111 0 : for(; it != bb.dataEnd(); ++it)
112 : {
113 0 : std::cout << __COUT_HDR_FL__ << ", " << std::hex << "0x" << (int)*it
114 0 : << std::endl;
115 : }
116 0 : }
117 : else
118 : {
119 0 : std::string output = std::string((const char*)bb.dataBegin());
120 0 : std::cout << __COUT_HDR_FL__ << output << std::endl;
121 0 : }
122 : }
123 : }
124 : else
125 : {
126 0 : std::cout << __COUT_HDR_FL__ << std::dec << "Run " << evt.run() << ", subrun "
127 0 : << evt.subRun() << ", event " << eventNumber << " has zero"
128 0 : << " UDP fragments." << std::endl;
129 : }
130 0 : }
131 :
132 0 : DEFINE_ART_MODULE(ots::UDPDump)
|