Skip to content

Commit a96d9fd

Browse files
committed
Cleanup ITSSharedClusterCompatibility and output errors
1 parent 42b4d4e commit a96d9fd

11 files changed

Lines changed: 125 additions & 483 deletions

File tree

Detectors/ITSMFT/ITS/workflow-ca/include/ITSCAWorkflow/CATrackerSpec.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class CATrackerDPL : public o2::framework::Task
8181
std::unique_ptr<o2::itsmft::tracking::Tracker> mTracker;
8282
std::unique_ptr<o2::itsmft::tracking::ClusterDecoder> mClusterDecoder;
8383
const o2::itsmft::TopologyDictionary* mDictionary = nullptr;
84-
o2::itsmft::tracking::ITSSharedClusterCompatibility mCompatibility;
8584
PublicationAdapter mPublication;
8685
};
8786

Detectors/ITSMFT/ITS/workflow-ca/include/ITSCAWorkflow/PublicationAdapter.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,43 @@
2020
#include <limits>
2121
#include <optional>
2222
#include <vector>
23+
#include <gsl/span>
2324

2425
#include "DetectorsCommonDataFormats/DetID.h"
2526
#include "GPUCommonMath.h"
26-
#include "ITSMFTTracking/detail/ITSSharedClusterCompatibility.h"
2727
#include "ITSMFTTracking/GenericTrack.h"
2828
#include "ITSMFTTracking/TimeFrame.h"
2929
#include "ITSMFTTracking/MathUtils.h"
3030

3131
namespace o2::its::ca
3232
{
3333

34-
// Workflow-owned ITS compatibility for generic tracking results.
34+
// Workflow-owned shared-cluster flags indexed by the global GenericTrack index.
3535
class PublicationAdapter
3636
{
3737
public:
38-
void adoptITSSharedClusterCompatibility(o2::itsmft::tracking::ITSSharedClusterCompatibility* sidecar) noexcept { mSidecar = sidecar; }
39-
o2::itsmft::tracking::ITSSharedClusterCompatibility* getITSSharedClusterCompatibility() const noexcept { return mSidecar; }
38+
gsl::span<const uint8_t> sharedClusterFlags() const noexcept
39+
{
40+
return mComplete ? gsl::span<const uint8_t>{mSharedClusterFlags} : gsl::span<const uint8_t>{};
41+
}
4042

4143
bool completeAccepted(gsl::span<const uint32_t> trackIndices,
4244
const o2::itsmft::IterationParameters& params,
4345
const o2::itsmft::tracking::TimeFrame& frame,
4446
bool final)
4547
{
46-
if (mSidecar == nullptr) {
47-
return true;
48-
}
48+
mComplete = false;
4949
if (!stageSharedClusterFlags(trackIndices, params, frame)) {
5050
return false;
5151
}
52-
return !final || mSidecar->replaceFromAcceptedTrackIndices(mAcceptedTrackIndices, mSharedClusterFlags);
52+
mComplete = final;
53+
return true;
5354
}
5455

5556
void reset() noexcept
5657
{
5758
mSharedClusterFlags.clear();
58-
mAcceptedTrackIndices.clear();
59-
if (mSidecar != nullptr) {
60-
mSidecar->clear();
61-
}
59+
mComplete = false;
6260
}
6361

6462
class Cleanup
@@ -116,16 +114,18 @@ class PublicationAdapter
116114
const o2::itsmft::IterationParameters& params,
117115
const o2::itsmft::tracking::TimeFrame& frame)
118116
{
119-
mAcceptedTrackIndices.reserve(mAcceptedTrackIndices.size() + trackIndices.size());
117+
auto nextIndex = mSharedClusterFlags.size();
120118
for (const auto index : trackIndices) {
121-
if (index >= frame.getGenericTracks().size() ||
122-
(!mAcceptedTrackIndices.empty() && mAcceptedTrackIndices.back() >= index)) {
119+
if (index >= frame.getGenericTracks().size() || index < nextIndex) {
123120
return false;
124121
}
125-
mAcceptedTrackIndices.push_back(index);
122+
nextIndex = static_cast<std::size_t>(index) + 1;
126123
}
127-
if (!trackIndices.empty() && mSharedClusterFlags.size() <= trackIndices.back()) {
128-
mSharedClusterFlags.resize(static_cast<std::size_t>(trackIndices.back()) + 1, 0);
124+
// Gaps belong to tracks not accepted by this adapter, and must not be
125+
// mistaken for accepted tracks without shared clusters at publication.
126+
mSharedClusterFlags.resize(nextIndex, std::numeric_limits<uint8_t>::max());
127+
for (const auto index : trackIndices) {
128+
mSharedClusterFlags[index] = 0;
129129
}
130130
if (!params.AllowSharingFirstCluster) {
131131
return true;
@@ -163,9 +163,8 @@ class PublicationAdapter
163163
return true;
164164
}
165165

166-
o2::itsmft::tracking::ITSSharedClusterCompatibility* mSidecar = nullptr;
167166
std::vector<uint8_t> mSharedClusterFlags;
168-
std::vector<uint32_t> mAcceptedTrackIndices;
167+
bool mComplete = false;
169168
};
170169

171170
} // namespace o2::its::ca

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ CATrackerDPL::CATrackerDPL(std::shared_ptr<o2::base::GRPGeomRequest> gr, Workflo
100100
: mGGCCDBRequest(std::move(gr)), mUseMC(options.useMC), mOptions(std::move(options))
101101
{
102102
mClusterDecoder = std::make_unique<o2::itsmft::tracking::ITSGeometryClusterDecoder>();
103-
mPublication.adoptITSSharedClusterCompatibility(&mCompatibility);
104103
}
105104

106105
void CATrackerDPL::addTruthSeedingVertices(const o2::InteractionRecord& origin, gsl::span<const o2::itsmft::ROFRecord> rofs)
@@ -238,7 +237,7 @@ o2::itsmft::tracking::TrackingOutcome CATrackerDPL::processTimeFrame(
238237
mSession.vertices.update(mSession.frame.getPrimaryVertices().data(), mSession.frame.getPrimaryVertices().size());
239238
} }, [&](const o2::itsmft::tracking::TrackingResult& result) {
240239
if (!completePublication(mPublication, mSession.frame, *mTracker, result)) {
241-
throw std::runtime_error{"failed to seal ITS tracking compatibility"};
240+
throw std::runtime_error{"failed to prepare ITS shared-cluster flags"};
242241
} });
243242
}
244243

