Skip to content

Commit 2bf44aa

Browse files
authored
Merge c8f7f4e into sapling-pr-archive-ktf
2 parents f84896b + c8f7f4e commit 2bf44aa

39 files changed

+1701
-984
lines changed

Detectors/Base/include/DetectorsBase/MatLayerCylSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class MatLayerCylSet : public o2::gpu::FlatObject
8787
void flatten();
8888

8989
MatLayerCyl& getLayer(int i) { return get()->mLayers[i]; }
90-
MatLayerCylSet* extractCopy(float rmin, float rmax, float tol = 1e-3) const;
90+
MatLayerCylSet* extractCopy(float rmin, float rmax, float tol = 1e-3, const MatLayerCylSet* toAdd = nullptr) const;
9191
void finalizeStructures();
9292

9393
#endif // !GPUCA_ALIGPUCODE

Detectors/Base/src/MatLayerCylSet.cxx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,12 @@ void MatLayerCylSet::fixPointers(char* oldPtr, char* newPtr, bool newPtrValid)
608608

609609
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
610610

611-
MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolerance) const
611+
MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolerance, const MatLayerCylSet* addTo) const
612612
{
613+
// extract layers in the covering rmin-rmax range. If addTo is provided, simply substitute its layers by those from this
614+
if (addTo && addTo->getNLayers() != getNLayers()) {
615+
LOGP(fatal, "addTo has {} layers, this has {}", addTo->getNLayers(), getNLayers());
616+
}
613617
Ray ray(std::max(getRMin(), rmin), 0., 0., std::min(getRMax(), rmax), 0., 0.);
614618
short lmin, lmax;
615619
if (!getLayersRange(ray, lmin, lmax)) {
@@ -618,23 +622,37 @@ MatLayerCylSet* MatLayerCylSet::extractCopy(float rmin, float rmax, float tolera
618622
}
619623
LOGP(info, "Will extract layers {}:{} (out of {} layers) for {} < r < {}", lmin, lmax, getNLayers(), rmin, rmax);
620624
MatLayerCylSet* copy = new MatLayerCylSet();
621-
int lrCount = 0;
622-
for (int il = lmin; il <= lmax; il++) {
623-
const auto& lr = getLayer(il);
625+
int lrCount = 0, lrCounOld = 0, lrCountTot = 0;
626+
auto addLr = [copy, &lrCountTot](const MatLayerCyl& lr) {
624627
float drphi = lr.getDPhi() * (lr.getRMin() + lr.getRMax()) / 2. * 0.999;
625628
copy->addLayer(lr.getRMin(), lr.getRMax(), lr.getZMax(), lr.getDZ(), drphi);
626-
auto& lrNew = copy->getLayer(lrCount);
629+
auto& lrNew = copy->getLayer(lrCountTot++);
627630
for (int iz = 0; iz < lrNew.getNZBins(); iz++) {
628631
for (int ip = 0; ip < lrNew.getNPhiBins(); ip++) {
629632
lrNew.getCellPhiBin(ip, iz).set(lr.getCellPhiBin(ip, iz));
630633
}
631634
}
635+
};
636+
if (addTo) {
637+
for (int il = 0; il < lmin; il++) {
638+
addLr(addTo->getLayer(il));
639+
lrCounOld++;
640+
}
641+
}
642+
for (int il = lmin; il <= lmax; il++) {
643+
addLr(getLayer(il));
632644
lrCount++;
633645
}
634-
646+
if (addTo) {
647+
for (int il = lmax + 1; il < getNLayers(); il++) {
648+
addLr(addTo->getLayer(il));
649+
lrCounOld++;
650+
}
651+
}
635652
copy->finalizeStructures();
636653
copy->optimizePhiSlices(tolerance);
637654
copy->flatten();
655+
LOGP(info, "Added layers {}:{} for {}<r<{} {}", lmin, lmax, rmin, rmax, fmt::format(", {} layers were transferred from additional set", lrCounOld));
638656
return copy;
639657
}
640658

Detectors/TPC/base/include/TPCBase/CalArray.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#include <boost/format.hpp>
2727
#endif
2828

29+
#ifdef NDEBUG
30+
#undef NDEBUG
31+
#include <cassert>
32+
#endif
33+
2934
namespace o2
3035
{
3136
namespace tpc
@@ -93,7 +98,11 @@ class CalArray
9398
int getPadSubsetNumber() const { return mPadSubsetNumber; }
9499

95100
void setValue(const size_t channel, const T& value) { mData[channel] = value; }
96-
const T getValue(const size_t channel) const { return mData[channel]; }
101+
const T getValue(const size_t channel) const
102+
{
103+
assert(channel < mData.size());
104+
return mData[channel];
105+
}
97106

98107
void setValue(const size_t row, const size_t pad, const T& value);
99108
const T getValue(const size_t row, const size_t pad) const;

Detectors/TPC/base/include/TPCBase/CalDet.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
#include "Rtypes.h"
3131
#endif
3232

33+
#ifndef NDEBUG
34+
#undef NDEBUG
35+
// always enable assert
36+
#include <cassert>
37+
#endif
38+
3339
namespace o2
3440
{
3541
namespace tpc
@@ -211,7 +217,26 @@ inline const T CalDet<T>::getValue(const ROC roc, const size_t row, const size_t
211217
}
212218
case PadSubset::Region: {
213219
const auto globalRow = roc.isOROC() ? mappedRow + mapper.getNumberOfRowsROC(ROC(0)) : mappedRow;
214-
return mData[Mapper::REGION[globalRow] + roc.getSector() * Mapper::NREGIONS].getValue(Mapper::OFFSETCRUGLOBAL[globalRow] + mappedPad);
220+
const auto dataRow = Mapper::REGION[globalRow] + roc.getSector() * Mapper::NREGIONS;
221+
const auto index = Mapper::OFFSETCRUGLOBAL[globalRow] + mappedPad;
222+
assert(dataRow < mData.size());
223+
if (index >= mData[dataRow].getData().size()) {
224+
// S. Wenzel: We shouldn't come here but we do. For instance for CalDet calibrations loaded from
225+
// creator.loadIDCPadFlags(1731274461770);
226+
227+
// In this case there is an index overflow, leading to invalid reads and potentially a segfault.
228+
// To increase stability, for now returning a trivial answer. This can be removed once either the algorithm
229+
// or the calibration data has been fixed.
230+
#ifndef GPUCA_ALIGPUCODE // hide from GPU standalone compilation
231+
static bool printMsg = true;
232+
if (printMsg) {
233+
LOG(error) << "Out of bound access in TPC CalDet ROC " << roc << " row " << row << " pad " << pad << " (no more messages printed)";
234+
}
235+
printMsg = false;
236+
#endif
237+
return T{};
238+
}
239+
return mData[dataRow].getValue(index);
215240
break;
216241
}
217242
}

Detectors/TPC/base/src/TPCFlagsMemberCustomStreamer.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void MemberVectorPadFlagsStreamer(TBuffer& R__b, void* objp, int n)
3939
}
4040
std::vector<o2::tpc::PadFlags>* obj = static_cast<std::vector<o2::tpc::PadFlags>*>(objp);
4141
if (R__b.IsReading()) {
42+
obj->clear();
4243
std::vector<int> R__stl;
4344
R__stl.clear();
4445
int R__n;
@@ -50,7 +51,8 @@ void MemberVectorPadFlagsStreamer(TBuffer& R__b, void* objp, int n)
5051
R__stl.push_back(readtemp);
5152
}
5253
auto data = reinterpret_cast<unsigned short*>(R__stl.data());
53-
for (int i = 0; i < R__n; ++i) {
54+
constexpr size_t bloatfactor = sizeof(int) / sizeof(o2::tpc::PadFlags);
55+
for (int i = 0; i < bloatfactor * R__n; ++i) {
5456
obj->push_back(static_cast<o2::tpc::PadFlags>(data[i]));
5557
}
5658
} else {
@@ -63,17 +65,22 @@ void MemberVectorPadFlagsStreamer(TBuffer& R__b, void* objp, int n)
6365
}
6466

6567
// register the streamer via static global initialization (on library load)
68+
// the streamer is only correct in combination with new ROOT
69+
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 33, 00)
6670
namespace ROOT
6771
{
6872
static __attribute__((used)) int _R__dummyStreamer_3 =
6973
([]() {
7074
auto cl = TClass::GetClass<o2::tpc::CalArray<o2::tpc::PadFlags>>();
7175
if (cl) {
72-
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
76+
if (!getenv("TPC_PADFLAGS_STREAMER_OFF")) {
77+
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
78+
}
7379
} else {
7480
// we should never come here ... and if we do we should assert/fail
7581
assert(false);
7682
}
7783
return 0;
7884
})();
7985
} // namespace ROOT
86+
#endif

Detectors/TPC/base/test/testTPCCalDet.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "TPCBase/CalDet.h"
2525
#include "TFile.h"
2626
#include "Framework/TypeTraits.h"
27+
#include "TPCBase/DeadChannelMapCreator.h"
2728

2829
namespace o2::tpc
2930
{
@@ -344,4 +345,12 @@ BOOST_AUTO_TEST_CASE(CalDetTypeTest)
344345
BOOST_CHECK(testDict == true);
345346
}
346347

348+
BOOST_AUTO_TEST_CASE(CalDetStreamerTest)
349+
{
350+
// simple code executing the TPC IDCPadFlags loading in a standalone env --> easy to valgrind
351+
o2::tpc::DeadChannelMapCreator creator{};
352+
creator.init("https://alice-ccdb.cern.ch");
353+
creator.loadIDCPadFlags(1731274461770);
354+
}
355+
347356
} // namespace o2::tpc

Framework/AnalysisSupport/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ if(TARGET JAliEn::JAliEn)
1616
set(EXTRA_TARGETS XRootD::Client JAliEn::JAliEn)
1717
endif()
1818

19+
o2_add_library(FrameworkOnDemandTablesSupport
20+
SOURCES src/OnDemandPlugin.cxx
21+
src/AODReaderHelpers.cxx
22+
PRIVATE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/src
23+
PUBLIC_LINK_LIBRARIES O2::Framework ${EXTRA_TARGETS})
24+
1925
o2_add_library(FrameworkAnalysisSupport
2026
SOURCES src/Plugin.cxx
2127
src/DataInputDirector.cxx

0 commit comments

Comments
 (0)