Skip to content

Commit 688d5c7

Browse files
committed
Build with more supported cases in tuple
1 parent 637615f commit 688d5c7

File tree

2 files changed

+130
-3
lines changed

2 files changed

+130
-3
lines changed

build/jsroot.js

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177541,6 +177541,7 @@ const ENTupleColumnType = {
177541177541
kReal64: 0x0D,
177542177542
kIndex32: 0x0E,
177543177543
kIndex64: 0x0F,
177544+
kSwitch: 0x10,
177544177545
kSplitInt16: 0x11,
177545177546
kSplitUInt16: 0x12,
177546177547
kSplitInt32: 0x13,
@@ -177683,6 +177684,17 @@ function DecodeDeltaIndex(blob, coltype) {
177683177684
return { blob: result, coltype };
177684177685
}
177685177686

177687+
function DecodeSwitchIndex(src) {
177688+
let o = 0, prev = BigInt(0);
177689+
while (o < src.byteLength) {
177690+
const v = prev + src.getBigInt64(o, LITTLE_ENDIAN);
177691+
src.setBigInt64(o, prev, LITTLE_ENDIAN);
177692+
prev = v;
177693+
o += 12;
177694+
}
177695+
return src;
177696+
}
177697+
177686177698
/**
177687177699
* @summary Decode a reconstructed signed integer buffer using ZigZag encoding
177688177700
*/
@@ -178414,7 +178426,7 @@ class ReaderItem {
178414178426
}
178415178427

178416178428
shift(entries) {
178417-
if (this.sz)
178429+
if (this.sz && this.simple)
178418178430
this.shift_o(this.sz * entries);
178419178431
else {
178420178432
while (entries-- > 0)
@@ -178475,6 +178487,16 @@ class ReaderItem {
178475178487
};
178476178488
this.sz = 8;
178477178489
break;
178490+
case ENTupleColumnType.kSwitch:
178491+
this.func = function(obj) {
178492+
// index not used in std::variant, may be in some other usecases
178493+
// obj[this.name] = Number(this.view.getBigInt64(this.o, LITTLE_ENDIAN));
178494+
this.shift_o(8); // skip value, not used yet
178495+
obj[this.name] = this.view.getInt32(this.o, LITTLE_ENDIAN);
178496+
this.shift_o(4);
178497+
};
178498+
this.sz = 12;
178499+
break;
178478178500
case ENTupleColumnType.kInt32:
178479178501
case ENTupleColumnType.kIndex32:
178480178502
this.func = function(obj) {
@@ -178612,6 +178634,74 @@ class ReaderItem {
178612178634
};
178613178635
}
178614178636

178637+
/** @summary implement reading of std::array<T,N> where item1 reads value element */
178638+
assignArrayReader(itemv, arrsize) {
178639+
this.itemv = itemv;
178640+
this.arrsize = arrsize;
178641+
178642+
itemv.funcv = itemv.func;
178643+
itemv.shiftv = itemv.shift;
178644+
// assign noop
178645+
itemv.func = itemv.shift = () => {};
178646+
178647+
// item itself can remain simple
178648+
itemv.set_simple(false);
178649+
178650+
this.func = function(tgtobj) {
178651+
const arr = [], tmp = {};
178652+
let len = this.arrsize;
178653+
while (len-- > 0) {
178654+
this.itemv.funcv(tmp);
178655+
arr.push(tmp[this.name]);
178656+
}
178657+
tgtobj[this.name] = arr;
178658+
};
178659+
178660+
this.shift = function(entries) {
178661+
if (entries > 0)
178662+
this.itemv.shiftv(entries * this.arrsize);
178663+
};
178664+
}
178665+
178666+
/** @summary assign all childs fields for std::variant reader */
178667+
assignVariantReader(items) {
178668+
this.items = items;
178669+
items.forEach(item => {
178670+
item.funcV = item.func;
178671+
item.func = item.shift = () => {};
178672+
item.set_simple(false);
178673+
});
178674+
this.set_simple(false);
178675+
178676+
this.funcV = this.func;
178677+
this.func = function(tgtobj) {
178678+
const tmp = {};
178679+
this.funcV(tmp);
178680+
const id = tmp[this.name];
178681+
if (id === 0)
178682+
tgtobj[this.name] = null; // set null
178683+
else if (Number.isInteger(id) && (id > 0) && (id <= this.items.length))
178684+
this.items[id - 1].funcV(tgtobj);
178685+
};
178686+
}
178687+
178688+
/** @summary assign all childs fields for std::variant reader */
178689+
assignTupleReader(items) {
178690+
this.items = items;
178691+
items.forEach(item => {
178692+
item.funcV = item.func;
178693+
item.func = item.shift = () => {};
178694+
item.set_simple(false);
178695+
});
178696+
this.set_simple(false);
178697+
178698+
this.func = function(tgtobj) {
178699+
const tuple = {};
178700+
this.items.forEach(item => item.funcV(tuple));
178701+
tgtobj[this.name] = tuple;
178702+
};
178703+
}
178704+
178615178705
/** @summary implement reading of std::pair where item1 reads first (key) element */
178616178706
assignPairReader(item_p1, item_p2) {
178617178707
this.item_p1 = item_p1;
@@ -178708,6 +178798,8 @@ class ReaderItem {
178708178798
// Handle split index types
178709178799
if (originalColtype === ENTupleColumnType.kSplitIndex32 || originalColtype === ENTupleColumnType.kSplitIndex64)
178710178800
view = new DataView(DecodeDeltaIndex(data.blob, data.coltype).blob.buffer);
178801+
else if (originalColtype === ENTupleColumnType.kSwitch)
178802+
view = DecodeSwitchIndex(data.blob);
178711178803
// Handle Split Signed Int types
178712178804
else if (originalColtype === ENTupleColumnType.kSplitInt16 || originalColtype === ENTupleColumnType.kSplitInt32 || originalColtype === ENTupleColumnType.kSplitInt64)
178713178805
view = new DataView(decodeZigzag(data.blob, data.coltype).blob.buffer);
@@ -178822,6 +178914,24 @@ async function rntupleProcess(rntuple, selector, args = {}) {
178822178914
return item;
178823178915
}
178824178916

178917+
if ((childs.length === 1) && (field.typeName.indexOf('std::array') === 0)) {
178918+
const item1 = addFieldReading(childs[0], tgtname),
178919+
item = new ReaderItem(null, tgtname);
178920+
handle.arr.push(item);
178921+
item.assignArrayReader(item1, Number(field.arraySize));
178922+
return item;
178923+
}
178924+
178925+
if ((childs.length > 0) && (field.typeName.indexOf('std::tuple') === 0)) {
178926+
const items = [];
178927+
for (let i = 0; i < childs.length; ++i)
178928+
items.push(addFieldReading(childs[i], `_${i}`));
178929+
const item = new ReaderItem(null, tgtname);
178930+
handle.arr.push(item);
178931+
item.assignTupleReader(items);
178932+
return item;
178933+
}
178934+
178825178935
throw new Error(`No columns found for field '${field.fieldName}' in RNTuple`);
178826178936
}
178827178937

@@ -178836,9 +178946,20 @@ async function rntupleProcess(rntuple, selector, args = {}) {
178836178946
return items; // second item performs complete reading of the string
178837178947
}
178838178948

178839-
if ((childs.length === 1) && (field.typeName.indexOf('std::vector') === 0 || field.typeName.indexOf('std::map') === 0)) {
178949+
let is_stl = false;
178950+
['vector', 'map', 'unordered_map', 'multimap', 'unordered_multimap', 'set', 'unordered_set', 'multiset', 'unordered_multiset'].forEach(name => {
178951+
if (field.typeName.indexOf('std::' + name) === 0)
178952+
is_stl = true;
178953+
});
178954+
178955+
if ((childs.length === 1) && is_stl) {
178840178956
const itemv = addFieldReading(childs[0], tgtname);
178841178957
item.assignCollectionReader(itemv);
178958+
} else if ((childs.length > 0) && (field.typeName.indexOf('std::variant') === 0)) {
178959+
const items = [];
178960+
for (let i = 0; i < childs.length; ++i)
178961+
items.push(addFieldReading(childs[i], tgtname));
178962+
item.assignVariantReader(items);
178842178963
}
178843178964

178844178965
return item;

changes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33

44
## Changes in dev
5-
1. Support std collections like `std::vector` and `std::map` in `RNtuple`
5+
1. Implement new data types in `RNtuple`
6+
- `std::vector`
7+
- `std::map`, `std::unordered_map`, `std::multimap`, `std::unordered_multimap` with `std::pair`
8+
- `std::set`, `std::unordered_set`, `std::multiset`, `std::unordered_multiset`
9+
- `std::array`
10+
- `std::variant`
11+
- `std::tuple`
612
1. Resort order of ranges in http request, fixing several long-standing problems #374
713
1. Implement for `TPie` 3d, text, title drawing including interactivity
814
1. Implement `TCanvas` support in `build3d` function #373

0 commit comments

Comments
 (0)