artdaq_core  v3_02_01
Fragment.hh
1 #ifndef artdaq_core_Data_Fragment_hh
2 #define artdaq_core_Data_Fragment_hh
3 
4 #include <algorithm>
5 //#include <cassert>
6 #include <cstddef>
7 #include <iosfwd>
8 #include <iterator>
9 #include <vector>
10 #include <list>
11 #include <memory>
12 #include <map>
13 #include <cmath>
14 #include <stdint.h>
15 #include <string.h>
16 
17 #include "artdaq-core/Data/detail/RawFragmentHeader.hh"
18 #include "artdaq-core/Data/detail/RawFragmentHeaderV0.hh"
19 #include "artdaq-core/Data/dictionarycontrol.hh"
20 #include "artdaq-core/Core/QuickVec.hh"
21 #include <iostream>
22 #if HIDE_FROM_ROOT
23 #include "trace.h" // TRACE
24 #endif
25 
29 namespace artdaq {
30 # define DATAVEC_T QuickVec<RawDataType>
31  //#define DATAVEC_T std::vector<RawDataType>
32 
40 
41  class Fragment;
45  typedef std::vector<Fragment> Fragments;
46 
53  typedef std::unique_ptr<Fragment> FragmentPtr;
54 
58  typedef std::list<FragmentPtr> FragmentPtrs;
59 
67 
74  std::ostream& operator<<(std::ostream& os, Fragment const& f);
75 }
76 
85 {
86 public:
90  Fragment();
91 
99  typedef uint8_t byte_t;
100 
101  // Hide most things from ROOT.
102 #if HIDE_FROM_ROOT
103 
104  // http://stackoverflow.com/questions/33939687
105  // This should generate an exception if artdaq::Fragment is not move-constructible
110  Fragment(const Fragment&) = default;
118  Fragment(Fragment&&) noexcept;
124  Fragment& operator=(const Fragment&) = default;
133  Fragment& operator=(Fragment&&) noexcept;
134 
135  typedef detail::RawFragmentHeader::version_t version_t;
136  typedef detail::RawFragmentHeader::type_t type_t;
137  typedef detail::RawFragmentHeader::sequence_id_t sequence_id_t;
138  typedef detail::RawFragmentHeader::fragment_id_t fragment_id_t;
139  typedef detail::RawFragmentHeader::timestamp_t timestamp_t;
140 
141  static constexpr version_t InvalidVersion = detail::RawFragmentHeader::InvalidVersion;
142  static constexpr sequence_id_t InvalidSequenceID = detail::RawFragmentHeader::InvalidSequenceID;
143  static constexpr fragment_id_t InvalidFragmentID = detail::RawFragmentHeader::InvalidFragmentID;
144  static constexpr timestamp_t InvalidTimestamp = detail::RawFragmentHeader::InvalidTimestamp;
145 
146  static constexpr type_t InvalidFragmentType = detail::RawFragmentHeader::InvalidFragmentType;
147  static constexpr type_t EndOfDataFragmentType = detail::RawFragmentHeader::EndOfDataFragmentType;
148  static constexpr type_t DataFragmentType = detail::RawFragmentHeader::DataFragmentType;
149  static constexpr type_t InitFragmentType = detail::RawFragmentHeader::InitFragmentType;
150  static constexpr type_t EndOfRunFragmentType = detail::RawFragmentHeader::EndOfRunFragmentType;
151  static constexpr type_t EndOfSubrunFragmentType = detail::RawFragmentHeader::EndOfSubrunFragmentType;
152  static constexpr type_t ShutdownFragmentType = detail::RawFragmentHeader::ShutdownFragmentType;
153  static constexpr type_t FirstUserFragmentType = detail::RawFragmentHeader::FIRST_USER_TYPE;
154  static constexpr type_t EmptyFragmentType = detail::RawFragmentHeader::EmptyFragmentType;
155  static constexpr type_t ContainerFragmentType = detail::RawFragmentHeader::ContainerFragmentType;
156 
162  static constexpr bool isUserFragmentType(type_t fragmentType);
163 
169  static constexpr bool isSystemFragmentType(type_t fragmentType);
170 
175  static std::map<type_t, std::string> MakeSystemTypeMap()
176  {
178  }
179 
180  typedef DATAVEC_T::reference reference;
181  typedef DATAVEC_T::iterator iterator;
182  typedef DATAVEC_T::const_iterator const_iterator;
183  typedef DATAVEC_T::value_type value_type;
184  typedef DATAVEC_T::difference_type difference_type;
185  typedef DATAVEC_T::size_type size_type;
186 
192  explicit Fragment(std::size_t n);
193 
200  static FragmentPtr FragmentBytes(std::size_t nbytes)
201  {
202  RawDataType nwords = ceil(nbytes / static_cast<double>(sizeof(RawDataType)));
203  return FragmentPtr(new Fragment(nwords));
204  }
205 
216  template <class T>
217  Fragment(std::size_t payload_size, sequence_id_t sequence_id,
218  fragment_id_t fragment_id, type_t type, const T& metadata,
220 
234  template <class T>
235  static FragmentPtr FragmentBytes(std::size_t payload_size_in_bytes,
236  sequence_id_t sequence_id,
237  fragment_id_t fragment_id,
238  type_t type, const T& metadata,
240  {
241  RawDataType nwords = ceil(payload_size_in_bytes /
242  static_cast<double>(sizeof(RawDataType)));
243  return FragmentPtr(new Fragment(nwords, sequence_id, fragment_id, type, metadata, timestamp));
244  }
245 
254  fragment_id_t fragID,
257 
262  void print(std::ostream& os) const;
263 
268  std::size_t size() const;
269 
274  version_t version() const;
275 
280  type_t type() const;
281 
286  std::string typeString() const;
287 
292  sequence_id_t sequenceID() const;
293 
298  fragment_id_t fragmentID() const;
299 
304  timestamp_t timestamp() const;
305 
310  void setUserType(type_t utype);
311 
316  void setSystemType(type_t stype);
317 
322  void setSequenceID(sequence_id_t sequence_id);
323 
328  void setFragmentID(fragment_id_t fragment_id);
329 
335 
340  std::size_t sizeBytes() const { return sizeof(RawDataType) * size(); }
341 
347  std::size_t dataSize() const;
348 
349 
355  std::size_t dataSizeBytes() const
356  {
357  return sizeof(RawDataType) * dataSize();
358  }
359 
364  bool hasMetadata() const;
365 
373  template <class T>
374  T* metadata();
375 
383  template <class T>
384  T const* metadata() const;
385 
394  template <class T>
395  void setMetadata(const T& md);
396 
404  template <class T>
405  void updateMetadata(const T& md);
406 
411  void resize(std::size_t sz);
412 
418  void resize(std::size_t sz, RawDataType val);
419 
426  void resizeBytes(std::size_t szbytes);
427 
435  void resizeBytes(std::size_t szbytes, byte_t val);
436 
440  void autoResize();
441 
447 
452  iterator dataEnd();
453 
473  template <typename T>
475  {
476  T newpointer = reinterpret_cast<T>(in);
477 
478  if (static_cast<const void*>(newpointer) != static_cast<const void*>(in))
479  {
480  throw cet::exception("Error in Fragment.hh: reinterpret_cast failed to return expected address-- please contact John Freeman at jcfree@fnal.gov");
481  }
482 
483  return newpointer;
484  }
485 
501  template <typename T>
503  {
504  T newpointer = reinterpret_cast<T>(in);
505 
506  if (static_cast<void*>(newpointer) != static_cast<void*>(in))
507  {
508  throw cet::exception("Error in Fragment.hh: reinterpret_cast failed to return expected address-- please contact John Freeman at jcfree@fnal.gov");
509  }
510 
511  return newpointer;
512  }
513 
522  byte_t* dataBeginBytes() { return reinterpret_cast_checked<byte_t*>(&* dataBegin()); }
523 
532  byte_t* dataEndBytes() { return reinterpret_cast_checked<byte_t*>(&* dataEnd()); }
533 
540 
545  byte_t* headerBeginBytes() { return reinterpret_cast_checked<byte_t*>(&* headerBegin()); }
546 
551  const_iterator dataBegin() const;
552 
557  const_iterator dataEnd() const;
558 
567  const byte_t* dataBeginBytes() const
568  {
569  return reinterpret_cast_checked<const byte_t*>(&* dataBegin());
570  }
571 
580  const byte_t* dataEndBytes() const
581  {
582  return reinterpret_cast_checked<const byte_t*>(&* dataEnd());
583  }
584 
590  const_iterator headerBegin() const; // See note for non-const, above.
591 
596  const byte_t* headerBeginBytes() const
597  {
598  return reinterpret_cast_checked<const byte_t*>(&* headerBegin());
599  }
600 
604  void clear();
605 
610  bool empty();
611 
616  void reserve(std::size_t cap);
617 
622  void swap(Fragment& other) noexcept;
623 
630  void swap(DATAVEC_T& other) noexcept { vals_.swap(other); };
631 
637 
650 
656  static FragmentPtr eodFrag(size_t nFragsToExpect);
657 
669  template<class InputIterator> static FragmentPtr dataFrag(sequence_id_t sequenceID,
670  fragment_id_t fragID,
671  InputIterator i,
672  InputIterator e)
673  {
674  FragmentPtr result(new Fragment(sequenceID, fragID));
675  result->vals_.reserve(std::distance(i, e) + detail::RawFragmentHeader::num_words());
676  std::copy(i, e, std::back_inserter(result->vals_));
677  result->updateFragmentHeaderWC_();
678  return result;
679  }
680 
691  fragment_id_t fragID,
692  RawDataType const* dataPtr,
693  size_t dataSize,
695 #endif
696 
697 private:
698  template <typename T>
699  static std::size_t validatedMetadataSize_();
700 
701  void updateFragmentHeaderWC_();
702 
703  DATAVEC_T vals_;
704 
705 #if HIDE_FROM_ROOT
706  detail::RawFragmentHeader* fragmentHeader();
707 
708  detail::RawFragmentHeader const* fragmentHeader() const;
709 #endif
710 };
711 
712 #if HIDE_FROM_ROOT
713 
714 
715 // http://stackoverflow.com/questions/33939687
716 // This should generate an exception if artdaq::Fragment is not move-constructible
717 inline artdaq::Fragment::Fragment(artdaq::Fragment&&) noexcept = default;
718 inline artdaq::Fragment& artdaq::Fragment::operator=(artdaq::Fragment&&) noexcept = default;
719 
720 inline
721 bool
722 constexpr
723 artdaq::Fragment::
724 isUserFragmentType(type_t fragmentType)
725 {
726  return fragmentType >= detail::RawFragmentHeader::FIRST_USER_TYPE &&
727  fragmentType <= detail::RawFragmentHeader::LAST_USER_TYPE;
728 }
729 
730 inline
731 bool
732 constexpr
735 {
736  return fragmentType >= detail::RawFragmentHeader::FIRST_SYSTEM_TYPE;
737 }
738 
739 template <typename T>
740 std::size_t
741 artdaq::Fragment::
742 validatedMetadataSize_()
743 {
744  // Make sure a size_t is big enough to hold the maximum metadata
745  // size. This *should* always be true, but it is a compile-time check
746  // and therefore cheap.
747  static_assert(sizeof(size_t) >=
748  sizeof(decltype(std::numeric_limits<detail::RawFragmentHeader::metadata_word_count_t>::max())),
749  "metadata_word_count_t is too big!");
750 
751  static size_t constexpr max_md_wc =
752  std::numeric_limits<detail::RawFragmentHeader::metadata_word_count_t>::max();
753  size_t requested_md_wc =
754  std::ceil(sizeof(T) / static_cast<double>(sizeof(artdaq::RawDataType)));
755  if (requested_md_wc > max_md_wc)
756  {
757  throw cet::exception("InvalidRequest")
758  << "The requested metadata structure is too large: "
759  << "requested word count = " << requested_md_wc
760  << ", maximum word count = " << max_md_wc;
761  }
762  return requested_md_wc;
763 }
764 
765 template <class T>
767 Fragment(std::size_t payload_size, sequence_id_t sequence_id,
768  fragment_id_t fragment_id,
769  type_t type, const T& metadata, timestamp_t timestamp) :
770  vals_((artdaq::detail::RawFragmentHeader::num_words() + // Header
771  validatedMetadataSize_<T>() + // Metadata
772  payload_size) // User data
773  )
774 {
775  TRACEN( "Fragment", 50, "Fragment ctor num_word()=%zu MetadataSize_=%zu payload_size=%zu"
776  ,artdaq::detail::RawFragmentHeader::num_words(), validatedMetadataSize_<T>(), payload_size );
777  // vals ctor w/o init val is used; make sure header is ALL initialized.
778  for (iterator ii = vals_.begin();
779  ii != (vals_.begin() + detail::RawFragmentHeader::num_words()); ++ii) {
780  *ii = -1;
781  }
783  updateFragmentHeaderWC_();
784  fragmentHeader()->sequence_id = sequence_id;
785  fragmentHeader()->fragment_id = fragment_id;
786  fragmentHeader()->timestamp = timestamp;
787  fragmentHeader()->type = type;
788 
789  fragmentHeader()->metadata_word_count =
790  vals_.size() -
791  (fragmentHeader()->num_words() + payload_size);
792 
793  memcpy(metadataAddress(), &metadata, sizeof(T));
794 }
795 
796 inline
797 std::size_t
799 {
800  return fragmentHeader()->word_count;
801 }
802 
803 inline
806 {
807  return fragmentHeader()->version;
808 }
809 
810 inline
813 {
814  return static_cast<type_t>(fragmentHeader()->type);
815 }
816 
817 inline
818 std::string
820 {
821  return std::to_string(type()) + (isSystemFragmentType(type()) ? " (" + detail::RawFragmentHeader::SystemTypeToString(type()) + ")" : "");
822 }
823 
824 inline
827 {
828  return fragmentHeader()->sequence_id;
829 }
830 
831 inline
834 {
835  return fragmentHeader()->fragment_id;
836 }
837 
838 inline
841 {
842  return fragmentHeader()->timestamp;
843 }
844 
845 inline
846 void
848 {
849  fragmentHeader()->setUserType(static_cast<uint8_t>(type));
850 }
851 
852 inline
853 void
855 {
856  fragmentHeader()->setSystemType(static_cast<uint8_t>(type));
857 }
858 
859 inline
860 void
862 {
863  assert(sequence_id <= detail::RawFragmentHeader::InvalidSequenceID);
864  fragmentHeader()->sequence_id = sequence_id;
865 }
866 
867 inline
868 void
870 {
871  fragmentHeader()->fragment_id = fragment_id;
872 }
873 
874 inline
875 void
877 {
878  fragmentHeader()->timestamp = timestamp;
879 }
880 
881 inline
882 void
883 artdaq::Fragment::updateFragmentHeaderWC_()
884 {
885  // Make sure vals_.size() fits inside 32 bits. Left-shift here should
886  // match bitfield size of word_count in RawFragmentHeader.
887  assert(vals_.size() < (1ULL << 32));
888  TRACEN( "Fragment", 50, "Fragment::updateFragmentHeaderWC_ adjusting fragmentHeader()->word_count from %u to %zu", (unsigned)(fragmentHeader()->word_count), vals_.size() );
889  fragmentHeader()->word_count = vals_.size();
890 }
891 
892 inline
893 std::size_t
895 {
896  return vals_.size() - fragmentHeader()->num_words() -
897  fragmentHeader()->metadata_word_count;
898 }
899 
900 inline
901 bool
903 {
904  return fragmentHeader()->metadata_word_count != 0;
905 }
906 
907 template <class T>
908 T*
910 {
911  if (fragmentHeader()->metadata_word_count == 0)
912  {
913  throw cet::exception("InvalidRequest")
914  << "No metadata has been stored in this Fragment.";
915  }
916 
917  return reinterpret_cast_checked<T *>
918  (&vals_[fragmentHeader()->num_words()]);
919 }
920 
921 template <class T>
922 T const*
924 {
925  if (fragmentHeader()->metadata_word_count == 0)
926  {
927  throw cet::exception("InvalidRequest")
928  << "No metadata has been stored in this Fragment.";
929  }
930  return reinterpret_cast_checked<T const *>
931  (&vals_[fragmentHeader()->num_words()]);
932 }
933 
934 template <class T>
935 void
937 {
938  if (fragmentHeader()->metadata_word_count != 0)
939  {
940  throw cet::exception("InvalidRequest")
941  << "Metadata has already been stored in this Fragment.";
942  }
943  auto const mdSize = validatedMetadataSize_<T>();
944  vals_.insert(dataBegin(), mdSize, 0);
945  updateFragmentHeaderWC_();
946  fragmentHeader()->metadata_word_count = mdSize;
947 
948  memcpy(metadataAddress(), &metadata, sizeof(T));
949 }
950 
951 template <class T>
952 void
954 {
955  if (fragmentHeader()->metadata_word_count == 0)
956  {
957  throw cet::exception("InvalidRequest")
958  << "No metadata in fragment; please use Fragment::setMetadata instead of Fragment::updateMetadata";
959  }
960 
961  auto const mdSize = validatedMetadataSize_<T>();
962 
963  if (fragmentHeader()->metadata_word_count != mdSize)
964  {
965  throw cet::exception("InvalidRequest")
966  << "Mismatch between type of metadata struct passed to updateMetadata and existing metadata struct";
967  }
968 
969  memcpy(metadataAddress(), &metadata, sizeof(T));
970 }
971 
972 inline void
974 {
975  vals_.resize(sz + fragmentHeader()->metadata_word_count +
976  fragmentHeader()->num_words());
977  updateFragmentHeaderWC_();
978 }
979 
980 inline
981 void
983 {
984  vals_.resize(sz + fragmentHeader()->metadata_word_count +
985  fragmentHeader()->num_words(), v);
986  updateFragmentHeaderWC_();
987 }
988 
989 inline void
990 artdaq::Fragment::resizeBytes(std::size_t szbytes)
991 {
992  RawDataType nwords = ceil(szbytes / static_cast<double>(sizeof(RawDataType)));
993  resize(nwords);
994 }
995 
996 inline
997 void
998 artdaq::Fragment::resizeBytes(std::size_t szbytes, byte_t v)
999 {
1000  RawDataType defaultval;
1001  byte_t* ptr = reinterpret_cast_checked<byte_t*>(&defaultval);
1002 
1003  for (uint8_t i = 0; i < sizeof(RawDataType); ++i)
1004  {
1005  *ptr = v;
1006  ptr++;
1007  }
1008 
1009  RawDataType nwords = ceil(szbytes / static_cast<double>(sizeof(RawDataType)));
1010 
1011  resize(nwords, defaultval);
1012 }
1013 
1014 
1015 inline
1016 void
1018 {
1019  vals_.resize(fragmentHeader()->word_count);
1020  updateFragmentHeaderWC_();
1021 }
1022 
1023 inline
1026 {
1027  return vals_.begin() + fragmentHeader()->num_words() +
1028  fragmentHeader()->metadata_word_count;
1029 }
1030 
1031 inline
1034 {
1035  return vals_.end();
1036 }
1037 
1038 inline
1041 {
1042  return vals_.begin();
1043 }
1044 
1045 inline
1048 {
1049  return vals_.begin() + fragmentHeader()->num_words() +
1050  fragmentHeader()->metadata_word_count;
1051 }
1052 
1053 inline
1056 {
1057  return vals_.end();
1058 }
1059 
1060 inline
1063 {
1064  return vals_.begin();
1065 }
1066 
1067 
1068 inline
1069 void
1071 {
1072  vals_.erase(dataBegin(), dataEnd());
1073  updateFragmentHeaderWC_();
1074 }
1075 
1076 inline
1077 bool
1079 {
1080  return (vals_.size() - fragmentHeader()->num_words() -
1081  fragmentHeader()->metadata_word_count) == 0;
1082 }
1083 
1084 inline
1085 void
1087 {
1088  vals_.reserve(cap + fragmentHeader()->num_words() +
1089  fragmentHeader()->metadata_word_count);
1090 }
1091 
1092 inline
1093 void
1095 {
1096  vals_.swap(other.vals_);
1097 }
1098 
1099 inline
1102 {
1103  return &vals_[0] + fragmentHeader()->num_words() +
1104  fragmentHeader()->metadata_word_count;
1105 }
1106 
1107 inline
1110 {
1111  if (fragmentHeader()->metadata_word_count == 0)
1112  {
1113  throw cet::exception("InvalidRequest")
1114  << "No metadata has been stored in this Fragment.";
1115  }
1116  return &vals_[0] + fragmentHeader()->num_words();
1117 }
1118 
1119 inline
1122 {
1123  return &vals_[0];
1124 }
1125 
1126 inline
1128 artdaq::Fragment::fragmentHeader()
1129 {
1130  auto hdr = reinterpret_cast_checked<detail::RawFragmentHeader *>(&vals_[0]);
1131  if (hdr->version != detail::RawFragmentHeader::CurrentVersion)
1132  {
1133  switch (hdr->version)
1134  {
1135  case 0xFFFF:
1136  //std::cout << "Not upgrading InvalidVersion Fragment" << std::endl;
1137  break;
1138  case 0:
1139  {
1140  std::cout << "Upgrading RawFragmentHeaderV0 (non const)" << std::endl;
1141  auto old_hdr = reinterpret_cast_checked<detail::RawFragmentHeaderV0 *>(&vals_[0]);
1142  auto new_hdr = old_hdr->upgrade();
1143 
1144  auto szDiff = hdr->num_words() - old_hdr->num_words();
1145  if (szDiff > 0) vals_.insert(vals_.begin(), szDiff, 0);
1146  memcpy(&vals_[0], &new_hdr, hdr->num_words() * sizeof(RawDataType));
1147  }
1148  break;
1149  default:
1150  throw cet::exception("Fragment") << "A Fragment with an unknown version (" << std::to_string(hdr->version) << ") was received!";
1151  break;
1152  }
1153  }
1154  return hdr;
1155 }
1156 
1157 inline
1159 artdaq::Fragment::fragmentHeader() const
1160 {
1161  auto hdr = reinterpret_cast_checked<detail::RawFragmentHeader const*>(&vals_[0]);
1162  if (hdr->version != detail::RawFragmentHeader::CurrentVersion)
1163  {
1164  switch (hdr->version)
1165  {
1166  case 0xFFFF:
1167  //std::cout << "Not upgrading InvalidVersion Fragment" << std::endl;
1168  break;
1169  case 0:
1170  {
1171  std::cout << "Upgrading RawFragmentHeaderV0 (const)" << std::endl;
1172  auto old_hdr = reinterpret_cast_checked<detail::RawFragmentHeaderV0 const*>(&vals_[0]);
1173  auto new_hdr = old_hdr->upgrade();
1174 
1175  auto szDiff = hdr->num_words() - old_hdr->num_words();
1176  auto vals_nc = const_cast<DATAVEC_T*>(&vals_);
1177  if (szDiff > 0) vals_nc->insert(vals_nc->begin(), szDiff, 0);
1178  memcpy(&(*vals_nc)[0], &new_hdr, hdr->num_words() * sizeof(RawDataType));
1179  }
1180  break;
1181  default:
1182  throw cet::exception("Fragment") << "A Fragment with an unknown version (" << std::to_string(hdr->version) << ") was received!";
1183  break;
1184  }
1185  }
1186  return hdr;
1187 }
1188 
1189 inline
1190 void
1191 swap(artdaq::Fragment& x, artdaq::Fragment& y) noexcept
1192 {
1193  x.swap(y);
1194 }
1195 
1196 inline
1197 std::ostream&
1198 artdaq::operator<<(std::ostream& os, artdaq::Fragment const& f)
1199 {
1200  f.print(os);
1201  return os;
1202 }
1203 #endif/* HIDE_FROM_ROOT */
1204 
1205 #endif /* artdaq_core_Data_Fragment_hh */
std::unique_ptr< Fragment > FragmentPtr
A std::unique_ptr to a Fragment object.
Definition: Fragment.hh:53
void reserve(std::size_t cap)
Reserves enough memory to hold cap RawDataType words in the Fragment payload.
Definition: Fragment.hh:1086
detail::RawFragmentHeader::timestamp_t timestamp_t
typedef for timestamp_t from RawFragmentHeader
Definition: Fragment.hh:139
RawDataType metadata_word_count
The number of RawDataType words in the user-defined metadata.
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.
std::size_t dataSizeBytes() const
Return the number of bytes in the data payload. This does not include the number of bytes in the head...
Definition: Fragment.hh:355
RawDataType type
The type of the fragment, either system or user-defined.
static constexpr type_t InvalidFragmentType
Copy InvalidFragmentType from RawFragmentHeader.
Definition: Fragment.hh:146
T reinterpret_cast_checked(const RawDataType *in) const
Wrapper around reinterpret_cast.
Definition: Fragment.hh:474
QuickVec< RawDataType >::difference_type difference_type
Alias difference_type type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:184
void setSequenceID(sequence_id_t sequence_id)
Sets the Sequence ID of the Fragment.
Definition: Fragment.hh:861
void setSystemType(type_t stype)
Sets the type of the Fragment, checking that it is a valid system type.
Definition: Fragment.hh:854
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most-commonly used system types.
std::vector< Fragment > Fragments
A std::vector of Fragment objects.
Definition: Fragment.hh:41
std::size_t size() const
Gets the size of the Fragment, from the Fragment header.
Definition: Fragment.hh:798
static constexpr type_t EndOfDataFragmentType
Copy EndOfDataFragmentType from RawFragmentHeader.
Definition: Fragment.hh:147
static constexpr timestamp_t InvalidTimestamp
Copy InvalidTimestamp from RawFragmentHeader.
Definition: Fragment.hh:144
void updateMetadata(const T &md)
Updates existing metadata with a new metadata object.
Definition: Fragment.hh:953
static constexpr type_t EmptyFragmentType
Copy EmptyFragmentType from RawFragmentHeader.
Definition: Fragment.hh:154
bool fragmentSequenceIDCompare(Fragment i, Fragment j)
Comparator for Fragment objects, based on their sequence_id.
Definition: Fragment.cc:8
const byte_t * dataEndBytes() const
Return const Fragment::byte_t* pointing at the end of the payload.
Definition: Fragment.hh:580
static constexpr bool isUserFragmentType(type_t fragmentType)
Returns whether the given type is in the range of user types.
Definition: Fragment.hh:724
detail::RawFragmentHeader::fragment_id_t fragment_id_t
typedef for fragment_id_t from RawFragmentHeader
Definition: Fragment.hh:138
std::size_t sizeBytes() const
Size of vals_ vector ( header + (optional) metadata + payload) in bytes.
Definition: Fragment.hh:340
byte_t * dataBeginBytes()
Return Fragment::byte_t* pointing at the beginning of the payload.
Definition: Fragment.hh:522
static constexpr std::size_t num_words()
Returns the number of RawDataType words present in the header.
The RawFragmentHeader class contains the basic fields used by artdaq for routing Fragment objects thr...
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
Definition: Fragment.hh:136
void resizeBytes(std::size_t szbytes)
Resize the data payload to hold szbytes bytes (padded by the 8-byte RawDataTypes, so...
Definition: Fragment.hh:990
static FragmentPtr dataFrag(sequence_id_t sequenceID, fragment_id_t fragID, InputIterator i, InputIterator e)
Creates a Fragment, copying data from given location. 12-Apr-2013, KAB - this method is deprecated...
Definition: Fragment.hh:669
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.
sequence_id_t sequenceID() const
Sequence ID of the Fragment, from the Fragment header.
Definition: Fragment.hh:826
timestamp_t timestamp() const
Timestamp of the Fragment, from the Fragment header.
Definition: Fragment.hh:840
static constexpr type_t DataFragmentType
Copy DataFragmentType from RawFragmentHeader.
Definition: Fragment.hh:148
QuickVec< RawDataType >::const_iterator const_iterator
Alias const_iterator type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:182
uint8_t byte_t
For byte representation.
Definition: Fragment.hh:99
void resize(std::size_t sz)
Resize the data payload to hold sz RawDataType words.
Definition: Fragment.hh:973
RawDataType version
The version of the fragment. Currently always InvalidVersion.
void autoResize()
Resize the fragment to hold the number of words indicated by the header.
Definition: Fragment.hh:1017
static constexpr type_t EndOfRunFragmentType
Copy EndOfRunFragmentType from RawFragmentHeader.
Definition: Fragment.hh:150
static constexpr fragment_id_t InvalidFragmentID
Copy InvalidFragmentID from RawFragmentHeader.
Definition: Fragment.hh:143
RawDataType fragment_id
The fragment_id uniquely identifies a particular piece of hardware within the artdaq system...
size_t size() const
Accesses the current size of the QuickVec.
Definition: QuickVec.hh:381
static constexpr type_t InitFragmentType
Copy InitFragmentType from RawFragmentHeader.
Definition: Fragment.hh:149
QuickVec< RawDataType >::reference reference
Alias reference type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:180
byte_t * headerBeginBytes()
Return a Fragment::byte_t pointer pointing to the beginning of the header.
Definition: Fragment.hh:545
static FragmentPtr FragmentBytes(std::size_t payload_size_in_bytes, sequence_id_t sequence_id, fragment_id_t fragment_id, type_t type, const T &metadata, timestamp_t timestamp=Fragment::InvalidTimestamp)
Create a Fragment with the given header values. Uses static factory function instead of constructor t...
Definition: Fragment.hh:235
detail::RawFragmentHeader::version_t version_t
typedef for version_t from RawFragmentHeader
Definition: Fragment.hh:135
void setTimestamp(timestamp_t timestamp)
Sets the Timestamp of the Fragment.
Definition: Fragment.hh:876
iterator headerBegin()
Return an iterator to the beginning of the header (should be used for serialization only: use setters...
Definition: Fragment.hh:1040
T reinterpret_cast_checked(RawDataType *in)
Wrapper around reinterpret_cast.
Definition: Fragment.hh:502
byte_t * dataEndBytes()
Return Fragment::byte_t* pointing at the end of the payload.
Definition: Fragment.hh:532
static constexpr version_t InvalidVersion
Copy InvalidVersion from RawFragmentHeader.
Definition: Fragment.hh:141
iterator dataBegin()
Return an iterator to the beginning of the data payload (after header and metadata) ...
Definition: Fragment.hh:1025
bool empty()
Determines if the Fragment contains no data.
Definition: Fragment.hh:1078
static constexpr sequence_id_t InvalidSequenceID
Copy InvalidSequenceID from RawFragmentHeader.
Definition: Fragment.hh:142
QuickVec< RawDataType >::value_type value_type
Alias value_type type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:183
static FragmentPtr eodFrag(size_t nFragsToExpect)
Creates an EndOfData Fragment.
Definition: Fragment.cc:74
void setUserType(type_t utype)
Sets the type of the Fragment, checking that it is a valid user type.
Definition: Fragment.hh:847
static constexpr type_t ContainerFragmentType
Copy ContainerFragmentType from RawFragmentHeader.
Definition: Fragment.hh:155
static std::map< type_t, std::string > MakeSystemTypeMap()
Returns a map of the most commonly-used system types.
Definition: Fragment.hh:175
std::ostream & operator<<(std::ostream &os, Fragment const &f)
Prints the given Fragment to the stream.
Definition: Fragment.hh:1198
void swap(QuickVec &other) noexcept
Exchanges references to two QuickVec objects.
Definition: QuickVec.hh:501
void setMetadata(const T &md)
Set the metadata in the Fragment to the contents of the specified structure. This throws an exception...
Definition: Fragment.hh:936
const byte_t * dataBeginBytes() const
Return const Fragment::byte_t* pointing at the beginning of the payload.
Definition: Fragment.hh:567
type_t type() const
Type of the Fragment, from the Fragment header.
Definition: Fragment.hh:812
RawDataType * dataAddress()
Returns a RawDataType pointer to the beginning of the payload.
Definition: Fragment.hh:1101
void print(std::ostream &os) const
Print out summary information for this Fragment to the given stream.
Definition: Fragment.cc:65
unsigned long long RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
T * metadata()
Return a pointer to the metadata. This throws an exception if the Fragment contains no metadata...
Definition: Fragment.hh:909
iterator dataEnd()
Return an iterator to the end of the data payload.
Definition: Fragment.hh:1033
static FragmentPtr FragmentBytes(std::size_t nbytes)
Create a Fragment using a static factory function rather than a constructor to allow for the function...
Definition: Fragment.hh:200
static constexpr type_t ShutdownFragmentType
Copy ShutdownFragmentType from RawFragmentHeader.
Definition: Fragment.hh:152
static constexpr type_t FirstUserFragmentType
Copy FIRST_USER_TYPE from RawFragmentHeader.
Definition: Fragment.hh:153
std::string typeString() const
Print the type of the Fragment.
Definition: Fragment.hh:819
detail::RawFragmentHeader::RawDataType RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
Definition: Fragment.hh:39
RawDataType * metadataAddress()
Get the address of the metadata. For internal use only, use metadata() instead.
Definition: Fragment.hh:1109
std::list< FragmentPtr > FragmentPtrs
A std::list of FragmentPtrs.
Definition: Fragment.hh:58
Fragment()
Create a Fragment with all header values zeroed.
Definition: Fragment.cc:13
void clear()
Removes all elements from the payload section of the Fragment.
Definition: Fragment.hh:1070
static constexpr bool isSystemFragmentType(type_t fragmentType)
Returns whether the given type is in the range of system types.
Definition: Fragment.hh:734
static const version_t CurrentVersion
The CurrentVersion field should be incremented whenever the RawFragmentHeader changes.
QuickVec< RawDataType >::iterator iterator
Alias iterator type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:181
bool hasMetadata() const
Test whether this Fragment has metadata.
Definition: Fragment.hh:902
QuickVec< RawDataType >::size_type size_type
Alias size_type type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:185
const byte_t * headerBeginBytes() const
Return a const Fragment::byte_t pointer pointing to the beginning of the header.
Definition: Fragment.hh:596
static std::string SystemTypeToString(type_t type)
Print a system type&#39;s string name.
void setFragmentID(fragment_id_t fragment_id)
Sets the Fragment ID of the Fragment.
Definition: Fragment.hh:869
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
Definition: Fragment.hh:84
void swap(Fragment &other) noexcept
Swaps two Fragment objects.
Definition: Fragment.hh:1094
static constexpr type_t EndOfSubrunFragmentType
Copy EndOfSubrunFragmentType from RawFragmentHeader.
Definition: Fragment.hh:151
std::size_t dataSize() const
Return the number of RawDataType words in the data payload. This does not include the number of words...
Definition: Fragment.hh:894
iterator begin()
Gets an iterator to the beginning of the QuickVec.
Definition: QuickVec.hh:387
void swap(QuickVec< RawDataType > &other) noexcept
Swaps two Fragment data vectors.
Definition: Fragment.hh:630
detail::RawFragmentHeader::sequence_id_t sequence_id_t
typedef for sequence_id_t from RawFragmentHeader
Definition: Fragment.hh:137
fragment_id_t fragmentID() const
Fragment ID of the Fragment, from the Fragment header.
Definition: Fragment.hh:833
RawDataType * headerAddress()
Gets the address of the header.
Definition: Fragment.hh:1121
version_t version() const
Version of the Fragment, from the Fragment header.
Definition: Fragment.hh:805