Skip to content

Commit 9d5eb1a

Browse files
committed
[rntuple] add support for streamed element
1 parent 7879013 commit 9d5eb1a

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

modules/rntuple.mjs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isStr, isObject } from './core.mjs';
2-
import { R__unzip } from './io.mjs';
2+
import { R__unzip, TBuffer } from './io.mjs';
33
import { TDrawSelector, treeDraw } from './tree.mjs';
44

55
// ENTupleColumnType - supported column types
@@ -1104,6 +1104,53 @@ class StringReaderItem extends ReaderItem {
11041104

11051105
}
11061106

1107+
/** @class reading Streamed field
1108+
* @private */
1109+
1110+
class StreamedReaderItem extends ReaderItem {
1111+
1112+
constructor(items, name, file, classname) {
1113+
super(items, name);
1114+
items[0]._is_offset_item = true;
1115+
items[1].set_not_simple();
1116+
this.file = file;
1117+
this.classname = classname;
1118+
this.off0 = 0;
1119+
}
1120+
1121+
reset_extras() {
1122+
this.off0 = 0;
1123+
}
1124+
1125+
func(tgtobj) {
1126+
const tmp = {}, res = {};
1127+
this.items[0].func(tmp);
1128+
const off = Number(tmp.len),
1129+
buf = new TBuffer(this.items[1].view, this.items[1].o, this.file, this.items[1].o + off - this.off0);
1130+
1131+
// TODO: if by chance object splited between two pages
1132+
if (this.items[1].view.byteLength < this.items[1].o + off - this.off0)
1133+
console.error('FAILURE - buffer is splitted, need to be read from next page');
1134+
1135+
buf.classStreamer(res, this.classname);
1136+
1137+
this.items[1].shift_o(off - this.off0);
1138+
this.off0 = off;
1139+
tgtobj[this.name] = res;
1140+
}
1141+
1142+
shift(entries) {
1143+
this.items[0].shift(entries - 1);
1144+
const tmp = {};
1145+
this.items[0].func(tmp);
1146+
const off = Number(tmp.len);
1147+
this.items[1].shift_o(off - this.off0);
1148+
this.off0 = off;
1149+
}
1150+
1151+
}
1152+
1153+
11071154
/** @class reading of std::array<T,N>
11081155
* @private */
11091156

@@ -1423,6 +1470,7 @@ async function rntupleProcess(rntuple, selector, args = {}) {
14231470
return new TupleReaderItem(items, tgtname);
14241471
}
14251472

1473+
// this is custom class which is decomposed on several fields
14261474
if ((childs.length > 0) && field.checksum && field.typeName) {
14271475
const items = [];
14281476
for (let i = 0; i < childs.length; ++i)
@@ -1444,6 +1492,14 @@ async function rntupleProcess(rntuple, selector, args = {}) {
14441492
return new BitsetReaderItem([itembit], tgtname, Number(field.arraySize));
14451493
}
14461494

1495+
if ((columns.length === 2) && field.checksum && field.typeName) {
1496+
if (!handle.file.getStreamer(field.typeName, { checksum: field.checksum }))
1497+
throw new Error(`No streamer for type '${field.typeName}' checksum ${field.checksum}`);
1498+
1499+
const itemlen = addColumnReadout(columns[0], 'len'),
1500+
itemb = addColumnReadout(columns[1], 'b');
1501+
return new StreamedReaderItem([itemlen, itemb], tgtname, handle.file, field.typeName);
1502+
}
14471503

14481504
let is_stl = false;
14491505
['vector', 'map', 'unordered_map', 'multimap', 'unordered_multimap', 'set', 'unordered_set', 'multiset', 'unordered_multiset'].forEach(name => {

0 commit comments

Comments
 (0)