Skip to content

Added ZigZag Logic Successfully #362

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 1 commit 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
14 changes: 12 additions & 2 deletions demo/node/rntuple_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ import { TSelector } from '../../modules/tree.mjs';
const selector = new TSelector();
selector.sum = 0;
selector.count = 0;
selector.addBranch('Nation');
selector.addBranch('Category');
selector.addBranch('Flag');
selector.addBranch('Age');
selector.addBranch('Service');
selector.addBranch('Children');
selector.addBranch('Grade');
selector.addBranch('Step');
selector.addBranch('Hrweek');
selector.addBranch('Cost');
selector.addBranch('Division');
selector.addBranch('Nation');

selector.Begin = function() {
console.log('Begin processing');
};
Expand All @@ -23,7 +33,7 @@ selector.Terminate = function() {
};

if (typeof window === 'undefined') {
openFile('./ntpl001_staff.root')
openFile('https://jsroot.gsi.de/files/tmp/ntpl001_staff.root')
.then(file => file.readObject('Staff'))
.then(rntuple => {
if (!rntuple) throw new Error('myNtuple not found');
Expand Down
46 changes: 45 additions & 1 deletion modules/rntuple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ function recontructUnsplitBuffer(blob, columnDescriptor) {
coltype === ENTupleColumnType.kSplitReal32 ||
coltype === ENTupleColumnType.kSplitReal64 ||
coltype === ENTupleColumnType.kSplitIndex32 ||
coltype === ENTupleColumnType.kSplitIndex64
coltype === ENTupleColumnType.kSplitIndex64 ||
coltype === ENTupleColumnType.kSplitInt16 ||
coltype === ENTupleColumnType.kSplitInt32 ||
coltype === ENTupleColumnType.kSplitInt64
) {
const byteSize = getTypeByteSize(coltype),
splitView = new DataView(blob.buffer, blob.byteOffset, blob.byteLength),
Expand Down Expand Up @@ -245,6 +248,15 @@ function recontructUnsplitBuffer(blob, columnDescriptor) {
case ENTupleColumnType.kSplitReal64:
newColtype = ENTupleColumnType.kReal64;
break;
case ENTupleColumnType.kSplitInt16:
newColtype = ENTupleColumnType.kInt16;
break;
case ENTupleColumnType.kSplitInt32:
newColtype = ENTupleColumnType.kInt32;
break;
case ENTupleColumnType.kSplitInt64:
newColtype = ENTupleColumnType.kInt64;
break;
default:
throw new Error(`Unsupported split coltype for reassembly: ${coltype}`);
}
Expand Down Expand Up @@ -279,6 +291,32 @@ function DecodeDeltaIndex(blob, coltype) {
return { blob: result, coltype };
}

/**
* @summary Decode a reconstructed signed integer buffer using ZigZag encoding
*/
function DecodeZigZag(blob, coltype) {
let zigzag, result;

if (coltype === ENTupleColumnType.kInt16) {
zigzag = new Uint16Array(blob.buffer || blob, blob.byteOffset || 0, blob.byteLength / 2);
result = new Int16Array(zigzag.length);
} else if (coltype === ENTupleColumnType.kInt32) {
zigzag = new Uint32Array(blob.buffer || blob, blob.byteOffset || 0, blob.byteLength / 4);
result = new Int32Array(zigzag.length);
} else if (coltype === ENTupleColumnType.kInt64) {
zigzag = new BigUint64Array(blob.buffer || blob, blob.byteOffset || 0, blob.byteLength / 8);
result = new BigInt64Array(zigzag.length);
} else
throw new Error(`DecodeZigZag: unsupported column type ${coltype}`);

for (let i = 0; i < zigzag.length; ++i) {
// ZigZag decode: (x >>> 1) ^ (-(x & 1))
const x = zigzag[i];
result[i] = (x >>> 1) ^ (-(x & 1));
}

return { blob: result, coltype };
}

// Envelope Types
// TODO: Define usage logic for envelope types in future
Expand Down Expand Up @@ -722,6 +760,12 @@ class RNTupleDescriptorBuilder {
processedBlob = decodedArray;
}

// Handle Split Signed Int types
if (originalColtype === ENTupleColumnType.kSplitInt16 || originalColtype === ENTupleColumnType.kSplitInt32 || originalColtype === ENTupleColumnType.kSplitInt64) {
const { blob: decodedArray } = DecodeZigZag(processedBlob, coltype);
processedBlob = decodedArray;
}

const byteSize = getTypeByteSize(coltype),
reader = new RBufferReader(processedBlob),
values = [];
Expand Down
Loading