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
34 changes: 34 additions & 0 deletions jsroot/jsroot_reader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,37 @@ export function floatToHex(num) {

return (sign ? "-" : "") + "0x" + leading + frac + "p" + expStr;
}

export function sortArrayOfNumbers(arr) {
return arr.sort((a, b) => a - b);
}

export function sortDeep(obj) {
sortArrayOfNumbers(obj); // sort nums inside array

obj.forEach((value) => { if (Array.isArray(value)) sortArrayOfNumbers(value); }); // sort elements inside inner array

obj.sort((a, b) => {
const len = Math.min(a.length, b.length);
for (let i = 0; i < len; i++) {
if (a[i] !== b[i]) return a[i] - b[i];
}
return a.length - b.length;
});

return obj;
}

export function pairArrayToMap(arr) {
// sort by key
arr.sort((a, b) =>
String(a.first).localeCompare(String(b.first)),
);

return Object.fromEntries(
arr.map((p) => [
p.first,
Array.isArray(p.second) ? pairArrayToMap(p.second) : p.second,
]),
);
}
4 changes: 4 additions & 0 deletions jsroot/types/map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::map`

- [`fundamental`](fundamental): `std::map<std::string, std::int32_t>`
- [`nested`](nested): `std::map<std::string, std::map<std::string, std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/map/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.map.fundamental.root",
output = "types.map.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
8 changes: 8 additions & 0 deletions jsroot/types/map/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [input = "types.map.nested.root", output = "types.map.nested.json"] =
process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
4 changes: 4 additions & 0 deletions jsroot/types/multimap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::multimap`

- [`fundamental`](fundamental): `std::multimap<std::string, ::int32_t>`
- [`nested`](nested): `std::multimap<std::string, std::multimap<std::string, std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/multimap/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.multimap.fundamental.root",
output = "types.multimap.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
10 changes: 10 additions & 0 deletions jsroot/types/multimap/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.multimap.nested.root",
output = "types.multimap.nested.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
4 changes: 4 additions & 0 deletions jsroot/types/multiset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::multiset`

* [`fundamental`](fundamental): `std::multiset<std::int32_t>`
* [`nested`](nested): `std::multiset<std::multiset<std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/multiset/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortArrayOfNumbers } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.multiset.fundamental.root",
output = "types.multiset.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, sortArrayOfNumbers);
10 changes: 10 additions & 0 deletions jsroot/types/multiset/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortDeep } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.set.multinested.root",
output = "types.multiset.nested.json",
] = process.argv.slice(2);

read(input, output, fields, sortDeep);
4 changes: 4 additions & 0 deletions jsroot/types/set/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::set`

* [`fundamental`](fundamental): `std::set<std::int32_t>`
* [`nested`](nested): `std::set<std::set<std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/set/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortArrayOfNumbers } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.set.fundamental.root",
output = "types.set.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, sortArrayOfNumbers);
8 changes: 8 additions & 0 deletions jsroot/types/set/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { read, sortDeep } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [input = "types.set.nested.root", output = "types.set.nested.json"] =
process.argv.slice(2);

read(input, output, fields, sortDeep);
4 changes: 4 additions & 0 deletions jsroot/types/unordered_map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::unordered_map`

- [`fundamental`](fundamental): `std::unordered_map<std::string, std::int32_t>`
- [`nested`](nested): `std::unordered_map<std::string, std::unordered_map<std::string, std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/unordered_map/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_map.fundamental.root",
output = "types.unordered_map.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
10 changes: 10 additions & 0 deletions jsroot/types/unordered_map/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_map.nested.root",
output = "types.unordered_map.nested.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
4 changes: 4 additions & 0 deletions jsroot/types/unordered_multimap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::unordered_map`

- [`fundamental`](fundamental): `std::unordered_map<std::string, std::int32_t>`
- [`nested`](nested): `std::unordered_map<std::string, std::unordered_map<std::string, std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/unordered_multimap/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_multimap.fundamental.root",
output = "types.unordered_multimap.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
10 changes: 10 additions & 0 deletions jsroot/types/unordered_multimap/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, pairArrayToMap } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_multimap.nested.root",
output = "types.unordered_multimap.nested.json",
] = process.argv.slice(2);

read(input, output, fields, pairArrayToMap);
4 changes: 4 additions & 0 deletions jsroot/types/unordered_multiset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::unordered_multiset`

* [`fundamental`](fundamental): `std::unordered_multiset<std::int32_t>`
* [`nested`](nested): `std::unordered_multiset<std::unordered_multiset<std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/unordered_multiset/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortArrayOfNumbers } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_multiset.fundamental.root",
output = "types.unordered_multiset.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, sortArrayOfNumbers);
10 changes: 10 additions & 0 deletions jsroot/types/unordered_multiset/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortDeep } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_multiset.nested.root",
output = "types.unordered_multiset.nested.json",
] = process.argv.slice(2);

read(input, output, fields, sortDeep);
4 changes: 4 additions & 0 deletions jsroot/types/unordered_set/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `std::unordered_set`

* [`fundamental`](fundamental): `std::unordered_set<std::int32_t>`
* [`nested`](nested): `std::unordered_set<std::unordered_set<std::int32_t>>`
10 changes: 10 additions & 0 deletions jsroot/types/unordered_set/fundamental/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortArrayOfNumbers } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_set.fundamental.root",
output = "types.unordered_set.fundamental.json",
] = process.argv.slice(2);

read(input, output, fields, sortArrayOfNumbers);
10 changes: 10 additions & 0 deletions jsroot/types/unordered_set/nested/read.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { read, sortDeep } from "../../../jsroot_reader.mjs";

const fields = ["Index32", "Index64", "SplitIndex32", "SplitIndex64"];

const [
input = "types.unordered_set.nested.root",
output = "types.unordered_set.nested.json",
] = process.argv.slice(2);

read(input, output, fields, sortDeep);