Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion roottest/root/tree/basket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@ ROOTTEST_ADD_TEST(basket
# Verify that it does.
ROOTTEST_ADD_TEST(corrupted_basket
COPY_TO_BUILDDIR corrupted.root
COMMAND ${ROOT_root_CMD} -q -l -e "(new TFile(\"corrupted.root\"))->template Get<TTree>(\"tree\")->GetEntry(0)"
COMMAND ${ROOT_root_CMD} -b -q -l -e "(new TFile(\"corrupted.root\"))->template Get<TTree>(\"tree\")->GetEntry(0)"
PASSREGEX "Inconsistent length for the entry offset buffer \\(4210752 events for a buffer size of 4\\)")

ROOT_ADD_TEST(test_TBasket_Resize
COMMAND ${ROOT_root_CMD} -b -q -l ${CMAKE_CURRENT_SOURCE_DIR}/test_basket_resize.C
OUTREF basketresize.ref
)

ROOT_ADD_TEST(test_TBasket_ReadResetBuffer
COMMAND ${ROOT_root_CMD} -b -q -l ${CMAKE_CURRENT_SOURCE_DIR}/test_basket_readreset.C
OUTREF basketreadreset.ref
)
4 changes: 4 additions & 0 deletions roottest/root/tree/basket/basketreadreset.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Processing test_basket_readreset.C...
Initial buffer size: 500000
Post-reset buffer size is smaller than initial: YES
Post-reset buffer satisfies safety floor requirement: YES
2 changes: 2 additions & 0 deletions roottest/root/tree/basket/basketresize.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Processing test_basket_resize.C...
Basket buffer size: 100
61 changes: 61 additions & 0 deletions roottest/root/tree/basket/test_basket_readreset.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "TBasket.h"
#include "TBranch.h"
#include "TBufferFile.h"
#include <iostream>

// Subclass to bypass the protected visibility of ReadResetBuffer
class TestBasket : public TBasket {
public:
TestBasket(TBranch *branch) {
fBranch = branch;
}

void InvokeReadResetBuffer(Int_t basketnumber) {
ReadResetBuffer(basketnumber);
}

void SetBufferForTesting(TBuffer *buf) {
fBuffer = buf;

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 minimal build CMAKE_CXX_STANDARD=20

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 asan ROOT_CTEST_CUSTOM_FLAGS=-E@\(^tutorial-\|cppinterop-CppInterOpTest\|roottest-cling-specialobj-runf02$\|roottest-root-collection-DeleteWarning$\|roottest-root-io-evolution-fixarr2$\|roottest-root-meta-rlibmap$\|roottest-root-treeproxy-vectorint-vectorint$\)

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma9 modules_off CMAKE_CXX_STANDARD=20

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma8

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo, builtin_zlib=ON, builtin_zstd=ON, CMAKE_CXX_STANDARD=20

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / debian13 dev=ON, CMAKE_CXX_FLAGS=-Wsuggest-override

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / rawhide Fedora pydebug no GIL CMAKE_CXX_STANDARD=23

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / fedora43

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / opensuse16 march_native

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu2604

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 clang Ninja builtins auto-registration off CMAKE_CXX_STANDARD=20

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / fedora44

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma9 CMAKE_BUILD_TYPE=Debug

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu22 imt=Off, CMAKE_BUILD_TYPE=Debug

incompatible pointer types assigning to 'char *' from 'TBuffer *'

Check failure on line 18 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu2404 CMAKE_BUILD_TYPE=Debug

incompatible pointer types assigning to 'char *' from 'TBuffer *'
}
};

void testTBasketReset() {
// Initialize mock environment
TBranch dummyBranch;
Int_t totalBaskets = 15;
dummyBranch.SetBufferEntries(totalBaskets);

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 minimal build CMAKE_CXX_STANDARD=20

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 asan ROOT_CTEST_CUSTOM_FLAGS=-E@\(^tutorial-\|cppinterop-CppInterOpTest\|roottest-cling-specialobj-runf02$\|roottest-root-collection-DeleteWarning$\|roottest-root-io-evolution-fixarr2$\|roottest-root-meta-rlibmap$\|roottest-root-treeproxy-vectorint-vectorint$\)

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma9 modules_off CMAKE_CXX_STANDARD=20

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma8

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo, builtin_zlib=ON, builtin_zstd=ON, CMAKE_CXX_STANDARD=20

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / debian13 dev=ON, CMAKE_CXX_FLAGS=-Wsuggest-override

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / rawhide Fedora pydebug no GIL CMAKE_CXX_STANDARD=23

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / fedora43

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / opensuse16 march_native

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu2604

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma10 clang Ninja builtins auto-registration off CMAKE_CXX_STANDARD=20

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / fedora44

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / alma9 CMAKE_BUILD_TYPE=Debug

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu22 imt=Off, CMAKE_BUILD_TYPE=Debug

no member named 'SetBufferEntries' in 'TBranch'

Check failure on line 26 in roottest/root/tree/basket/test_basket_readreset.C

View workflow job for this annotation

GitHub Actions / ubuntu2404 CMAKE_BUILD_TYPE=Debug

no member named 'SetBufferEntries' in 'TBranch'

Int_t currentBasketIdx = 2;
Int_t maximumNeededInWindow = 2000;

// Setup lookahead window metadata for the next 10 baskets
for (int i = 0; i < totalBaskets; ++i) {
if (i >= currentBasketIdx && i <= (currentBasketIdx + 10)) {
dummyBranch.GetBasketBytes()[i] = maximumNeededInWindow;
} else {
dummyBranch.GetBasketBytes()[i] = 1000;
}
}

TestBasket basket(&dummyBranch);

// Allocate heavily bloated buffer
Int_t massiveBufferSize = 500000;
TBufferFile* bloatedBuffer = new TBufferFile(TBuffer::kRead, massiveBufferSize);
bloatedBuffer->SetBufferOffset(massiveBufferSize);
basket.SetBufferForTesting(bloatedBuffer);

std::cout << "Initial buffer size: " << bloatedBuffer->BufferSize() << std::endl;

// Trigger the shrinking behavior
basket.InvokeReadResetBuffer(currentBasketIdx);

Int_t postResetSize = bloatedBuffer->BufferSize();
std::cout << "Post-reset buffer size is smaller than initial: "
<< (postResetSize < massiveBufferSize ? "YES" : "NO") << std::endl;

std::cout << "Post-reset buffer satisfies safety floor requirement: "
<< (postResetSize >= maximumNeededInWindow ? "YES" : "NO") << std::endl;

delete bloatedBuffer;
}
25 changes: 25 additions & 0 deletions roottest/root/tree/basket/test_basket_resize.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "TTree.h"
#include "TMemFile.h"
#include "TBranch.h"
#include "TBasket.h"
#include <iostream>

void test_basket_resize() {
TMemFile f("test_resize.root", "RECREATE");
TTree tree("T", "Tree for testing basket resizing");

int value;
// Set small initial basket size to force automatic buffer resizing
TBranch *branch = tree.Branch("b", &value, "value/I", 64);
for (int i = 0; i < 100; ++i) {
value = i;
tree.Fill();
}
tree.Write();
TBasket *basket = branch->GetBasket(0);
if (basket) {
Int_t newSize = basket->GetBufferSize();
std::cout << "Basket buffer size: " << newSize << std::endl;
}
f.Close();
}
Loading