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