Skip to content

Commit 53906e7

Browse files
committed
cluster binary dump
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 8895e66 commit 53906e7

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/Clusterer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ class Clusterer
188188
std::fill(std::begin(column1), std::end(column1), -1);
189189
std::fill(std::begin(column2), std::end(column2), -1);
190190
}
191+
192+
bool StartOfNewTF{true};
193+
static constexpr bool DumpClusterBin{true};
194+
void dumppCluster(const ChipPixelData* chip, const BBox& box);
191195
};
192196
//=========================================================
193197

Detectors/ITSMFT/common/reconstruction/src/Clusterer.cxx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/// \file Clusterer.cxx
1313
/// \brief Implementation of the ITS cluster finder
1414
#include <algorithm>
15+
#include <fstream>
1516
#include <TTree.h>
1617
#include "Framework/Logger.h"
1718
#include "ITSMFTReconstruction/Clusterer.h"
@@ -27,6 +28,7 @@ using namespace o2::itsmft;
2728
void Clusterer::process(int nThreads, PixelReader& reader, CompClusCont* compClus,
2829
PatternCont* patterns, ROFRecCont* vecROFRec, MCTruth* labelsCl)
2930
{
31+
bool startTF{true};
3032
#ifdef _PERFORM_TIMING_
3133
mTimer.Start(kFALSE);
3234
#endif
@@ -100,6 +102,10 @@ void Clusterer::process(int nThreads, PixelReader& reader, CompClusCont* compClu
100102
labelsCl ? reader.getDigitsMCTruth() : nullptr,
101103
labelsCl ? &mThreads[ith]->labels : nullptr, rof);
102104
} else { // put directly to the destination
105+
if (startTF) {
106+
startTF = false;
107+
mThreads[0]->StartOfNewTF = true;
108+
}
103109
mThreads[0]->process(0, nFired, compClus, patterns, labelsCl ? reader.getDigitsMCTruth() : nullptr, labelsCl, rof);
104110
}
105111
}
@@ -270,6 +276,9 @@ void Clusterer::ClustererThread::finishChip(ChipPixelData* curChipData, CompClus
270276
}
271277
preCluster2.index = -1;
272278
}
279+
if constexpr (DumpClusterBin) {
280+
dumppCluster(curChipData, bbox);
281+
}
273282
if (bbox.isAcceptableSize()) {
274283
parent->streamCluster(pixArrBuff, &labelsBuff, bbox, parent->mPattIdConverter, compClusPtr, patternsPtr, labelsClusPtr, nlab);
275284
} else {
@@ -326,6 +335,12 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(uint32_t hit, ChipPixel
326335
}
327336
}
328337

338+
if constexpr (DumpClusterBin) {
339+
BBox bbox(curChipData->getChipID());
340+
bbox.adjust(row, col);
341+
dumppCluster(curChipData, bbox);
342+
}
343+
329344
// add to compact clusters, which must be always filled
330345
unsigned char patt[ClusterPattern::MaxPatternBytes]{0x1 << (7 - (0 % 8))}; // unrolled 1 hit version of full loop in finishChip
331346
uint16_t pattID = (parent->mPattIdConverter.size() == 0) ? CompCluster::InvalidPatternID : parent->mPattIdConverter.findGroupID(1, 1, patt);
@@ -337,6 +352,38 @@ void Clusterer::ClustererThread::finishChipSingleHitFast(uint32_t hit, ChipPixel
337352
compClusPtr->emplace_back(row, col, pattID, curChipData->getChipID());
338353
}
339354

355+
void Clusterer::ClustererThread::dumppCluster(const Clusterer::ChipPixelData* chip, const Clusterer::BBox& bbox)
356+
{
357+
static std::ofstream out;
358+
if (StartOfNewTF) {
359+
StartOfNewTF = false;
360+
static int counter{0};
361+
out = std::ofstream(std::format("clusters_{}.bin", counter++), std::ios::binary);
362+
}
363+
uint32_t sensorId = chip->getChipID();
364+
uint16_t row = bbox.rowMin;
365+
uint16_t col = bbox.colMin;
366+
uint16_t height = bbox.rowSpan();
367+
uint16_t width = bbox.colSpan();
368+
out.write(reinterpret_cast<const char*>(&sensorId), 4);
369+
out.write(reinterpret_cast<const char*>(&row), 2);
370+
out.write(reinterpret_cast<const char*>(&col), 2);
371+
out.write(reinterpret_cast<const char*>(&height), 2);
372+
out.write(reinterpret_cast<const char*>(&width), 2);
373+
if (height == 1 && width == 1) {
374+
return;
375+
}
376+
size_t nbytes = (size_t(height) * width + 7) / 8;
377+
std::vector<uint8_t> patt(nbytes, 0);
378+
for (const auto& pix : pixArrBuff) {
379+
int ir = pix.getRowDirect() - bbox.rowMin;
380+
int ic = pix.getCol() - bbox.colMin;
381+
int bitIdx = ir * width + ic;
382+
patt[bitIdx >> 3] |= (0x1 << (7 - (bitIdx % 8)));
383+
}
384+
out.write(reinterpret_cast<const char*>(patt.data()), nbytes);
385+
}
386+
340387
//__________________________________________________
341388
Clusterer::Clusterer() : mPattIdConverter()
342389
{

0 commit comments

Comments
 (0)