Skip to content
Merged
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
74 changes: 61 additions & 13 deletions demo/node/rntuple_test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { version, openFile } from 'jsroot';
import { version, openFile, TSelector } from 'jsroot';

import { readHeaderFooter } from 'jsroot/rntuple';
import { readHeaderFooter, readEntry, rntupleProcess } 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');
const file = await openFile('simple.root'),
rntuple = await file.readObject('myNtuple');
const file = await openFile('./rntuple_test.root'),
rntuple = await file.readObject('Data');

await readHeaderFooter(rntuple);

console.log('Performing Validations and debugging info');

if (rntuple.builder?.name !== 'Staff')
if (rntuple.builder?.name !== 'Data')
console.error('FAILURE: name differs from expected');
else
console.log('OK: name is', rntuple.builder?.name);
Expand All @@ -21,7 +21,7 @@ else
if (rntuple.builder?.description !== '')
console.error('FAILURE: description should be the empty string');
else
console.log('OK: description is', rntuple.builder.description);
console.log('OK: description is empty string');

if (rntuple.builder?.xxhash3 === undefined || rntuple.builder.xxhash3 === null)
console.warn('WARNING: xxhash3 is missing');
Expand All @@ -41,11 +41,11 @@ else {
else
console.log(`OK: Field ${i}: ${field.fieldName} (${field.typeName})`);
if (i === 0) {
if (field.fieldName !== 'Category' || field.typeName !== 'std::int32_t')
console.error(`FAILURE: First field should be 'Category (std::int32_t)' but got '${field.fieldName} (${field.typeName})'`);
if (field.fieldName !== 'IntField' || field.typeName !== 'std::int32_t')
console.error(`FAILURE: First field should be 'IntField (std::int32_t)' but got '${field.fieldName} (${field.typeName})'`);
} else if (i === rntuple.builder.fieldDescriptors.length - 1){
if (field.fieldName !== 'Nation' || field.typeName !== 'std::string')
console.error(`FAILURE: Last field should be 'Nation (std::string)' but got '${field.fieldName} (${field.typeName})'`);
if (field.fieldName !== 'StringField' || field.typeName !== 'std::string')
console.error(`FAILURE: Last field should be 'StringField (std::string)' but got '${field.fieldName} (${field.typeName})'`);
}
}
}
Expand All @@ -64,10 +64,58 @@ else {
console.log(`OK: Column ${i} fieldId: ${column.fieldId} `);
if (i === 0) {
if (column.fieldId !== 0)
console.error('FAILURE: First column should be for fieldId 0 (Category)');
console.error('FAILURE: First column should be for fieldId 0 (IntField)');
} else if (i === rntuple.builder.columnDescriptors.length - 1){
if (column.fieldId !== 10)
console.error('FAILURE: Last column should be for fieldId 10 (Nation)');
if (column.fieldId !== 3)
console.error('FAILURE: Last column should be for fieldId 3 (StringField)');
}
}
}

// Setup selector to process all fields (so cluster gets loaded)
const selector = new TSelector(),
fields = ['IntField', 'FloatField', 'DoubleField', 'StringField'];
for (const f of fields) selector.addBranch(f);

selector.Begin = () => {
console.log('\nBegin processing to load cluster data...');
};
selector.Process = function() {};
selector.Terminate = () => {
console.log('Finished dummy processing');
};

// Run rntupleProcess to ensure cluster is loaded
await rntupleProcess(rntuple, selector);

// Now validate entry data
const EPSILON = 1e-10;

for (let entryIndex = 0; entryIndex < 10; ++entryIndex) {
console.log(`\nChecking entry ${entryIndex}:`);

const expected = {
IntField: entryIndex,
FloatField: entryIndex * entryIndex,
DoubleField: entryIndex * 0.5,
StringField: `entry_${entryIndex}`
};

for (const field of fields) {
try {
const value = readEntry(rntuple, field, entryIndex),
expectedValue = expected[field],

pass = typeof value === 'number'
? Math.abs(value - expectedValue) < EPSILON
: value === expectedValue;

if (!pass)
console.error(`FAILURE: ${field} at entry ${entryIndex} expected ${expectedValue}, got ${value}`);
else
console.log(`OK: ${field} at entry ${entryIndex} = ${value}`);
} catch (err) {
console.error(`ERROR: Failed to read ${field} at entry ${entryIndex}: ${err.message}`);
}
}
}
Binary file added demo/node/rntuple_test.root
Binary file not shown.
2 changes: 1 addition & 1 deletion modules/rntuple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -928,4 +928,4 @@ async function tupleHierarchy(tuple_node, tuple) {
});
}

export { tupleHierarchy, readHeaderFooter, RBufferReader, rntupleProcess };
export { tupleHierarchy, readHeaderFooter, RBufferReader, rntupleProcess, readEntry };
Loading