$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_05_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_core_Data_detail_RawFragmentHeaderV0_hh 00002 #define artdaq_core_Data_detail_RawFragmentHeaderV0_hh 00003 // detail::RawFragmentHeaderV0 is an overlay that provides the user's view 00004 // of the data contained within a Fragment. It is intended to be hidden 00005 // from the user of Fragment, as an implementation detail. The interface 00006 // of Fragment is intended to be used to access the data. 00007 00008 //#include <cstddef> 00009 #include "artdaq-core/Data/dictionarycontrol.hh" 00010 #include "cetlib_except/exception.h" 00011 #include <map> 00012 #include "artdaq-core/Data/detail/RawFragmentHeader.hh" 00013 #include "artdaq-core/Utilities/TimeUtils.hh" 00014 00015 extern "C" 00016 { 00017 #include <stdint.h> 00018 } 00019 00020 namespace artdaq 00021 { 00022 namespace detail 00023 { 00024 struct RawFragmentHeaderV0; 00025 } 00026 } 00027 00036 struct artdaq::detail::RawFragmentHeaderV0 00037 { 00041 typedef unsigned long long RawDataType; 00042 00043 #if HIDE_FROM_ROOT 00044 typedef uint16_t version_t; 00045 typedef uint64_t sequence_id_t; 00046 typedef uint8_t type_t; 00047 typedef uint16_t fragment_id_t; 00048 typedef uint8_t metadata_word_count_t; 00049 typedef uint32_t timestamp_t; 00050 00051 // define special values for type_t 00052 static constexpr type_t INVALID_TYPE = 0; 00053 static constexpr type_t FIRST_USER_TYPE = 1; 00054 static constexpr type_t LAST_USER_TYPE = 224; 00055 static constexpr type_t FIRST_SYSTEM_TYPE = 225; 00056 static constexpr type_t LAST_SYSTEM_TYPE = 255; 00057 static constexpr type_t InvalidFragmentType = INVALID_TYPE; 00058 static constexpr type_t EndOfDataFragmentType = FIRST_SYSTEM_TYPE; 00059 static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1; 00060 static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2; 00061 static constexpr type_t EndOfRunFragmentType = FIRST_SYSTEM_TYPE + 3; 00062 static constexpr type_t EndOfSubrunFragmentType = FIRST_SYSTEM_TYPE + 4; 00063 static constexpr type_t ShutdownFragmentType = FIRST_SYSTEM_TYPE + 5; 00064 static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6; 00065 static constexpr type_t ContainerFragmentType = FIRST_SYSTEM_TYPE + 7; 00066 00071 static std::map<type_t, std::string> MakeSystemTypeMap() 00072 { 00073 return std::map<type_t, std::string>{ 00074 {226, "Data"}, 00075 { 231, "Empty" }, 00076 { 232, "Container" } 00077 }; 00078 } 00079 00084 static std::map<type_t, std::string> MakeVerboseSystemTypeMap() 00085 { 00086 return std::map<type_t, std::string>{ 00087 {225, "EndOfData"}, 00088 { 226, "Data" }, 00089 { 227, "Init" }, 00090 { 228, "EndOfRun" }, 00091 { 229, "EndOfSubrun" }, 00092 { 230,"Shutdown" }, 00093 { 231, "Empty" }, 00094 { 232, "Container" } 00095 }; 00096 } 00097 00098 // Each of the following invalid values is chosen based on the 00099 // size of the bitfield in which the corresponding data are 00100 // encoded; if any of the sizes are changed, the corresponding 00101 // values must be updated. 00102 static const version_t InvalidVersion = 0xFFFF; 00103 static const version_t CurrentVersion = 0x0; 00104 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF; 00105 static const fragment_id_t InvalidFragmentID = 0xFFFF; 00106 static const timestamp_t InvalidTimestamp = 0xFFFFFFFF; 00107 00108 RawDataType word_count : 32; 00109 RawDataType version : 16; 00110 RawDataType type : 8; 00111 RawDataType metadata_word_count : 8; 00112 00113 RawDataType sequence_id : 48; 00114 RawDataType fragment_id : 16; 00115 RawDataType timestamp : 32; 00116 00117 RawDataType unused1 : 16; 00118 RawDataType unused2 : 16; 00119 00124 constexpr static std::size_t num_words(); 00125 00131 void setUserType(uint8_t utype); 00132 00138 void setSystemType(uint8_t stype); 00139 00150 RawFragmentHeader upgrade() const; 00151 00152 #endif /* HIDE_FROM_ROOT */ 00153 }; 00154 00155 #if HIDE_FROM_ROOT 00156 inline 00157 constexpr 00158 std::size_t 00159 artdaq::detail::RawFragmentHeaderV0::num_words() 00160 { 00161 return sizeof(detail::RawFragmentHeaderV0) / sizeof(RawDataType); 00162 } 00163 00164 // Compile-time check that the assumption made in num_words() above is 00165 // actually true. 00166 static_assert((artdaq::detail::RawFragmentHeaderV0::num_words() * 00167 sizeof(artdaq::detail::RawFragmentHeaderV0::RawDataType)) == 00168 sizeof(artdaq::detail::RawFragmentHeaderV0), 00169 "sizeof(RawFragmentHeader) is not an integer " 00170 "multiple of sizeof(RawDataType)!"); 00171 00172 inline 00173 void 00174 artdaq::detail::RawFragmentHeaderV0::setUserType(uint8_t utype) 00175 { 00176 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE) 00177 { 00178 throw cet::exception("InvalidValue") 00179 << "RawFragmentHeader user types must be in the range of " 00180 << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE) 00181 << " (bad type is " << ((int)utype) << ")."; 00182 } 00183 type = utype; 00184 } 00185 00186 inline 00187 void 00188 artdaq::detail::RawFragmentHeaderV0::setSystemType(uint8_t stype) 00189 { 00190 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/) 00191 { 00192 throw cet::exception("InvalidValue") 00193 << "RawFragmentHeader system types must be in the range of " 00194 << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE); 00195 } 00196 type = stype; 00197 } 00198 00199 inline 00200 artdaq::detail::RawFragmentHeader 00201 artdaq::detail::RawFragmentHeaderV0::upgrade() const 00202 { 00203 RawFragmentHeader output; 00204 output.word_count = word_count; 00205 output.version = RawFragmentHeader::CurrentVersion; 00206 output.type = type; 00207 output.metadata_word_count = metadata_word_count; 00208 00209 output.sequence_id = sequence_id; 00210 output.fragment_id = fragment_id; 00211 output.timestamp = timestamp; 00212 00213 output.valid = true; 00214 output.complete = true; 00215 00216 auto time = artdaq::TimeUtils::get_realtime_clock(); 00217 output.atime_ns = time.tv_nsec; 00218 output.atime_s = time.tv_sec; 00219 00220 return output; 00221 } 00222 #endif 00223 00224 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV0_hh */