25#include <arrow/buffer.h>
26#include <arrow/dataset/file_base.h>
27#include <arrow/io/interfaces.h>
28#include <arrow/memory_pool.h>
29#include <arrow/record_batch.h>
30#include <arrow/status.h>
47 std::shared_ptr<arrow::dataset::FileFormat>
format,
48 arrow::compute::Expression partition_expression,
49 std::shared_ptr<arrow::Schema> physical_schema)
50 : FileFragment(
source,
format,
std::move(partition_expression), physical_schema)
52 auto rootFS = std::dynamic_pointer_cast<VirtualRootFileSystemBase>(this->
source().filesystem());
53 if (rootFS.get() ==
nullptr) {
55 source.filesystem()->type_name().c_str(),
source.path().c_str());
57 auto objectHandler = rootFS->GetObjectHandler(
source);
58 if (!objectHandler->format->Equals(*
format)) {
59 throw runtime_error_f(
"Cannot read source %s with format %s to populate a NativeAODFileFragment.",
60 source.path().c_str(), objectHandler->format->type_name().c_str());
65 if (
auto nativeFS = std::dynamic_pointer_cast<NativeAODFileSystem>(rootFS)) {
66 if (
auto plan = nativeFS->planFor(
source.path())) {
67 mSource = std::make_unique<o2::aod::native::PlannedByteSource>(mHandle->
source, std::move(plan));
70 mDecoder = std::make_unique<BranchDecoder>(mSource ? *mSource : *mHandle->
source, mHandle->
options);
75 std::vector<ColumnOp>&
ops() {
return mOps; }
79 std::unique_ptr<o2::aod::native::ByteSource> mSource;
80 std::unique_ptr<BranchDecoder> mDecoder;
81 std::vector<ColumnOp> mOps;
92 const std::shared_ptr<arrow::ResizableBuffer>&
buffer)
93 : mFragment(
std::move(fragment)),
98 mutable_data_(
buffer->mutable_data())
111 if (position_ < capacity_) {
112 RETURN_NOT_OK(buffer_->Resize(position_,
false));
115 return arrow::Status::OK();
118 [[nodiscard]]
bool closed()
const override {
return !is_open_; }
119 [[nodiscard]] arrow::Result<int64_t>
Tell()
const override {
return position_; }
121 arrow::Status
Write(
const void*
data, int64_t nbytes)
override
123 if (ARROW_PREDICT_FALSE(!is_open_)) {
124 return arrow::Status::IOError(
"OutputStream is closed");
126 if (ARROW_PREDICT_TRUE(nbytes == 0)) {
127 return arrow::Status::OK();
129 if (ARROW_PREDICT_FALSE(position_ + nbytes >= capacity_)) {
130 RETURN_NOT_OK(Reserve(nbytes));
132 auto& ops = mFragment->ops();
135 if (ref < 0 || ref >= (int64_t)ops.size()) {
136 memcpy(mutable_data_ + position_,
data, nbytes);
138 return arrow::Status::OK();
141 if ((int64_t)
op.byteSize != nbytes) {
142 return arrow::Status::Invalid(
"Deferred read of ", nbytes,
" bytes for an operation of ",
op.byteSize);
147 return arrow::Status::OK();
150 using OutputStream::Write;
153 arrow::Status Reserve(int64_t nbytes)
155 int64_t new_capacity = position_ + nbytes;
156 if (new_capacity > capacity_) {
157 RETURN_NOT_OK(buffer_->Resize(new_capacity));
158 capacity_ = new_capacity;
159 mutable_data_ = buffer_->mutable_data();
161 return arrow::Status::OK();
164 std::shared_ptr<NativeAODFileFragment> mFragment;
165 std::shared_ptr<arrow::ResizableBuffer> buffer_;
176 : FileWriteOptions(
format)
183 size_t& mTotCompressedSize;
184 size_t& mTotUncompressedSize;
189 mTotCompressedSize(totalCompressedSize),
190 mTotUncompressedSize(totalUncompressedSize)
194 std::string
type_name()
const override {
return "native-ttree"; }
200 auto fs = std::dynamic_pointer_cast<VirtualRootFileSystemBase>(
source.filesystem());
204 return fs->CheckSupport(
source);
207 arrow::Result<std::shared_ptr<arrow::Schema>>
Inspect(
const arrow::dataset::FileSource&
source)
const override
209 auto fs = std::dynamic_pointer_cast<VirtualRootFileSystemBase>(
source.filesystem());
213 auto objectHandler = fs->GetObjectHandler(
source);
214 if (!objectHandler->format->Equals(*
this)) {
222 return arrow::Status::IOError(
e.what());
226 arrow::Result<std::shared_ptr<arrow::dataset::FileFragment>>
MakeFragment(
227 arrow::dataset::FileSource
source, arrow::compute::Expression partition_expression,
228 std::shared_ptr<arrow::Schema> physical_schema)
override
230 return std::make_shared<NativeAODFileFragment>(
source, std::dynamic_pointer_cast<arrow::dataset::FileFormat>(shared_from_this()),
231 std::move(partition_expression), physical_schema);
234 arrow::Result<std::shared_ptr<arrow::dataset::FileWriter>>
MakeWriter(std::shared_ptr<arrow::io::OutputStream>, std::shared_ptr<arrow::Schema>,
235 std::shared_ptr<arrow::dataset::FileWriteOptions>, arrow::fs::FileLocator)
const override
237 return arrow::Status::NotImplemented(
"The native AO2D reader cannot write files");
242 return std::make_shared<NativeAODFileWriteOptions>(shared_from_this());
246 const std::shared_ptr<arrow::dataset::ScanOptions>& options,
247 const std::shared_ptr<arrow::dataset::FileFragment>& fragment)
const override
249 assert(options->dataset_schema !=
nullptr);
251 auto nativeFragment = std::dynamic_pointer_cast<NativeAODFileFragment>(fragment);
252 if (nativeFragment.get() ==
nullptr) {
253 return {arrow::Status::NotImplemented(
"Not a native AO2D fragment")};
256 auto generator = [pool = options->pool, nativeFragment,
datasetSchema, &totalCompressedSize = mTotCompressedSize,
257 &totalUncompressedSize = mTotUncompressedSize]() -> arrow::Future<std::shared_ptr<arrow::RecordBatch>> {
258 auto*
handle = nativeFragment->handle();
261 O2_SIGNPOST_START(native_aod, tid,
"Generator",
"Creating batch for tree %{public}s",
tree.name.c_str());
263 throw runtime_error_f(
"One TTree must have all the fields requested in a table");
268 auto& ops = nativeFragment->ops();
271 std::vector<std::shared_ptr<arrow::Buffer>> placeholders;
272 for (
size_t i = 0;
i < ops.size(); ++
i) {
273 placeholders.push_back(std::make_shared<arrow::Buffer>((
uint8_t*)
i, ops[
i].byteSize));
274 O2_SIGNPOST_EVENT_EMIT(native_aod, tid,
"Op",
"Created op for branch %{public}s with %lli entries, size of the buffer %zu.",
275 ops[
i].branch->name.c_str(), (
long long)ops[
i].branch->entries, ops[
i].byteSize);
278 totalCompressedSize +=
tree.zipBytes;
279 totalUncompressedSize +=
tree.totBytes;
280 O2_SIGNPOST_END(native_aod, tid,
"Generator",
"Done creating batch compressed:%zu uncompressed:%zu", totalCompressedSize, totalUncompressedSize);
290 std::shared_ptr<NativeAODFileFormat>
format =
nullptr;
296 context->
format = std::make_shared<NativeAODFileFormat>(context->totalCompressedSize, context->totalUncompressedSize);
298 .
options = [context]() {
return context->format->DefaultWriteOptions(); },
299 .format = [context]() {
return context->format; },
300 .deferredOutputStreamer = [](std::shared_ptr<arrow::dataset::FileFragment> fragment,
const std::shared_ptr<arrow::ResizableBuffer>&
buffer) -> std::shared_ptr<arrow::io::OutputStream> {
301 auto nativeFragment = std::dynamic_pointer_cast<NativeAODFileFragment>(fragment);
302 return std::make_shared<NativeAODDeferredReadOutputStream>(nativeFragment,
buffer);
318 .
name =
"native-ttree",
319 .lfn2objectPath = [](std::string
s) {
return s; },
320 .getHandle = [](std::shared_ptr<arrow::fs::FileSystem> fs, std::string
const&
path) ->
void* {
321 auto nativeFS = std::dynamic_pointer_cast<NativeAODFileSystem>(fs);
326 return nativeFS->getTreeHandle(
path);
329 }
catch (std::exception
const&
e) {
334 .checkSupport = [](
char const*
className) ->
bool {
return std::string_view(
className) ==
"TTree"; },
335 .accountBytes = [](
void*
handle,
size_t& compressed,
size_t& uncompressed) {
337 compressed +=
h->tree.zipBytes;
338 uncompressed +=
h->tree.totBytes; },
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc true
#define DEFINE_DPL_PLUGIN_INSTANCE(NAME, KIND)
#define DEFINE_DPL_PLUGINS_END
#define DEFINE_DPL_PLUGINS_BEGIN
#define O2_DECLARE_DYNAMIC_LOG(name)
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer)
#define O2_SIGNPOST_END(log, id, name, format,...)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
#define O2_SIGNPOST_START(log, id, name, format,...)
Class for time synchronization of RawReader instances.
arrow::Result< int64_t > Tell() const override
~NativeAODDeferredReadOutputStream() override=default
arrow::Status Write(const void *data, int64_t nbytes) override
bool closed() const override
arrow::Status Close() override
NativeAODDeferredReadOutputStream(std::shared_ptr< NativeAODFileFragment > fragment, const std::shared_ptr< arrow::ResizableBuffer > &buffer)
std::vector< ColumnOp > & ops()
BranchDecoder & decoder()
NativeAODFileFragment(arrow::dataset::FileSource source, std::shared_ptr< arrow::dataset::FileFormat > format, arrow::compute::Expression partition_expression, std::shared_ptr< arrow::Schema > physical_schema)
NativeTreeHandle * handle()
NativeAODFileWriteOptions(std::shared_ptr< arrow::dataset::FileFormat > format)
GLsizei GLsizei GLchar * source
GLsizei const GLchar *const * path
GLint GLint GLsizei GLint GLenum format
std::shared_ptr< arrow::Schema > datasetSchema(std::shared_ptr< arrow::Schema > const &physical)
The physical schema without the *_size fields, as DataInputDirector derives it.
std::shared_ptr< arrow::RecordBatch > makeBatch(std::shared_ptr< arrow::Schema > const &schema, std::vector< ColumnOp > const &ops, std::vector< std::shared_ptr< arrow::Buffer > > const &buffers, int64_t rows)
Wraps the buffers of ops (one per op, in order) into a record batch.
std::shared_ptr< arrow::Schema > physicalSchema(TreeInfo const &tree)
std::vector< ColumnOp > planColumns(TreeInfo const &tree, std::shared_ptr< arrow::Schema > const &schema, BranchDecoder &decoder, arrow::MemoryPool *pool, int64_t &rows)
void executeColumnOp(BranchDecoder &decoder, ColumnOp const &op, uint8_t *dst)
Fills the buffer of op, which is exactly op.byteSize bytes.
Defining ITS Vertex explicitly as messageable.
@ RootObjectReadingImplementation
RootArrowFactory * createNativeAODFactory()
RuntimeErrorRef runtime_error_f(const char *,...)
RootObjectReadingCapability * create() override
RootArrowFactory * create() override
std::shared_ptr< NativeAODFileFormat > format
size_t totalCompressedSize
size_t totalUncompressedSize
std::shared_ptr< o2::aod::native::ByteSource > source
o2::aod::native::Options options
std::function< std::shared_ptr< arrow::dataset::FileWriteOptions >()> options
VectorOfTObjectPtrs other
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< ReadoutWindowData > rows