Project
Loading...
Searching...
No Matches
IOMCTruthContainerView.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_DATAFORMATS_IOMCTRUTHVIEW_H_
17#define ALICEO2_DATAFORMATS_IOMCTRUTHVIEW_H_
18
19#include "GPUCommonRtypes.h" // to have the ClassDef macros
20#include <vector>
21#include <gsl/span>
22
23namespace o2
24{
25namespace dataformats
26{
27
37{
38 public:
40
43 IOMCTruthContainerView(std::vector<char> const& input)
44 {
45 adopt(gsl::span<const char>(&(input[0]), input.size()));
46 }
47
48 IOMCTruthContainerView(gsl::span<const char> const input)
49 {
50 adopt(input);
51 }
52
54 {
55 if (!mIsView) {
56 delete[] part1;
57 delete[] part2;
58 delete[] part3;
59 delete[] part4;
60 delete[] part5;
61 delete[] part6;
62 delete[] part7;
63 delete[] part8;
64 delete[] part9;
65 delete[] part10;
66 }
67 }
68
70 void adopt(gsl::span<const char> const input)
71 {
72 mIsView = true;
73 const auto delta = input.size() / N;
74 N2 = input.size() - (N - 1) * delta;
75 N1 = delta;
76 // TODO: this could benefit from a loop expansion
77 part1 = &input[0];
78 part2 = &input[delta];
79 part3 = &input[2 * delta];
80 part4 = &input[3 * delta];
81 part5 = &input[4 * delta];
82 part6 = &input[5 * delta];
83 part7 = &input[6 * delta];
84 part8 = &input[7 * delta];
85 part9 = &input[8 * delta];
86 part10 = &input[9 * delta];
87 }
88
91 template <typename Alloc>
92 void copyandflatten(std::vector<char, Alloc>& output) const
93 {
94 // TODO: this could benefit from a loop expansion
95 copyhelper(part1, N1, output);
96 copyhelper(part2, N1, output);
97 copyhelper(part3, N1, output);
98 copyhelper(part4, N1, output);
99 copyhelper(part5, N1, output);
100 copyhelper(part6, N1, output);
101 copyhelper(part7, N1, output);
102 copyhelper(part8, N1, output);
103 copyhelper(part9, N1, output);
104 copyhelper(part10, N2, output);
105 }
106
108 size_t getSize() const { return N1 * (N - 1) + N2; }
109
110 private:
111 static constexpr int N = 10;
112 int N1 = 0;
113 int N2 = 0;
114 const char* part1 = nullptr; //[N1]
115 const char* part2 = nullptr; //[N1]
116 const char* part3 = nullptr; //[N1]
117 const char* part4 = nullptr; //[N1]
118 const char* part5 = nullptr; //[N1]
119 const char* part6 = nullptr; //[N1]
120 const char* part7 = nullptr; //[N1]
121 const char* part8 = nullptr; //[N1]
122 const char* part9 = nullptr; //[N1]
123 const char* part10 = nullptr; //[N2]
124
125 bool mIsView = false;
126 // we need to know this for the destructor
127
128 template <typename Alloc>
129 void copyhelper(const char* input, int size, std::vector<char, Alloc>& output) const
130 {
131 gsl::span<const char> tmp(input, size);
132 std::copy(tmp.begin(), tmp.end(), std::back_inserter(output));
133 }
134
135 ClassDefNV(IOMCTruthContainerView, 1);
136};
137} // namespace dataformats
138} // namespace o2
139
140#endif
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
IOMCTruthContainerView(gsl::span< const char > const input)
void adopt(gsl::span< const char > const input)
"adopt" (without taking ownership) from an existing buffer
IOMCTruthContainerView(std::vector< char > const &input)
void copyandflatten(std::vector< char, Alloc > &output) const
size_t getSize() const
return total size in bytes
GLsizeiptr size
Definition glcorearb.h:659
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...