artdaq_core  v1_07_08
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
RawFragmentHeader.hh
1 #ifndef artdaq_core_Data_detail_RawFragmentHeader_hh
2 #define artdaq_core_Data_detail_RawFragmentHeader_hh
3 // detail::RawFragmentHeader 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/exception.h"
11 #include <map>
12 
13 extern "C"
14 {
15 #include <stdint.h>
16 }
17 
18 namespace artdaq
19 {
20  namespace detail
21  {
22  struct RawFragmentHeader;
23  }
24 }
25 
34 {
38  typedef unsigned long long 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 uint64_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  }
76 
81  static std::map<type_t, std::string> MakeVerboseSystemTypeMap()
82  {
83  return std::map<type_t, std::string>{
84  {225, "EndOfData"},
85  { 226, "Data" },
86  { 227, "Init" },
87  { 228, "EndOfRun" },
88  { 229, "EndOfSubrun" },
89  { 230,"Shutdown" },
90  { 231, "Empty" },
91  { 232, "Container" }
92  };
93  }
94 
95  // Each of the following invalid values is chosen based on the
96  // size of the bitfield in which the corresponding data are
97  // encoded; if any of the sizes are changed, the corresponding
98  // values must be updated.
99  static const version_t InvalidVersion = 0xFFFF;
100  static const version_t CurrentVersion = 0x1;
101  static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
102  static const fragment_id_t InvalidFragmentID = 0xFFFF;
103  static const timestamp_t InvalidTimestamp = 0xFFFFFFFFFFFFFFFF;
104 
109 
113 
114 
115  // ****************************************************
116  // New fields MUST be added to the END of this list!!!
117  // ****************************************************
118 
123  static constexpr std::size_t num_words();
124 
130  void setUserType(uint8_t utype);
131 
137  void setSystemType(uint8_t stype);
138 
139 #endif /* HIDE_FROM_ROOT */
140 };
141 
142 #if HIDE_FROM_ROOT
143 inline
144 constexpr
145 std::size_t
147 {
148  return sizeof(detail::RawFragmentHeader) / sizeof(RawDataType);
149 }
150 
151 
152 // Compile-time check that the assumption made in num_words() above is
153 // actually true.
157  "sizeof(RawFragmentHeader) is not an integer "
158  "multiple of sizeof(RawDataType)!");
159 
160 inline
161 void
163 {
164  if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
165  {
166  throw cet::exception("InvalidValue")
167  << "RawFragmentHeader user types must be in the range of "
168  << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE)
169  << " (bad type is " << ((int)utype) << ").";
170  }
171  type = utype;
172 }
173 
174 inline
175 void
177 {
178  if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
179  {
180  throw cet::exception("InvalidValue")
181  << "RawFragmentHeader system types must be in the range of "
182  << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE);
183  }
184  type = stype;
185 }
186 #endif
187 
188 #endif /* artdaq_core_Data_detail_RawFragmentHeader_hh */
RawDataType metadata_word_count
The number of RawDataType words in the user-defined metadata.
RawDataType word_count
number of RawDataType words in this Fragment
static const sequence_id_t InvalidSequenceID
The sequence_id field is currently 48-bits.
static constexpr type_t FIRST_SYSTEM_TYPE
The first system type.
RawDataType type
The type of the fragment, either system or user-defined.
uint8_t type_t
type field is 8 bits
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most-commonly used system types.
void setSystemType(uint8_t stype)
Sets the type field to the specified system type.
static constexpr std::size_t num_words()
Returns the number of RawDataType words present in the header.
static constexpr type_t DataFragmentType
This Fragment holds data. Used for RawEvent Fragments sent from the EventBuilder to the Aggregator...
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...
static constexpr type_t InvalidFragmentType
Marks a Fragment as Invalid.
RawDataType sequence_id
The 48-bit sequence_id uniquely identifies events within the artdaq system.
RawDataType version
The version of the fragment. Currently always InvalidVersion.
static constexpr type_t ShutdownFragmentType
This Fragment indicates a system shutdown to art
static constexpr type_t LAST_USER_TYPE
The last user-accessible type (types above this number are system types.
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
static const version_t InvalidVersion
The version field is currently 16-bits.
void setUserType(uint8_t utype)
Sets the type field to the specified user type.
uint64_t timestamp_t
timestamp field is 32 bits
static constexpr type_t EmptyFragmentType
This Fragment contains no data and serves as a placeholder for when no data from a FragmentGenerator ...
static constexpr type_t FIRST_USER_TYPE
The first user-accessible type.
static std::map< type_t, std::string > MakeVerboseSystemTypeMap()
Returns a map of all system types.
static const timestamp_t InvalidTimestamp
The timestamp field is currently 32-bits.
unsigned long long RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
uint64_t sequence_id_t
sequence_id field is 48 bits
static const fragment_id_t InvalidFragmentID
The fragment_id field is currently 16-bits.
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeader changes.
static constexpr type_t ContainerFragmentType
This Fragment is a ContainerFragment and analysis code should unpack it.
static constexpr type_t EndOfDataFragmentType
This Fragment indicates the end of data to art
uint16_t version_t
version field is 16 bits
static constexpr type_t LAST_SYSTEM_TYPE
The last system type.
static constexpr type_t EndOfSubrunFragmentType
This Fragment indicates the end of a subrun to art
uint16_t fragment_id_t
fragment_id field is 16 bits
static constexpr type_t EndOfRunFragmentType
This Fragment indicates the end of a run to art
uint8_t metadata_word_count_t
metadata_word_count field is 8 bits
static constexpr type_t InitFragmentType
This Fragment holds the necessary data for initializing art
static constexpr type_t INVALID_TYPE
Marks a Fragment as Invalid.