Skip to content

Commit f3d7f7a

Browse files
committed
Fix in CTPRunScalers::getRate
1 parent d4f11dc commit f3d7f7a

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

DataFormats/Detectors/CTP/src/Scalers.cxx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -674,35 +674,35 @@ std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex,
674674

675675
// then we can use binary search to find the right entries
676676
auto iter = std::lower_bound(mScalerRecordO2.begin(), mScalerRecordO2.end(), orbit, [&](CTPScalerRecordO2 const& a, uint32_t value) { return a.intRecord.orbit <= value; });
677-
auto nextindex = iter - mScalerRecordO2.begin(); // this points to the first index that has orbit greater or equal to given orbit
677+
auto nextindex = std::distance(mScalerRecordO2.begin(), iter); // this points to the first index that has orbit greater or equal to given orbit
678678

679679
auto calcRate = [&](auto index1, auto index2) -> double {
680-
auto next = &mScalerRecordO2[index2];
681-
auto prev = &mScalerRecordO2[index1];
682-
auto timedelta = (next->intRecord.orbit - prev->intRecord.orbit) * 88.e-6; // converts orbits into time
680+
const auto& snext = mScalerRecordO2[index2];
681+
const auto& sprev = mScalerRecordO2[index1];
682+
auto timedelta = (snext.intRecord.orbit - sprev.intRecord.orbit) * 88.e-6; // converts orbits into time
683683
if (type < 7) {
684-
auto s0 = &(prev->scalers[classindex]); // type CTPScalerO2*
685-
auto s1 = &(next->scalers[classindex]);
684+
const auto& s0 = sprev.scalers[classindex]; // type CTPScalerO2*
685+
const auto& s1 = snext.scalers[classindex];
686686
switch (type) {
687687
case 1:
688-
return (s1->lmBefore - s0->lmBefore) / timedelta;
688+
return (s1.lmBefore - s0.lmBefore) / timedelta;
689689
case 2:
690-
return (s1->lmAfter - s0->lmAfter) / timedelta;
690+
return (s1.lmAfter - s0.lmAfter) / timedelta;
691691
case 3:
692-
return (s1->l0Before - s0->l0Before) / timedelta;
692+
return (s1.l0Before - s0.l0Before) / timedelta;
693693
case 4:
694-
return (s1->l0After - s0->l0After) / timedelta;
694+
return (s1.l0After - s0.l0After) / timedelta;
695695
case 5:
696-
return (s1->l1Before - s0->l1Before) / timedelta;
696+
return (s1.l1Before - s0.l1Before) / timedelta;
697697
case 6:
698-
return (s1->l1After - s0->l1After) / timedelta;
698+
return (s1.l1After - s0.l1After) / timedelta;
699699
default:
700700
LOG(error) << "Wrong type:" << type;
701701
return -1; // wrong type
702702
}
703703
} else if (type == 7) {
704-
auto s0 = &(prev->scalersInps[classindex]); // type CTPScalerO2*
705-
auto s1 = &(next->scalersInps[classindex]);
704+
auto s0 = sprev.scalersInps[classindex]; // type CTPScalerO2*
705+
auto s1 = snext.scalersInps[classindex];
706706
return (s1 - s0) / timedelta;
707707
} else {
708708
LOG(error) << "Wrong type:" << type;
@@ -738,37 +738,37 @@ std::pair<double, double> CTPRunScalers::getRateGivenT(double timestamp, int cla
738738
// this points to the first index that has orbit greater to given orbit;
739739
// If this is 0, it means that the above condition was false from the beginning, basically saying that the timestamp is below any of the ScalerRecords' orbits.
740740
// If this is mScalerRecordO2.size(), it means mScalerRecordO2.end() was returned, condition was met throughout all ScalerRecords, basically saying the timestamp is above any of the ScalarRecordss orbits.
741-
auto nextindex = iter - mScalerRecordO2.begin();
741+
auto nextindex = std::distance(mScalerRecordO2.begin(), iter);
742742

743743
auto calcRate = [&](auto index1, auto index2) -> double {
744-
auto next = &mScalerRecordO2[index2];
745-
auto prev = &mScalerRecordO2[index1];
746-
auto timedelta = (next->intRecord.orbit - prev->intRecord.orbit) * 88.e-6; // converts orbits into time
744+
const auto& snext = mScalerRecordO2[index2];
745+
const auto& sprev = mScalerRecordO2[index1];
746+
auto timedelta = (snext.intRecord.orbit - sprev.intRecord.orbit) * 88.e-6; // converts orbits into time
747747
// std::cout << "timedelta:" << timedelta << std::endl;
748748
if (type < 7) {
749-
auto s0 = &(prev->scalers[classindex]); // type CTPScalerO2*
750-
auto s1 = &(next->scalers[classindex]);
749+
const auto& s0 = sprev.scalers[classindex]; // type CTPScalerO2*
750+
const auto& s1 = snext.scalers[classindex];
751751
switch (type) {
752752
case 1:
753-
return (s1->lmBefore - s0->lmBefore) / timedelta;
753+
return (s1.lmBefore - s0.lmBefore) / timedelta;
754754
case 2:
755-
return (s1->lmAfter - s0->lmAfter) / timedelta;
755+
return (s1.lmAfter - s0.lmAfter) / timedelta;
756756
case 3:
757-
return (s1->l0Before - s0->l0Before) / timedelta;
757+
return (s1.l0Before - s0.l0Before) / timedelta;
758758
case 4:
759-
return (s1->l0After - s0->l0After) / timedelta;
759+
return (s1.l0After - s0.l0After) / timedelta;
760760
case 5:
761-
return (s1->l1Before - s0->l1Before) / timedelta;
761+
return (s1.l1Before - s0.l1Before) / timedelta;
762762
case 6:
763-
return (s1->l1After - s0->l1After) / timedelta;
763+
return (s1.l1After - s0.l1After) / timedelta;
764764
default:
765765
LOG(error) << "Wrong type:" << type;
766766
return -1; // wrong type
767767
}
768768
} else if (type == 7) {
769769
// LOG(info) << "doing input:";
770-
auto s0 = prev->scalersInps[classindex]; // type CTPScalerO2*
771-
auto s1 = next->scalersInps[classindex];
770+
auto s0 = sprev.scalersInps[classindex]; // type CTPScalerO2*
771+
auto s1 = snext.scalersInps[classindex];
772772
return (s1 - s0) / timedelta;
773773
} else {
774774
LOG(error) << "Wrong type:" << type;

0 commit comments

Comments
 (0)