$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_05_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_core_Data_detail_RawFragmentHeaderV1_hh 00002 #define artdaq_core_Data_detail_RawFragmentHeaderV1_hh 00003 // detail::RawFragmentHeaderV1 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 00014 extern "C" 00015 { 00016 #include <stdint.h> 00017 } 00018 00019 namespace artdaq 00020 { 00021 namespace detail 00022 { 00023 struct RawFragmentHeaderV1; 00024 } 00025 } 00026 00035 struct artdaq::detail::RawFragmentHeaderV1 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 uint64_t timestamp_t; 00049 00050 // define special values for type_t 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 { type_t(DataFragmentType), "Data"}, 00074 { type_t(EmptyFragmentType), "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 { type_t(EndOfDataFragmentType), "EndOfData" }, 00087 { type_t(DataFragmentType), "Data" }, 00088 { type_t(InitFragmentType), "Init" }, 00089 { type_t(EndOfRunFragmentType), "EndOfRun" }, 00090 { type_t(EndOfSubrunFragmentType), "EndOfSubrun" }, 00091 { type_t(ShutdownFragmentType),"Shutdown" }, 00092 { type_t(EmptyFragmentType), "Empty" }, 00093 { type_t(ContainerFragmentType), "Container" } 00094 }; 00095 } 00096 00102 static std::string SystemTypeToString(type_t type) { 00103 switch (type) { 00104 case INVALID_TYPE: 00105 return "INVALID"; 00106 case EndOfDataFragmentType: 00107 return "EndOfData"; 00108 case DataFragmentType: 00109 return "Data"; 00110 case InitFragmentType: 00111 return "Init"; 00112 case EndOfRunFragmentType: 00113 return "EndOfRun"; 00114 case EndOfSubrunFragmentType: 00115 return "EndOfSubrun"; 00116 case ShutdownFragmentType: 00117 return "Shutdown"; 00118 case EmptyFragmentType: 00119 return "Empty"; 00120 case ContainerFragmentType: 00121 return "Container"; 00122 } 00123 return "Unknown"; 00124 } 00125 00126 // Each of the following invalid values is chosen based on the 00127 // size of the bitfield in which the corresponding data are 00128 // encoded; if any of the sizes are changed, the corresponding 00129 // values must be updated. 00130 static const version_t InvalidVersion = 0xFFFF; 00131 static const version_t CurrentVersion = 0x1; 00132 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF; 00133 static const fragment_id_t InvalidFragmentID = 0xFFFF; 00134 static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF; 00135 00136 RawDataType word_count : 32; 00137 RawDataType version : 16; 00138 RawDataType type : 8; 00139 RawDataType metadata_word_count : 8; 00140 00141 RawDataType sequence_id : 48; 00142 RawDataType fragment_id : 16; 00143 RawDataType timestamp : 64; 00144 00145 00146 // **************************************************** 00147 // New fields MUST be added to the END of this list!!! 00148 // **************************************************** 00149 00154 static constexpr std::size_t num_words(); 00155 00161 void setUserType(uint8_t utype); 00162 00168 void setSystemType(uint8_t stype); 00169 00180 RawFragmentHeader upgrade() const; 00181 00182 #endif /* HIDE_FROM_ROOT */ 00183 }; 00184 00185 #if HIDE_FROM_ROOT 00186 inline 00187 constexpr 00188 std::size_t 00189 artdaq::detail::RawFragmentHeaderV1::num_words() 00190 { 00191 return sizeof(detail::RawFragmentHeaderV1) / sizeof(RawDataType); 00192 } 00193 00194 00195 // Compile-time check that the assumption made in num_words() above is 00196 // actually true. 00197 static_assert((artdaq::detail::RawFragmentHeaderV1::num_words() * 00198 sizeof(artdaq::detail::RawFragmentHeaderV1::RawDataType)) == 00199 sizeof(artdaq::detail::RawFragmentHeaderV1), 00200 "sizeof(RawFragmentHeaderV1) is not an integer " 00201 "multiple of sizeof(RawDataType)!"); 00202 00203 inline 00204 void 00205 artdaq::detail::RawFragmentHeaderV1::setUserType(uint8_t utype) 00206 { 00207 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE) 00208 { 00209 throw cet::exception("InvalidValue") 00210 << "RawFragmentHeaderV1 user types must be in the range of " 00211 << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE) 00212 << " (bad type is " << ((int)utype) << ")."; 00213 } 00214 type = utype; 00215 } 00216 00217 inline 00218 void 00219 artdaq::detail::RawFragmentHeaderV1::setSystemType(uint8_t stype) 00220 { 00221 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/) 00222 { 00223 throw cet::exception("InvalidValue") 00224 << "RawFragmentHeaderV1 system types must be in the range of " 00225 << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE); 00226 } 00227 type = stype; 00228 } 00229 00230 inline 00231 artdaq::detail::RawFragmentHeader 00232 artdaq::detail::RawFragmentHeaderV1::upgrade() const 00233 { 00234 RawFragmentHeader output; 00235 output.word_count = word_count; 00236 output.version = RawFragmentHeader::CurrentVersion; 00237 output.type = type; 00238 output.metadata_word_count = metadata_word_count; 00239 00240 output.sequence_id = sequence_id; 00241 output.fragment_id = fragment_id; 00242 output.timestamp = timestamp; 00243 00244 output.valid = true; 00245 output.complete = true; 00246 00247 auto time = artdaq::TimeUtils::get_realtime_clock(); 00248 output.atime_ns = time.tv_nsec; 00249 output.atime_s = time.tv_sec; 00250 00251 return output; 00252 } 00253 #endif 00254 00255 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV1_hh */