20#include <fairlogger/Logger.h>
30 reader.
init(fromFile);
31 writer.
init(toFile, toTreeName);
34 std::unique_ptr<ClusterNative[]> clusterBuffer;
40 LOG(info) <<
"converting entry " <<
entry;
44 LOG(info) <<
"added " <<
result <<
" clusters to index";
46 LOG(error) <<
"filling of clusters index failed with " <<
result;
50 LOG(info) <<
"wrote " <<
result <<
" clusters to tree";
53 LOG(error) <<
"filling of tree failed with " <<
result;
56 LOG(info) <<
"... done, converted " <<
nClusters <<
" clusters";
68 LOG(error) <<
"Received two containers for the same sector / row";
69 return std::unique_ptr<ClusterNativeAccess>();
83 for (
unsigned int j = 0;
j <
clusters[
i].clusters.size();
j++) {
84 for (
auto const&
label : (*mcTruth)[
i].getLabels(
j)) {
90 return (std::move(
retVal));
93ClusterNativeHelper::Reader::~Reader()
98ClusterNativeHelper::Reader::Reader()
100 memset(&mSectorRawSize, 0,
sizeof(mSectorRawSize));
101 memset(&mSectorRaw, 0,
sizeof(mSectorRaw));
104void ClusterNativeHelper::Reader::init(
const char*
filename,
const char* treename)
106 if (treename !=
nullptr && treename[0] != 0) {
107 mTreeName = treename;
113 mTree =
reinterpret_cast<TTree*
>(mFile->GetObjectUnchecked(mTreeName.c_str()));
115 LOG(error) <<
"can not find tree " << mTreeName <<
" in file " <<
filename;
119 const bool singleBranch = mTree->GetBranch(mDataBranchName.data());
121 size_t nofDataBranches = 0;
122 size_t nofMCBranches = 0;
123 for (
size_t sector = 0; sector <
NSectors; ++sector) {
124 auto branchname = singleBranch ? mDataBranchName : mDataBranchName +
"_" +
std::to_string(sector);
125 TBranch* branch = mTree->GetBranch(branchname.c_str());
127 TBranch* sizebranch = mTree->GetBranch((branchname +
"Size").c_str());
129 branch->SetAddress(&mSectorRaw[sector]);
130 sizebranch->SetAddress(&mSectorRawSize[sector]);
133 LOG(error) <<
"can not find corresponding 'Size' branch for data branch " << branchname <<
", skipping it";
136 branchname = singleBranch ? mMCBranchName : mMCBranchName +
"_" +
std::to_string(sector);
137 branch = mTree->GetBranch(branchname.c_str());
139 branch->SetAddress(&mSectorMCPtr[sector]);
147 LOG(info) <<
"reading " << nofDataBranches <<
" data branch(es) and " << nofMCBranches <<
" mc branch(es)";
150void ClusterNativeHelper::Reader::read(
size_t entry)
152 if (
entry >= getTreeSize()) {
156 mTree->GetEntry(
entry);
159void ClusterNativeHelper::Reader::clear()
161 memset(&mSectorRawSize, 0,
sizeof(mSectorRawSize));
162 for (
auto data : mSectorRaw) {
167 memset(&mSectorRaw, 0,
sizeof(mSectorRaw));
173 std::vector<gsl::span<const char>> clustersTPC;
174 std::vector<ConstMCLabelContainer> constMCLabelContainers;
175 std::vector<ConstMCLabelContainerView> constMCLabelContainerViews;
178 if (mSectorRaw[
index]) {
180 LOG(error) <<
"inconsistent raw size for sector " <<
index <<
": " << mSectorRaw[
index]->size() <<
" v.s. " << mSectorRawSize[
index];
181 mSectorRaw[
index]->clear();
183 clustersTPC.emplace_back(mSectorRaw[
index]->
data(), mSectorRawSize[
index]);
186 if (mSectorMCPtr[
index]) {
187 auto& view = constMCLabelContainers.emplace_back();
188 mSectorMCPtr[
index]->copyandflatten(view);
189 constMCLabelContainerViews.emplace_back(view);
193 int result = fillIndex(clusterIndex, clusterBuffer, mcBuffer, clustersTPC, constMCLabelContainerViews);
197int ClusterNativeHelper::Reader::parseSector(
const char*
buffer,
size_t size, gsl::span<ConstMCLabelContainerView const>
const& mcinput,
ClusterNativeAccess& clusterIndex,
204 auto mcIterator = mcinput.begin();
207 size_t numberOfClusters = 0;
209 int nSectorClusters = 0;
216 throw std::runtime_error(
"inconsistent buffer size");
222 if (nSectorClusters > 0) {
223 if (mcIterator != mcinput.end()) {
224 clustersMCTruth[
i] = &(*mcIterator);
226 if (mcIterator != mcinput.end()) {
227 throw std::runtime_error(
"can only have one MCLabel block per sector");
233 return numberOfClusters;
243 mFile.reset(TFile::Open(
filename,
"RECREATE"));
247 mTree = std::make_unique<TTree>(treename, treename);
252 mTree->Branch(
"event", &mEvent,
"Event/I");
253 mTree->Branch(
"NativeClusters",
"std::vector<o2::tpc::ClusterNativeHelper::TreeWriter::BranchData>", &mStore);
255 mStoreClusters.clear();
264 for (
size_t sector = 0; sector <
MAXSECTOR; ++sector) {
267 if (
result >= 0 && locres >= 0) {
285 std::fill(mStoreClusters.begin(), mStoreClusters.end(),
BranchData{sector, padrow});
Helper class to read the binary format of TPC ClusterNative.
Utilities for parsing of data sequences.
A reader class for the raw cluster native data.
size_t getTreeSize() const
int fillIndex(ClusterNativeAccess &clusterIndex, std::unique_ptr< ClusterNative[]> &clusterBuffer, ConstMCLabelContainerViewWithBuffer &mcBuffer)
void init(const char *filename, const char *treename=nullptr)
Utility to write native cluster format to a ROOT tree.
void init(const char *filename, const char *treename)
int fillFrom(ClusterNativeAccess const &clusterIndex)
fill tree from the full index of cluster arrays
static std::unique_ptr< ClusterNativeAccess > createClusterNativeIndex(std::unique_ptr< ClusterNative[]> &buffer, std::vector< ClusterNativeContainer > &clusters, MCLabelContainer *bufferMC=nullptr, std::vector< MCLabelContainer > *mcTruth=nullptr)
static constexpr unsigned int NSectors
ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer ConstMCLabelContainerViewWithBuffer
static void convert(const char *fromFile, const char *toFile, const char *toTreeName="tpcnative")
GLuint GLsizei const GLchar * label
constexpr int MAXGLOBALPADROW
Global TPC definitions and constants.
std::string to_string(gsl::span< T, Size > span)
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters