Skip to content

Commit 0c38cad

Browse files
committed
Hoist slice creation outside the inner loop
1 parent 5750b62 commit 0c38cad

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

PWGHF/TableProducer/trackIndexSkimCreator.cxx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include <cstdlib>
8484
#include <iterator> // std::distance
8585
#include <numeric>
86+
#include <optional>
8687
#include <string> // std::string
8788
#include <utility> // std::forward
8889
#include <vector> // std::vector
@@ -2391,6 +2392,9 @@ struct HfTrackIndexSkimCreator {
23912392

23922393
// first loop over positive tracks
23932394
const auto groupedTrackIndicesPos1 = positiveFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
2395+
const auto groupedTrackIndicesNeg1 = negativeFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
2396+
std::optional<decltype(positiveSoftPions->sliceByCached(aod::track::collisionId, 0, cache))> groupedTrackIndicesSoftPionsPos;
2397+
std::optional<decltype(negativeSoftPions->sliceByCached(aod::track::collisionId, 0, cache))> groupedTrackIndicesSoftPionsNeg;
23942398
int lastFilledD0 = -1; // index to be filled in table for D* mesons
23952399
for (auto trackIndexPos1 = groupedTrackIndicesPos1.begin(); trackIndexPos1 != groupedTrackIndicesPos1.end(); ++trackIndexPos1) {
23962400
const auto trackPos1 = trackIndexPos1.template track_as<TTracks>();
@@ -2409,7 +2413,6 @@ struct HfTrackIndexSkimCreator {
24092413
}
24102414

24112415
// first loop over negative tracks
2412-
const auto groupedTrackIndicesNeg1 = negativeFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
24132416
for (auto trackIndexNeg1 = groupedTrackIndicesNeg1.begin(); trackIndexNeg1 != groupedTrackIndicesNeg1.end(); ++trackIndexNeg1) {
24142417
const auto trackNeg1 = trackIndexNeg1.template track_as<TTracks>();
24152418

@@ -3189,8 +3192,10 @@ struct HfTrackIndexSkimCreator {
31893192
// if D* enabled and pt of the D0 is larger than the minimum of the D* one within 20% (D* and D0 momenta are very similar, always within 20% according to PYTHIA8)
31903193
// second loop over positive tracks
31913194
if (TESTBIT(whichHypo2Prong[kN2ProngDecays], 0) && (!config.applyKaonPidIn3Prongs || TESTBIT(trackIndexNeg1.isIdentifiedPid(), ChannelKaonPid))) { // only for D0 candidates; moreover if kaon PID enabled, apply to the negative track
3192-
auto groupedTrackIndicesSoftPionsPos = positiveSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
3193-
for (auto trackIndexPos2 = groupedTrackIndicesSoftPionsPos.begin(); trackIndexPos2 != groupedTrackIndicesSoftPionsPos.end(); ++trackIndexPos2) {
3195+
if (!groupedTrackIndicesSoftPionsPos) {
3196+
groupedTrackIndicesSoftPionsPos.emplace(positiveSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache));
3197+
}
3198+
for (auto trackIndexPos2 = groupedTrackIndicesSoftPionsPos->begin(); trackIndexPos2 != groupedTrackIndicesSoftPionsPos->end(); ++trackIndexPos2) {
31943199
if (trackIndexPos2 == trackIndexPos1) {
31953200
continue;
31963201
}
@@ -3226,8 +3231,10 @@ struct HfTrackIndexSkimCreator {
32263231

32273232
// second loop over negative tracks
32283233
if (TESTBIT(whichHypo2Prong[kN2ProngDecays], 1) && (!config.applyKaonPidIn3Prongs || TESTBIT(trackIndexPos1.isIdentifiedPid(), ChannelKaonPid))) { // only for D0bar candidates; moreover if kaon PID enabled, apply to the positive track
3229-
auto groupedTrackIndicesSoftPionsNeg = negativeSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
3230-
for (auto trackIndexNeg2 = groupedTrackIndicesSoftPionsNeg.begin(); trackIndexNeg2 != groupedTrackIndicesSoftPionsNeg.end(); ++trackIndexNeg2) {
3234+
if (!groupedTrackIndicesSoftPionsNeg) {
3235+
groupedTrackIndicesSoftPionsNeg.emplace(negativeSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache));
3236+
}
3237+
for (auto trackIndexNeg2 = groupedTrackIndicesSoftPionsNeg->begin(); trackIndexNeg2 != groupedTrackIndicesSoftPionsNeg->end(); ++trackIndexNeg2) {
32313238
if (trackIndexNeg1 == trackIndexNeg2) {
32323239
continue;
32333240
}

0 commit comments

Comments
 (0)