Project
Loading...
Searching...
No Matches
CompressedClustersHelpers.h
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
15
16#ifndef ALICEO2_DATAFORMATSTPC_COMPRESSEDCLUSTERSHELPERS_H
17#define ALICEO2_DATAFORMATSTPC_COMPRESSEDCLUSTERSHELPERS_H
18
19#include <type_traits>
20#include <cassert>
21#include <stdexcept>
22#include <vector>
25
27
28namespace o2::tpc
29{
38 template <typename Op, typename BufferType>
39 static size_t apply(Op op, BufferType& ptr, CompressedClustersROOT& c)
40 {
41 size_t size = 0;
42 size += op(ptr, c.nAttachedClusters, c.qTotA, c.qMaxA, c.flagsA, c.sigmaPadA, c.sigmaTimeA);
43 size += op(ptr, c.nUnattachedClusters, c.qTotU, c.qMaxU, c.flagsU, c.padDiffU, c.timeDiffU, c.sigmaPadU, c.sigmaTimeU);
44 size += op(ptr, c.nAttachedClustersReduced, c.rowDiffA, c.sliceLegDiffA, c.padResA, c.timeResA);
45 size += op(ptr, c.nTracks, c.qPtA, c.rowA, c.sliceA, c.timeA, c.padA, c.nTrackClusters);
46 size += op(ptr, c.nSliceRows, c.nSliceRowClusters);
47 return size;
48 }
49
52 template <typename ContainerType>
53 static size_t flattenTo(ContainerType& container, CompressedClustersROOT& clusters)
54 {
55 static_assert(sizeof(typename ContainerType::value_type) == 1);
56 char* dummyptr = nullptr;
57 auto calc_size = [](auto&... args) { return flatten::calc_size(args...); };
58 auto copy_to = [](auto&... args) { return flatten::copy_to(args...); };
59 size_t size = apply(calc_size, dummyptr, clusters);
60 container.resize(size);
61 auto wrtptr = container.data();
62 size_t copySize = apply(copy_to, wrtptr, clusters);
63 assert(copySize == size);
64 return copySize;
65 }
66
68 template <typename ContainerType>
69 static size_t restoreFrom(ContainerType& container, CompressedClustersROOT& clusters)
70 {
71 static_assert(sizeof(typename ContainerType::value_type) == 1);
72 char* dummyptr = nullptr;
73 auto calc_size = [](auto&... args) { return flatten::calc_size(args...); };
74 auto set_from = [](auto&... args) { return flatten::set_from(args...); };
75 size_t size = apply(calc_size, dummyptr, clusters);
76 if (container.size() != size) {
77 // for the moment we don not support changes in the member layout, we can implement the
78 // handling in the custom streamer
79 throw std::runtime_error("mismatch between raw buffer size and counters, schema evolution is not yet supported");
80 }
81 auto readptr = container.data();
82 size_t checkSize = apply(set_from, readptr, clusters);
83 assert(checkSize == size);
84 return checkSize;
85 }
86};
87
88} // namespace o2::tpc
89
90#endif // ALICEO2_DATAFORMATSTPC_COMPRESSEDCLUSTERSHELPERS_H
Container to store compressed TPC cluster data.
Utilities to copy complex objects to flat buffer and restore.
uint32_t op
uint32_t c
Definition RawData.h:2
TBranch * ptr
GLsizeiptr size
Definition glcorearb.h:659
Global TPC definitions and constants.
Definition SimTraits.h:167
static size_t apply(Op op, BufferType &ptr, CompressedClustersROOT &c)
static size_t flattenTo(ContainerType &container, CompressedClustersROOT &clusters)
static size_t restoreFrom(ContainerType &container, CompressedClustersROOT &clusters)
Restore the array pointers from the data in the container.
std::vector< Cluster > clusters