13#include <catch_amalgamated.hpp>
23 explicit RecordingSource(
size_t n) :
bytes(
n)
25 for (
size_t i = 0;
i <
n; ++
i) {
32 reads.emplace_back(off,
len);
35 void readvInto(std::span<ReadRequest> requests)
override
37 for (
auto&
r : requests) {
43 std::string
url()
const override {
return "memory"; }
45 std::vector<uint8_t>
bytes;
46 std::vector<std::pair<uint64_t, size_t>> reads;
49bool holds(std::span<const uint8_t> span, uint64_t
offset)
51 for (
size_t i = 0;
i < span.size(); ++
i) {
62 options.coalesceGap = gap;
67TEST_CASE(
"ranges closer than the gap are fetched in one read, on first use")
69 auto source = std::make_shared<RecordingSource>(1 << 20);
75 REQUIRE(
source->reads.empty());
77 auto bytes = plan.find(1150, 50);
78 REQUIRE(holds(
bytes, 1150));
79 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 310}, {5000, 200}});
80 REQUIRE(plan.bytesHeld() == 510);
82 REQUIRE(holds(plan.find(5100, 100), 5100));
83 REQUIRE(holds(plan.find(1000, 310), 1000));
84 REQUIRE(
source->reads.size() == 2);
87TEST_CASE(
"ranges which were never registered are not found")
89 auto source = std::make_shared<RecordingSource>(1 << 20);
92 REQUIRE(plan.find(900, 50).empty());
93 REQUIRE(plan.find(1050, 100).empty());
94 REQUIRE(plan.find(5000, 1).empty());
95 REQUIRE(
source->reads.size() == 1);
98TEST_CASE(
"ranges added after a fetch are fetched on their first use")
100 auto source = std::make_shared<RecordingSource>(1 << 20);
103 REQUIRE(holds(plan.find(1000, 100), 1000));
104 auto first = plan.find(1000, 100);
110 REQUIRE(holds(plan.find(1500, 100), 1500));
111 REQUIRE(holds(plan.find(500, 100), 500));
112 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 100}, {500, 100}, {1500, 100}});
114 REQUIRE(plan.find(1000, 100).data() ==
first.data());
115 REQUIRE(holds(
first, 1000));
118TEST_CASE(
"ranges past the end of the file are left to the reader")
120 auto source = std::make_shared<RecordingSource>(1000);
124 REQUIRE(plan.find(900, 100).empty());
125 REQUIRE(
source->reads.empty());
128TEST_CASE(
"a planned source serves planned ranges from memory and the rest from the source")
130 auto source = std::make_shared<RecordingSource>(1 << 20);
131 auto plan = std::make_shared<ReadPlan>(
source, withGap(0));
132 plan->add(1000, 100);
135 REQUIRE(holds(planned.tryMap(1010, 20), 1010));
136 std::vector<uint8_t> out(30);
137 planned.readInto(1020, 30, out.data());
138 REQUIRE(holds(out, 1020));
139 REQUIRE(planned.tryMap(3000, 10).empty());
140 planned.readInto(3000, 30, out.data());
141 REQUIRE(holds(out, 3000));
142 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 100}, {3000, 30}});
143 REQUIRE(planned.readCalls() == 2);
146TEST_CASE(
"concurrent lookups fetch the pending ranges once")
148 auto source = std::make_shared<RecordingSource>(1 << 20);
150 for (
int i = 0;
i < 64; ++
i) {
151 plan.add(
i * 10000, 1000);
153 std::vector<std::thread> threads;
154 std::atomic<int> good = 0;
155 for (
int t = 0;
t < 8; ++
t) {
156 threads.emplace_back([&,
t] {
157 for (
int i =
t;
i < 64;
i += 8) {
158 good += holds(plan.find(
i * 10000 + 10, 900),
i * 10000 + 10);
162 for (
auto&
t : threads) {
166 REQUIRE(
source->reads.size() == 64);
169TEST_CASE(
"buffers of finished plans are reused by the next one")
171 auto source = std::make_shared<RecordingSource>(1 << 20);
172 auto pool = std::make_shared<ReadBufferPool>();
176 plan.add(1000, 1000);
177 first = plan.find(1000, 1000).data();
180 next.add(50000, 900);
181 auto bytes = next.find(50000, 900);
183 REQUIRE(holds(
bytes, 50000));
185 auto big = pool->get(1 << 16);
186 REQUIRE(big.capacity >= 1 << 16);
189TEST_CASE(
"a pool with a budget drops the largest free buffers beyond it")
192 auto small = pool.
get(400);
193 auto medium = pool.get(500);
194 auto large = pool.get(2000);
195 auto* smallData = small.
data.get();
196 auto* mediumData = medium.data.get();
197 pool.put(std::move(small));
198 pool.put(std::move(medium));
199 pool.put(std::move(large));
200 REQUIRE(pool.get(300).data.get() == smallData);
201 REQUIRE(pool.get(480).data.get() == mediumData);
204TEST_CASE(
"bytesOf counts the baskets a plan reads, not the embedded ones")
208 tree.branches[0].baskets = {
BasketRef{100, 300, 0, 10,
false, {}},
BasketRef{400, 200, 10, 5,
false, {}}};
209 tree.branches[1].baskets = {
BasketRef{600, 50, 0, 10,
false, {}},
BasketRef{0, 0, 10, 5,
true, {1, 2, 3}}};
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
virtual std::string url() const =0
virtual uint64_t bytesRead() const =0
virtual uint64_t size() const =0
virtual void readInto(uint64_t off, size_t len, void *dst)=0
Throws IoError, or CorruptData when the range is past the end of the file.
virtual uint64_t readCalls() const =0
virtual void readvInto(std::span< ReadRequest > requests)=0
Buffer get(size_t size)
The smallest free buffer of at least size bytes, or a new one.
static uint64_t bytesOf(TreeInfo const &tree)
The bytes add(tree) registers.
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei len
std::unique_ptr< uint8_t[], Unmap > data
std::vector< BranchInfo > branches
TEST_CASE("ranges closer than the gap are fetched in one read, on first use")
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))