$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_06_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 <map> 00010 #include "artdaq-core/Data/detail/RawFragmentHeader.hh" 00011 #include "artdaq-core/Data/dictionarycontrol.hh" 00012 #include "cetlib_except/exception.h" 00013 00014 extern "C" { 00015 #include <stdint.h> // NOLINT(modernize-deprecated-headers) 00016 } 00017 00018 namespace artdaq { 00019 namespace detail { 00020 struct RawFragmentHeaderV1; 00021 } 00022 } // namespace artdaq 00023 00032 struct artdaq::detail::RawFragmentHeaderV1 00033 { 00037 typedef uint64_t RawDataType; 00038 00039 #if HIDE_FROM_ROOT 00040 typedef uint16_t version_t; 00041 typedef uint64_t sequence_id_t; 00042 typedef uint8_t type_t; 00043 typedef uint16_t fragment_id_t; 00044 typedef uint8_t metadata_word_count_t; 00045 typedef uint64_t timestamp_t; 00046 00047 // define special values for type_t 00048 static constexpr type_t INVALID_TYPE = 0; 00049 static constexpr type_t FIRST_USER_TYPE = 1; 00050 static constexpr type_t LAST_USER_TYPE = 224; 00051 static constexpr type_t FIRST_SYSTEM_TYPE = 225; 00052 static constexpr type_t LAST_SYSTEM_TYPE = 255; 00053 static constexpr type_t InvalidFragmentType = INVALID_TYPE; 00054 static constexpr type_t EndOfDataFragmentType = FIRST_SYSTEM_TYPE; 00055 static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1; 00056 static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2; 00057 static constexpr type_t EndOfRunFragmentType = FIRST_SYSTEM_TYPE + 3; 00058 static constexpr type_t EndOfSubrunFragmentType = FIRST_SYSTEM_TYPE + 4; 00059 static constexpr type_t ShutdownFragmentType = FIRST_SYSTEM_TYPE + 5; 00060 static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6; 00061 static constexpr type_t ContainerFragmentType = FIRST_SYSTEM_TYPE + 7; 00062 00067 static std::map<type_t, std::string> MakeSystemTypeMap() 00068 { 00069 return std::map<type_t, std::string>{ 00070 {type_t(DataFragmentType), "Data"}, 00071 {type_t(EmptyFragmentType), "Empty"}, 00072 {232, "Container"}}; 00073 } 00074 00079 static std::map<type_t, std::string> MakeVerboseSystemTypeMap() 00080 { 00081 return std::map<type_t, std::string>{ 00082 {type_t(EndOfDataFragmentType), "EndOfData"}, 00083 {type_t(DataFragmentType), "Data"}, 00084 {type_t(InitFragmentType), "Init"}, 00085 {type_t(EndOfRunFragmentType), "EndOfRun"}, 00086 {type_t(EndOfSubrunFragmentType), "EndOfSubrun"}, 00087 {type_t(ShutdownFragmentType), "Shutdown"}, 00088 {type_t(EmptyFragmentType), "Empty"}, 00089 {type_t(ContainerFragmentType), "Container"}}; 00090 } 00091 00097 static std::string SystemTypeToString(type_t type) 00098 { 00099 switch (type) 00100 { 00101 case INVALID_TYPE: 00102 return "INVALID"; 00103 case EndOfDataFragmentType: 00104 return "EndOfData"; 00105 case DataFragmentType: 00106 return "Data"; 00107 case InitFragmentType: 00108 return "Init"; 00109 case EndOfRunFragmentType: 00110 return "EndOfRun"; 00111 case EndOfSubrunFragmentType: 00112 return "EndOfSubrun"; 00113 case ShutdownFragmentType: 00114 return "Shutdown"; 00115 case EmptyFragmentType: 00116 return "Empty"; 00117 case ContainerFragmentType: 00118 return "Container"; 00119 default: 00120 return "Unknown"; 00121 } 00122 } 00123 00124 // Each of the following invalid values is chosen based on the 00125 // size of the bitfield in which the corresponding data are 00126 // encoded; if any of the sizes are changed, the corresponding 00127 // values must be updated. 00128 static const version_t InvalidVersion = 0xFFFF; 00129 static const version_t CurrentVersion = 0x1; 00130 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF; 00131 static const fragment_id_t InvalidFragmentID = 0xFFFF; 00132 static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF; 00133 00134 RawDataType word_count : 32; 00135 RawDataType version : 16; 00136 RawDataType type : 8; 00137 RawDataType metadata_word_count : 8; 00138 00139 RawDataType sequence_id : 48; 00140 RawDataType fragment_id : 16; 00141 RawDataType timestamp : 64; 00142 00143 // **************************************************** 00144 // New fields MUST be added to the END of this list!!! 00145 // **************************************************** 00146 00151 static constexpr std::size_t num_words(); 00152 00158 void setUserType(uint8_t utype); 00159 00165 void setSystemType(uint8_t stype); 00166 00177 RawFragmentHeader upgrade() const; 00178 00179 #endif /* HIDE_FROM_ROOT */ 00180 }; 00181 00182 #if HIDE_FROM_ROOT 00183 inline constexpr std::size_t 00184 artdaq::detail::RawFragmentHeaderV1::num_words() 00185 { 00186 return sizeof(detail::RawFragmentHeaderV1) / sizeof(RawDataType); 00187 } 00188 00189 // Compile-time check that the assumption made in num_words() above is 00190 // actually true. 00191 static_assert((artdaq::detail::RawFragmentHeaderV1::num_words() * 00192 sizeof(artdaq::detail::RawFragmentHeaderV1::RawDataType)) == 00193 sizeof(artdaq::detail::RawFragmentHeaderV1), 00194 "sizeof(RawFragmentHeaderV1) is not an integer " 00195 "multiple of sizeof(RawDataType)!"); 00196 00197 inline void 00198 artdaq::detail::RawFragmentHeaderV1::setUserType(uint8_t utype) 00199 { 00200 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE) 00201 { 00202 throw cet::exception("InvalidValue") // NOLINT(cert-err60-cpp) 00203 << "RawFragmentHeaderV1 user types must be in the range of " 00204 << static_cast<int>(FIRST_SYSTEM_TYPE) << " to " << static_cast<int>(LAST_SYSTEM_TYPE) 00205 << " (bad type is " << static_cast<int>(utype) << ")."; 00206 } 00207 type = utype; 00208 } 00209 00210 inline void 00211 artdaq::detail::RawFragmentHeaderV1::setSystemType(uint8_t stype) 00212 { 00213 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/) 00214 { 00215 throw cet::exception("InvalidValue") // NOLINT(cert-err60-cpp) 00216 << "RawFragmentHeaderV1 system types must be in the range of " 00217 << static_cast<int>(FIRST_SYSTEM_TYPE) << " to " << static_cast<int>(LAST_SYSTEM_TYPE); 00218 } 00219 type = stype; 00220 } 00221 00222 inline artdaq::detail::RawFragmentHeader 00223 artdaq::detail::RawFragmentHeaderV1::upgrade() const 00224 { 00225 RawFragmentHeader output; 00226 output.word_count = word_count; 00227 output.version = RawFragmentHeader::CurrentVersion; 00228 output.type = type; 00229 output.metadata_word_count = metadata_word_count; 00230 00231 output.sequence_id = sequence_id; 00232 output.fragment_id = fragment_id; 00233 output.timestamp = timestamp; 00234 00235 output.valid = true; 00236 output.complete = true; 00237 00238 // ELF 10/1/19: Due to how many times upgrade() gets called during an analysis process, better to just zero these fields 00239 // auto time = artdaq::TimeUtils::get_realtime_clock(); 00240 // output.atime_ns = time.tv_nsec; 00241 // output.atime_s = time.tv_sec; 00242 output.atime_ns = 0; 00243 output.atime_s = 0; 00244 00245 return output; 00246 } 00247 #endif 00248 00249 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV1_hh */