artdaq_core  v3_06_01
RawFragmentHeaderV0.hh
1 #ifndef artdaq_core_Data_detail_RawFragmentHeaderV0_hh
2 #define artdaq_core_Data_detail_RawFragmentHeaderV0_hh
3 // detail::RawFragmentHeaderV0 is an overlay that provides the user's view
4 // of the data contained within a Fragment. It is intended to be hidden
5 // from the user of Fragment, as an implementation detail. The interface
6 // of Fragment is intended to be used to access the data.
7 
8 //#include <cstddef>
9 #include <map>
10 #include "artdaq-core/Data/detail/RawFragmentHeader.hh"
11 #include "artdaq-core/Data/dictionarycontrol.hh"
12 #include "artdaq-core/Utilities/TimeUtils.hh"
13 #include "cetlib_except/exception.h"
14 
15 extern "C" {
16 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
17 }
18 
19 namespace artdaq {
20 namespace detail {
21 struct RawFragmentHeaderV0;
22 }
23 } // namespace artdaq
24 
34 {
38  typedef uint64_t RawDataType;
39 
40 #if HIDE_FROM_ROOT
41  typedef uint16_t version_t;
42  typedef uint64_t sequence_id_t;
43  typedef uint8_t type_t;
44  typedef uint16_t fragment_id_t;
45  typedef uint8_t metadata_word_count_t;
46  typedef uint32_t timestamp_t;
47 
48  // define special values for type_t
49  static constexpr type_t INVALID_TYPE = 0;
50  static constexpr type_t FIRST_USER_TYPE = 1;
51  static constexpr type_t LAST_USER_TYPE = 224;
52  static constexpr type_t FIRST_SYSTEM_TYPE = 225;
53  static constexpr type_t LAST_SYSTEM_TYPE = 255;
56  static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1;
57  static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2;
61  static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6;
63 
68  static std::map<type_t, std::string> MakeSystemTypeMap()
69  {
70  return std::map<type_t, std::string>{
71  {226, "Data"},
72  {231, "Empty"},
73  {232, "Container"}};
74  }
75 
80  static std::map<type_t, std::string> MakeVerboseSystemTypeMap()
81  {
82  return std::map<type_t, std::string>{
83  {225, "EndOfData"},
84  {226, "Data"},
85  {227, "Init"},
86  {228, "EndOfRun"},
87  {229, "EndOfSubrun"},
88  {230, "Shutdown"},
89  {231, "Empty"},
90  {232, "Container"}};
91  }
92 
93  // Each of the following invalid values is chosen based on the
94  // size of the bitfield in which the corresponding data are
95  // encoded; if any of the sizes are changed, the corresponding
96  // values must be updated.
97  static const version_t InvalidVersion = 0xFFFF;
98  static const version_t CurrentVersion = 0x0;
99  static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
100  static const fragment_id_t InvalidFragmentID = 0xFFFF;
101  static const timestamp_t InvalidTimestamp = 0xFFFFFFFF;
102 
107 
111 
114 
119  constexpr static std::size_t num_words();
120 
126  void setUserType(uint8_t utype);
127 
133  void setSystemType(uint8_t stype);
134 
145  RawFragmentHeader upgrade() const;
146 
147 #endif /* HIDE_FROM_ROOT */
148 };
149 
150 #if HIDE_FROM_ROOT
151 inline constexpr std::size_t
153 {
154  return sizeof(detail::RawFragmentHeaderV0) / sizeof(RawDataType);
155 }
156 
157 // Compile-time check that the assumption made in num_words() above is
158 // actually true.
162  "sizeof(RawFragmentHeader) is not an integer "
163  "multiple of sizeof(RawDataType)!");
164 
165 inline void
167 {
168  if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
169  {
170  throw cet::exception("InvalidValue") // NOLINT(cert-err60-cpp)
171  << "RawFragmentHeader user types must be in the range of "
172  << static_cast<int>(FIRST_SYSTEM_TYPE) << " to " << static_cast<int>(LAST_SYSTEM_TYPE)
173  << " (bad type is " << static_cast<int>(utype) << ").";
174  }
175  type = utype;
176 }
177 
178 inline void
180 {
181  if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
182  {
183  throw cet::exception("InvalidValue") // NOLINT(cert-err60-cpp)
184  << "RawFragmentHeader system types must be in the range of "
185  << static_cast<int>(FIRST_SYSTEM_TYPE) << " to " << static_cast<int>(LAST_SYSTEM_TYPE);
186  }
187  type = stype;
188 }
189 
192 {
193  RawFragmentHeader output;
194  output.word_count = word_count;
196  output.type = type;
197  output.metadata_word_count = metadata_word_count;
198 
199  output.sequence_id = sequence_id;
200  output.fragment_id = fragment_id;
201  output.timestamp = timestamp;
202 
203  output.valid = true;
204  output.complete = true;
205 
206  // ELF 10/1/19: Due to how many times upgrade() gets called during an analysis process, better to just zero these fields
207  // auto time = artdaq::TimeUtils::get_realtime_clock();
208  // output.atime_ns = time.tv_nsec;
209  // output.atime_s = time.tv_sec;
210  output.atime_ns = 0;
211  output.atime_s = 0;
212 
213  return output;
214 }
215 #endif
216 
217 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV0_hh */
static const version_t InvalidVersion
The version field is currently 16-bits.
RawDataType metadata_word_count
The number of RawDataType words in the user-defined metadata.
RawDataType word_count
number of RawDataType words in this Fragment
RawDataType type
The type of the fragment, either system or user-defined.
The RawFragmentHeaderV0 class contains the basic fields used by artdaq for routing Fragment objects t...
RawDataType timestamp
The 64-bit timestamp field is the output of a user-defined clock used for building time-correlated ev...
static constexpr type_t EndOfRunFragmentType
This Fragment indicates the end of a run to art
static const fragment_id_t InvalidFragmentID
The fragment_id field is currently 16-bits.
static constexpr type_t ShutdownFragmentType
This Fragment indicates a system shutdown to art
RawDataType type
The type of the fragment, either system or user-defined.
The RawFragmentHeader class contains the basic fields used by artdaq for routing Fragment objects thr...
RawDataType timestamp
The 64-bit timestamp field is the output of a user-defined clock used for building time-correlated ev...
uint32_t timestamp_t
timestamp field is 32 bits
RawDataType sequence_id
The 48-bit sequence_id uniquely identifies events within the artdaq system.
static const sequence_id_t InvalidSequenceID
The sequence_id field is currently 48-bits.
uint16_t fragment_id_t
fragment_id field is 16 bits
RawDataType version
The version of the fragment.
RawDataType atime_s
Last access time of the Fragment, second part (measured from epoch)
static const timestamp_t InvalidTimestamp
The timestamp field is currently 32-bits.
static constexpr std::size_t num_words()
Returns the number of RawDataType words present in the header.
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
static constexpr type_t EndOfSubrunFragmentType
This Fragment indicates the end of a subrun to art
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most-commonly used system types.
RawDataType sequence_id
The 48-bit sequence_id uniquely identifies events within the artdaq system.
static constexpr type_t LAST_SYSTEM_TYPE
The last system type.
static std::map< type_t, std::string > MakeVerboseSystemTypeMap()
Returns a map of all system types.
static constexpr type_t ContainerFragmentType
This Fragment is a ContainerFragment and analysis code should unpack it.
uint64_t sequence_id_t
sequence_id field is 48 bits
static constexpr type_t FIRST_USER_TYPE
The first user-accessible type.
static constexpr type_t FIRST_SYSTEM_TYPE
The first system type.
static constexpr type_t LAST_USER_TYPE
The last user-accessible type (types above this number are system types.
RawDataType valid
Flag for whether the Fragment has been transported correctly through the artdaq system.
void setSystemType(uint8_t stype)
Sets the type field to the specified system type.
static constexpr type_t InitFragmentType
This Fragment holds the necessary data for initializing art
static constexpr type_t EmptyFragmentType
This Fragment contains no data and serves as a placeholder for when no data from a FragmentGenerator ...
RawDataType word_count
number of RawDataType words in this Fragment
RawFragmentHeader upgrade() const
Upgrades the RawFragmentHeaderV0 to a RawFragmentHeader (Current version)
uint8_t type_t
type field is 8 bits
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeader changes.
uint16_t version_t
version field is 16 bits
static constexpr type_t EndOfDataFragmentType
This Fragment indicates the end of data to art
uint8_t metadata_word_count_t
metadata_word_count field is 8 bits
RawDataType atime_ns
Last access time of the Fragment, nanosecond part.
RawDataType version
The version of the fragment. Currently always InvalidVersion.
static constexpr type_t DataFragmentType
This Fragment holds data. Used for RawEvent Fragments sent from the EventBuilder to the Aggregator...
uint64_t RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
RawDataType metadata_word_count
The number of RawDataType words in the user-defined metadata.
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeader changes.
static constexpr type_t INVALID_TYPE
Marks a Fragment as Invalid.
static constexpr type_t InvalidFragmentType
Marks a Fragment as Invalid.
void setUserType(uint8_t utype)
Sets the type field to the specified user type.
RawDataType complete
Flag for whether the Fragment completely represents an event for its hardware.