Skip to content

Commit be4ed34

Browse files
authored
Merge 9f0c915 into sapling-pr-archive-ktf
2 parents 34be6cb + 9f0c915 commit be4ed34

13 files changed

Lines changed: 121 additions & 26 deletions

File tree

DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,11 @@ class TrackITSExt : public TrackITS
192192
getClusterRefs().setEntries(ncl);
193193
}
194194

195-
GPUhdi() const int getClusterIndex(int lr) const { return mIndex[lr]; }
195+
GPUhdi() int getClusterIndex(int lr) const { return mIndex[lr]; }
196196

197-
GPUh() const int getFirstLayerClusterIndex() const
197+
GPUh() int getFirstLayerClusterIndex() const
198198
{
199-
int firstLayer = getFirstClusterLayer();
200-
return getClusterIndex(firstLayer);
199+
return getClusterIndex(getFirstClusterLayer());
201200
}
202201

203202
GPUhdi() void setExternalClusterIndex(int layer, int idx, bool newCluster = false)

Detectors/ITSMFT/ITS/tracking/GPU/cuda/TrackerTraitsGPU.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ void TrackerTraitsGPU<NLayers>::findRoads(const int iteration)
309309
bounded_vector<TrackSeed<NLayers>> trackSeeds(this->getMemoryPool().get());
310310
for (int startCellTopologyId{0}; startCellTopologyId < hostTopology.nCells; ++startCellTopologyId) {
311311
const int startLayer = hostTopology.getCell(startCellTopologyId).hitLayerMask.last();
312-
if ((this->mTrkParams[iteration].StartLayerMask & (1 << startLayer)) == 0 ||
313-
mTimeFrameGPU->getNCells()[startCellTopologyId] == 0) {
312+
if (!(this->mTrkParams[iteration].StartLayerMask.has(startLayer)) || mTimeFrameGPU->getNCells()[startCellTopologyId] == 0) {
314313
continue;
315314
}
316315
processNeighboursHandler<NLayers>(startLevel,

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Configuration.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "CommonUtils/EnumFlags.h"
2727
#include "DetectorsBase/Propagator.h"
2828
#include "ITStracking/Constants.h"
29+
#include "ITStracking/LayerMask.h"
2930

3031
namespace o2::its
3132
{
@@ -70,10 +71,9 @@ struct TrackingParameters {
7071
float DiamondCov[6] = {25.e-6f, 0.f, 0.f, 25.e-6f, 0.f, 36.f};
7172

7273
/// General parameters
73-
int ClusterSharing = 0;
7474
int MinTrackLength = 7;
7575
int MaxHoles = 0;
76-
uint16_t HoleLayerMask = 0;
76+
LayerMask HoleLayerMask = 0;
7777
float NSigmaCut = 5;
7878
float PVres = 1.e-2f;
7979
/// Trackleting cuts
@@ -86,7 +86,7 @@ struct TrackingParameters {
8686
float MaxChi2NDF = 30.f;
8787
int ReseedIfShorter = 6; // reseed for the final fit track with the length shorter than this
8888
std::vector<float> MinPt = {0.f, 0.f, 0.f, 0.f};
89-
uint16_t StartLayerMask = 0x7F;
89+
LayerMask StartLayerMask = 0x7F;
9090
bool RepeatRefitOut = false; // repeat outward refit using inward refit as a seed
9191
bool ShiftRefToCluster = true; // TrackFit: after update shift the linearization reference to cluster
9292
bool PerPrimaryVertexProcessing = false;
@@ -103,6 +103,7 @@ struct TrackingParameters {
103103
float SharedClusterMaxDeltaPhi = 0.05f; // For tracks sharing clusters, maximum allowed delta phi at the cluster position
104104
float SharedClusterMaxDeltaEta = 0.03f; // For tracks sharing clusters, maximum allowed delta eta at the cluster position
105105
bool SharedClusterOppositeSign = false; // For tracks sharing clusters, require opposite sign of the tracklets
106+
int SharedMaxClusters = 0; // Maximal allowed shared clusters (excluding first cluster)
106107
};
107108

108109
struct VertexingParameters {

Detectors/ITSMFT/ITS/tracking/src/Configuration.cxx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ using namespace o2::its;
2424

2525
std::string TrackingParameters::asString() const
2626
{
27-
std::string str = std::format("NZb:{} NPhB:{} PerVtx:{} DropFail:{} ClSh:{} TtklMinPt:{:.2f} MinCl:{} MaxHoles:{} HoleMask:{:#x}",
28-
ZBins, PhiBins, PerPrimaryVertexProcessing, DropTFUponFailure, ClusterSharing, TrackletMinPt, MinTrackLength, MaxHoles, HoleLayerMask);
27+
std::string str = std::format("NZb:{} NPhB:{} PerVtx:{} DropFail:{} TtklMinPt:{:.2f} MinCl:{}", ZBins, PhiBins, PerPrimaryVertexProcessing, DropTFUponFailure, TrackletMinPt, MinTrackLength);
28+
auto isSet = [](auto e) { return e >= 0; };
29+
auto isAnySet = [&isSet](auto v) { return !v.empty() && std::any_of(v.begin(), v.end(), isSet); };
2930
bool first = true;
3031
for (int il = NLayers; il >= MinTrackLength; il--) {
3132
int slot = NLayers - il;
@@ -37,18 +38,27 @@ std::string TrackingParameters::asString() const
3738
str += std::format("L{}:{:.2f} ", il, MinPt[slot]);
3839
}
3940
}
40-
if (!SystErrorY2.empty() || !SystErrorZ2.empty()) {
41+
if (isAnySet(SystErrorY2) || isAnySet(SystErrorZ2)) {
4142
str += " SystErrY/Z:";
4243
for (size_t i = 0; i < SystErrorY2.size(); i++) {
4344
str += std::format("{:.2e}/{:.2e} ", SystErrorY2[i], SystErrorZ2[i]);
4445
}
4546
}
46-
if (!AddTimeError.empty()) {
47+
if (isAnySet(AddTimeError)) {
4748
str += " AddTimeError:";
4849
for (unsigned int i : AddTimeError) {
4950
str += std::format("{} ", i);
5051
}
5152
}
53+
if (SharedMaxClusters) {
54+
str += std::format(" ShaMaxCls:{} ", SharedMaxClusters);
55+
}
56+
if (AllowSharingFirstCluster) {
57+
str += std::format(" ShaClsDPhi:{} ShaClsDEta:{} ShaClsSign:{}", SharedClusterMaxDeltaPhi, SharedClusterMaxDeltaEta, SharedClusterOppositeSign);
58+
}
59+
if (MaxHoles) {
60+
str += std::format(" MaxHoles:{} HoleMask:{}", MaxHoles, HoleLayerMask.asString());
61+
}
5262
if (std::numeric_limits<size_t>::max() != MaxMemory) {
5363
str += std::format(" MemLimit {:.2f} GB", double(MaxMemory) / constants::GB);
5464
}

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,7 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
681681
bounded_vector<TrackSeedN> trackSeeds(mMemoryPool.get());
682682
for (int startCellTopologyId{0}; startCellTopologyId < topology.nCells; ++startCellTopologyId) {
683683
const int startLayer = topology.getCell(startCellTopologyId).hitLayerMask.last();
684-
if ((mTrkParams[iteration].StartLayerMask & (1 << startLayer)) == 0 ||
685-
mTimeFrame->getCells()[startCellTopologyId].empty()) {
684+
if (!(mTrkParams[iteration].StartLayerMask.has(startLayer)) || mTimeFrame->getCells()[startCellTopologyId].empty()) {
686685
continue;
687686
}
688687

@@ -814,7 +813,7 @@ void TrackerTraits<NLayers>::acceptTracks(int iteration, bounded_vector<TrackITS
814813
}
815814

816815
/// do not account for the first cluster in the shared clusters number if it is allowed
817-
if (nShared - int(isFirstShared && mTrkParams[iteration].AllowSharingFirstCluster) > mTrkParams[iteration].ClusterSharing) {
816+
if (nShared - int(isFirstShared && mTrkParams[iteration].AllowSharingFirstCluster) > mTrkParams[iteration].SharedMaxClusters) {
818817
continue;
819818
}
820819

Detectors/Upgrades/ALICE3/GlobalReconstruction/workflow/src/TrackerSpec.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ std::vector<o2::its::TrackingParameters> TrackerDPL::createTrackingParamsFromCon
113113
if (paramConfig.contains("PhiBins")) {
114114
params.PhiBins = paramConfig["PhiBins"].get<int>();
115115
}
116-
if (paramConfig.contains("ClusterSharing")) {
117-
params.ClusterSharing = paramConfig["ClusterSharing"].get<int>();
116+
if (paramConfig.contains("SharedMaxClusters")) {
117+
params.SharedMaxClusters = paramConfig["SharedMaxClusters"].get<int>();
118118
}
119119
if (paramConfig.contains("MinTrackLength")) {
120120
params.MinTrackLength = paramConfig["MinTrackLength"].get<int>();

Framework/Core/include/Framework/DataRefUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <gsl/gsl>
2525

26+
#include <span>
2627
#include <type_traits>
2728
#include <typeinfo>
2829

@@ -184,6 +185,10 @@ struct DataRefUtils {
184185
// Decode a CCDB object using the CcdbApi.
185186
static void* decodeCCDB(DataRef const& ref, std::type_info const& info);
186187
static std::map<std::string, std::string> extractCCDBHeaders(DataRef const& ref);
188+
/// Return a span over the raw CCDB payload bytes, stripping the flattened HTTP
189+
/// headers footer that CCDBFetcherHelper appends. Use this when the CCDB entry is
190+
/// a binary blob rather than a ROOT-serialised object.
191+
static std::span<const char> getCCDBPayloadBlob(DataRef const& ref);
187192

188193
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef& ref)
189194
{

Framework/Core/include/Framework/InputRecord.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <memory>
3636
#include <type_traits>
3737
#include <concepts>
38+
#include <span>
3839

3940
#include <fairmq/FwdDecls.h>
4041

@@ -45,6 +46,12 @@ namespace o2::framework
4546
struct CCDBMetadataExtractor {
4647
};
4748

49+
/// Tag type to retrieve the raw binary payload of a CCDB entry without ROOT
50+
/// deserialization. The returned span is valid for the duration of the
51+
/// processing callback. Use as: inputs.get<CCDBBlob>("binding")
52+
struct CCDBBlob {
53+
};
54+
4855
struct InputSpec;
4956
class InputSpan;
5057
class CallbackService;
@@ -522,6 +529,18 @@ class InputRecord
522529
return cache.idToMetadata[id];
523530
}
524531

532+
template <typename T = DataRef, typename R>
533+
std::span<const char> get(R binding, int part = 0) const
534+
requires std::same_as<T, CCDBBlob>
535+
{
536+
auto ref = getRef(binding, part);
537+
auto header = DataRefUtils::getHeader<header::DataHeader*>(ref);
538+
if (header->payloadSerializationMethod != header::gSerializationMethodCCDB) {
539+
throw runtime_error("Attempt to extract CCDBBlob from a non-CCDB-serialized message");
540+
}
541+
return DataRefUtils::getCCDBPayloadBlob(ref);
542+
}
543+
525544
template <typename T>
526545
requires(std::same_as<T, DataRef>)
527546
decltype(auto) get(ConcreteDataMatcher matcher, int part = 0)

Framework/Core/src/DPLWebSocket.cxx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ struct WriteRequestContext {
516516
struct BulkWriteRequestContext {
517517
std::vector<uv_buf_t> buffers;
518518
ServiceRegistryRef ref;
519+
std::vector<char*>* freeList = nullptr; // if non-null, return chunks here instead of freeing
519520
};
520521

521522
void ws_client_write_callback(uv_write_t* h, int status)
@@ -543,11 +544,14 @@ void ws_client_bulk_write_callback(uv_write_t* h, int status)
543544
state.loopReason |= (DeviceState::WS_COMMUNICATION | DeviceState::WS_WRITING);
544545
if (status < 0) {
545546
LOG(error) << "uv_write error: " << uv_err_name(status);
546-
free(h);
547-
return;
548547
}
549-
if (context->buffers.size()) {
550-
for (auto& b : context->buffers) {
548+
// Return chunks to the free list (capped) so flushPending can pre-seed
549+
// the backlog for the next cycle without malloc-ing.
550+
constexpr size_t kMaxFreeChunks = 4;
551+
for (auto& b : context->buffers) {
552+
if (context->freeList && b.base && context->freeList->size() < kMaxFreeChunks) {
553+
context->freeList->push_back(b.base);
554+
} else {
551555
free(b.base);
552556
}
553557
}
@@ -584,4 +588,18 @@ void WSDPLClient::write(std::vector<uv_buf_t>& outputs)
584588
context->buffers.size(), ws_client_bulk_write_callback);
585589
}
586590

591+
void WSDPLClient::write(std::vector<uv_buf_t>& outputs, std::vector<char*>& freeList)
592+
{
593+
if (outputs.empty()) {
594+
return;
595+
}
596+
auto* write_req = (uv_write_t*)malloc(sizeof(uv_write_t));
597+
auto* context = new BulkWriteRequestContext{.ref = mContext->ref};
598+
context->buffers.swap(outputs);
599+
context->freeList = &freeList;
600+
write_req->data = context;
601+
uv_write(write_req, (uv_stream_t*)mStream, &context->buffers.at(0),
602+
context->buffers.size(), ws_client_bulk_write_callback);
603+
}
604+
587605
} // namespace o2::framework

Framework/Core/src/DPLWebSocket.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ struct WSDPLClient : public HTTPParser {
8989
/// Helper to write n buffers containing websockets frames to a server
9090
void write(std::vector<uv_buf_t>& outputs);
9191

92+
/// Like write() above but recycles the chunk memory into freeList once the
93+
/// kernel has consumed the buffers, instead of freeing it.
94+
void write(std::vector<uv_buf_t>& outputs, std::vector<char*>& freeList);
95+
9296
/// Dump headers
9397
void dumpHeaders();
9498
void sendHandshake();

0 commit comments

Comments
 (0)