Project
Loading...
Searching...
No Matches
DataBlock.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <fmt/format.h>
14
15namespace o2::mch::raw
16{
17void appendDataBlockHeader(std::vector<std::byte>& outBuffer, DataBlockHeader header)
18{
19 gsl::span<std::byte> ph(reinterpret_cast<std::byte*>(&header), sizeof(ph));
20 outBuffer.insert(outBuffer.end(), ph.begin(), ph.end());
21}
22
23int forEachDataBlockRef(gsl::span<const std::byte> buffer,
24 std::function<void(DataBlockRef ref)> f)
25{
26 int index{0};
27 int nheaders{0};
28 DataBlockHeader header;
29 while (index < buffer.size()) {
30 memcpy(&header, &buffer[index], sizeof(header));
31 nheaders++;
32 if (f) {
33 DataBlock block{header, buffer.subspan(index + sizeof(header), header.payloadSize)};
34 DataBlockRef ref{block, index};
35 f(ref);
36 }
37 index += header.payloadSize + sizeof(header);
38 }
39 return nheaders;
40}
41
42int countHeaders(gsl::span<const std::byte> buffer)
43{
44 return forEachDataBlockRef(buffer, nullptr);
45}
46
47std::ostream& operator<<(std::ostream& os, const DataBlockHeader& header)
48{
49 os << fmt::format("ORB{:6d} BC{:4d} SOLAR{:4d} PAYLOADSIZE{:6d}",
50 header.orbit, header.bc, header.solarId, header.payloadSize);
51 return os;
52}
53
54std::ostream& operator<<(std::ostream& os, const DataBlock& block)
55{
56 os << block.header;
57 os << fmt::format(" SIZE {:8d}", block.size());
58 return os;
59}
60
61std::ostream& operator<<(std::ostream& os, const DataBlockRef& ref)
62{
63 os << ref.block;
64 if (ref.offset.has_value()) {
65 os << fmt::format(" OFFSET {:8d}", ref.offset.value());
66 }
67 return os;
68}
69
71{
72 if (a.solarId < b.solarId) {
73 return true;
74 }
75 if (a.solarId > b.solarId) {
76 return false;
77 }
78 if (a.orbit < b.orbit) {
79 return true;
80 }
81 if (a.orbit > b.orbit) {
82 return false;
83 }
84 return (a.bc < b.bc);
85 // if (a.bc < b.bc) {
86 // return true;
87 // }
88 // if (a.bc > b.bc) {
89 // return false;
90 // }
91};
92
94{
95 return a.block.header < b.block.header;
96}
97} // namespace o2::mch::raw
GLuint buffer
Definition glcorearb.h:655
GLuint index
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
int countHeaders(gsl::span< const std::byte > buffer)
Count the headers in the input buffer.
Definition DataBlock.cxx:42
void appendDataBlockHeader(std::vector< std::byte > &outBuffer, DataBlockHeader header)
Convert the header into bytes.
Definition DataBlock.cxx:17
int forEachDataBlockRef(gsl::span< const std::byte > buffer, std::function< void(DataBlockRef ref)> f)
Definition DataBlock.cxx:23
bool operator<(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
A lightweight struct to describe a MCH Raw Data Block.
Definition DataBlock.h:26
a DataBlockRef is a pair (DataBlock,offset) The offset is an offset into some external buffer
Definition DataBlock.h:45
A DataBlock is a pair (DataBlockHeader,payload)
Definition DataBlock.h:34
uint64_t size() const
Definition DataBlock.h:37
DataBlockHeader header
Definition DataBlock.h:35