@@ -293,8 +292,7 @@ void CATrackerDPL::run(ProcessingContext& pc)
293292
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock,
294293
kLayerToLayout,
295294
&mSession.externalIndices, &mSession.clusterSizes};
296-
o2::itsmft::tracking::GenericTrackOutputAdapterError error = o2::itsmft::tracking::GenericTrackOutputAdapterError::None;
297-
const auto staged = o2::itsmft::tracking::stageITSGenericTrackOutput(mSession.frame, context, mCompatibility, mUseMC, error);
295+
const auto staged = o2::itsmft::tracking::stageITSGenericTrackOutput(mSession.frame, context, mPublication.sharedClusterFlags(), mUseMC);
298296
if (!staged) {
299297
throw std::runtime_error{"ITS GenericTrack output staging failed"};
300298
}

Detectors/ITSMFT/ITS/workflow-ca/test/testITSCATrackerDPLContract.cxx

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <boost/test/unit_test.hpp>
2222

2323
#include <algorithm>
24+
#include <array>
25+
#include <limits>
2426
#include <string>
2527

2628
#include "Framework/DataProcessorSpec.h"
@@ -94,28 +96,58 @@ BOOST_AUTO_TEST_CASE(DeviceNameIsStable)
9496
BOOST_CHECK_EQUAL(spec.name, "its-ca-tracker");
9597
}
9698

