artdaq_core  v3_04_09
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 "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 RawFragmentHeaderV0;
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 uint32_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  {226, "Data"},
74  { 231, "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  {225, "EndOfData"},
87  { 226, "Data" },
88  { 227, "Init" },
89  { 228, "EndOfRun" },
90  { 229, "EndOfSubrun" },
91  { 230,"Shutdown" },
92  { 231, "Empty" },
93  { 232, "Container" }
94  };
95  }
96 
97  // Each of the following invalid values is chosen based on the
98  // size of the bitfield in which the corresponding data are
99  // encoded; if any of the sizes are changed, the corresponding
100  // values must be updated.
101  static const version_t InvalidVersion = 0xFFFF;
102  static const version_t CurrentVersion = 0x0;
103  static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
104  static const fragment_id_t InvalidFragmentID = 0xFFFF;
105  static const timestamp_t InvalidTimestamp = 0xFFFFFFFF;
106 
111 
115 
118 
123  constexpr static std::size_t num_words();
124 
130  void setUserType(uint8_t utype);
131 
137  void setSystemType(uint8_t stype);
138 
149  RawFragmentHeader upgrade() const;
150 
151 #endif /* HIDE_FROM_ROOT */
152 };
153 
154 #if HIDE_FROM_ROOT
155 inline
156 constexpr
157 std::size_t
159 {
160  return sizeof(detail::RawFragmentHeaderV0) / sizeof(RawDataType);
161 }
162 
163 // Compile-time check that the assumption made in num_words() above is
164 // actually true.
168  "sizeof(RawFragmentHeader) is not an integer "
169  "multiple of sizeof(RawDataType)!");
170 
171 inline
172 void
174 {
175  if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
176  {
177  throw cet::exception("InvalidValue")
178  << "RawFragmentHeader user types must be in the range of "
179  << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE)
180  << " (bad type is " << ((int)utype) << ").";
181  }
182  type = utype;
183 }
184 
185 inline
186 void
188 {
189  if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
190  {
191  throw cet::exception("InvalidValue")
192  << "RawFragmentHeader system types must be in the range of "
193  << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE);
194  }
195  type = stype;
196 }
197 
198 inline
201 {
202  RawFragmentHeader output;
203  output.word_count = word_count;
205  output.type = type;
206  output.metadata_word_count = metadata_word_count;
207 
208  output.sequence_id = sequence_id;
209  output.fragment_id = fragment_id;
210  output.timestamp = timestamp;
211 
212  return output;
213 }
214 #endif
215 
216 #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.
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.
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
unsigned long long RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
uint8_t metadata_word_count_t
metadata_word_count field is 8 bits
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...
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.