17#ifndef CLUSTERNATIVEHELPER_H
18#define CLUSTERNATIVEHELPER_H
150 static void convert(
const char* fromFile,
const char* toFile,
const char* toTreeName =
"tpcnative");
157 std::vector<MCLabelContainer>* mcTruth =
nullptr);
162 template <
typename AttributeT>
169 const auto& groupAttribute = *
reinterpret_cast<AttributeT*
>(
buffer);
172 clusterIndex.
clusters[groupAttribute.sector][groupAttribute.globalPadRow] = ptrClusters;
173 clusterIndex.
nClusters[groupAttribute.sector][groupAttribute.globalPadRow] = nofClusters;
186 void init(
const char*
filename,
const char* treename =
nullptr);
189 return (mTree ? mTree->GetEntries() : 0);
221 template <
typename DataArrayType,
typename MCArrayType>
225 unsigned long sectorMask = 0xFFFFFFFFF);
227 template <
typename DataArrayType>
230 DataArrayType& inputs,
unsigned long sectorMask = 0xFFFFFFFFF)
234 std::vector<std::unique_ptr<MCLabelContainer>> dummy;
237 return fillIndex(clusterIndex, clusterBuffer, mcBuffer, inputs, dummy, sectorMask);
251 template <
typename ContainerT>
252 static int parseSector(ContainerT
const cont, gsl::span<ConstMCLabelContainerView const>
const& mcinput,
256 using T =
typename std::remove_pointer<ContainerT>::type;
257 static_assert(
sizeof(
typename T::value_type) == 1,
"raw container must be byte-type");
258 T
const* container =
nullptr;
259 if constexpr (std::is_pointer<ContainerT>::value) {
260 if (cont ==
nullptr) {
267 return parseSector(container->data(), container->size(), mcinput, clusterIndex, clustersMCTruth);
272 std::string mTreeName =
"tpcrec";
274 std::string mDataBranchName =
"TPCClusterNative";
276 std::string mMCBranchName =
"TPCClusterNativeMCTruth";
279 std::unique_ptr<TFile> mFile;
281 TTree* mTree =
nullptr;
283 std::array<std::vector<char>*,
NSectors> mSectorRaw = {
nullptr};
285 std::array<size_t, NSectors> mSectorRawSize = {0};
287 std::array<dataformats::IOMCTruthContainerView*, NSectors> mSectorMCPtr{};
310 time = rhs.getTime();
316 flags = rhs.getFlags();
332 std::unique_ptr<TFile> mFile;
334 std::unique_ptr<TTree> mTree;
336 std::vector<BranchData> mStoreClusters = {};
338 std::vector<BranchData>* mStore = &mStoreClusters;
348 template <
typename BufferType,
typename MCArrayType>
352template <
typename DataArrayType,
typename MCArrayType>
355 DataArrayType& inputs, MCArrayType
const& mcinputs,
unsigned long sectorMask)
357 if (mcinputs.size() > 0 && mcinputs.size() != inputs.size()) {
358 std::runtime_error(
"inconsistent size of MC label array " +
std::to_string(mcinputs.size()) +
", expected " +
std::to_string(inputs.size()));
360 memset(&clusterIndex, 0,
sizeof(clusterIndex));
361 if (inputs.size() == 1) {
365 memcpy((
void*)&clusterIndex.
nClusters[0][0], hdr,
sizeof(*hdr));
368 if (mcinputs.size() > 0) {
375 if (sectorMask != 0xFFFFFFFFF) {
376 for (
unsigned int sector = 0; sector <
NSectors; sector++) {
377 if (!(sectorMask & (1ul << sector)) && clusterIndex.
nClustersSector[sector]) {
378 throw std::runtime_error(
"TPC sector mask provided, but received more sectors than set. (A filter could be implemented here if needed.)");
390 std::size_t extent = 0;
391 if (
index < mcinputs.size()) {
392 labelsptr = &mcinputs[
index];
395 int locres =
parseSector(inputs[
index], {labelsptr, extent}, clusterIndex, clustersMCTruth);
407 bool mcPresent =
false;
411 int sectorLabelId = 0;
414 if (clustersMCTruth[
i]) {
416 for (
unsigned int k = 0; k < old.
nClusters[
i][
j]; k++, sectorLabelId++) {
417 for (
auto const&
label : clustersMCTruth[
i]->
getLabels(sectorLabelId)) {
426 mcBuffer.second = mcBuffer.first;
433template <
typename BufferType,
typename MCArrayType>
436 static_assert(
sizeof(
typename BufferType::value_type) == 1,
"Target container must be byte-type");
437 if (
index.clustersLinear ==
nullptr) {
444 nRows +=
index.nClusters[sector][
row] > 0 ? 1 : 0;
451 if (
index.nClusters[sector][
row] == 0) {
459 if (
index.clustersMCTruth) {
460 mcTarget.emplace_back();
461 for (
unsigned int k = 0; k <
index.nClusters[sector][
row]; k++) {
462 for (
auto const&
label :
index.clustersMCTruth->getLabels(k +
index.clusterOffset[sector][
row])) {
463 mcTarget.back().addElement(k,
label);
Meta data for a group describing it by sector number and global padrow.
Class of a TPC cluster in TPC-native coordinates (row, time)
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
A reader class for the raw cluster native data.
size_t getTreeSize() const
static int fillIndex(ClusterNativeAccess &clusterIndex, std::unique_ptr< ClusterNative[]> &clusterBuffer, DataArrayType &inputs, unsigned long sectorMask=0xFFFFFFFFF)
int fillIndex(ClusterNativeAccess &clusterIndex, std::unique_ptr< ClusterNative[]> &clusterBuffer, ConstMCLabelContainerViewWithBuffer &mcBuffer)
void init(const char *filename, const char *treename=nullptr)
static int parseSector(ContainerT const cont, gsl::span< ConstMCLabelContainerView const > const &mcinput, ClusterNativeAccess &clusterIndex, const ConstMCLabelContainerView *(&clustersMCTruth)[NSectors])
static int parseSector(const char *buffer, size_t size, gsl::span< ConstMCLabelContainerView const > const &mcinput, ClusterNativeAccess &clusterIndex, const ConstMCLabelContainerView *(&clustersMCTruth)[NSectors])
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
static constexpr unsigned int NPadRows
ClusterNativeHelper()=default
static void copySectorData(ClusterNativeAccess const &index, int sector, BufferType &target, MCArrayType &mcTarget)
ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer ConstMCLabelContainerViewWithBuffer
static void convert(const char *fromFile, const char *toFile, const char *toTreeName="tpcnative")
static int addFlatBuffer(ClusterNativeAccess &clusterIndex, unsigned char *buffer, size_t size)
~ClusterNativeHelper()=default
GLuint GLsizei const GLchar * label
constexpr int MAXGLOBALPADROW
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
size_t getFlatSize() const
size_t getNClusters() const
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const value_type * data() const
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClustersSector[constants::MAXSECTOR]
const o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > * clustersMCTruth
std::pair< ConstMCLabelContainer, ConstMCLabelContainerView > ConstMCLabelContainerViewWithBuffer
unsigned int nClustersTotal
const ClusterNative * clusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int clusterOffset[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clustersLinear
ClusterGroupHeader attribute_type
const value_type * data() const
size_t getFlatSize() const
std::vector< ClusterNative > clusters
size_t getFlatSize() const
const value_type * data() const
ClusterGroupAttribute attribute_type
BranchData & operator=(ClusterNative const &rhs)
std::vector< Cluster > clusters