Skip to content

Commit 9e83c87

Browse files
authored
Merge 13071e7 into sapling-pr-archive-ktf
2 parents 128121f + 13071e7 commit 9e83c87

6 files changed

Lines changed: 134 additions & 4 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,28 @@ class Table
23082308
template <uint32_t D, soa::is_column... C>
23092309
using InPlaceTable = Table<o2::aod::Hash<"TEST"_h>, o2::aod::Hash<D>, o2::aod::Hash<"TEST"_h>, C...>;
23102310

2311+
template <typename Narrow>
2312+
std::shared_ptr<arrow::Table> projectColumns(std::shared_ptr<arrow::Table> const& src)
2313+
{
2314+
auto indices = []<typename... C>(framework::pack<C...>, std::shared_ptr<arrow::Schema> const& sch) {
2315+
return std::vector<int>{sch->GetFieldIndex(C::columnLabel())...};
2316+
}(typename Narrow::persistent_columns_t{}, src->schema());
2317+
return src->SelectColumns(indices).ValueOrDie();
2318+
}
2319+
2320+
template <typename Narrow, is_table T>
2321+
requires(!is_filtered_table<T>)
2322+
Narrow as_table(T const& wide)
2323+
{
2324+
return Narrow{projectColumns<Narrow>(wide.asArrowTable()), wide.offset()};
2325+
}
2326+
2327+
template <typename Narrow, is_filtered_table T>
2328+
soa::Filtered<Narrow> as_table(T const& wide)
2329+
{
2330+
return soa::Filtered<Narrow>({projectColumns<Narrow>(wide.asArrowTable())}, wide.getSelectedRows(), wide.offset());
2331+
}
2332+
23112333
void getterNotFound(const char* targetColumnLabel);
23122334
void emptyColumnLabel();
23132335

Framework/Core/test/test_ASoA.cxx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,70 @@ TEST_CASE("TestJoinedTables")
320320
}
321321
}
322322

323+
TEST_CASE("TestAsTableProjection")
324+
{
325+
TableBuilder builderX;
326+
auto rowWriterX = builderX.persist<int32_t>({"fX"});
327+
for (int i = 0; i < 8; ++i) {
328+
rowWriterX(0, i);
329+
}
330+
auto tableX = builderX.finalize();
331+
332+
TableBuilder builderY;
333+
auto rowWriterY = builderY.persist<int32_t>({"fY"});
334+
for (int i = 0; i < 8; ++i) {
335+
rowWriterY(0, 7 - i);
336+
}
337+
auto tableY = builderY.finalize();
338+
339+
TableBuilder builderZ;
340+
auto rowWriterZ = builderZ.persist<int32_t>({"fZ"});
341+
for (int i = 0; i < 8; ++i) {
342+
rowWriterZ(0, 8);
343+
}
344+
auto tableZ = builderZ.finalize();
345+
346+
using TestX = InPlaceTable<"A0"_h, o2::aod::test::X>;
347+
using TestY = InPlaceTable<"A1"_h, o2::aod::test::Y>;
348+
using TestZ = InPlaceTable<"A2"_h, o2::aod::test::Z>;
349+
using Wide = Join<TestX, TestY, TestZ>;
350+
351+
Wide wide{{tableX, tableY, tableZ}, 0};
352+
REQUIRE(wide.asArrowTable()->num_columns() == 3);
353+
354+
// Project the wide join onto just the X table: the resulting arrow table
355+
// shares the data but exposes a single column, and iteration sees only x.
356+
auto narrow = as_table<TestX>(wide);
357+
REQUIRE(narrow.asArrowTable()->num_columns() == 1);
358+
REQUIRE(narrow.size() == 8);
359+
int sum = 0;
360+
for (auto& r : narrow) {
361+
sum += r.x();
362+
}
363+
REQUIRE(sum == (0 + 1 + 2 + 3 + 4 + 5 + 6 + 7));
364+
365+
// Projecting onto two of the three tables keeps two columns.
366+
auto narrow2 = as_table<Join<TestX, TestY>>(wide);
367+
REQUIRE(narrow2.asArrowTable()->num_columns() == 2);
368+
for (auto& r : narrow2) {
369+
REQUIRE(7 == r.x() + r.y());
370+
}
371+
372+
// Filtered projection: the selection carries over to the narrow table, so the
373+
// narrow view iterates exactly the selected rows of the projected column.
374+
Filtered<Wide> wideF{{tableX, tableY, tableZ}, SelectionVector{1, 3, 5}, 0};
375+
auto narrowF = as_table<TestX>(wideF);
376+
REQUIRE(narrowF.asArrowTable()->num_columns() == 1);
377+
int sumF = 0;
378+
int nF = 0;
379+
for (auto& r : narrowF) {
380+
sumF += r.x();
381+
++nF;
382+
}
383+
REQUIRE(nF == 3);
384+
REQUIRE(sumF == (1 + 3 + 5));
385+
}
386+
323387
TEST_CASE("TestConcatTables")
324388
{
325389
TableBuilder builderA;

GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <cstring>
2020
#include <map>
2121
#include <queue>
22+
#include <fstream>
2223

2324
using namespace o2::gpu;
2425

@@ -106,7 +107,7 @@ void GenerateCodes(const INode* node, const HuffCode& prefix, HuffCodeMap& outCo
106107
} // anonymous namespace
107108
} // namespace o2::gpu
108109

