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