1 #ifndef EUDAQ_INCLUDED_RawDataEvent
2 #define EUDAQ_INCLUDED_RawDataEvent
7 #include "eudaq/Event.hh"
8 #include "eudaq/Platform.hh"
18 typedef unsigned char byte_t;
19 typedef std::vector<byte_t> data_t;
21 block_t(
unsigned id,
const data_t& data)
22 : id(
id), data(data) {}
23 block_t(
unsigned id, data_t&& data)
24 : id(
id), data(std::move(data)) {}
26 : id(-1), data(data_t()) {}
29 void Append(
const data_t &data);
34 RawDataEvent(std::string type,
unsigned run,
unsigned event);
39 m_blocks.push_back(
block_t(
id, data_t()));
40 return m_blocks.size() - 1;
45 size_t AddBlock(
unsigned id,
const std::vector<T> &data) {
46 m_blocks.push_back(
block_t(
id, make_vector(data)));
47 return m_blocks.size() - 1;
52 size_t AddBlock(
unsigned id,
const T *data,
size_t bytes) {
53 m_blocks.push_back(
block_t(
id, make_vector(data, bytes)));
54 return m_blocks.size() - 1;
60 m_blocks[index].Append(make_vector(data));
66 m_blocks[index].Append(make_vector(data, bytes));
69 unsigned GetID(
size_t i)
const;
76 const data_t &GetBlock(
size_t i)
const;
77 byte_t GetByte(
size_t block,
size_t index)
const;
80 size_t NumBlocks()
const {
return m_blocks.size(); }
82 virtual void Print(std::ostream &)
const;
83 static RawDataEvent BORE(std::string type,
unsigned run) {
84 return RawDataEvent(type, run, (
unsigned)-1, Event::FLAG_BORE);
86 static RawDataEvent *newBORE(std::string type,
unsigned run) {
88 return new RawDataEvent(type, run, (
unsigned)-1, Event::FLAG_BORE);
90 static RawDataEvent EORE(std::string type,
unsigned run,
unsigned event) {
91 return RawDataEvent(type, run, event, Event::FLAG_EORE);
93 static RawDataEvent *newEORE(std::string type,
unsigned run,
96 return new RawDataEvent(type, run, event, Event::FLAG_EORE);
98 virtual void Serialize(Serializer &)
const;
106 RawDataEvent(std::string type,
unsigned run,
unsigned event,
108 :
Event(run, event, NOTIMESTAMP, flag), m_type(type) {}
110 template <
typename T>
111 static data_t make_vector(
const T *data,
size_t bytes) {
112 const unsigned char *ptr =
reinterpret_cast<const byte_t *
>(data);
113 return data_t(ptr, ptr + bytes);
116 template <
typename T>
117 static data_t make_vector(
const std::vector<T> &data) {
118 const unsigned char *ptr =
reinterpret_cast<const byte_t *
>(&data[0]);
119 return data_t(ptr, ptr + data.size() *
sizeof(T));
123 std::vector<block_t> m_blocks;
127 #endif // EUDAQ_INCLUDED_RawDataEvent
size_t NumBlocks() const
Return the number of data blocks in the RawDataEvent.
Definition: RawDataEvent.hh:80
size_t AddBlock(unsigned id, const T *data, size_t bytes)
Add a data block as array with given size.
Definition: RawDataEvent.hh:52
size_t AddBlock(unsigned id, const std::vector< T > &data)
Add a data block as std::vector.
Definition: RawDataEvent.hh:45
virtual std::string GetSubType() const
Return the type string.
Definition: RawDataEvent.hh:101
Definition: Serializer.hh:156
void AppendBlock(size_t index, const T *data, size_t bytes)
Append data to a block as array with given size.
Definition: RawDataEvent.hh:65
Definition: RawDataEvent.hh:20
void AppendBlock(size_t index, const std::vector< T > &data)
Append data to a block as std::vector.
Definition: RawDataEvent.hh:59
Definition: Serializable.hh:13
Definition: RawDataEvent.hh:14
Definition: Serializer.hh:19
size_t AddBlock(unsigned id)
Add an empty block.
Definition: RawDataEvent.hh:38