$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_ots_Overlays_UDPFragment_hh 00002 #define artdaq_ots_Overlays_UDPFragment_hh 00003 00004 #include "artdaq-core/Data/Fragment.hh" 00005 #include "cetlib_except/exception.h" 00006 00007 #include <ostream> 00008 #include <vector> 00009 00010 // Implementation of "UDPFragment", an artdaq::Fragment overlay class 00011 00012 namespace ots 00013 { 00014 class UDPFragment; 00015 00016 // Let the "<<" operator dump the UDPFragment's data to stdout 00017 std::ostream& operator<<(std::ostream&, UDPFragment const&); 00018 } // namespace ots 00019 00020 class ots::UDPFragment 00021 { 00022 public: 00023 // The "Metadata" struct is used to store info primarily related to 00024 // the upstream hardware environment from where the fragment came 00025 00026 // "data_t" is a typedef of the fundamental unit of data the 00027 // metadata structure thinks of itself as consisting of; it can give 00028 // its size via the static "size_words" variable ( 00029 // UDPFragment::Metadata::size_words ) 00030 00031 struct Metadata 00032 { 00033 typedef uint64_t data_t; 00034 00035 data_t port : 16; 00036 data_t address : 32; 00037 data_t unused : 16; 00038 00039 static size_t const size_words = 1ull; // Units of Metadata::data_t 00040 }; 00041 00042 static_assert(sizeof(Metadata) == Metadata::size_words * sizeof(Metadata::data_t), 00043 "UDPFragment::Metadata size changed"); 00044 00045 // The "Header" struct contains "metadata" specific to the fragment 00046 // which is not hardware-related 00047 00048 // Header::data_t -- not to be confused with Metadata::data_t ! -- 00049 // describes the standard size of a data type not just for the 00050 // header data, but ALSO the physics data beyond it; the size of the 00051 // header in units of Header::data_t is given by "size_words", and 00052 // the size of the fragment beyond the header in units of 00053 // Header::data_t is given by "event_size" 00054 00055 // Notice only the first 28 bits of the first 32-bit unsigned 00056 // integer in the Header is used to hold the event_size ; this means 00057 // that you can't represent a fragment larger than 2**28 units of 00058 // data_t, or 1,073,741,824 bytes 00059 00060 struct Header 00061 { 00062 typedef uint32_t data_t; 00063 00064 typedef uint32_t event_size_t; 00065 typedef uint32_t data_type_t; 00066 00067 event_size_t event_size : 28; 00068 event_size_t type : 4; 00069 00070 static size_t const size_words = 1ul; // Units of Header::data_t 00071 }; 00072 00073 static_assert(sizeof(Header) == Header::size_words * sizeof(Header::data_t), 00074 "UDPFragment::Header size changed"); 00075 00076 // The constructor simply sets its const private member "artdaq_Fragment_" 00077 // to refer to the artdaq::Fragment object 00078 00079 UDPFragment(artdaq::Fragment const& f) : artdaq_Fragment_(f) {} 00080 00081 // const getter functions for the data in the header 00082 00083 Header::event_size_t hdr_event_size() const { return header_()->event_size; } 00084 Header::data_type_t hdr_data_type() const { return header_()->type; } 00085 static constexpr size_t hdr_size_words() { return Header::size_words; } 00086 00087 // UDP Data Word Count 00088 size_t udp_data_words() const 00089 { 00090 return (hdr_event_size() - hdr_size_words()) * bytes_per_word_(); 00091 } 00092 00093 // Start of the UDP data, returned as a pointer 00094 uint8_t const* dataBegin() const 00095 { 00096 return reinterpret_cast<uint8_t const*>(header_() + 1); 00097 } 00098 00099 // End of the UDP data, returned as a pointer 00100 uint8_t const* dataEnd() const { return dataBegin() + udp_data_words(); } 00101 00102 protected: 00103 // Functions to translate between byte size and the size of 00104 // this fragment overlay's concept of a unit of data (i.e., 00105 // Header::data_t). 00106 00107 static constexpr size_t bytes_per_word_() 00108 { 00109 return sizeof(Header::data_t) / sizeof(uint8_t); 00110 } 00111 00112 // header_() simply takes the address of the start of this overlay's 00113 // data (i.e., where the UDPFragment::Header object begins) and 00114 // casts it as a pointer to UDPFragment::Header 00115 00116 Header const* header_() const 00117 { 00118 return reinterpret_cast<UDPFragment::Header const*>( 00119 artdaq_Fragment_.dataBeginBytes()); 00120 } 00121 00122 private: 00123 artdaq::Fragment const& artdaq_Fragment_; 00124 }; 00125 00126 #endif /* artdaq_ots_Overlays_UDPFragment_hh */