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;
2728void 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// __________________________________________________
341388Clusterer::Clusterer () : mPattIdConverter()
342389{
0 commit comments