@@ -793,15 +793,15 @@ struct CascadeBuilderDerivedToDerivedProducts : o2::framework::ProducesGroup {
793793class 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};
0 commit comments