Skip to content

Commit a740637

Browse files
wiechuladavidrohr
authored andcommitted
adapt file reading part to new data structures for clusters and MC
1 parent d6707f3 commit a740637

2 files changed

Lines changed: 31 additions & 15 deletions

File tree

DataFormats/Detectors/TPC/include/DataFormatsTPC/ClusterNativeHelper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "DataFormatsTPC/ClusterNative.h"
1919
#include "DataFormatsTPC/ClusterGroupAttribute.h"
2020
#include "DataFormatsTPC/Constants.h"
21+
#include "SimulationDataFormat/IOMCTruthContainerView.h"
2122
#include "SimulationDataFormat/ConstMCTruthContainer.h"
2223
#include "SimulationDataFormat/MCCompLabel.h"
2324
#include <gsl/gsl>
@@ -132,6 +133,7 @@ class ClusterNativeHelper
132133
{
133134
public:
134135
using MCLabelContainer = o2::dataformats::MCLabelContainer;
136+
using ConstMCLabelContainer = o2::dataformats::ConstMCLabelContainer;
135137
using ConstMCLabelContainerView = o2::dataformats::ConstMCLabelContainerView;
136138
using ConstMCLabelContainerViewWithBuffer = ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer;
137139

@@ -279,10 +281,8 @@ class ClusterNativeHelper
279281
std::array<std::vector<char>*, NSectors> mSectorRaw = {nullptr};
280282
/// the array of raw buffers
281283
std::array<size_t, NSectors> mSectorRawSize = {0};
282-
/// the array of MC label containers
283-
std::array<std::vector<MCLabelContainer>, NSectors> mSectorMC;
284284
/// pointers on the elements of array of MC label containers
285-
std::array<std::vector<MCLabelContainer>*, NSectors> mSectorMCPtr = {nullptr};
285+
std::array<dataformats::IOMCTruthContainerView*, NSectors> mSectorMCPtr{};
286286
};
287287

288288
/// @class TreeWriter

DataFormats/Detectors/TPC/src/ClusterNativeHelper.cxx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ void ClusterNativeHelper::Reader::init(const char* filename, const char* treenam
114114
LOG(ERROR) << "can not find tree " << mTreeName << " in file " << filename;
115115
return;
116116
}
117+
118+
const bool singleBranch = mTree->GetBranch(mDataBranchName.data());
119+
117120
size_t nofDataBranches = 0;
118121
size_t nofMCBranches = 0;
119122
for (size_t sector = 0; sector < NSectors; ++sector) {
120-
auto branchname = mDataBranchName + "_" + std::to_string(sector);
123+
auto branchname = singleBranch ? mDataBranchName : mDataBranchName + "_" + std::to_string(sector);
121124
TBranch* branch = mTree->GetBranch(branchname.c_str());
122125
if (branch) {
123126
TBranch* sizebranch = mTree->GetBranch((branchname + "Size").c_str());
@@ -129,13 +132,16 @@ void ClusterNativeHelper::Reader::init(const char* filename, const char* treenam
129132
LOG(ERROR) << "can not find corresponding 'Size' branch for data branch " << branchname << ", skipping it";
130133
}
131134
}
132-
branchname = mMCBranchName + "_" + std::to_string(sector);
135+
branchname = singleBranch ? mMCBranchName : mMCBranchName + "_" + std::to_string(sector);
133136
branch = mTree->GetBranch(branchname.c_str());
134137
if (branch) {
135-
mSectorMCPtr[sector] = &mSectorMC[sector];
136138
branch->SetAddress(&mSectorMCPtr[sector]);
137139
++nofMCBranches;
138140
}
141+
142+
if (singleBranch) {
143+
break;
144+
}
139145
}
140146
LOG(INFO) << "reading " << nofDataBranches << " data branch(es) and " << nofMCBranches << " mc branch(es)";
141147
}
@@ -163,18 +169,28 @@ void ClusterNativeHelper::Reader::clear()
163169
int ClusterNativeHelper::Reader::fillIndex(ClusterNativeAccess& clusterIndex, std::unique_ptr<ClusterNative[]>& clusterBuffer,
164170
ConstMCLabelContainerViewWithBuffer& mcBuffer)
165171
{
172+
std::vector<gsl::span<const char>> clustersTPC;
173+
std::vector<ConstMCLabelContainer> constMCLabelContainers;
174+
std::vector<ConstMCLabelContainerView> constMCLabelContainerViews;
175+
166176
for (size_t index = 0; index < mSectorRaw.size(); ++index) {
167-
if (mSectorRaw[index] && mSectorRaw[index]->size() != mSectorRawSize[index]) {
168-
LOG(ERROR) << "inconsistent raw size for sector " << index << ": " << mSectorRaw[index]->size() << " v.s. " << mSectorRawSize[index];
169-
mSectorRaw[index]->clear();
177+
if (mSectorRaw[index]) {
178+
if (mSectorRaw[index]->size() != mSectorRawSize[index]) {
179+
LOG(ERROR) << "inconsistent raw size for sector " << index << ": " << mSectorRaw[index]->size() << " v.s. " << mSectorRawSize[index];
180+
mSectorRaw[index]->clear();
181+
} else {
182+
clustersTPC.emplace_back(mSectorRaw[index]->data(), mSectorRawSize[index]);
183+
}
184+
}
185+
if (mSectorMCPtr[index]) {
186+
auto& view = constMCLabelContainers.emplace_back();
187+
mSectorMCPtr[index]->copyandflatten(view);
188+
constMCLabelContainerViews.emplace_back(view);
170189
}
171190
}
172-
// after changing this ClusterNative transport format, this functionality needs
173-
// to be adapted
174-
throw std::runtime_error("code path currently not supported");
175-
//int result = fillIndex(clusterIndex, clusterBuffer, mcBuffer, mSectorRaw, mSectorMC, [](auto&) { return true; });
176-
//return result;
177-
return 0;
191+
192+
int result = fillIndex(clusterIndex, clusterBuffer, mcBuffer, clustersTPC, constMCLabelContainerViews, [](auto&) { return true; });
193+
return result;
178194
}
179195

180196
int ClusterNativeHelper::Reader::parseSector(const char* buffer, size_t size, gsl::span<ConstMCLabelContainerView const> const& mcinput, ClusterNativeAccess& clusterIndex,

0 commit comments

Comments
 (0)