Project
Loading...
Searching...
No Matches
ReadPlan.h
Go to the documentation of this file.
1// Copyright 2019-2026 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
12#ifndef O2_FRAMEWORK_AODNATIVE_READPLAN_H_
13#define O2_FRAMEWORK_AODNATIVE_READPLAN_H_
14
16#include "AODNative/Objects.h"
17#include <memory>
18#include <mutex>
19#include <span>
20#include <vector>
21
22namespace o2::aod::native
23{
24
29{
30 public:
31 struct Buffer {
32 std::unique_ptr<uint8_t[]> data;
33 size_t capacity = 0;
34 };
36 Buffer get(size_t size);
37 void put(Buffer buffer);
38
39 private:
40 static constexpr size_t kMaxFree = 2;
41 std::mutex mMutex;
42 std::vector<Buffer> mFree;
43};
44
50{
51 public:
53 ReadPlan(std::shared_ptr<ByteSource> source, Options const& options, std::shared_ptr<ReadBufferPool> pool = nullptr);
54 ~ReadPlan();
55 ReadPlan(ReadPlan const&) = delete;
56 ReadPlan& operator=(ReadPlan const&) = delete;
57
58 void add(uint64_t offset, size_t length);
60 void add(TreeInfo const& tree);
64 std::span<const uint8_t> find(uint64_t offset, size_t length);
66 void fetch();
67 size_t bytesHeld() const;
68
69 private:
70 struct Chunk {
71 uint64_t offset;
72 uint8_t* data;
73 size_t size;
74 };
75 std::span<const uint8_t> lookup(uint64_t offset, size_t length) const;
76 void fetchPending();
77
78 std::shared_ptr<ByteSource> mSource;
79 std::shared_ptr<ReadBufferPool> mPool;
80 size_t mCoalesceGap;
81 std::vector<std::pair<uint64_t, size_t>> mPending;
82 std::vector<Chunk> mChunks; // sorted by offset, not overlapping
83 std::vector<ReadBufferPool::Buffer> mBuffers;
84 mutable std::mutex mMutex;
85};
86
90{
91 public:
92 PlannedByteSource(std::shared_ptr<ByteSource> source, std::shared_ptr<ReadPlan> plan);
93 uint64_t size() const override { return mSource->size(); }
94 void readInto(uint64_t off, size_t len, void* dst) override;
95 void readvInto(std::span<ReadRequest> requests) override;
96 std::span<const uint8_t> tryMap(uint64_t off, size_t len) override;
97 uint64_t bytesRead() const override { return mSource->bytesRead(); }
98 uint64_t readCalls() const override { return mSource->readCalls(); }
99 std::string url() const override { return mSource->url(); }
100
101 private:
102 std::shared_ptr<ByteSource> mSource;
103 std::shared_ptr<ReadPlan> mPlan;
104};
105
106} // namespace o2::aod::native
107
108#endif // O2_FRAMEWORK_AODNATIVE_READPLAN_H_
void readInto(uint64_t off, size_t len, void *dst) override
Throws IoError, or CorruptData when the range is past the end of the file.
Definition ReadPlan.cxx:183
void readvInto(std::span< ReadRequest > requests) override
Definition ReadPlan.cxx:193
std::string url() const override
Definition ReadPlan.h:99
uint64_t readCalls() const override
Definition ReadPlan.h:98
uint64_t bytesRead() const override
Definition ReadPlan.h:97
uint64_t size() const override
Definition ReadPlan.h:93
std::span< const uint8_t > tryMap(uint64_t off, size_t len) override
A view of the bytes without copying them, if the backend can provide it.
Definition ReadPlan.cxx:177
void put(Buffer buffer)
Definition ReadPlan.cxx:41
Buffer get(size_t size)
The smallest free buffer of at least size bytes, or a new one.
Definition ReadPlan.cxx:19
ReadPlan & operator=(ReadPlan const &)=delete
ReadPlan(ReadPlan const &)=delete
void fetch()
Fetches the pending ranges now, rather than on the first find().
Definition ReadPlan.cxx:154
std::span< const uint8_t > find(uint64_t offset, size_t length)
Definition ReadPlan.cxx:143
void add(uint64_t offset, size_t length)
Definition ReadPlan.cxx:62
size_t bytesHeld() const
Definition ReadPlan.cxx:162
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLenum GLenum dst
Definition glcorearb.h:1767
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
std::unique_ptr< uint8_t[]> data
Definition ReadPlan.h:32
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))