109-
void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess* clustersNative, const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param)
110+
void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess* clustersNative, const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param, bool dumpCSV)
110111
{
111112
uint32_t decodingErrors = 0;
112113
o2::tpc::ClusterNativeAccess clustersNativeDecoded;
@@ -185,6 +186,49 @@ void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess*
185186
FillStatisticCombined(mPQU, clustersCompressed->qMaxU, clustersCompressed->qTotU, clustersCompressed->nUnattachedClusters, P_MAX_QMAX);
186187
FillStatisticCombined(mProwSectorA, clustersCompressed->rowDiffA, clustersCompressed->sliceLegDiffA, clustersCompressed->nAttachedClustersReduced, GPUTPCGeometry::NROWS);
187188
mNTotalClusters += clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters;
189+
190+
if (dumpCSV) {
191+
std::ofstream csv("clusters_raw.csv");
192+
csv << "sector,row,time,pad,flags,qtot,qmax,sigmatime,sigmapad\n";
193+
for (uint32_t i = 0; i < NSECTORS; i++) {
194+
for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) {
195+
for (uint32_t k = 0; k < clustersNativeDecoded.nClusters[i][j]; k++) {
196+
const auto& cl = clustersNativeDecoded.clusters[i][j][k];
197+
csv << i << ',' << j << ',' << cl.getTimePacked() << ',' << cl.padPacked << ',' << (uint32_t)cl.getFlags() << ',' << cl.qTot << ',' << cl.qMax << ',' << (uint32_t)cl.sigmaTimePacked << ',' << (uint32_t)cl.sigmaPadPacked << '\n';
198+
}
199+
}
200+
}
201+
202+
csv = std::ofstream("attachedCl.csv");
203+
csv << "qTotA,qMaxA,flagsA,sigmaPadA,sigmaTimeA\n";
204+
for (uint32_t i = 0; i < clustersCompressed->nAttachedClusters; i++) {
205+
csv << clustersCompressed->qTotA[i] << ',' << clustersCompressed->qMaxA[i] << ',' << (uint32_t)clustersCompressed->flagsA[i] << ',' << (uint32_t)clustersCompressed->sigmaPadA[i] << ',' << (uint32_t)clustersCompressed->sigmaTimeA[i] << "\n";
206+
}
207+
208+
csv = std::ofstream("attachedClred.csv");
209+
csv << "rodDiffA,legDiffA,padResA,timeResA\n";
210+
for (uint32_t i = 0; i < clustersCompressed->nAttachedClustersReduced; i++) {
211+
csv << (uint32_t)clustersCompressed->rowDiffA[i] << ',' << (uint32_t)clustersCompressed->sliceLegDiffA[i] << ',' << clustersCompressed->padResA[i] << ',' << clustersCompressed->timeResA[i] << "\n";
212+
}
213+
214+
csv = std::ofstream("nClU.csv");
215+
csv << "sliceRowCl\n";
216+
for (uint32_t i = 0; i < clustersCompressed->nSliceRows; i++) {
217+
csv << clustersCompressed->nSliceRowClusters[i] << "\n";
218+
}
219+
220+
csv = std::ofstream("trk.csv");
221+
csv << "qPtA,rowA,sliceA,timeA,padA,nCl\n";
222+
for (uint32_t i = 0; i < clustersCompressed->nTracks; i++) {
223+
csv << (uint32_t)clustersCompressed->qPtA[i] << ',' << (uint32_t)clustersCompressed->rowA[i] << ',' << (uint32_t)clustersCompressed->sliceA[i] << ',' << clustersCompressed->timeA[i] << ',' << clustersCompressed->padA[i] << ',' << clustersCompressed->nTrackClusters[i] << "\n";
224+
}
225+
226+
csv = std::ofstream("unattachedCl.csv");
227+
csv << "qTotU,qMaxU,flagsU,padDiffU,timeDiffU,sigmaPadU,sigmaTimeU\n";
228+
for (uint32_t i = 0; i < clustersCompressed->nUnattachedClusters; i++) {
229+
csv << clustersCompressed->qTotU[i] << ',' << clustersCompressed->qMaxU[i] << ',' << (uint32_t)clustersCompressed->flagsU[i] << ',' << clustersCompressed->padDiffU[i] << ',' << clustersCompressed->timeDiffU[i] << ',' << (uint32_t)clustersCompressed->sigmaPadU[i] << ',' << (uint32_t)clustersCompressed->sigmaTimeU[i] << "\n";
230+
}
231+
}
188232
}
189233