97-
BOOST_AUTO_TEST_CASE(PublicationCompatibilityIsClearedOnEveryWorkflowExit)
99+
BOOST_AUTO_TEST_CASE(PublicationFlagsAreClearedOnEveryWorkflowExit)
98100
{
99101
o2::its::ca::PublicationAdapter publication;
100-
o2::itsmft::tracking::ITSSharedClusterCompatibility compatibility;
101-
publication.adoptITSSharedClusterCompatibility(&compatibility);
102102
o2::itsmft::tracking::TimeFrame frame;
103+
frame.getGenericTracks().resize(1);
103104
o2::itsmft::IterationParameters parameters;
105+
parameters.AllowSharingFirstCluster = false;
106+
const std::array<uint32_t, 1> indices{0};
104107
for (bool fail : {false, true}) {
105-
BOOST_REQUIRE(publication.completeAccepted({}, parameters, frame, true));
106-
BOOST_REQUIRE(compatibility.isSealed());
108+
BOOST_REQUIRE(publication.completeAccepted(indices, parameters, frame, true));
109+
BOOST_REQUIRE_EQUAL(publication.sharedClusterFlags().size(), 1u);
107110
try {
108111
auto cleanup = publication.cleanupOnExit();
109-
BOOST_CHECK(!compatibility.isSealed());
110-
BOOST_REQUIRE(publication.completeAccepted({}, parameters, frame, true));
111-
BOOST_CHECK(compatibility.isSealed());
112+
BOOST_CHECK(publication.sharedClusterFlags().empty());
113+
BOOST_REQUIRE(publication.completeAccepted(indices, parameters, frame, true));
114+
BOOST_REQUIRE_EQUAL(publication.sharedClusterFlags().size(), 1u);
115+
BOOST_CHECK_EQUAL(publication.sharedClusterFlags()[0], 0);
112116
if (fail) {
113117
throw std::runtime_error{"publication failure"};
114118
}
115119
} catch (const std::runtime_error&) {
116120
BOOST_CHECK(fail);
117121
}
118-
BOOST_CHECK(!compatibility.isSealed());
119-
BOOST_CHECK(compatibility.entries().empty());
122+
BOOST_CHECK(publication.sharedClusterFlags().empty());
120123
}
121124
}
125+
126+
BOOST_AUTO_TEST_CASE(PublicationFlagsRequireFinalCompletionAndAcceptedIndices)
127+
{
128+
o2::its::ca::PublicationAdapter publication;
129+
o2::itsmft::tracking::TimeFrame frame;
130+
frame.getGenericTracks().resize(3);
131+
o2::itsmft::IterationParameters parameters;
132+
parameters.AllowSharingFirstCluster = false;
133+
const std::array<uint32_t, 1> first{0}, last{2}, outOfRange{3};
134+
BOOST_REQUIRE(publication.completeAccepted(first, parameters, frame, false));
135+
BOOST_CHECK(publication.sharedClusterFlags().empty());
136+
BOOST_REQUIRE(publication.completeAccepted(last, parameters, frame, true));
137+
const auto flags = publication.sharedClusterFlags();
138+
BOOST_REQUIRE_EQUAL(flags.size(), 3u);
139+
BOOST_CHECK_EQUAL(flags[0], 0);
140+
BOOST_CHECK_EQUAL(flags[1], std::numeric_limits<uint8_t>::max());
141+
BOOST_CHECK_EQUAL(flags[2], 0);
142+
BOOST_CHECK(!publication.completeAccepted(last, parameters, frame, true));
143+
BOOST_CHECK(publication.sharedClusterFlags().empty());
144+
publication.reset();
145+
BOOST_CHECK(!publication.completeAccepted(outOfRange, parameters, frame, true));
146+
const std::array<uint32_t, 2> reversed{2, 0}, repeated{0, 0};
147+
BOOST_CHECK(!publication.completeAccepted(reversed, parameters, frame, true));
148+
BOOST_CHECK(!publication.completeAccepted(repeated, parameters, frame, true));
149+
BOOST_REQUIRE(publication.completeAccepted(first, parameters, frame, false));
150+
BOOST_REQUIRE(publication.completeAccepted({}, parameters, frame, true));
151+
BOOST_REQUIRE_EQUAL(publication.sharedClusterFlags().size(), 1u);
152+
BOOST_CHECK_EQUAL(publication.sharedClusterFlags()[0], 0);
153+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ void CATrackerDPL::run(ProcessingContext& pc)
224224
gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock,
225225
kLayerToLayout,
226226
&mSession.externalIndices, &mSession.clusterSizes};
227-
o2::itsmft::tracking::GenericTrackOutputAdapterError error = o2::itsmft::tracking::GenericTrackOutputAdapterError::None;
228-
const auto staged = o2::itsmft::tracking::stageMFTGenericTrackOutput(mSession.frame, context, mUseMC, error);
227+
const auto staged = o2::itsmft::tracking::stageMFTGenericTrackOutput(mSession.frame, context, mUseMC);
229228
if (!staged) {
230229
throw std::runtime_error{"MFT GenericTrack output staging failed"};
231230
}

0 commit comments

Comments
 (0)