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:
33 struct Unmap {
34 size_t size = 0;
35 void operator()(uint8_t* p) const;
36 };
37 struct Buffer {
38 std::unique_ptr<uint8_t[], Unmap> data;
39 size_t capacity = 0;
40 };
43 explicit ReadBufferPool(size_t maxFreeBytes = 0) : mMaxFreeBytes(maxFreeBytes) {}
45 Buffer get(size_t size);
46 void put(Buffer buffer);
47
48 private:
49 static constexpr size_t kMaxFree = 2;
50 size_t mMaxFreeBytes;
51 std::mutex mMutex;
52 std::vector<Buffer> mFree;
53};
54
60{
61 public:
63 ReadPlan(std::shared_ptr<ByteSource> source, Options const& options, std::shared_ptr<ReadBufferPool> pool = nullptr);
64 ~ReadPlan();
65 ReadPlan(ReadPlan const&) = delete;
66 ReadPlan& operator=(ReadPlan const&) = delete;
67
68 void add(uint64_t offset, size_t length);
70 void add(TreeInfo const& tree);
72 static uint64_t bytesOf(TreeInfo const& tree);
76 std::span<const uint8_t> find(uint64_t offset, size_t length);
78 void fetch();
79 size_t bytesHeld() const;
80
81 private:
82 struct Chunk {
85 size_t size;
86 };
87 std::span<const uint8_t> lookup(uint64_t offset, size_t length) const;
88 void fetchPending();
89
90 std::shared_ptr<ByteSource> mSource;
91 std::shared_ptr<ReadBufferPool> mPool;
92 size_t mCoalesceGap;
93 std::vector<std::pair<uint64_t, size_t>> mPending;
94 std::vector<Chunk> mChunks; // sorted by offset, not overlapping
95 std::vector<ReadBufferPool::Buffer> mBuffers;
96 mutable std::mutex mMutex;
97};
98
102{
103 public:
104 PlannedByteSource(std::shared_ptr<ByteSource> source, std::shared_ptr<ReadPlan> plan);
105 uint64_t size() const override { return mSource->size(); }
106 void readInto(uint64_t off, size_t len, void* dst) override;
107 void readvInto(std::span<ReadRequest> requests) override;
108 std::span<const uint8_t> tryMap(uint64_t off, size_t len) override;
109 uint64_t bytesRead() const override { return mSource->bytesRead(); }
110 uint64_t readCalls() const override { return mSource->readCalls(); }
111 std::string url() const override { return mSource->url(); }
112
113 private:
114 std::shared_ptr<ByteSource> mSource;
115 std::shared_ptr<ReadPlan> mPlan;
116};
117
118} // namespace o2::aod::native
119
120#endif // O2_FRAMEWORK_AODNATIVE_READPLAN_H_
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 Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
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:219
void readvInto(std::span< ReadRequest > requests) override
Definition ReadPlan.cxx:229
std::string url() const override
Definition ReadPlan.h:111
uint64_t readCalls() const override
Definition ReadPlan.h:110
uint64_t bytesRead() const override
Definition ReadPlan.h:109
uint64_t size() const override
Definition ReadPlan.h:105
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:213
ReadBufferPool(size_t maxFreeBytes=0)
Definition ReadPlan.h:43
void put(Buffer buffer)
Definition ReadPlan.cxx:52
Buffer get(size_t size)
The smallest free buffer of at least size bytes, or a new one.
Definition ReadPlan.cxx:21
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:190
static uint64_t bytesOf(TreeInfo const &tree)
The bytes add(tree) registers.
Definition ReadPlan.cxx:106
std::span< const uint8_t > find(uint64_t offset, size_t length)
Definition ReadPlan.cxx:179
void add(uint64_t offset, size_t length)
Definition ReadPlan.cxx:85
size_t bytesHeld() const
Definition ReadPlan.cxx:198
GLsizeiptr size
Definition glcorearb.h:659
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLenum GLenum dst
Definition glcorearb.h:1767
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[], Unmap > data
Definition ReadPlan.h:38
void operator()(uint8_t *p) const
Definition ReadPlan.cxx:47
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))