artdaq_core  v3_05_00
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 #include "artdaq-core/Utilities/TimeUtils.hh"
14 
15 extern "C"
16 {
17 #include <stdint.h>
18 }
19 
20 namespace artdaq
21 {
22  namespace detail
23  {
24  struct RawFragmentHeaderV0;
25  }
26 }
27 
37 {
41  typedef unsigned long long RawDataType;
42 
43 #if HIDE_FROM_ROOT
44  typedef uint16_t version_t;
45  typedef uint64_t sequence_id_t;
46  typedef uint8_t type_t;
47  typedef uint16_t fragment_id_t;
48  typedef uint8_t metadata_word_count_t;
49  typedef uint32_t timestamp_t;
50 
51  // define special values for type_t
52  static constexpr type_t INVALID_TYPE = 0;
53  static constexpr type_t FIRST_USER_TYPE = 1;
54  static constexpr type_t LAST_USER_TYPE = 224;
55  static constexpr type_t FIRST_SYSTEM_TYPE = 225;
56  static constexpr type_t LAST_SYSTEM_TYPE = 255;
59  static constexpr type_t DataFragmentType = FIRST_SYSTEM_TYPE + 1;
60  static constexpr type_t InitFragmentType = FIRST_SYSTEM_TYPE + 2;
64  static constexpr type_t EmptyFragmentType = FIRST_SYSTEM_TYPE + 6;
66 
71  static std::map<type_t, std::string> MakeSystemTypeMap()
72  {
73  return std::map<type_t, std::string>{
74  {226, "Data"},
75  { 231, "Empty" },
76  { 232, "Container" }
77  };
78  }
79 
84  static std::map<type_t, std::string> MakeVerboseSystemTypeMap()
85  {
86  return std::map<type_t, std::string>{
87  {225, "EndOfData"},
88  { 226, "Data" },
89  { 227, "Init" },
90  { 228, "EndOfRun" },
91  { 229, "EndOfSubrun" },
92  { 230,"Shutdown" },
93  { 231, "Empty" },
94  { 232, "Container" }
95  };
96  }
97 
98  // Each of the following invalid values is chosen based on the
99  // size of the bitfield in which the corresponding data are
100  // encoded; if any of the sizes are changed, the corresponding
101  // values must be updated.
102  static const version_t InvalidVersion = 0xFFFF;
103  static const version_t CurrentVersion = 0x0;
104  static const sequence_id_t InvalidSequenceID = 0xFFFFFFFFFFFF;
105  static const fragment_id_t InvalidFragmentID = 0xFFFF;
106  static const timestamp_t InvalidTimestamp = 0xFFFFFFFF;
107 
112 
116 
119 
124  constexpr static std::size_t num_words();
125 
131  void setUserType(uint8_t utype);
132 
138  void setSystemType(uint8_t stype);
139 
150  RawFragmentHeader upgrade() const;
151 
152 #endif /* HIDE_FROM_ROOT */
153 };
154 
155 #if HIDE_FROM_ROOT
156 inline
157 constexpr
158 std::size_t
160 {
161  return sizeof(detail::RawFragmentHeaderV0) / sizeof(RawDataType);
162 }
163 
164 // Compile-time check that the assumption made in num_words() above is
165 // actually true.
169  "sizeof(RawFragmentHeader) is not an integer "
170  "multiple of sizeof(RawDataType)!");
171 
172 inline
173 void
175 {
176  if (utype < FIRST_USER_TYPE || utype > LAST_USER_TYPE)
177  {
178  throw cet::exception("InvalidValue")
179  << "RawFragmentHeader user types must be in the range of "
180  << ((int)FIRST_USER_TYPE) << " to " << ((int)LAST_USER_TYPE)
181  << " (bad type is " << ((int)utype) << ").";
182  }
183  type = utype;
184 }
185 
186 inline
187 void
189 {
190  if (stype < FIRST_SYSTEM_TYPE /*|| stype > LAST_SYSTEM_TYPE*/)
191  {
192  throw cet::exception("InvalidValue")
193  << "RawFragmentHeader system types must be in the range of "
194  << ((int)FIRST_SYSTEM_TYPE) << " to " << ((int)LAST_SYSTEM_TYPE);
195  }
196  type = stype;
197 }
198 
199 inline
202 {
203  RawFragmentHeader output;
204  output.word_count = word_count;
206  output.type = type;
207  output.metadata_word_count = metadata_word_count;
208 
209  output.sequence_id = sequence_id;
210  output.fragment_id = fragment_id;
211  output.timestamp = timestamp;
212 
213  output.valid = true;
214  output.complete = true;
215 
217  output.atime_ns = time.tv_nsec;
218  output.atime_s = time.tv_sec;
219 
220  return output;
221 }
222 #endif
223 
224 #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.
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
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
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 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...
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.