12#ifndef TRACKINGITSU_INCLUDE_ROFOVERLAPTABLE_H_
13#define TRACKINGITSU_INCLUDE_ROFOVERLAPTABLE_H_
54 throw std::invalid_argument{
"negative ROF layer count"};
82 LOGP(info,
"Imposed time structure:");
83 for (int32_t iL{0}; iL < getEntries(); ++iL) {
103 std::vector<std::vector<TableEntry>> table(
static_cast<size_t>(getEntries()) * getEntries());
104 for (int32_t
i{0};
i < getEntries(); ++
i) {
105 for (int32_t
j{0};
j < getEntries(); ++
j) {
107 buildMapping(
i,
j, table[
static_cast<size_t>(
i) * getEntries() +
j]);
120 view.mLayerCount = getEntries();
129 view.mLayers = deviceLayerTimingPtr;
130 view.mLayerCount = getEntries();
140 const auto& layerFrom = this->
mLayers[from];
141 const auto& layerTo = this->
mLayers[to];
142 table.resize(layerFrom.mNROFsTF);
144 for (int32_t iROF{0}; iROF < layerFrom.mNROFsTF; ++iROF) {
146 int64_t fromEnd = (
int64_t)layerFrom.getROFEndInBC(iROF) + layerFrom.mROFAddTimeErr;
148 int32_t firstROFTo = o2::gpu::CAMath::Max(0, (int32_t)((fromStart - (
int64_t)layerTo.mROFAddTimeErr - (
int64_t)layerTo.mROFDelay - (
int64_t)layerTo.mROFBias) / (
int64_t)layerTo.mROFLength));
149 auto lastROFTo = (int32_t)((fromEnd + (
int64_t)layerTo.mROFAddTimeErr - (
int64_t)layerTo.mROFDelay - (
int64_t)layerTo.mROFBias - 1) / (
int64_t)layerTo.mROFLength);
150 firstROFTo = o2::gpu::CAMath::Max(0, firstROFTo);
151 lastROFTo = o2::gpu::CAMath::Min((int32_t)layerTo.mNROFsTF - 1, lastROFTo);
153 while (firstROFTo <= lastROFTo) {
155 int64_t toEnd = (
int64_t)layerTo.getROFEndInBC(firstROFTo) + layerTo.mROFAddTimeErr;
156 if (toEnd > fromStart && toStart < fromEnd) {
161 while (lastROFTo >= firstROFTo) {
163 int64_t toEnd = (
int64_t)layerTo.getROFEndInBC(lastROFTo) + layerTo.mROFAddTimeErr;
164 if (toEnd > fromStart && toStart < fromEnd) {
169 int32_t
count = (firstROFTo <= lastROFTo) ? (lastROFTo - firstROFTo + 1) : 0;
170 table[iROF] = {
static_cast<T>(firstROFTo),
static_cast<T>(
count)};
177 for (int32_t
i{0};
i < getEntries(); ++
i) {
178 for (int32_t
j{0};
j < getEntries(); ++
j) {
180 total += table[
static_cast<size_t>(
i) * getEntries() +
j].size();
188 for (int32_t
i{0};
i < getEntries(); ++
i) {
189 for (int32_t
j{0};
j < getEntries(); ++
j) {
190 size_t idx =
static_cast<size_t>(
i) * getEntries() +
j;
193 mIndices[
idx].setEntries(
static_cast<T>(table[
static_cast<size_t>(
i) * getEntries() +
j].size()));
194 mFlatTable.insert(
mFlatTable.end(), table[
static_cast<size_t>(
i) * getEntries() +
j].begin(), table[
static_cast<size_t>(
i) * getEntries() +
j].end());
229 if (nVertices > std::numeric_limits<T>::max()) {
230 LOGF(fatal,
"too many vertices %zu, max supported is %u", nVertices, std::numeric_limits<T>::max());
233 std::vector<std::vector<TableEntry>> table(getEntries());
235 buildMapping(
layer, vertices, nVertices, table[
layer]);
263 size_t nROFs = idx.getEntries();
264 for (
size_t iROF = 0; iROF < nROFs; ++iROF) {
265 updateROFMapping(
layer, iROF, vertices, nVertices,
offset + iROF);
277 view.mLayerCount = getEntries();
286 view.mLayers = deviceLayerTimingPtr;
287 view.mLayerCount = getEntries();
296 table.resize(layerDef.mNROFsTF);
297 size_t vertexSearchStart = 0;
298 for (int32_t iROF{0}; iROF < layerDef.mNROFsTF; ++iROF) {
300 int64_t rofUpper = (
int64_t)layerDef.getROFEndInBC(iROF) + layerDef.mROFAddTimeErr;
301 size_t lastVertex = binarySearchFirst(vertices, nVertices, vertexSearchStart, rofUpper);
302 size_t firstVertex = vertexSearchStart;
303 while (firstVertex < lastVertex) {
304 auto vUpper = (
int64_t)vertices[firstVertex].getTimeStamp().upper();
305 if (vUpper > rofLower) {
310 size_t count = (lastVertex > firstVertex) ? (lastVertex - firstVertex) : 0;
311 table[iROF] = {
static_cast<T>(firstVertex),
static_cast<T>(
count)};
312 vertexSearchStart = firstVertex;
317 GPUh()
void updateROFMapping(int32_t
layer,
size_t iROF,
const o2::its::
Vertex* vertices,
size_t nVertices,
size_t flatTableIdx)
321 int64_t rofUpper = (
int64_t)layerDef.getROFEndInBC(iROF) + layerDef.mROFAddTimeErr;
322 size_t lastVertex = binarySearchFirst(vertices, nVertices, 0, rofUpper);
323 size_t firstVertex = 0;
324 while (firstVertex < lastVertex) {
327 if (vUpper > rofLower) {
332 size_t count = (lastVertex > firstVertex) ? (lastVertex - firstVertex) : 0;
333 mFlatTable[flatTableIdx].setFirstEntry(
static_cast<T>(firstVertex));
338 GPUh() size_t binarySearchFirst(
const o2::its::
Vertex* vertices,
size_t nVertices,
size_t searchStart,
BCType targetBC)
const
340 size_t left = searchStart;
341 size_t right = nVertices;
345 if (
lower < targetBC) {
359 for (int32_t
i{0};
i < getEntries(); ++
i) {
360 total += table[
i].size();
367 for (int32_t
i{0};
i < getEntries(); ++
i) {
393 int32_t totalROFs = 0;
395 mLayerROFOffsets[
layer] = totalROFs;
396 totalROFs += this->getLayer(
layer).mNROFsTF;
398 mLayerROFOffsets[getEntries()] = totalROFs;
414 assert(firstRof >= 0);
415 assert(firstRof + nRofs <= mLayerROFOffsets[
layer + 1] - mLayerROFOffsets[
layer]);
422 const int32_t bcStart = t.getFirstEntry();
423 const int32_t bcEnd = t.getEntriesBound();
425 const auto& lay = this->getLayer(
layer);
428 if (
static_cast<int32_t
>(lay.getROFStartInBC(
rofId)) < bcEnd &&
429 static_cast<int32_t
>(lay.getROFEndInBC(
rofId)) > bcStart) {
440 for (
const auto& t : ts) {
445 GPUh()
void resetMask(uint8_t s = 0u)
461 std::swap(mLayerROFOffsets,
other.mLayerROFOffsets);
468 view.mLayerROFOffsets = mLayerROFOffsets.data();
469 view.mLayerCount = getEntries();
476 view.mFlatMask = deviceFlatMaskPtr;
477 view.mLayerROFOffsets = deviceOffsetPtr;
478 view.mLayerCount = getEntries();
483 std::vector<TableIndex> mLayerROFOffsets;
495template <
int32_t NLayers>
500 GPUhdi() constexpr int32_t getEntries() const noexcept {
return NLayers; }
503template <
int32_t NLayers,
typename TableEntry,
typename TableIndex>
505template <
int32_t NLayers,
typename TableEntry,
typename TableIndex>
507template <
int32_t NLayers,
typename TableEntry,
typename TableIndex>
510template <
int32_t NLayers>
515 GPUhdi() constexpr int32_t getEntries()
const noexcept {
return NLayers; }
516 static GPUh() constexpr
size_t getIndicesSize() {
return static_cast<size_t>(NLayers) * NLayers; }
519template <
int32_t NLayers>
524 GPUhdi() constexpr int32_t getEntries()
const noexcept {
return NLayers; }
525 static GPUh() constexpr
size_t getIndicesSize() {
return NLayers; }
528template <
int32_t NLayers>
536 if (
timing.getEntries() != NLayers) {
537 throw std::invalid_argument{
"ROF mask layer count differs from legacy table extent"};
541 GPUhdi() constexpr int32_t getEntries() const noexcept {
return NLayers; }
std::string asString(TDataMember const &dm, char *pointer)
Header to collect LHC related constants.
Class to refer to the 1st entry and N elements of some group in the continuous container.
GPUhdi() const expr int32_t getEntries() const noexcept
GPUhdi() const expr int32_t getEntries() const noexcept
GPUh() explicit ROFMaskTable(const o2
GPUh() void swap(ROFMaskTable &other) noexcept
static GPUh() const expr size_t getIndicesSize()
GPUhdi() const expr int32_t getEntries() const noexcept
GPUhdi() const expr int32_t getEntries() const noexcept
static GPUh() const expr size_t getIndicesSize()
GPUh() void print() const
GPUh() int32_t getEntries() const noexcept
GPUh() void defineLayer(int32_t layer
LayerTimingBase(int32_t nLayers=0)
std::vector< LayerTiming > mLayers
GPUh() const LayerTiming &getLayer(int32_t layer) const
const LayerTiming & timing
GPUh() void setROFEnabled(int32_t layer
GPUh() explicit ROFMaskTable(const LayerTimingBase &timingBase)
ROFMaskTable(int32_t nLayers=0)
ROFMaskView< TableEntry, TableIndex > View
std::vector< TableEntry > mFlatMask
dataformats::RangeReference< T, T > BCRange
GPUh() size_t getFlatMaskSize() const noexcept
const TableIndex const LayerTiming *deviceLayerTimingPtr const
GPUh() size_t getIndicesSize() const noexcept
ROFOverlapTable(int32_t nLayers=0)
GPUh() View getView() const
GPUh() size_t getFlatTableSize() const noexcept
const TableIndex * deviceIndicesPtr
dataformats::RangeReference< T, T > TableEntry
GPUh() void init(const o2
LayerTiming::BCType BCType
GPUh() size_t getIndicesSize() const noexcept
GPUh() void update(const o2
const TableIndex const LayerTiming *deviceLayerTimingPtr const
GPUh() size_t getFlatTableSize() const noexcept
dataformats::RangeReference< T, T > TableEntry
const TableIndex * deviceIndicesPtr
GPUh() View getView() const
ROFVertexLookupTable(int32_t nLayers=0)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLenum GLuint GLint GLint layer
uint32_t trackClusterIndicesSize noexcept
ROFTimingLayer LayerTiming
uint64_t getTimeStamp(o2::framework::ProcessingContext &pc)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
const TableEntry * mFlatTable
o2::its::TimeStampType BCType
const TableEntry * mFlatTable
VectorOfTObjectPtrs other