All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FragmentDumper.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/Decode/DecoderTools/Dumpers/FragmentDumper.cxx
3  * @brief Utility to dump a artDAQ fragment on screen.
4  * @date April 5, 2021
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see icaruscode/Decode/DecoderTools/Dumpers/FragmentDumper.h
7  *
8  */
9 
10 // library header
12 
13 // ICARUS/SBN libraries
14 #include "icarusalg/Utilities/BinaryDumpUtils.h" // icarus::ns::util::hexdump()
15 
16 // C/C++ standard libraries
17 #include <ostream>
18 #include <cstddef> // std::size_t
19 #include <cassert>
20 
21 
22 // -----------------------------------------------------------------------------
23 // forward declarations
24 namespace { void dumpFragmentImpl(std::ostream&, artdaq::Fragment const&); }
25 
26 
27 // -----------------------------------------------------------------------------
28 std::ostream& sbndaq::details::operator<<
29  (std::ostream& out, DumpFragWrap const& wrap)
30  { ::dumpFragmentImpl(out, wrap.frag); return out; }
31 
32 
33 // -----------------------------------------------------------------------------
35  { return details::DumpFragWrap{ frag }; }
36 
37 
38 // -----------------------------------------------------------------------------
39 namespace {
40 
41  void dumpFragmentImpl(std::ostream& out, artdaq::Fragment const& frag) {
42 
43  out << "Fragment summary: " << frag; // ends with <CR>
44 
45  artdaq::Fragment::byte_t const* headerData = frag.headerBeginBytes();
46  std::size_t const headerSize = frag.headerSizeBytes();
47  assert(headerData); // this is the pointer to the begin of everything
48  artdaq::Fragment::byte_t const* payloadData = frag.dataBeginBytes();
49  std::size_t const payloadSize = frag.dataSizeBytes();
50  artdaq::Fragment::byte_t const* metaData
51  = frag.metadata<artdaq::Fragment::byte_t>();
52  std::size_t const metadataSize = metaData? (payloadData - metaData): 0;
53 
54  out << " - header (" << headerSize << " bytes):";
55  if (headerData)
56  out << icarus::ns::util::hexdump(headerData, headerSize);
57  else out << " n/a" << "\n";
58  out << " - metadata (" << metadataSize << " bytes):";
59  if (metaData)
60  out << icarus::ns::util::hexdump(metaData, metadataSize);
61  else out << " n/a" << "\n";
62  out << " - data (" << payloadSize << " bytes):";
63  if (payloadData)
64  out << icarus::ns::util::hexdump(payloadData, payloadSize);
65  else out << " n/a" << "\n";
66 
67  } // dumpFragmentImpl()
68 
69 } // local namespace
70 
71 
72 // -----------------------------------------------------------------------------
details::HexDumper< Atom > hexdump(Atom const *data, std::size_t size, unsigned int columns=16U)
Returns a wrapper to print the specified data in hex dump format.
Utility to dump a artDAQ fragment on screen.
details::DumpFragWrap dumpFragment(artdaq::Fragment const &frag)
Dump a artDAQ fragment into an output stream.
Functions to dump the content of binary data chunks to console.