Skip to content

Commit 9b2f986

Browse files
committed
Feat: cleanup derived to derived builder/producer
1 parent 4dd5374 commit 9b2f986

7 files changed

Lines changed: 170 additions & 92 deletions

File tree

PWGCF/Femto/Core/cascadeBuilder.h

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,15 @@ struct CascadeBuilderDerivedToDerivedProducts : o2::framework::ProducesGroup {
793793
class CascadeBuilderDerivedToDerived
794794
{
795795
public:
796-
CascadeBuilderDerivedToDerived() = default;
797-
~CascadeBuilderDerivedToDerived() = default;
798-
799796
template <typename T>
800797
void init(T& config)
801798
{
802799
mLimitXi = config.limitXi.value;
803800
mLimitOmega = config.limitOmega.value;
804801

802+
if (mLimitXi < 0 || mLimitOmega < 0) {
803+
LOG(fatal) << "Cascade limits must be non-negative (got " << mLimitXi << " and " << mLimitOmega << "). Breaking...";
804+
}
805805
if (mLimitXi == 0 && mLimitOmega == 0) {
806806
LOG(fatal) << "Both xi limit and omega limit are 0. Breaking...";
807807
}
@@ -810,34 +810,40 @@ class CascadeBuilderDerivedToDerived
810810
template <typename T1, typename T2, typename T3, typename T4>
811811
bool collisionHasTooFewXis(T1 const& col, T2 const& /*xiTable*/, T3& partitionXi, T4& cache)
812812
{
813+
if (mLimitXi == 0) { // xis disabled, cannot reject on them
814+
return false;
815+
}
813816
auto xiSlice = partitionXi->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
814-
return xiSlice.size() < mLimitXi;
817+
return xiSlice.size() < static_cast<int64_t>(mLimitXi);
815818
}
816819

817820
template <typename T1, typename T2, typename T3, typename T4>
818821
bool collisionHasTooFewOmegas(T1 const& col, T2 const& /*omegaTable*/, T3& partitionOmega, T4& cache)
819822
{
823+
if (mLimitOmega == 0) { // omegas disabled, cannot reject on them
824+
return false;
825+
}
820826
auto omegaSlice = partitionOmega->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
821-
return omegaSlice.size() < mLimitOmega;
827+
return omegaSlice.size() < static_cast<int64_t>(mLimitOmega);
822828
}
823829

824830
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
825831
void processXis(T1 const& col, T2 const& /*xiTable*/, T3 const& oldTrackTable, T4& partitionXi, T5& trackBuilder, T6& cache, T7& newXiTable, T8& newTrackTable, T9& newCollisionTable)
826832
{
833+
if (mLimitXi == 0) { // xis disabled
834+
return;
835+
}
836+
827837
auto xiSlice = partitionXi->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
828838

829839
for (auto const& xi : xiSlice) {
840+
auto bachelor = oldTrackTable.rawIteratorAt(this->daughterRow(xi.bachelorId(), oldTrackTable));
841+
auto posDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(xi.posDauId(), oldTrackTable));
842+
auto negDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(xi.negDauId(), oldTrackTable));
830843

831-
// auto bachelor = xi.template bachelor_as<T3>();
832-
// auto posDaughter = xi.template posDau_as<T3>();
833-
// auto negDaughter = xi.template negDau_as<T3>();
834-
auto bachelor = oldTrackTable.rawIteratorAt(xi.bachelorId() - oldTrackTable.offset());
835-
auto posDaughter = oldTrackTable.rawIteratorAt(xi.posDauId() - oldTrackTable.offset());
836-
auto negDaughter = oldTrackTable.rawIteratorAt(xi.negDauId() - oldTrackTable.offset());
837-
838-
int bachelorIndex = trackBuilder.getDaughterIndex(bachelor, newTrackTable, newCollisionTable);
839-
int posDaughterIndex = trackBuilder.getDaughterIndex(posDaughter, newTrackTable, newCollisionTable);
840-
int negDaughterIndex = trackBuilder.getDaughterIndex(negDaughter, newTrackTable, newCollisionTable);
844+
int64_t bachelorIndex = trackBuilder.getDaughterIndex(bachelor, newTrackTable, newCollisionTable);
845+
int64_t posDaughterIndex = trackBuilder.getDaughterIndex(posDaughter, newTrackTable, newCollisionTable);
846+
int64_t negDaughterIndex = trackBuilder.getDaughterIndex(negDaughter, newTrackTable, newCollisionTable);
841847

842848
newXiTable.producedXis(newCollisionTable.producedCollision.lastIndex(),
843849
xi.signedPt(),
@@ -854,20 +860,20 @@ class CascadeBuilderDerivedToDerived
854860
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
855861
void processOmegas(T1 const& col, T2 const& /*omegaTable*/, T3 const& oldTrackTable, T4& partitionOmega, T5& trackBuilder, T6& cache, T7& newOmegaTable, T8& newTrackTable, T9& newCollisionTable)
856862
{
863+
if (mLimitOmega == 0) { // omegas disabled
864+
return;
865+
}
866+
857867
auto omegaSlice = partitionOmega->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
858868

859869
for (auto const& omega : omegaSlice) {
870+
auto bachelor = oldTrackTable.rawIteratorAt(this->daughterRow(omega.bachelorId(), oldTrackTable));
871+
auto posDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(omega.posDauId(), oldTrackTable));
872+
auto negDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(omega.negDauId(), oldTrackTable));
860873

861-
// auto bachelor = omega.template bachelor_as<T3>();
862-
// auto posDaughter = omega.template posDau_as<T3>();
863-
// auto negDaughter = omega.template negDau_as<T3>();
864-
auto bachelor = oldTrackTable.rawIteratorAt(omega.bachelorId() - oldTrackTable.offset());
865-
auto posDaughter = oldTrackTable.rawIteratorAt(omega.posDauId() - oldTrackTable.offset());
866-
auto negDaughter = oldTrackTable.rawIteratorAt(omega.negDauId() - oldTrackTable.offset());
867-
868-
int bachelorIndex = trackBuilder.getDaughterIndex(bachelor, newTrackTable, newCollisionTable);
869-
int posDaughterIndex = trackBuilder.getDaughterIndex(posDaughter, newTrackTable, newCollisionTable);
870-
int negDaughterIndex = trackBuilder.getDaughterIndex(negDaughter, newTrackTable, newCollisionTable);
874+
int64_t bachelorIndex = trackBuilder.getDaughterIndex(bachelor, newTrackTable, newCollisionTable);
875+
int64_t posDaughterIndex = trackBuilder.getDaughterIndex(posDaughter, newTrackTable, newCollisionTable);
876+
int64_t negDaughterIndex = trackBuilder.getDaughterIndex(negDaughter, newTrackTable, newCollisionTable);
871877

872878
newOmegaTable.producedOmegas(newCollisionTable.producedCollision.lastIndex(),
873879
omega.signedPt(),
@@ -882,6 +888,20 @@ class CascadeBuilderDerivedToDerived
882888
}
883889

884890
private:
891+
/// Translate a global daughter index into a row of the current track table frame.
892+
/// Aborts if the index does not fall inside the frame, which would otherwise
893+
/// silently produce an out-of-range iterator.
894+
template <typename T>
895+
int64_t daughterRow(int64_t daughterId, T const& trackTable) const
896+
{
897+
const int64_t row = daughterId - trackTable.offset();
898+
if (daughterId < 0 || row < 0 || row >= static_cast<int64_t>(trackTable.size())) {
899+
LOG(fatal) << "Daughter index " << daughterId << " out of range for track table (offset "
900+
<< trackTable.offset() << ", size " << trackTable.size() << "). Breaking...";
901+
}
902+
return row;
903+
}
904+
885905
int mLimitXi = 0;
886906
int mLimitOmega = 0;
887907
};

PWGCF/Femto/Core/kinkBuilder.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -730,24 +730,24 @@ struct ConfKinkTablesDerivedToDerived : o2::framework::ConfigurableGroup {
730730
};
731731

732732
struct KinkBuilderDerivedToDerivedProducts : o2::framework::ProducesGroup {
733-
o2::framework::Produces<o2::aod::StoredFSigmas_002> producedSigmas;
734-
o2::framework::Produces<o2::aod::StoredFSigmaMasks_001> producedSigmaMasks;
735-
o2::framework::Produces<o2::aod::StoredFSigmaPlus_001> producedSigmaPluses;
736-
o2::framework::Produces<o2::aod::StoredFSigmaPlusMasks_001> producedSigmaPlusMasks;
733+
o2::framework::Produces<o2::aod::StoredFSigmas> producedSigmas;
734+
o2::framework::Produces<o2::aod::StoredFSigmaMasks> producedSigmaMasks;
735+
o2::framework::Produces<o2::aod::StoredFSigmaPlus> producedSigmaPluses;
736+
o2::framework::Produces<o2::aod::StoredFSigmaPlusMasks> producedSigmaPlusMasks;
737737
};
738738

739739
class KinkBuilderDerivedToDerived
740740
{
741741
public:
742-
KinkBuilderDerivedToDerived() = default;
743-
~KinkBuilderDerivedToDerived() = default;
744-
745742
template <typename T>
746743
void init(T& config)
747744
{
748745
mLimitSigma = config.limitSigma.value;
749746
mLimitSigmaPlus = config.limitSigmaPlus.value;
750747

748+
if (mLimitSigma < 0 || mLimitSigmaPlus < 0) {
749+
LOG(fatal) << "Kink limits must be non-negative (got " << mLimitSigma << " and " << mLimitSigmaPlus << "). Breaking...";
750+
}
751751
if (mLimitSigma == 0 && mLimitSigmaPlus == 0) {
752752
LOG(fatal) << "Both sigma limit and sigmaplus limit are 0. Breaking...";
753753
}
@@ -756,27 +756,36 @@ class KinkBuilderDerivedToDerived
756756
template <typename T1, typename T2, typename T3, typename T4>
757757
bool collisionHasTooFewSigma(T1 const& col, T2 const& /*sigmaTable*/, T3& partitionSigma, T4& cache)
758758
{
759+
if (mLimitSigma == 0) { // sigmas disabled, cannot reject on them
760+
return false;
761+
}
759762
auto sigmaSlice = partitionSigma->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
760-
return sigmaSlice.size() < mLimitSigma;
763+
return sigmaSlice.size() < static_cast<int64_t>(mLimitSigma);
761764
}
762765

763766
template <typename T1, typename T2, typename T3, typename T4>
764767
bool collisionHasTooFewSigmaPlus(T1 const& col, T2 const& /*sigmaPlusTable*/, T3& partitionSigmaPlus, T4& cache)
765768
{
769+
if (mLimitSigmaPlus == 0) { // sigma pluses disabled, cannot reject on them
770+
return false;
771+
}
766772
auto sigmaPlusSlice = partitionSigmaPlus->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
767-
return sigmaPlusSlice.size() < mLimitSigmaPlus;
773+
return sigmaPlusSlice.size() < static_cast<int64_t>(mLimitSigmaPlus);
768774
}
769775

770776
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
771777
void processSigma(T1 const& col, T2 const& /*sigmaTable*/, T3 const& oldTrackTable, T4& partitionSigma, T5& trackBuilder, T6& cache, T7& newSigmaTable, T8& newTrackTable, T9& newCollisionTable)
772778
{
779+
if (mLimitSigma == 0) { // sigmas disabled
780+
return;
781+
}
782+
773783
auto sigmaSlice = partitionSigma->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
774784

775785
for (auto const& sigma : sigmaSlice) {
786+
auto chaDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(sigma.chaDauId(), oldTrackTable));
776787

777-
auto chaDaughter = oldTrackTable.rawIteratorAt(sigma.chaDauId() - oldTrackTable.offset());
778-
779-
int chaDaughterIndex = trackBuilder.getDaughterIndex(chaDaughter, newTrackTable, newCollisionTable);
788+
int64_t chaDaughterIndex = trackBuilder.getDaughterIndex(chaDaughter, newTrackTable, newCollisionTable);
780789

781790
newSigmaTable.producedSigmas(newCollisionTable.producedCollision.lastIndex(),
782791
sigma.signedPt(),
@@ -791,13 +800,16 @@ class KinkBuilderDerivedToDerived
791800
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
792801
void processSigmaPlus(T1 const& col, T2 const& /*sigmaPlusTable*/, T3 const& oldTrackTable, T4& partitionSigmaPlus, T5& trackBuilder, T6& cache, T7& newSigmaPlusTable, T8& newTrackTable, T9& newCollisionTable)
793802
{
803+
if (mLimitSigmaPlus == 0) { // sigma pluses disabled
804+
return;
805+
}
806+
794807
auto sigmaPlusSlice = partitionSigmaPlus->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
795808

796809
for (auto const& sigmaPlus : sigmaPlusSlice) {
810+
auto chaDaughter = oldTrackTable.rawIteratorAt(this->daughterRow(sigmaPlus.chaDauId(), oldTrackTable));
797811

798-
auto chaDaughter = oldTrackTable.rawIteratorAt(sigmaPlus.chaDauId() - oldTrackTable.offset());
799-
800-
int chaDaughterIndex = trackBuilder.getDaughterIndex(chaDaughter, newTrackTable, newCollisionTable);
812+
int64_t chaDaughterIndex = trackBuilder.getDaughterIndex(chaDaughter, newTrackTable, newCollisionTable);
801813

802814
newSigmaPlusTable.producedSigmaPluses(newCollisionTable.producedCollision.lastIndex(),
803815
sigmaPlus.signedPt(),
@@ -810,6 +822,20 @@ class KinkBuilderDerivedToDerived
810822
}
811823

812824
private:
825+
/// Translate a global daughter index into a row of the current track table frame.
826+
/// Aborts if the index does not fall inside the frame, which would otherwise
827+
/// silently produce an out-of-range iterator.
828+
template <typename T>
829+
int64_t daughterRow(int64_t daughterId, T const& trackTable) const
830+
{
831+
const int64_t row = daughterId - trackTable.offset();
832+
if (daughterId < 0 || row < 0 || row >= static_cast<int64_t>(trackTable.size())) {
833+
LOG(fatal) << "Daughter index " << daughterId << " out of range for track table (offset "
834+
<< trackTable.offset() << ", size " << trackTable.size() << "). Breaking...";
835+
}
836+
return row;
837+
}
838+
813839
int mLimitSigma = 0;
814840
int mLimitSigmaPlus = 0;
815841
};

PWGCF/Femto/Core/partitions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
(o2::aod::femtocollisions::posZ >= (selection).vtxZMin && o2::aod::femtocollisions::posZ <= (selection).vtxZMax) && \
2323
(o2::aod::femtocollisions::mult >= (selection).multMin && o2::aod::femtocollisions::mult <= (selection).multMax) && \
2424
(o2::aod::femtocollisions::cent >= (selection).centMin && o2::aod::femtocollisions::cent <= (selection).centMax) && \
25-
(o2::aod::femtocollisions::magField >= o2::framework::expressions::as<int8_t>((selection).magFieldMin)) && \
26-
(o2::aod::femtocollisions::magField <= o2::framework::expressions::as<int8_t>((selection).magFieldMax)) && \
25+
(o2::aod::femtocollisions::magField >= o2::framework::expressions::as<int8_t>((selection).magFieldMin) && \
26+
o2::aod::femtocollisions::magField <= o2::framework::expressions::as<int8_t>((selection).magFieldMax)) && \
2727
ncheckbit(o2::aod::femtocollisions::mask, (selection).collisionMask)
2828

2929
// macro for track momentum, i.e. ||q|*pT/q| * cosh(eta)

PWGCF/Femto/Core/trackBuilder.h

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,15 @@ struct ConfTrackTablesDerivedToDerived : o2::framework::ConfigurableGroup {
848848
class TrackBuilderDerivedToDerived
849849
{
850850
public:
851-
TrackBuilderDerivedToDerived() = default;
852-
~TrackBuilderDerivedToDerived() = default;
853-
854851
template <typename T>
855852
void init(T& config)
856853
{
857854
mLimitTrack1 = config.limitTrack1.value;
858855
mLimitTrack2 = config.limitTrack2.value;
859856

857+
if (mLimitTrack1 < 0 || mLimitTrack2 < 0) {
858+
LOG(fatal) << "Track limits must be non-negative (got " << mLimitTrack1 << " and " << mLimitTrack2 << "). Breaking...";
859+
}
860860
if (mLimitTrack1 == 0 && mLimitTrack2 == 0) {
861861
LOG(fatal) << "Both track limits are 0. Breaking...";
862862
}
@@ -867,13 +867,15 @@ class TrackBuilderDerivedToDerived
867867
{
868868
auto trackSlice1 = partitionTrack1->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
869869
auto trackSlice2 = partitionTrack2->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
870-
return trackSlice1.size() < mLimitTrack1 || trackSlice2.size() < mLimitTrack2;
870+
871+
const bool tooFew1 = (mLimitTrack1 > 0) && (trackSlice1.size() < static_cast<int64_t>(mLimitTrack1));
872+
const bool tooFew2 = (mLimitTrack2 > 0) && (trackSlice2.size() < static_cast<int64_t>(mLimitTrack2));
873+
return tooFew1 || tooFew2;
871874
}
872875

873876
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
874877
void processTracks(T1& col, T2& /*trackTable*/, T3& partitionTrack1, T4& partitionTrack2, T5& cache, T6& newTrackTable, T7& newCollisionTable)
875878
{
876-
877879
if (mLimitTrack1 > 0) {
878880
auto trackSlice1 = partitionTrack1->sliceByCached(o2::aod::femtobase::stored::fColId, col.globalIndex(), cache);
879881
for (auto const& track : trackSlice1) {
@@ -889,32 +891,34 @@ class TrackBuilderDerivedToDerived
889891
}
890892
}
891893

894+
/// Fill a track into the output table, or return its index if it was already filled.
895+
/// \return index of the track in the produced track table
892896
template <typename T1, typename T2, typename T3>
893-
void fillTrack(T1 const& track, T2& trackProducts, T3& collisionProducts)
897+
int64_t fillTrack(T1 const& track, T2& trackProducts, T3& collisionProducts)
894898
{
895-
if (indexMap.find(track.globalIndex()) == indexMap.end()) { // protect against double filling
896-
trackProducts.producedTracks(collisionProducts.producedCollision.lastIndex(),
897-
track.signedPt(),
898-
track.eta(),
899-
track.phi());
900-
trackProducts.producedTrackMasks(track.mask());
901-
if constexpr (utils::HasMass<T1>) {
902-
trackProducts.producedTrackMass(track.mass());
903-
}
904-
indexMap.emplace(track.globalIndex(), trackProducts.producedTracks.lastIndex());
899+
auto index = utils::getIndex(track.globalIndex(), indexMap);
900+
if (index) { // protect against double filling
901+
return index.value();
902+
}
903+
904+
trackProducts.producedTracks(collisionProducts.producedCollision.lastIndex(),
905+
track.signedPt(),
906+
track.eta(),
907+
track.phi());
908+
trackProducts.producedTrackMasks(track.mask());
909+
if constexpr (utils::HasMass<T1>) {
910+
trackProducts.producedTrackMass(track.mass());
905911
}
912+
913+
const int64_t idx = trackProducts.producedTracks.lastIndex();
914+
indexMap.emplace(track.globalIndex(), idx);
915+
return idx;
906916
}
907917

908918
template <typename T1, typename T2, typename T3>
909919
int64_t getDaughterIndex(const T1& daughter, T2& trackProducts, T3& collisionProducts)
910920
{
911-
auto result = utils::getIndex(daughter.globalIndex(), indexMap);
912-
if (result) {
913-
return result.value();
914-
}
915-
this->fillTrack(daughter, trackProducts, collisionProducts);
916-
int64_t idx = trackProducts.producedTracks.lastIndex();
917-
return idx;
921+
return this->fillTrack(daughter, trackProducts, collisionProducts);
918922
}
919923

920924
template <typename T>
@@ -928,7 +932,7 @@ class TrackBuilderDerivedToDerived
928932
int mLimitTrack1 = 0;
929933
int mLimitTrack2 = 0;
930934

931-
std::unordered_map<int64_t, int64_t> indexMap; // for mapping tracks to daughers of lambdas, cascades and resonances ...
935+
std::unordered_map<int64_t, int64_t> indexMap; // for mapping tracks to daughters of lambdas, cascades and resonances ...
932936
};
933937
} // namespace o2::analysis::femto::trackbuilder
934938

0 commit comments

Comments
 (0)