Skip to content

Commit 1295950

Browse files
committed
Remove timing helpers
1 parent 3c728a3 commit 1295950

7 files changed

Lines changed: 89 additions & 118 deletions

File tree

Detectors/ITSMFT/ITS/workflow-ca/src/CATrackerSpec.cxx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
160160
const std::vector<std::vector<uint32_t>>* externalIndicesBySurface = nullptr,
161161
const std::vector<std::vector<uint32_t>>* clusterSizesBySurface = nullptr)
162162
{
163-
const auto selection = selectGenericTracksForSurfaces(frame, kLayerToLayout);
163+
auto selection = selectGenericTracksForSurfaces(frame, kLayerToLayout);
164164
if (!selection) {
165165
return std::nullopt;
166166
}
167167
if (withMC && frame.getTrackLabels().size() != frame.getGenericTracks().size()) {
168168
return std::nullopt;
169169
}
170-
const auto ordered = makeLegacyOutputOrder(frame, *selection, context.clock);
170+
const auto ordered = makeLegacyOutputOrder(frame, std::move(*selection), context.clock);
171171
if (!ordered) {
172172
return std::nullopt;
173173
}
@@ -177,10 +177,10 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
177177
staged.labels.reserve(withMC ? ordered->size() : 0);
178178
std::vector<o2::its::TimeStamp> times;
179179
times.reserve(ordered->size());
180-
for (const auto& orderedTrack : *ordered) {
181-
const auto index = orderedTrack.globalIndex;
180+
for (const auto index : *ordered) {
182181
o2::track::TrackParCovF inner, outer;
183182
const auto& common = frame.getGenericTracks()[index];
183+
const auto timestamp = makeOutputTimestamp(common.timestamp, context.clock);
184184
if (!exportTrackState(common.innerState, inner) || !exportTrackState(common.outerState, outer)) {
185185
return std::nullopt;
186186
}
@@ -194,9 +194,9 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
194194
return std::nullopt;
195195
output.setPattern(pattern);
196196
output.setSharedClusters(sharedClusterFlags[index] != 0);
197-
output.getTimeStamp() = orderedTrack.timestamp;
197+
output.getTimeStamp() = timestamp;
198198
staged.tracks.push_back(std::move(output));
199-
times.push_back(orderedTrack.timestamp);
199+
times.push_back(timestamp);
200200
if (withMC)
201201
staged.labels.push_back(frame.getTrackLabels()[index]);
202202
}
@@ -409,9 +409,8 @@ void CATrackerDPL::run(ProcessingContext& pc)
409409
}
410410

411411
{
412-
mSession.publicationClock.emplace(mSession.overlap.getView().getClockLayer());
413412
const o2::itsmft::tracking::TrackPublicationTimingContext context{
414-
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock};
413+
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, mSession.overlap.getView().getClockLayer()};
415414
const auto staged = stageTrackOutput(mSession.frame, context, mPublication.sharedClusterFlags(), mUseMC,
416415
&mSession.externalIndices, &mSession.clusterSizes);
417416
if (!staged) {

Detectors/ITSMFT/MFT/workflow/src/CATrackerSpec.cxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
168168
const std::vector<std::vector<uint32_t>>* externalIndicesBySurface = nullptr,
169169
const std::vector<std::vector<uint32_t>>* clusterSizesBySurface = nullptr)
170170
{
171-
const auto selection = selectGenericTracksForSurfaces(frame, kLayerToLayout);
171+
auto selection = selectGenericTracksForSurfaces(frame, kLayerToLayout);
172172
if (!selection)
173173
return std::nullopt;
174174
if (withMC && frame.getTrackLabels().size() != frame.getGenericTracks().size()) {
175175
return std::nullopt;
176176
}
177-
const auto ordered = makeLegacyOutputOrder(frame, *selection, context.clock);
177+
const auto ordered = makeLegacyOutputOrder(frame, std::move(*selection), context.clock);
178178
if (!ordered) {
179179
return std::nullopt;
180180
}
@@ -184,9 +184,9 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
184184
staged.seedPatterns.reserve(ordered->size());
185185
std::vector<o2::its::TimeStamp> times;
186186
times.reserve(ordered->size());
187-
for (const auto& orderedTrack : *ordered) {
188-
const auto index = orderedTrack.globalIndex;
187+
for (const auto index : *ordered) {
189188
const auto& common = frame.getGenericTracks()[index];
189+
const auto timestamp = makeOutputTimestamp(common.timestamp, context.clock);
190190
o2::track::TrackParCovFwd inner, outer;
191191
if (!exportTrackState(common.innerState, inner) || !exportTrackState(common.outerState, outer)) {
192192
return std::nullopt;
@@ -207,7 +207,7 @@ std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame,
207207
return std::nullopt;
208208
staged.tracks.push_back(std::move(output));
209209
staged.seedPatterns.push_back(static_cast<uint16_t>(pattern));
210-
times.push_back(orderedTrack.timestamp);
210+
times.push_back(timestamp);
211211
if (withMC)
212212
staged.labels.push_back(frame.getTrackLabels()[index]);
213213
}
@@ -360,9 +360,8 @@ void CATrackerDPL::run(ProcessingContext& pc)
360360
}
361361

362362
{
363-
mSession.publicationClock.emplace(mSession.overlap.getView().getClockLayer());
364363
const o2::itsmft::tracking::TrackPublicationTimingContext context{
365-
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock};
364+
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, mSession.overlap.getView().getClockLayer()};
366365
const auto staged = stageTrackOutput(mSession.frame, context, mUseMC,
367366
&mSession.externalIndices, &mSession.clusterSizes);
368367
if (!staged) {

Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/TrackPublicationHelpers.h

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -33,62 +33,32 @@ namespace o2::itsmft::tracking
3333

3434
#ifndef GPUCA_GPUCODE
3535

36-
// Host-only immutable output view around the established clock-layer
37-
// implementation. Symmetry, clamping, and ROF lookup stay in LayerTiming.
38-
class ClockTimingPublicationView
36+
// Tracks already carry a symmetric timestamp. Apply the publication clock's
37+
// uncertainty limit without modifying the frame-owned track.
38+
inline o2::its::TimeStamp makeOutputTimestamp(o2::its::TimeStamp timestamp, const o2::its::LayerTiming& clock) noexcept
3939
{
40-
public:
41-
explicit ClockTimingPublicationView(const o2::its::LayerTiming& clock) : mClock{clock} {}
42-
43-
std::optional<o2::its::TimeStamp> makeOutputTimestamp(const o2::its::TimeStamp& timestamp) const noexcept
44-
{
45-
if (!std::isfinite(timestamp.getTimeStamp()) || !std::isfinite(timestamp.getTimeStampError()) ||
46-
timestamp.getTimeStampError() <= 0.f) {
47-
return std::nullopt;
48-
}
49-
auto symmetric = timestamp;
50-
const float clamp = mClock.mROFLength * 0.5f;
51-
if (symmetric.getTimeStampError() > clamp) {
52-
symmetric.setTimeStampError(clamp);
53-
}
54-
return symmetric;
55-
}
56-
57-
int getROF(const o2::its::TimeStamp& timestamp) const noexcept { return mClock.getROF(timestamp); }
58-
uint32_t getROFCount() const noexcept { return mClock.mNROFsTF; }
59-
const o2::its::LayerTiming& getLegacyClockLayer() const noexcept { return mClock; }
60-
61-
private:
62-
o2::its::LayerTiming mClock;
63-
};
64-
65-
struct TrackPublicationSelection {
66-
std::vector<uint32_t> globalIndices;
67-
};
68-
69-
struct TrackPublicationOrderEntry {
70-
uint32_t globalIndex{};
71-
o2::its::TimeStamp timestamp{};
72-
};
40+
timestamp.setTimeStampError(std::min(timestamp.getTimeStampError(), clock.mROFLength * 0.5f));
41+
return timestamp;
42+
}
7343

7444
// This context is intentionally source-local. ROFRecord payload is copied
7545
// only into the returned publication product, never into TimeFrame.
7646
struct TrackPublicationTimingContext {
7747
gsl::span<const o2::itsmft::ROFRecord> inputROFs;
78-
ClockTimingPublicationView clock;
48+
o2::its::LayerTiming clock;
7949
};
8050

81-
inline std::optional<TrackPublicationSelection> selectGenericTracksForSurfaces(
51+
inline std::optional<std::vector<uint32_t>> selectGenericTracksForSurfaces(
8252
const TimeFrame& frame,
8353
gsl::span<const LayerId> sourceSurfaces)
8454
{
8555
const auto& tracks = frame.getGenericTracks();
8656
if (tracks.size() > std::numeric_limits<uint32_t>::max()) {
8757
return std::nullopt;
8858
}
89-
TrackPublicationSelection selection;
59+
std::vector<uint32_t> selection;
9060
const auto& references = frame.getTrackClusterIndices();
91-
selection.globalIndices.reserve(tracks.size());
61+
selection.reserve(tracks.size());
9262
for (uint32_t globalIndex = 0; globalIndex < tracks.size(); ++globalIndex) {
9363
const auto& track = tracks[globalIndex];
9464
if (!isValidTrackRange(track, static_cast<uint32_t>(references.size()))) {
@@ -109,37 +79,39 @@ inline std::optional<TrackPublicationSelection> selectGenericTracksForSurfaces(
10979
return std::nullopt;
11080
}
11181
if (requested) {
112-
selection.globalIndices.push_back(globalIndex);
82+
selection.push_back(globalIndex);
11383
}
11484
}
11585
return selection;
11686
}
11787

118-
inline std::optional<std::vector<TrackPublicationOrderEntry>> makeLegacyOutputOrder(
119-
const TimeFrame& frame, const TrackPublicationSelection& selection,
120-
const ClockTimingPublicationView& clock)
88+
inline std::optional<std::vector<uint32_t>> makeLegacyOutputOrder(
89+
const TimeFrame& frame, std::vector<uint32_t> selection,
90+
const o2::its::LayerTiming& clock)
12191
{
122-
std::vector<TrackPublicationOrderEntry> ordered;
123-
ordered.reserve(selection.globalIndices.size());
124-
for (const auto index : selection.globalIndices) {
125-
const auto timestamp = clock.makeOutputTimestamp(frame.getGenericTracks()[index].timestamp);
126-
if (!timestamp) {
92+
const auto& tracks = frame.getGenericTracks();
93+
for (const auto index : selection) {
94+
const auto& timestamp = tracks[index].timestamp;
95+
if (!std::isfinite(timestamp.getTimeStamp()) || !std::isfinite(timestamp.getTimeStampError()) ||
96+
timestamp.getTimeStampError() <= 0.f) {
12797
return std::nullopt;
12898
}
129-
ordered.push_back({index, *timestamp});
13099
}
100+
// Sort only indices, using the same clamped timestamp that will be published.
131101
// Match Tracker::sortTracks(): lower timestamp edge, then chi2.
132-
std::sort(ordered.begin(), ordered.end(), [&frame](const auto& left, const auto& right) {
133-
const auto& leftTrack = frame.getGenericTracks()[left.globalIndex];
134-
const auto& rightTrack = frame.getGenericTracks()[right.globalIndex];
135-
const auto leftLower = left.timestamp.getTimeStamp() - left.timestamp.getTimeStampError();
136-
const auto rightLower = right.timestamp.getTimeStamp() - right.timestamp.getTimeStampError();
102+
std::sort(selection.begin(), selection.end(), [&](uint32_t left, uint32_t right) {
103+
const auto& leftTrack = tracks[left];
104+
const auto& rightTrack = tracks[right];
105+
const auto leftTime = makeOutputTimestamp(leftTrack.timestamp, clock);
106+
const auto rightTime = makeOutputTimestamp(rightTrack.timestamp, clock);
107+
const auto leftLower = leftTime.getTimeStamp() - leftTime.getTimeStampError();
108+
const auto rightLower = rightTime.getTimeStamp() - rightTime.getTimeStampError();
137109
if (leftLower != rightLower) {
138110
return leftLower < rightLower;
139111
}
140112
return leftTrack.chi2 < rightTrack.chi2;
141113
});
142-
return ordered;
114+
return selection;
143115
}
144116

145117
inline void finalizeROFs(std::vector<o2::itsmft::ROFRecord>& rofs, const std::vector<o2::its::TimeStamp>& times,

Detectors/ITSMFT/common/tracking/include/ITSMFTTracking/WorkflowSession.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <algorithm>
1616
#include <limits>
17-
#include <optional>
1817
#include <string>
1918
#include <type_traits>
2019
#include <utility>
@@ -82,7 +81,6 @@ class WorkflowSession
8281
ROFVertexLookupTable vertices;
8382
ROFMaskTable mask;
8483
ROFMaskTable upcMask;
85-
std::optional<ClockTimingPublicationView> publicationClock;
8684

8785
class Cleanup
8886
{
@@ -114,7 +112,6 @@ class WorkflowSession
114112
}
115113
void invalidatePublication() noexcept
116114
{
117-
publicationClock.reset();
118115
externalIndices.clear();
119116
clusterSizes.clear();
120117
frame.setROFViews({});
@@ -161,7 +158,6 @@ class WorkflowSession
161158
}
162159
// Only owned timing structure survives between TFs. The key includes every
163160
// layer's extent and timing fields, so readout/CCDB changes rebuild it.
164-
publicationClock.reset();
165161
frame.setROFViews({});
166162
if (!matchesTiming(timings)) {
167163
ROFOverlapTable nextOverlap{nLayers};

Detectors/ITSMFT/common/tracking/test/testCombinedTrackingComposition.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace
5858
struct GenericTrackPublicationExport {
5959
o2::detectors::DetID::ID detector{};
6060
ClusterSourceId source{};
61-
ClockTimingPublicationView clock;
61+
o2::its::LayerTiming clock;
6262
gsl::span<const LayerId> layerMapping;
6363
};
6464

@@ -350,8 +350,8 @@ struct CombinedTrackingComposer {
350350

351351
test::CombinedTrackingPlan plan;
352352
TimeFrame* frame = nullptr;
353-
std::optional<ClockTimingPublicationView> itsClock;
354-
std::optional<ClockTimingPublicationView> mftClock;
353+
std::optional<o2::its::LayerTiming> itsClock;
354+
std::optional<o2::its::LayerTiming> mftClock;
355355
bool publicationValid = false;
356356

357357
CombinedTrackingComposer(std::vector<TrackingParameters> itsParams, std::vector<TrackingParameters> mftParams)

0 commit comments

Comments
 (0)