diff --git a/jsroot/jsroot_reader.mjs b/jsroot/jsroot_reader.mjs index daffa75..6a5fd8e 100644 --- a/jsroot/jsroot_reader.mjs +++ b/jsroot/jsroot_reader.mjs @@ -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, + ]), + ); +} diff --git a/jsroot/types/map/README.md b/jsroot/types/map/README.md new file mode 100644 index 0000000..5a2277b --- /dev/null +++ b/jsroot/types/map/README.md @@ -0,0 +1,4 @@ +# `std::map` + +- [`fundamental`](fundamental): `std::map` +- [`nested`](nested): `std::map>` diff --git a/jsroot/types/map/fundamental/read.mjs b/jsroot/types/map/fundamental/read.mjs new file mode 100644 index 0000000..6eda36e --- /dev/null +++ b/jsroot/types/map/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/map/nested/read.mjs b/jsroot/types/map/nested/read.mjs new file mode 100644 index 0000000..9de8e5c --- /dev/null +++ b/jsroot/types/map/nested/read.mjs @@ -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); diff --git a/jsroot/types/multimap/README.md b/jsroot/types/multimap/README.md new file mode 100644 index 0000000..f6878c4 --- /dev/null +++ b/jsroot/types/multimap/README.md @@ -0,0 +1,4 @@ +# `std::multimap` + +- [`fundamental`](fundamental): `std::multimap` +- [`nested`](nested): `std::multimap>` diff --git a/jsroot/types/multimap/fundamental/read.mjs b/jsroot/types/multimap/fundamental/read.mjs new file mode 100644 index 0000000..8b7897c --- /dev/null +++ b/jsroot/types/multimap/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/multimap/nested/read.mjs b/jsroot/types/multimap/nested/read.mjs new file mode 100644 index 0000000..93380ef --- /dev/null +++ b/jsroot/types/multimap/nested/read.mjs @@ -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); diff --git a/jsroot/types/multiset/README.md b/jsroot/types/multiset/README.md new file mode 100644 index 0000000..637bdcf --- /dev/null +++ b/jsroot/types/multiset/README.md @@ -0,0 +1,4 @@ +# `std::multiset` + + * [`fundamental`](fundamental): `std::multiset` + * [`nested`](nested): `std::multiset>` diff --git a/jsroot/types/multiset/fundamental/read.mjs b/jsroot/types/multiset/fundamental/read.mjs new file mode 100644 index 0000000..13300a5 --- /dev/null +++ b/jsroot/types/multiset/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/multiset/nested/read.mjs b/jsroot/types/multiset/nested/read.mjs new file mode 100644 index 0000000..264bf98 --- /dev/null +++ b/jsroot/types/multiset/nested/read.mjs @@ -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); diff --git a/jsroot/types/set/README.md b/jsroot/types/set/README.md new file mode 100644 index 0000000..59141d6 --- /dev/null +++ b/jsroot/types/set/README.md @@ -0,0 +1,4 @@ +# `std::set` + + * [`fundamental`](fundamental): `std::set` + * [`nested`](nested): `std::set>` diff --git a/jsroot/types/set/fundamental/read.mjs b/jsroot/types/set/fundamental/read.mjs new file mode 100644 index 0000000..39855fa --- /dev/null +++ b/jsroot/types/set/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/set/nested/read.mjs b/jsroot/types/set/nested/read.mjs new file mode 100644 index 0000000..fc15f97 --- /dev/null +++ b/jsroot/types/set/nested/read.mjs @@ -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); diff --git a/jsroot/types/unordered_map/README.md b/jsroot/types/unordered_map/README.md new file mode 100644 index 0000000..5938a8b --- /dev/null +++ b/jsroot/types/unordered_map/README.md @@ -0,0 +1,4 @@ +# `std::unordered_map` + +- [`fundamental`](fundamental): `std::unordered_map` +- [`nested`](nested): `std::unordered_map>` diff --git a/jsroot/types/unordered_map/fundamental/read.mjs b/jsroot/types/unordered_map/fundamental/read.mjs new file mode 100644 index 0000000..15b7648 --- /dev/null +++ b/jsroot/types/unordered_map/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/unordered_map/nested/read.mjs b/jsroot/types/unordered_map/nested/read.mjs new file mode 100644 index 0000000..774104d --- /dev/null +++ b/jsroot/types/unordered_map/nested/read.mjs @@ -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); diff --git a/jsroot/types/unordered_multimap/README.md b/jsroot/types/unordered_multimap/README.md new file mode 100644 index 0000000..5938a8b --- /dev/null +++ b/jsroot/types/unordered_multimap/README.md @@ -0,0 +1,4 @@ +# `std::unordered_map` + +- [`fundamental`](fundamental): `std::unordered_map` +- [`nested`](nested): `std::unordered_map>` diff --git a/jsroot/types/unordered_multimap/fundamental/read.mjs b/jsroot/types/unordered_multimap/fundamental/read.mjs new file mode 100644 index 0000000..25e83b6 --- /dev/null +++ b/jsroot/types/unordered_multimap/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/unordered_multimap/nested/read.mjs b/jsroot/types/unordered_multimap/nested/read.mjs new file mode 100644 index 0000000..562475f --- /dev/null +++ b/jsroot/types/unordered_multimap/nested/read.mjs @@ -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); diff --git a/jsroot/types/unordered_multiset/README.md b/jsroot/types/unordered_multiset/README.md new file mode 100644 index 0000000..21eb0a2 --- /dev/null +++ b/jsroot/types/unordered_multiset/README.md @@ -0,0 +1,4 @@ +# `std::unordered_multiset` + + * [`fundamental`](fundamental): `std::unordered_multiset` + * [`nested`](nested): `std::unordered_multiset>` diff --git a/jsroot/types/unordered_multiset/fundamental/read.mjs b/jsroot/types/unordered_multiset/fundamental/read.mjs new file mode 100644 index 0000000..e221a34 --- /dev/null +++ b/jsroot/types/unordered_multiset/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/unordered_multiset/nested/read.mjs b/jsroot/types/unordered_multiset/nested/read.mjs new file mode 100644 index 0000000..1879e8f --- /dev/null +++ b/jsroot/types/unordered_multiset/nested/read.mjs @@ -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); diff --git a/jsroot/types/unordered_set/README.md b/jsroot/types/unordered_set/README.md new file mode 100644 index 0000000..3a8ff4b --- /dev/null +++ b/jsroot/types/unordered_set/README.md @@ -0,0 +1,4 @@ +# `std::unordered_set` + + * [`fundamental`](fundamental): `std::unordered_set` + * [`nested`](nested): `std::unordered_set>` diff --git a/jsroot/types/unordered_set/fundamental/read.mjs b/jsroot/types/unordered_set/fundamental/read.mjs new file mode 100644 index 0000000..28fc7f7 --- /dev/null +++ b/jsroot/types/unordered_set/fundamental/read.mjs @@ -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); diff --git a/jsroot/types/unordered_set/nested/read.mjs b/jsroot/types/unordered_set/nested/read.mjs new file mode 100644 index 0000000..7b0e9a6 --- /dev/null +++ b/jsroot/types/unordered_set/nested/read.mjs @@ -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);