3131#include " TStopwatch.h"
3232#include " TTreeReader.h"
3333#include " TTreeReaderValue.h"
34+ #include " ROOT/TTreeProcessorMT.hxx"
3435
3536using namespace o2 ::gpu;
3637
@@ -541,9 +542,6 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
541542
542543 TStopwatch watch3;
543544
544- // TTreeProcessorMT treeProcessor(*voxResTree); // multi-threaded tree processor
545- // treeProcessor.Init(voxResTree);
546-
547545 // read the data ROC by ROC
548546
549547 // data in the tree is not sorted by row
@@ -554,44 +552,40 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
554552 float mCx , mCy , mCz ; // corrections to the local coordinates
555553 };
556554
557- std::vector<VoxelData> vRocData[nRows];
558- for (int ir = 0 ; ir < nRows; ir++) {
555+ std::vector<VoxelData> vRocData[nRows * nROCs ];
556+ for (int ir = 0 ; ir < nRows * nROCs ; ir++) {
559557 vRocData[ir].resize (nY2Xbins * nZ2Xbins);
560558 }
561559
562- for ( int iRoc = 0 ; iRoc < nROCs; iRoc++) {
560+ { // read data from the tree to vRocData
563561
564- for (int ir = 0 ; ir < nRows; ir++) {
565- for (int iv = 0 ; iv < nY2Xbins * nZ2Xbins; iv++) {
566- vRocData[ir][iv].mNentries = 0 ;
567- }
568- }
562+ ROOT::TTreeProcessorMT processor (*voxResTree, mNthreads );
569563
570- const int rocDataStart = iRoc * trackResiduals.getNVoxelsPerSector ();
571- const int rocDataEnd = rocDataStart + trackResiduals.getNVoxelsPerSector ();
572-
573- TTreeReader reader (voxResTree);
574- reader.SetEntriesRange (rocDataStart, rocDataEnd);
575- TTreeReaderValue<o2::tpc::TrackResiduals::VoxRes> v (reader, " voxRes" );
576- for (int iVox = rocDataStart; iVox < rocDataEnd; iVox++) {
577- reader.Next ();
578- // voxResTree->GetEntry(iVox);
579- if ((int )v->bsec != iRoc) {
580- LOG (fatal) << " Error reading voxels: voxel ROC number " << v->bsec << " is not equal to the expected " << iRoc;
581- continue ;
582- }
583- int iRow = (int )v->bvox [o2::tpc::TrackResiduals::VoxX]; // bin number in x (= pad row)
584- if (iRow < 0 || iRow >= nRows) {
585- LOG (fatal) << " Row number " << iRow << " is out of range" ;
564+ auto myThread = [&](TTreeReader& readerSubRange) {
565+ TTreeReaderValue<o2::tpc::TrackResiduals::VoxRes> v (readerSubRange, " voxRes" );
566+ while (readerSubRange.Next ()) {
567+ int iRoc = (int )v->bsec ;
568+ if (iRoc < 0 || iRoc >= nROCs) {
569+ LOG (fatal) << " Error reading voxels: voxel ROC number " << iRoc << " is out of range" ;
570+ continue ;
571+ }
572+ int iRow = (int )v->bvox [o2::tpc::TrackResiduals::VoxX]; // bin number in x (= pad row)
573+ if (iRow < 0 || iRow >= nRows) {
574+ LOG (fatal) << " Row number " << iRow << " is out of range" ;
575+ }
576+ int iy = v->bvox [o2::tpc::TrackResiduals::VoxF]; // bin number in y/x 0..14
577+ int iz = v->bvox [o2::tpc::TrackResiduals::VoxZ]; // bin number in z/x 0..4
578+ auto & vox = vRocData[iRoc * nRows + iRow][iy * nZ2Xbins + iz];
579+ vox.mNentries = (int )v->stat [o2::tpc::TrackResiduals::VoxV];
580+ vox.mCx = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResX] : v->D [o2::tpc::TrackResiduals::ResX];
581+ vox.mCy = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResY] : v->D [o2::tpc::TrackResiduals::ResY];
582+ vox.mCz = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResZ] : v->D [o2::tpc::TrackResiduals::ResZ];
586583 }
587- int iy = v->bvox [o2::tpc::TrackResiduals::VoxF]; // bin number in y/x 0..14
588- int iz = v->bvox [o2::tpc::TrackResiduals::VoxZ]; // bin number in z/x 0..4
589- auto & vox = vRocData[iRow][iy * nZ2Xbins + iz];
590- vox.mNentries = (int )v->stat [o2::tpc::TrackResiduals::VoxV];
591- vox.mCx = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResX] : v->D [o2::tpc::TrackResiduals::ResX];
592- vox.mCy = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResY] : v->D [o2::tpc::TrackResiduals::ResY];
593- vox.mCz = useSmoothed ? v->DS [o2::tpc::TrackResiduals::ResZ] : v->D [o2::tpc::TrackResiduals::ResZ];
594- }
584+ };
585+ processor.Process (myThread);
586+ }
587+
588+ for (int iRoc = 0 ; iRoc < nROCs; iRoc++) {
595589
596590 // now process the data row-by-row
597591
@@ -615,7 +609,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
615609 bool isDataFound = false ;
616610 for (int iy = 0 ; iy < nY2Xbins; iy++) {
617611 for (int iz = 0 ; iz < nZ2Xbins; iz++) {
618- auto & data = vRocData[iRow][iy * nZ2Xbins + iz];
612+ auto & data = vRocData[iRoc * nRows + iRow][iy * nZ2Xbins + iz];
619613 auto & vox = vRowVoxels[iy * nZ2Xbins + iz];
620614 // y/x coordinate of the bin ~-0.15 ... 0.15
621615 double y2x = trackResiduals.getY2X (xBin, iy);
@@ -661,7 +655,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
661655 for (int ismooth = 1 ; ismooth <= 2 ; ismooth++) {
662656 for (int iy = 0 ; iy < nY2Xbins; iy++) {
663657 for (int iz = 0 ; iz < nZ2Xbins; iz++) {
664- auto & data = vRocData[iRow][iy * nZ2Xbins + iz];
658+ auto & data = vRocData[iRoc * nRows + iRow][iy * nZ2Xbins + iz];
665659 auto & vox = vRowVoxels[iy * nZ2Xbins + iz];
666660 if (vox.mSmoothingStep <= ismooth) { // already filled
667661 continue ;
@@ -673,7 +667,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
673667 double w = 0 .;
674668 bool filled = false ;
675669 auto update = [&](int iy1, int iz1) {
676- auto & data1 = vRocData[iRow][iy1 * nZ2Xbins + iz1];
670+ auto & data1 = vRocData[iRoc * nRows + iRow][iy1 * nZ2Xbins + iz1];
677671 auto & vox1 = vRowVoxels[iy1 * nZ2Xbins + iz1];
678672 if (vox1.mSmoothingStep >= ismooth) {
679673 return false ;
@@ -746,7 +740,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
746740
747741 for (int iy = 0 ; iy < nY2Xbins; iy++) {
748742 for (int iz = 0 ; iz < nZ2Xbins; iz++) {
749- auto & data = vRocData[iRow][iy * nZ2Xbins + iz];
743+ auto & data = vRocData[iRoc * nRows + iRow][iy * nZ2Xbins + iz];
750744 auto & vox = vRowVoxels[iy * nZ2Xbins + iz];
751745 if (vox.mSmoothingStep > 2 ) {
752746 LOG (fatal) << " empty voxel is not repared" ;
@@ -812,7 +806,6 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
812806 for (auto & th : threads) {
813807 th.join ();
814808 }
815-
816809 } // iRoc
817810
818811 LOGP (info, " Reading & reparing of the track residuals tooks: {}s" , watch3.RealTime ());
0 commit comments