artdaq_core  v3_05_00
RawFragmentHeaderV1.hh
1 #ifndef artdaq_core_Data_detail_RawFragmentHeaderV1_hh
2 #define artdaq_core_Data_detail_RawFragmentHeaderV1_hh
3 // detail::RawFragmentHeaderV1 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 "artdaq-core/Data/dictionarycontrol.hh"
10 #include "cetlib_except/exception.h"
11 #include <map>
12 #include "artdaq-core/Data/detail/RawFragmentHeader.hh"
13 
14 extern "C"
15 {
16 #include <stdint.h>
17 }
18 
19 namespace artdaq
20 {
21  namespace detail
22  {
23  struct RawFragmentHeaderV1;
24  }
25 }
26 
36 {
40  typedef unsigned long long RawDataType;
41 
42 #if HIDE_FROM_ROOT
43  typedef uint16_t version_t;
44  typedef uint64_t sequence_id_t;
45  typedef uint8_t type_t;
46  typedef uint16_t fragment_id_t;
47  typedef uint8_t metadata_word_count_t;
48  typedef uint64_t timestamp_t;
49 
50  // define special values for type_t
51  static constexpr type_t INVALID_TYPE = 0;
52  static constexpr type_t FIRST_USER_TYPE = 1;
53  static constexpr type_t LAST_USER_TYPE = 224;
54  static constexpr type_t FIRST_SYSTEM_TYPE = 225;
55  static constexpr type_t LAST_SYSTEM_TYPE = 255;
58  static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1;
59  static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2;
63  static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6;
65 
70  static std::map<type_t, std::string> MakeSystemTypeMap()
71  {
72  return std::map<type_t, std::string>{
73  { type_t(DataFragmentType), "Data"},
74  { type_t(EmptyFragmentType), "Empty" },
75  { 232, "Container" }
76  };
77  }
78 
83  static std::map<type_t, std::string> MakeVerboseSystemTypeMap()
84  {
85  return std::map<type_t, std::string>{
86  { type_t(EndOfDataFragmentType), "EndOfData" },
87  { type_t(DataFragmentType), "Data" },
88  { type_t(InitFragmentType), "Init" },
89  { type_t(EndOfRunFragmentType), "EndOfRun" },
90  { type_t(EndOfSubrunFragmentType), "EndOfSubrun" },
91  { type_t(ShutdownFragmentType),"Shutdown" },
92  { type_t(EmptyFragmentType), "Empty" },
93  { type_t(ContainerFragmentType), "Container" }
94  };
95  }
96 
102  static std::string SystemTypeToString(type_t type) {
103  switch (type) {
104  case INVALID_TYPE:
105  return "INVALID";
107  return "EndOfData";
108  case DataFragmentType:
109  return "Data";
110  case InitFragmentType:
111  return "Init";
113  return "EndOfRun";
115  return "EndOfSubrun";
117  return "Shutdown";
118  case EmptyFragmentType:
119  return "Empty";
121  return "Container";
122  }
123  return "Unknown";
124  }
125 
126  // Each of the following invalid values is chosen based on the
127  // size of the bitfield in which the corresponding data are
128  // encoded; if any of the sizes are changed, the corresponding
129  // values must be updated.
130  static const version_t InvalidVersion = 0xFFFF;
131  static const version_t CurrentVersion = 0x1;
132  static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
133  static const fragment_id_t InvalidFragmentID = 0xFFFF;
134  static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF;
135 
140 
144 
145 
146  // ****************************************************
147  // New fields MUST be added to the END of this list!!!
148  // ****************************************************
149 
154  static constexpr std::size_t num_words();
155 
161  void setUserType(uint8_t utype);
162 
168  void setSystemType(uint8_t stype);
169 
180  RawFragmentHeader upgrade() const;
181 
182 #endif /* HIDE_FROM_ROOT */
183 };
184 
185 #if HIDE_FROM_ROOT
186 inline
187 constexpr
188 std::size_t
190 {
191  return sizeof(detail::RawFragmentHeaderV1) / sizeof(RawDataType);
192 }
193 
194 
195 // Compile-time check that the assumption made in num_words() above is
196 // actually true.
200  "sizeof(RawFragmentHeaderV1) is not an integer "
201  "multiple of sizeof(RawDataType)!");
202 
203 inline
204 void
206 {
207  if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
208  {
209  throw cet::exception("InvalidValue")
210  << "RawFragmentHeaderV1 user types must be in the range of "
211  << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE)
212  << " (bad type is " << ((int)utype) << ").";
213  }
214  type = utype;
215 }
216 
217 inline
218 void
220 {
221  if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
222  {
223  throw cet::exception("InvalidValue")
224  << "RawFragmentHeaderV1 system types must be in the range of "
225  << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE);
226  }
227  type = stype;
228 }
229 
230 inline
233 {
234  RawFragmentHeader output;
235  output.word_count = word_count;
237  output.type = type;
238  output.metadata_word_count = metadata_word_count;
239 
240  output.sequence_id = sequence_id;
241  output.fragment_id = fragment_id;
242  output.timestamp = timestamp;
243 
244  output.valid = true;
245  output.complete = true;
246 
248  output.atime_ns = time.tv_nsec;
249  output.atime_s = time.tv_sec;
250 
251  return output;
252 }
253 #endif
254 
255 #endif /* artdaq_core_Data_detail_RawFragmentHeaderV1_hh */
RawDataType metadata_word_count
The number of RawDataType words in the user-defined metadata.
static constexpr type_t ShutdownFragmentType
This Fragment indicates a system shutdown to art
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.
static constexpr std::size_t num_words()
Returns the number of RawDataType words present in the header.
uint64_t timestamp_t
timestamp field is 32 bits
static constexpr type_t FIRST_SYSTEM_TYPE
The first system type.
The RawFragmentHeader class contains the basic fields used by artdaq for routing Fragment objects thr...
static const fragment_id_t InvalidFragmentID
The fragment_id field is currently 16-bits.
static constexpr type_t EndOfSubrunFragmentType
This Fragment indicates the end of a subrun to art
RawDataType timestamp
The 64-bit timestamp field is the output of a user-defined clock used for building time-correlated ev...
RawDataType timestamp
The 64-bit timestamp field is the output of a user-defined clock used for building time-correlated ev...
RawDataType sequence_id
The 48-bit sequence_id uniquely identifies events within the artdaq system.
static constexpr type_t EndOfRunFragmentType
This Fragment indicates the end of a run to art
RawFragmentHeader upgrade() const
Upgrades the RawFragmentHeaderV1 to a RawFragmentHeader (Current version)
static constexpr type_t FIRST_USER_TYPE
The first user-accessible type.
RawDataType version
The version of the fragment.
RawDataType atime_s
Last access time of the Fragment, second part (measured from epoch)
static const sequence_id_t InvalidSequenceID
The sequence_id field is currently 48-bits.
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
static const timestamp_t InvalidTimestamp
The timestamp field is currently 64-bits.
uint16_t fragment_id_t
fragment_id field is 16 bits
static constexpr type_t LAST_SYSTEM_TYPE
The last system type.
unsigned long long RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
static constexpr type_t InitFragmentType
This Fragment holds the necessary data for initializing art
struct timespec get_realtime_clock()
Get the current time of day as a pair of seconds and nanoseconds (from clock_gettime(CLOCK_REALTIME, ...) system call)
Definition: TimeUtils.cc:58
RawDataType valid
Flag for whether the Fragment has been transported correctly through the artdaq system.
RawDataType type
The type of the fragment, either system or user-defined.
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeaderV1 changes.
static constexpr type_t DataFragmentType
This Fragment holds data. Used for RawEvent Fragments sent from the EventBuilder to the Aggregator...
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
uint64_t sequence_id_t
sequence_id field is 48 bits
static constexpr type_t INVALID_TYPE
Marks a Fragment as Invalid.
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most-commonly used system types.
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeader changes.
uint8_t metadata_word_count_t
metadata_word_count field is 8 bits
static std::map< type_t, std::string > MakeVerboseSystemTypeMap()
Returns a map of all system types.
static constexpr type_t EmptyFragmentType
This Fragment contains no data and serves as a placeholder for when no data from a FragmentGenerator ...
static std::string SystemTypeToString(type_t type)
Print a system type&#39;s string name.
RawDataType atime_ns
Last access time of the Fragment, nanosecond part.
uint16_t version_t
version field is 16 bits
static constexpr type_t ContainerFragmentType
This Fragment is a ContainerFragment and analysis code should unpack it.
static constexpr type_t InvalidFragmentType
Marks a Fragment as Invalid.
The RawFragmentHeaderV1 class contains the basic fields used by artdaq for routing Fragment objects t...
static constexpr type_t EndOfDataFragmentType
This Fragment indicates the end of data to art
static const version_t InvalidVersion
The version field is currently 16-bits.
static constexpr type_t LAST_USER_TYPE
The last user-accessible type (types above this number are system types.
RawDataType word_count
number of RawDataType words in this Fragment
void setUserType(uint8_t utype)
Sets the type field to the specified user type.
RawDataType sequence_id
The 48-bit sequence_id uniquely identifies events within the artdaq system.
void setSystemType(uint8_t stype)
Sets the type field to the specified system type.
uint8_t type_t
type field is 8 bits
RawDataType version
The version of the fragment.
RawDataType complete
Flag for whether the Fragment completely represents an event for its hardware.