00001 #ifndef artdaq_core_Data_detail_RawFragmentHeader_hh
00002 #define artdaq_core_Data_detail_RawFragmentHeader_hh
00003
00004
00005
00006
00007
00008
00009 #include "artdaq-core/Data/dictionarycontrol.hh"
00010 #include "cetlib/exception.h"
00011 #include <map>
00012
00013 extern "C"
00014 {
00015 #include <stdint.h>
00016 }
00017
00018 namespace artdaq
00019 {
00020 namespace detail
00021 {
00022 struct RawFragmentHeader;
00023 }
00024 }
00025
00033 struct artdaq::detail::RawFragmentHeader
00034 {
00038 typedef unsigned long long RawDataType;
00039
00040 #if HIDE_FROM_ROOT
00041 typedef uint16_t version_t;
00042 typedef uint64_t sequence_id_t;
00043 typedef uint8_t type_t;
00044 typedef uint16_t fragment_id_t;
00045 typedef uint8_t metadata_word_count_t;
00046 typedef uint64_t timestamp_t;
00047
00048
00049 static constexpr type_t INVALID_TYPE = 0;
00050 static constexpr type_t FIRST_USER_TYPE = 1;
00051 static constexpr type_t LAST_USER_TYPE = 224;
00052 static constexpr type_t FIRST_SYSTEM_TYPE = 225;
00053 static constexpr type_t LAST_SYSTEM_TYPE = 255;
00054 static constexpr type_t InvalidFragmentType = INVALID_TYPE;
00055 static constexpr type_t EndOfDataFragmentType = FIRST_SYSTEM_TYPE;
00056 static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1;
00057 static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2;
00058 static constexpr type_t EndOfRunFragmentType = FIRST_SYSTEM_TYPE + 3;
00059 static constexpr type_t EndOfSubrunFragmentType = FIRST_SYSTEM_TYPE + 4;
00060 static constexpr type_t ShutdownFragmentType = FIRST_SYSTEM_TYPE + 5;
00061 static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6;
00062 static constexpr type_t ContainerFragmentType = FIRST_SYSTEM_TYPE + 7;
00063
00068 static std::map<type_t, std::string> MakeSystemTypeMap()
00069 {
00070 return std::map<type_t, std::string>{
00071 {226, "Data"},
00072 { 231, "Empty" },
00073 { 232, "Container" }
00074 };
00075 }
00076
00081 static std::map<type_t, std::string> MakeVerboseSystemTypeMap()
00082 {
00083 return std::map<type_t, std::string>{
00084 {225, "EndOfData"},
00085 { 226, "Data" },
00086 { 227, "Init" },
00087 { 228, "EndOfRun" },
00088 { 229, "EndOfSubrun" },
00089 { 230,"Shutdown" },
00090 { 231, "Empty" },
00091 { 232, "Container" }
00092 };
00093 }
00094
00095
00096
00097
00098
00099 static const version_t InvalidVersion = 0xFFFF;
00100 static const version_t CurrentVersion = 0x1;
00101 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
00102 static const fragment_id_t InvalidFragmentID = 0xFFFF;
00103 static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF;
00104
00105 RawDataType word_count : 32;
00106 RawDataType version : 16;
00107 RawDataType type : 8;
00108 RawDataType metadata_word_count : 8;
00109
00110 RawDataType sequence_id : 48;
00111 RawDataType fragment_id : 16;
00112 RawDataType timestamp : 64;
00113
00114
00115
00116
00117
00118
00123 static constexpr std::size_t num_words();
00124
00130 void setUserType(uint8_t utype);
00131
00137 void setSystemType(uint8_t stype);
00138
00139 #endif
00140 };
00141
00142 #if HIDE_FROM_ROOT
00143 inline
00144 constexpr
00145 std::size_t
00146 artdaq::detail::RawFragmentHeader::num_words()
00147 {
00148 return sizeof(detail::RawFragmentHeader) / sizeof(RawDataType);
00149 }
00150
00151
00152
00153
00154 static_assert((artdaq::detail::RawFragmentHeader::num_words() *
00155 sizeof(artdaq::detail::RawFragmentHeader::RawDataType)) ==
00156 sizeof(artdaq::detail::RawFragmentHeader),
00157 "sizeof(RawFragmentHeader) is not an integer "
00158 "multiple of sizeof(RawDataType)!");
00159
00160 inline
00161 void
00162 artdaq::detail::RawFragmentHeader::setUserType(uint8_t utype)
00163 {
00164 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
00165 {
00166 throw cet::exception("InvalidValue")
00167 << "RawFragmentHeader user types must be in the range of "
00168 << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE)
00169 << " (bad type is " << ((int)utype) << ").";
00170 }
00171 type = utype;
00172 }
00173
00174 inline
00175 void
00176 artdaq::detail::RawFragmentHeader::setSystemType(uint8_t stype)
00177 {
00178 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
00179 {
00180 throw cet::exception("InvalidValue")
00181 << "RawFragmentHeader system types must be in the range of "
00182 << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE);
00183 }
00184 type = stype;
00185 }
00186 #endif
00187
00188 #endif