$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_04_20a
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_core_Data_detail_RawFragmentHeader_hh 00002 #define artdaq_core_Data_detail_RawFragmentHeader_hh 00003 // detail::RawFragmentHeader 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 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 // define special values for type_t 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 static constexpr type_t ErrorFragmentType = FIRST_SYSTEM_TYPE + 8; 00064 00069 static std::map<type_t, std::string> MakeSystemTypeMap() 00070 { 00071 return std::map<type_t, std::string>{ 00072 { type_t(DataFragmentType), "Data"}, 00073 { type_t(EmptyFragmentType), "Empty" }, 00074 { type_t(ErrorFragmentType), "Error" }, 00075 { type_t(InvalidFragmentType), "Invalid"}, 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 { type_t(EndOfDataFragmentType), "EndOfData" }, 00088 { type_t(DataFragmentType), "Data" }, 00089 { type_t(InitFragmentType), "Init" }, 00090 { type_t(EndOfRunFragmentType), "EndOfRun" }, 00091 { type_t(EndOfSubrunFragmentType), "EndOfSubrun" }, 00092 { type_t(ShutdownFragmentType),"Shutdown" }, 00093 { type_t(EmptyFragmentType), "Empty" }, 00094 { type_t(ContainerFragmentType), "Container" } 00095 }; 00096 } 00097 00103 static std::string SystemTypeToString(type_t type) { 00104 switch (type) { 00105 case INVALID_TYPE: 00106 return "INVALID"; 00107 case EndOfDataFragmentType: 00108 return "EndOfData"; 00109 case DataFragmentType: 00110 return "Data"; 00111 case InitFragmentType: 00112 return "Init"; 00113 case EndOfRunFragmentType: 00114 return "EndOfRun"; 00115 case EndOfSubrunFragmentType: 00116 return "EndOfSubrun"; 00117 case ShutdownFragmentType: 00118 return "Shutdown"; 00119 case EmptyFragmentType: 00120 return "Empty"; 00121 case ContainerFragmentType: 00122 return "Container"; 00123 } 00124 return "Unknown"; 00125 } 00126 00127 // Each of the following invalid values is chosen based on the 00128 // size of the bitfield in which the corresponding data are 00129 // encoded; if any of the sizes are changed, the corresponding 00130 // values must be updated. 00131 static const version_t InvalidVersion = 0xFFFF; 00132 static const version_t CurrentVersion = 0x1; 00133 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF; 00134 static const fragment_id_t InvalidFragmentID = 0xFFFF; 00135 static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF; 00136 00137 RawDataType word_count : 32; 00138 RawDataType version : 16; 00139 RawDataType type : 8; 00140 RawDataType metadata_word_count : 8; 00141 00142 RawDataType sequence_id : 48; 00143 RawDataType fragment_id : 16; 00144 RawDataType timestamp : 64; 00145 00146 00147 // **************************************************** 00148 // New fields MUST be added to the END of this list!!! 00149 // **************************************************** 00150 00155 static constexpr std::size_t num_words(); 00156 00162 void setUserType(uint8_t utype); 00163 00169 void setSystemType(uint8_t stype); 00170 00171 #endif /* HIDE_FROM_ROOT */ 00172 }; 00173 00174 #if HIDE_FROM_ROOT 00175 inline 00176 constexpr 00177 std::size_t 00178 artdaq::detail::RawFragmentHeader::num_words() 00179 { 00180 return sizeof(detail::RawFragmentHeader) / sizeof(RawDataType); 00181 } 00182 00183 00184 // Compile-time check that the assumption made in num_words() above is 00185 // actually true. 00186 static_assert((artdaq::detail::RawFragmentHeader::num_words() * 00187 sizeof(artdaq::detail::RawFragmentHeader::RawDataType)) == 00188 sizeof(artdaq::detail::RawFragmentHeader), 00189 "sizeof(RawFragmentHeader) is not an integer " 00190 "multiple of sizeof(RawDataType)!"); 00191 00192 inline 00193 void 00194 artdaq::detail::RawFragmentHeader::setUserType(uint8_t utype) 00195 { 00196 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE) 00197 { 00198 throw cet::exception("InvalidValue") 00199 << "RawFragmentHeader user types must be in the range of " 00200 << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE) 00201 << " (bad type is " << ((int)utype) << ")."; 00202 } 00203 type = utype; 00204 } 00205 00206 inline 00207 void 00208 artdaq::detail::RawFragmentHeader::setSystemType(uint8_t stype) 00209 { 00210 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/) 00211 { 00212 throw cet::exception("InvalidValue") 00213 << "RawFragmentHeader system types must be in the range of " 00214 << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE); 00215 } 00216 type = stype; 00217 } 00218 #endif 00219 00220 #endif /* artdaq_core_Data_detail_RawFragmentHeader_hh */