Project
Loading...
Searching...
No Matches
FairMQResizableBuffer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <fairmq/Message.h>
14#include <arrow/status.h>
15#include <arrow/util/config.h>
16#include <cassert>
17#include <utility>
18
19using arrow::Status;
20
22{
23void CloseFromDestructor(FileInterface* file);
24}
25
26namespace o2::framework
27{
28static constexpr int64_t kBufferMinimumSize = 256;
29
30FairMQOutputStream::FairMQOutputStream()
31 : is_open_(false), capacity_(0), position_(0), mutable_data_(nullptr) {}
32
33FairMQOutputStream::FairMQOutputStream(const std::shared_ptr<arrow::ResizableBuffer>& buffer)
34 : buffer_(buffer),
35 is_open_(true),
36 capacity_(buffer->size()),
37 position_(0),
38 mutable_data_(buffer->mutable_data()) {}
39
40arrow::Result<std::shared_ptr<FairMQOutputStream>> FairMQOutputStream::Create(
41 int64_t initial_capacity, arrow::MemoryPool* pool)
42{
43 // ctor is private, so cannot use make_shared
44 auto ptr = std::shared_ptr<FairMQOutputStream>(new FairMQOutputStream);
45 RETURN_NOT_OK(ptr->Reset(initial_capacity, pool));
46 return ptr;
47}
48
49Status FairMQOutputStream::Reset(int64_t initial_capacity, arrow::MemoryPool* pool)
50{
51 ARROW_ASSIGN_OR_RAISE(buffer_, AllocateResizableBuffer(initial_capacity, pool));
52 is_open_ = true;
53 capacity_ = initial_capacity;
54 position_ = 0;
55 mutable_data_ = buffer_->mutable_data();
56 return Status::OK();
57}
58
60{
61 if (is_open_) {
62 is_open_ = false;
63 if (position_ < capacity_) {
64 RETURN_NOT_OK(buffer_->Resize(position_, false));
65 }
66 }
67 return Status::OK();
68}
69
70bool FairMQOutputStream::closed() const { return !is_open_; }
71
72arrow::Result<std::shared_ptr<arrow::Buffer>> FairMQOutputStream::Finish()
73{
74 RETURN_NOT_OK(Close());
75 buffer_->ZeroPadding();
76 is_open_ = false;
77 return std::move(buffer_);
78}
79
80arrow::Result<int64_t> FairMQOutputStream::Tell() const { return position_; }
81
83{
84 if (ARROW_PREDICT_FALSE(!is_open_)) {
85 return Status::IOError("OutputStream is closed");
86 }
87 if (ARROW_PREDICT_TRUE(nbytes > 0)) {
88 if (ARROW_PREDICT_FALSE(position_ + nbytes >= capacity_)) {
89 RETURN_NOT_OK(Reserve(nbytes));
90 }
91 memcpy(mutable_data_ + position_, data, nbytes);
92 position_ += nbytes;
93 }
94 return Status::OK();
95}
96
97Status FairMQOutputStream::Reserve(int64_t nbytes)
98{
99 // Always overallocate by doubling. It seems that it is a better growth
100 // strategy, at least for memory_benchmark.cc.
101 // This may be because it helps match the allocator's allocation buckets
102 // more exactly. Or perhaps it hits a sweet spot in jemalloc.
103 int64_t new_capacity = std::max(kBufferMinimumSize, capacity_);
104 new_capacity = position_ + nbytes;
105 if (new_capacity > capacity_) {
106 RETURN_NOT_OK(buffer_->Resize(new_capacity));
107 capacity_ = new_capacity;
108 mutable_data_ = buffer_->mutable_data();
109 }
110 return Status::OK();
111}
112
114
115// Creates an empty message
117 : ResizableBuffer(nullptr, 0),
118 mMessage{nullptr},
119 mCreator{std::move(creator)}
120{
121 this->data_ = nullptr;
122 this->capacity_ = 0;
123 this->size_ = 0;
124}
125
126arrow::Status FairMQResizableBuffer::Resize(const int64_t newSize, bool shrink_to_fit)
127{
128 // NOTE: we ignore "shrink_to_fit" because in any case we
129 // invoke SetUsedSize when we send the message. This
130 // way we avoid unneeded copies at the arrow level.
131 if (newSize > this->capacity_) {
132 auto status = this->Reserve(newSize);
133 if (status.ok() == false) {
134 return status;
135 }
136 }
137 assert(newSize <= this->capacity_);
138
139 this->size_ = newSize;
140 assert(this->size_ <= mMessage->GetSize());
141 return arrow::Status::OK();
142}
143
144arrow::Status FairMQResizableBuffer::Reserve(const int64_t capacity)
145{
146 assert(!mMessage || this->size_ <= mMessage->GetSize());
147 assert(!mMessage || this->capacity_ == mMessage->GetSize());
148 if (capacity <= this->capacity_) {
149 return arrow::Status::OK();
150 }
151 auto newMessage = mCreator(capacity);
152 assert(!mMessage || capacity > mMessage->GetSize());
153 if (mMessage) {
154 memcpy(newMessage->GetData(), mMessage->GetData(), mMessage->GetSize());
155 }
156 mMessage = std::move(newMessage);
157 assert(mMessage);
158 this->data_ = reinterpret_cast<uint8_t*>(mMessage->GetData());
159 this->capacity_ = static_cast<int64_t>(mMessage->GetSize());
160 assert(this->data_);
161 return arrow::Status::OK();
162}
163
164std::unique_ptr<fair::mq::Message> FairMQResizableBuffer::Finalise()
165{
166 this->data_ = nullptr;
167 this->capacity_ = 0;
168 this->size_ = 0;
169 return std::move(mMessage);
170}
171
172} // namespace o2::framework
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
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 Replace constant variables static by constexpr expressions false
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
TBranch * ptr
arrow::Result< std::shared_ptr< arrow::Buffer > > Finish()
Close the stream and return the buffer.
arrow::Result< int64_t > Tell() const override
arrow::Status Close() override
Close the stream, preserving the buffer (retrieve it with Finish()).
static arrow::Result< std::shared_ptr< FairMQOutputStream > > Create(int64_t initial_capacity=4096, arrow::MemoryPool *pool=arrow::default_memory_pool())
Create in-memory output stream with indicated capacity using a memory pool.
arrow::Status Write(const void *data, int64_t nbytes) override
arrow::Status Reset(int64_t initial_capacity=1024, arrow::MemoryPool *pool=arrow::default_memory_pool())
Initialize state of OutputStream with newly allocated memory and set position to 0.
arrow::Status Reserve(const int64_t capacity) override
arrow::Status Resize(const int64_t new_size, bool shrink_to_fit) override
std::unique_ptr< fair::mq::Message > Finalise()
std::function< std::unique_ptr< fair::mq::Message >(size_t)> Creator
GLsizeiptr size
Definition glcorearb.h:659
void CloseFromDestructor(FileInterface *file)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288