$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_05_04
$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> 00016 } 00017 00018 namespace artdaq { 00019 namespace detail { 00020 struct RawFragmentHeaderV1; 00021 } 00022 } // namespace artdaq 00023 00032 struct artdaq::detail::RawFragmentHeaderV1 00033 { 00037 typedef unsigned long long 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 } 00120 return "Unknown"; 00121 } 00122 00123 // Each of the following invalid values is chosen based on the 00124 // size of the bitfield in which the corresponding data are 00125 // encoded; if any of the sizes are changed, the corresponding 00126 // values must be updated. 00127 static const version_t InvalidVersion = 0xFFFF; 00128 static const version_t CurrentVersion = 0x1; 00129 static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF; 00130 static const fragment_id_t InvalidFragmentID = 0xFFFF; 00131 static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF; 00132 00133 RawDataType word_count : 32; 00134 RawDataType version : 16; 00135 RawDataType type : 8; 00136 RawDataType metadata_word_count : 8; 00137 00138 RawDataType sequence_id : 48; 00139 RawDataType fragment_id : 16; 00140 RawDataType timestamp : 64; 00141 00142 // **************************************************** 00143 // New fields MUST be added to the END of this list!!! 00144 // **************************************************** 00145 00150 static constexpr std::size_t num_words(); 00151 00157 void setUserType(uint8_t utype); 00158 00164 void setSystemType(uint8_t stype); 00165 00176 RawFragmentHeader upgrade() const; 00177 00178 #endif /* HIDE_FROM_ROOT */ 00179 }; 00180 00181 #if HIDE_FROM_ROOT 00182 inline constexpr std::size_t 00183 artdaq::detail::RawFragmentHeaderV1::num_words() 00184 { 00185 return sizeof(detail::RawFragmentHeaderV1) / sizeof(RawDataType); 00186 } 00187 00188 // Compile-time check that the assumption made in num_words() above is 00189 // actually true. 00190 static_assert((artdaq::detail::RawFragmentHeaderV1::num_words() * 00191 sizeof(artdaq::detail::RawFragmentHeaderV1::RawDataType)) == 00192 sizeof(artdaq::detail::RawFragmentHeaderV1), 00193 "sizeof(RawFragmentHeaderV1) is not an integer " 00194 "multiple of sizeof(RawDataType)!"); 00195 00196 inline void 00197 artdaq::detail::RawFragmentHeaderV1::setUserType(uint8_t utype) 00198 { 00199 if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE) 00200 { 00201 throw cet::exception("InvalidValue") 00202 << "RawFragmentHeaderV1 user types must be in the range of " 00203 << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE) 00204 << " (bad type is " << ((int)utype) << ")."; 00205 } 00206 type = utype; 00207 } 00208 00209 inline void 00210 artdaq::detail::RawFragmentHeaderV1::setSystemType(uint8_t stype) 00211 { 00212 if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/) 00213 { 00214 throw cet::exception("InvalidValue") 00215 << "RawFragmentHeaderV1 system types must be in the range of " 00216 << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE); 00217 } 00218 type = stype; 00219 } 00220 00221 inline artdaq::detail::RawFragmentHeader 00222 artdaq::detail::RawFragmentHeaderV1::upgrade() const 00223 { 00224 RawFragmentHeader output; 00225 output.word_count = word_count; 00226 output.version = RawFragmentHeader::CurrentVersion; 00227 output.type = type; 00228 output.metadata_word_count = metadata_word_count; 00229 00230 output.sequence_id = sequence_id; 00231 output.fragment_id = fragment_id; 00232 output.timestamp = timestamp; 00233 00234 output.valid = true; 00235 output.complete = true; 00236 00237 auto time = artdaq::TimeUtils::get_realtime_clock(); 00238 output.atime_ns = time.tv_nsec; 00239 output.atime_s = time.tv_sec; 00240 00241 return output; 00242 } 00243 #endif 00244 00245 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV1_hh */