19#include <fairlogger/Logger.h>
29 reader.
init(fromFile);
30 writer.
init(toFile, toTreeName);
33 std::unique_ptr<ClusterNative[]> clusterBuffer;
39 LOG(info) <<
"converting entry " <<
entry;
43 LOG(info) <<
"added " <<
result <<
" clusters to index";
45 LOG(error) <<
"filling of clusters index failed with " <<
result;
49 LOG(info) <<
"wrote " <<
result <<
" clusters to tree";
52 LOG(error) <<
"filling of tree failed with " <<
result;
55 LOG(info) <<
"... done, converted " <<
nClusters <<
" clusters";
67 LOG(error) <<
"Received two containers for the same sector / row";
68 return std::unique_ptr<ClusterNativeAccess>();
82 for (
unsigned int j = 0;
j <
clusters[
i].clusters.size();
j++) {
83 for (
auto const&
label : (*mcTruth)[
i].getLabels(
j)) {
89 return (std::move(
retVal));
92ClusterNativeHelper::Reader::~Reader()
97ClusterNativeHelper::Reader::Reader()
99 memset(&mSectorRawSize, 0,
sizeof(mSectorRawSize));
100 memset(&mSectorRaw, 0,
sizeof(mSectorRaw));
103void ClusterNativeHelper::Reader::init(
const char*
filename,
const char* treename)
105 if (treename !=
nullptr && treename[0] != 0) {
106 mTreeName = treename;
112 mTree =
reinterpret_cast<TTree*
>(mFile->GetObjectUnchecked(mTreeName.c_str()));
114 LOG(error) <<
"can not find tree " << mTreeName <<
" in file " <<
filename;
118 const bool singleBranch = mTree->GetBranch(mDataBranchName.data());
120 size_t nofDataBranches = 0;
121 size_t nofMCBranches = 0;
122 for (
size_t sector = 0; sector <
NSectors; ++sector) {
123 auto branchname = singleBranch ? mDataBranchName : mDataBranchName +
"_" +
std::to_string(sector);
124 TBranch* branch = mTree->GetBranch(branchname.c_str());
126 TBranch* sizebranch = mTree->GetBranch((branchname +
"Size").c_str());
128 branch->SetAddress(&mSectorRaw[sector]);
129 sizebranch->SetAddress(&mSectorRawSize[sector]);
132 LOG(error) <<
"can not find corresponding 'Size' branch for data branch " << branchname <<
", skipping it";
135 branchname = singleBranch ? mMCBranchName : mMCBranchName +
"_" +
std::to_string(sector);
136 branch = mTree->GetBranch(branchname.c_str());
138 branch->SetAddress(&mSectorMCPtr[sector]);
146 LOG(info) <<
"reading " << nofDataBranches <<
" data branch(es) and " << nofMCBranches <<
" mc branch(es)";
149void ClusterNativeHelper::Reader::read(
size_t entry)
151 if (
entry >= getTreeSize()) {
155 mTree->GetEntry(
entry);
158void ClusterNativeHelper::Reader::clear()
160 memset(&mSectorRawSize, 0,
sizeof(mSectorRawSize));
161 for (
auto data : mSectorRaw) {
166 memset(&mSectorRaw, 0,
sizeof(mSectorRaw));
172 std::vector<gsl::span<const char>> clustersTPC;
173 std::vector<ConstMCLabelContainer> constMCLabelContainers;
174 std::vector<ConstMCLabelContainerView> constMCLabelContainerViews;
177 if (mSectorRaw[
index]) {
179 LOG(error) <<
"inconsistent raw size for sector " <<
index <<
": " << mSectorRaw[
index]->size() <<
" v.s. " << mSectorRawSize[
index];
180 mSectorRaw[
index]->clear();
182 clustersTPC.emplace_back(mSectorRaw[
index]->
data(), mSectorRawSize[
index]);
185 if (mSectorMCPtr[
index]) {
186 auto& view = constMCLabelContainers.emplace_back();
187 mSectorMCPtr[
index]->copyandflatten(view);
188 constMCLabelContainerViews.emplace_back(view);
192 int result = fillIndex(clusterIndex, clusterBuffer, mcBuffer, clustersTPC, constMCLabelContainerViews);
196int ClusterNativeHelper::Reader::parseSector(
const char*
buffer,
size_t size, gsl::span<ConstMCLabelContainerView const>
const& mcinput,
ClusterNativeAccess& clusterIndex,
203 auto mcIterator = mcinput.begin();
206 size_t numberOfClusters = 0;
208 int nSectorClusters = 0;
215 throw std::runtime_error(
"inconsistent buffer size");
221 if (nSectorClusters > 0) {
222 if (mcIterator != mcinput.end()) {
223 clustersMCTruth[
i] = &(*mcIterator);
225 if (mcIterator != mcinput.end()) {
226 throw std::runtime_error(
"can only have one MCLabel block per sector");
232 return numberOfClusters;
242 mFile.reset(TFile::Open(
filename,
"RECREATE"));
246 mTree = std::make_unique<TTree>(treename, treename);
251 mTree->Branch(
"event", &mEvent,
"Event/I");
252 mTree->Branch(
"NativeClusters",
"std::vector<o2::tpc::ClusterNativeHelper::TreeWriter::BranchData>", &mStore);
254 mStoreClusters.clear();
263 for (
size_t sector = 0; sector <
MAXSECTOR; ++sector) {
266 if (
result >= 0 && locres >= 0) {
284 std::fill(mStoreClusters.begin(), mStoreClusters.end(),
BranchData{sector, padrow});
Helper class to read the binary format of TPC ClusterNative.
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