From 842e1979da8feec042a898844ee6610d75b104c1 Mon Sep 17 00:00:00 2001 From: brauliorivas Date: Mon, 17 Jun 2024 22:36:43 +0000 Subject: [PATCH] =?UTF-8?q?Deploy=20preview=20for=20PR=2036=20=F0=9F=9B=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...e4e256db2022cde860fee7431094e5989400b.idx} | Bin 12216 -> 12216 bytes ...4e256db2022cde860fee7431094e5989400b.pack} | Bin 151611 -> 151611 bytes ...e4e256db2022cde860fee7431094e5989400b.rev} | Bin 1644 -> 1644 bytes pr-preview/pr-36/js/types/dynamic.js | 2 +- pr-preview/pr-36/js/types/links.js | 1 + pr-preview/pr-36/js/types/load.js | 2 +- pr-preview/pr-36/test/dynamic.test.js | 2 +- pr-preview/pr-36/test/load.json | 247 ++++++++++++++++++ pr-preview/pr-36/test/load.test.js | 52 +++- 9 files changed, 302 insertions(+), 4 deletions(-) rename pr-preview/pr-36/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.idx => pack-fd5e4e256db2022cde860fee7431094e5989400b.idx} (97%) rename pr-preview/pr-36/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.pack => pack-fd5e4e256db2022cde860fee7431094e5989400b.pack} (98%) rename pr-preview/pr-36/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.rev => pack-fd5e4e256db2022cde860fee7431094e5989400b.rev} (87%) create mode 100644 pr-preview/pr-36/test/load.json diff --git a/pr-preview/pr-36/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx b/pr-preview/pr-36/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.idx similarity index 97% rename from pr-preview/pr-36/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx rename to pr-preview/pr-36/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.idx index 064be2d538a3d6fb96008f0218b024c2c05a8dca..a115939cbd14d3c0eb2fd3e2d5655655f5bd63ab 100644 GIT binary patch delta 92 zcmV-i0Hgo7U$|eeCMyDEyOSs@G6G@=lUyq%0`pOmge$@VUe1$9EJ6bHjI)d^RsjNK yJ+tI3tN|$fUQQ)#vH~pLh7ay^F$qpti9ieQ+8v7w_nNZSv-ID5coD_;S$?sBUngY% delta 92 zcmV-i0Hgo7U$|eeCMyDBfRiXIG6G)ClUyq%0`-HFge$@VVu_PTEJ6bFQL~IJRsjNH y0<+{TtN|!Di6b?Sf8!bs2Ro8>Q9+^8qpfx4!oQ aX;>8fUQQ)#vH~pLh7ay^F$qpti9iedcpNMM delta 68 zcmV-K0K5OYpb5L634pW#&R(|(Vgb7Yx6WPxI|H}GWdV(iw~X}xG6J_z^8q^ox4!oQ aX;>6Di6b?Sf8!bs2Ro8>Q98GA`In1^}KQ8$kd7 delta 78 zcmaFE^M+@GIWunq0|TQH0|P@b5bxgX!ractdIres+I)efgi*u1Q`xk?{;?DvyY-~9 hK*wkGr$Z~}b+Fk?nLT;=v<-pV-X8tL*ss!L4*;Ik8~gwO diff --git a/pr-preview/pr-36/js/types/dynamic.js b/pr-preview/pr-36/js/types/dynamic.js index eb722a61..fa250270 100644 --- a/pr-preview/pr-36/js/types/dynamic.js +++ b/pr-preview/pr-36/js/types/dynamic.js @@ -25,7 +25,7 @@ export function loadOneToOneRelations( const linkType = linkTypes[name]; const link = new linkType(object, toObject); - oneToOne[name] = link; + oneToOne[name].push(link); object.oneToOneRelations[name] = link; } } diff --git a/pr-preview/pr-36/js/types/links.js b/pr-preview/pr-36/js/types/links.js index c95fc73c..5f2914d1 100644 --- a/pr-preview/pr-36/js/types/links.js +++ b/pr-preview/pr-36/js/types/links.js @@ -133,4 +133,5 @@ export const linkTypes = { "daughters": DaughterLink, "trackerHits": Link, "startVertex": Link, + "particles": Link, }; diff --git a/pr-preview/pr-36/js/types/load.js b/pr-preview/pr-36/js/types/load.js index ea7340b9..1623a67d 100644 --- a/pr-preview/pr-36/js/types/load.js +++ b/pr-preview/pr-36/js/types/load.js @@ -12,7 +12,7 @@ export function loadObjectType(collection, datatype, type) { let oneToOne = {}; if (datatype.oneToOneRelations) datatype.oneToOneRelations.forEach((relation) => { - oneToOne[relation.name] = null; + oneToOne[relation.name] = []; if (colors[relation.name] === undefined) { colors[relation.name] = generateRandomColor(); } diff --git a/pr-preview/pr-36/test/dynamic.test.js b/pr-preview/pr-36/test/dynamic.test.js index 0fed4546..10c2d7dd 100644 --- a/pr-preview/pr-36/test/dynamic.test.js +++ b/pr-preview/pr-36/test/dynamic.test.js @@ -167,7 +167,7 @@ test("load one to one relations with some definition and data", () => { }, ]; const oneToOne = { - "startVertex": null, + "startVertex": [], }; loadOneToOneRelations(object, data, oneToOneRelations, oneToOne, []); expect(object.oneToOneRelations).not.toBeNull(); diff --git a/pr-preview/pr-36/test/load.json b/pr-preview/pr-36/test/load.json new file mode 100644 index 00000000..daa5c4c7 --- /dev/null +++ b/pr-preview/pr-36/test/load.json @@ -0,0 +1,247 @@ +{ + "Event 0": {}, + "Event 1": { + "Particle": { + "collID": 11, + "collType": "edm4hep::MCParticleCollection", + "collection": [ + { + "PDG": 11, + "charge": -1.0, + "colorFlow": { + "a": 0, + "b": 0 + }, + "daughters": [ + { + "collectionID": 11, + "index": 2 + } + ], + "endpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "generatorStatus": 4, + "mass": 0.0005109999910928309, + "momentum": { + "x": 0.0, + "y": 0.0, + "z": 120.0 + }, + "momentumAtEndpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "parents": [], + "simulatorStatus": 0, + "spin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "time": 0.0, + "vertex": { + "x": -0.01184066478163004, + "y": -2.074451003863942e-06, + "z": -0.08278788626194 + } + }, + { + "PDG": -11, + "charge": 1.0, + "colorFlow": { + "a": 0, + "b": 0 + }, + "daughters": [], + "endpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "generatorStatus": 4, + "mass": 0.0005109999910928309, + "momentum": { + "x": 0.0, + "y": 0.0, + "z": -120.0 + }, + "momentumAtEndpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "parents": [], + "simulatorStatus": 0, + "spin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "time": 0.0, + "vertex": { + "x": -0.01184066478163004, + "y": -2.074451003863942e-06, + "z": -0.08278788626194 + } + }, + { + "PDG": 11, + "charge": -1.0, + "colorFlow": { + "a": 0, + "b": 0 + }, + "daughters": [], + "endpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "generatorStatus": 21, + "mass": 0.0, + "momentum": { + "x": 0.0, + "y": 0.0, + "z": 120.0 + }, + "momentumAtEndpoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "parents": [ + { + "collectionID": 11, + "index": 0 + } + ], + "simulatorStatus": 0, + "spin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "time": 0.0, + "vertex": { + "x": -0.01184066478163004, + "y": -2.074451003863942e-06, + "z": -0.08278788626194 + } + } + ] + }, + "AllMuon": { + "collID": 12, + "collType": "edm4hep::ReconstructedParticleCollection", + "collection": [] + }, + "Jet": { + "collID": 13, + "collType": "edm4hep::ReconstructedParticleCollection", + "collection": [ + { + "charge": 1.0, + "clusters": [], + "covMatrix": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "energy": 12.062528610229492, + "goodnessOfPID": 0.0, + "mass": 2.315242290496826, + "momentum": { + "x": 11.738886833190918, + "y": 1.2114704847335815, + "z": 0.9354811906814575 + }, + "particleIDUsed": { + "collectionID": -2, + "index": -2 + }, + "particleIDs": [ + { + "collectionID": 4, + "index": 45 + } + ], + "particles": [ + { + "collectionID": 14, + "index": 1 + } + ], + "referencePoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "startVertex": { + "collectionID": -2, + "index": -2 + }, + "tracks": [], + "type": 0 + }, + { + "charge": 1.0, + "clusters": [], + "covMatrix": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "energy": 7.181974411010742, + "goodnessOfPID": 0.0, + "mass": 2.346627712249756, + "momentum": { + "x": 1.1801066398620605, + "y": -4.268080234527588, + "z": -5.144407749176025 + }, + "particleIDUsed": { + "collectionID": -2, + "index": -2 + }, + "particleIDs": [ + { + "collectionID": 4, + "index": 46 + } + ], + "particles": [], + "referencePoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "startVertex": { + "collectionID": -2, + "index": -2 + }, + "tracks": [], + "type": 0 + } + ] + } + }, + "Event 2": {} +} \ No newline at end of file diff --git a/pr-preview/pr-36/test/load.test.js b/pr-preview/pr-36/test/load.test.js index a795c391..c9e813c4 100644 --- a/pr-preview/pr-36/test/load.test.js +++ b/pr-preview/pr-36/test/load.test.js @@ -1,6 +1,7 @@ -import { loadObjectType } from "../js/types/load.js"; +import { loadObjectType, loadObjects } from "../js/types/load.js"; import { datatypes } from "../output/datatypes.js"; import { objectTypes } from "../js/types/objects.js"; +import json from "./load.json" assert { type: "json" }; test("load a collection of particles", () => { const type = "edm4hep::Track"; @@ -171,3 +172,52 @@ test("load a collection of particles", () => { expect(trackerHits.length).toEqual(6); expect(tracks.length).toEqual(0); }); + +test("load a json file with a collection of objects", () => { + const objects = loadObjects(json, 1, [ + "edm4hep::MCParticle", + "edm4hep::ReconstructedParticle", + ]); + + expect(objects["edm4hep::MCParticle"]).toBeDefined(); + expect(objects["edm4hep::ReconstructedParticle"]).toBeDefined(); + + expect(objects["edm4hep::MCParticle"].collection.length).toEqual(3); + expect( + objects["edm4hep::MCParticle"].collection.map((val) => val.id) + ).toEqual([0, 1, 2]); + expect(objects["edm4hep::MCParticle"].oneToMany["daughters"]).toBeDefined(); + expect(objects["edm4hep::MCParticle"].oneToMany["parents"]).toBeDefined(); + expect( + objects["edm4hep::MCParticle"].oneToMany["daughters"][0].from.id + ).toEqual(0); + expect( + objects["edm4hep::MCParticle"].oneToMany["daughters"][0].to.id + ).toEqual(2); + + expect(objects["edm4hep::ReconstructedParticle"].collection.length).toEqual( + 2 + ); + expect( + objects["edm4hep::ReconstructedParticle"].collection.map((val) => val.id) + ).toEqual([0, 1]); + expect( + objects["edm4hep::ReconstructedParticle"].oneToMany["particles"] + ).toBeDefined(); + expect( + objects["edm4hep::ReconstructedParticle"].oneToOne["startVertex"] + ).toBeDefined(); + expect( + objects["edm4hep::ReconstructedParticle"].oneToMany["particles"][0].from.id + ).toEqual(0); + expect( + objects["edm4hep::ReconstructedParticle"].oneToMany["particles"][0].to.id + ).toEqual(1); + + expect( + objects["edm4hep::ReconstructedParticle"].oneToOne["startVertex"][0].to + ).toBeUndefined(); + expect( + objects["edm4hep::ReconstructedParticle"].oneToOne["startVertex"][1].to + ).toBeUndefined(); +});