Skip to content

$file.readBuffer to read the data from disk #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/jsroot-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
node demo/node/file_proxy.js multi ./hsimple.root
node demo/node/file_proxy.js buffer ./hsimple.root
node demo/node/buffer_test.js
node demo/node/rntuple_test.js

tests_ubuntu:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -176,6 +177,8 @@ jobs:
node demo/node/file_proxy.js multi ./hsimple.root
node demo/node/file_proxy.js buffer ./hsimple.root
node demo/node/buffer_test.js
node demo/node/rntuple_test.js


build-windows:
runs-on: windows-latest
Expand Down Expand Up @@ -223,4 +226,5 @@ jobs:
node demo/node/file_proxy.js multi ./hsimple.root
node demo/node/file_proxy.js buffer ./hsimple.root
node demo/node/buffer_test.js
node demo/node/rntuple_test.js

6 changes: 4 additions & 2 deletions demo/node/rntuple_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { readHeaderFooter } from 'jsroot/rntuple';


console.log(`JSROOT version ${version}`);
// const file = await openFile('https://jsroot.gsi.de/files/tmp/ntpl001_staff.root'),
// rntuple = await file.readObject('Staff');

let file = await openFile('https://jsroot.gsi.de/files/tmp/ntpl001_staff.root');
const file = await openFile('./simple.root'),

let rntuple = await file.readObject('Staff');
rntuple = await file.readObject('myNtuple');

await readHeaderFooter(rntuple);

Expand Down
Binary file added demo/node/simple.root
Binary file not shown.
39 changes: 37 additions & 2 deletions modules/rntuple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ const numRecordCluster = reader.readU32();
this.pageLocations = clusterPageLocations;
}

// Example Of Deserializing Page Content
deserializePage(blob) {
const reader = new RBufferReader(blob);
console.log('Deserializing first 10 double values from data page ');
for (let i = 0; i < 10; ++i) {
const val = reader.readF64();
console.log(val);
}
}


}


Expand Down Expand Up @@ -527,7 +538,7 @@ async function readHeaderFooter(tuple) {
tuple.builder.deserializeHeader(header_blob);

tuple.builder.deserializeFooter(footer_blob);

// Deserialize the Page List Envelope
const group = tuple.builder.clusterGroups?.[0];
if (!group || !group.pageListLocator)
throw new Error('No valid cluster group or page list locator found');
Expand All @@ -545,7 +556,31 @@ async function readHeaderFooter(tuple) {
throw new Error(`Unzipped page list is not a DataView, got ${Object.prototype.toString.call(unzipped_blob)}`);

tuple.builder.deserializePageList(unzipped_blob);
return true;


// Read the first page data
const firstPage = tuple.builder?.pageLocations?.[0]?.[0]?.pages?.[0];
if (!firstPage || !firstPage.locator)
throw new Error('No valid first page found in pageLocations');

const pageOffset = Number(firstPage.locator.offset),
pageSize = Number(firstPage.locator.size),
uncompressedPageSize = 8000;
console.log('Compressed size :', pageSize);

return tuple.$file.readBuffer([pageOffset, pageSize]).then(compressedPage => {
if (!(compressedPage instanceof DataView))
throw new Error('Compressed page readBuffer did not return a DataView');

return R__unzip(compressedPage, uncompressedPageSize).then(unzippedPage => {
if (!(unzippedPage instanceof DataView))
throw new Error('Unzipped page is not a DataView');

tuple.builder.deserializePage(unzippedPage);

return true;
});
});
});
});
});
Expand Down
Loading