190234
void GPUTPCClusterStatistics::Finish()

GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GPUTPCClusterStatistics
3030
{
3131
public:
3232
static constexpr uint32_t NSECTORS = GPUTPCGeometry::NSECTORS;
33-
void RunStatistics(const o2::tpc::ClusterNativeAccess* clustersNative, const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param);
33+
void RunStatistics(const o2::tpc::ClusterNativeAccess* clustersNative, const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param, bool dumpCSV);
3434
void Finish();
3535

3636
protected:

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ AddOption(serializeGPU, int8_t, 0, "", 0, "Synchronize after each kernel call (b
342342
AddOption(recoTaskTiming, bool, 0, "", 0, "Perform summary timing after whole reconstruction tasks")
343343
AddOption(deterministicGPUReconstruction, int32_t, -1, "", 0, "Make CPU and GPU debug output comparable (sort / skip concurrent parts), -1 = automatic if debugLevel >= 6 or deterministic compile flag set", def(1))
344344
AddOption(showOutputStat, bool, false, "", 0, "Print some track output statistics")
345-
AddOption(runCompressionStatistics, bool, false, "compressionStat", 0, "Run statistics and verification for cluster compression")
345+
AddOption(runCompressionStatistics, int8_t, 0, "compressionStat", 0, "Run statistics and verification for cluster compression, 2 to dump clusters and entropy-reduced clusters to CSV", def(1))
346346
AddOption(resetTimers, int8_t, 1, "", 0, "Reset timers every event")
347347
AddOption(deviceTimers, bool, true, "", 0, "Use device timers instead of host-based time measurement")
348348
AddOption(keepAllMemory, bool, false, "", 0, "Allocate all memory on both device and host, and do not reuse")

GPU/GPUTracking/Global/GPUChainTracking.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ int32_t GPUChainTracking::RunChainFinalize()
789789
{
790790
if (mIOPtrs.clustersNative && (GetRecoSteps() & RecoStep::TPCCompression) && GetProcessingSettings().runCompressionStatistics) {
791791
CompressedClusters c = *mIOPtrs.tpcCompressedClusters;
792-
mCompressionStatistics->RunStatistics(mIOPtrs.clustersNative, &c, param());
792+
mCompressionStatistics->RunStatistics(mIOPtrs.clustersNative, &c, param(), GetProcessingSettings().runCompressionStatistics >= 2);
793793
}
794794

795795
if (GetProcessingSettings().outputSanityCheck) {

0 commit comments

Comments
 (0)