diff --git a/README.md b/README.md index 884944a..9ce51c2 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,91 @@ https://eic.github.io/firebird/ Run `ng serve` in `firebird-ng` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. +# Firebird Data Exchange format + +Data exchange is both JSON and Javascript object compatible. + +It starts with version, any custom origin info and a list of entries. +In HENP physics `entry` may correspond to `event` data. + +```json +{ + "version": "0.01", + "origin": {any custom origin info here"}, + "entries": [ + entry1, entry2, ... + ] +} +``` + +- **version** - is JSON schema version +- **origin** - designed for any general custom info such as original file name, + timestamp, simulation software version, etc. +- **entries** - list of entries/events. The format is below. + +## Entry format + +Entry is an object with `id` and `components` properties. +By design components represent different hits, tracks, vertices, collections, etc. +While can be any arbitary data, that will be further rendered by the frontend. + +```json +{ + "id": "entry number or unique string", + "components": [ + + ... + + ] +} +``` + +requrired fields are `id` and `components`. + + +## Component format + +- "name": unique string id +- "type": string with type (depends on what component will be used in the frontend to render it) +- "originType": optional string with type of origin, e.g. "edm4eic::TrackerHitData", +- all other fields are depend on "type" + +So far example of exchange format looks like (only required fields are used here): + +```json +{ + "version": "0.01", + "entries": [ + { + "id": "event 0", + "components": [ + { + "name": "BarrelVertexHits", + "type": "HitBox", + ..., + }, + ... + ] + }, + ... + ] +} +``` + +## HitBox component + +```json +{ + "pos": [1, 2, 3], + "dim": [10, 10, 1], + "t": [4, 1], + "ed": [0.001, 0.0001] +} +``` +Hit has + +- "pos": position [mm] (x, y, z), +- "dim": box dimensions [mm] (dx, dy, dz), +- "t": time information [ns] (time, err_time), +- "ed": energy deposit with error [GeV] (edep, err_edep) + diff --git a/firebird-ng/src/app/app.config.ts b/firebird-ng/src/app/app.config.ts index 53dbcee..c6dc804 100644 --- a/firebird-ng/src/app/app.config.ts +++ b/firebird-ng/src/app/app.config.ts @@ -2,7 +2,7 @@ import {APP_INITIALIZER, ApplicationConfig, importProvidersFrom} from '@angular/ import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import {provideAnimations} from "@angular/platform-browser/animations"; -import {FirebirdConfigService} from "./firebird-config.service"; +import {ServerConfigService} from "./server-config.service"; import {provideHttpClient, withFetch} from "@angular/common/http"; export const appConfig: ApplicationConfig = { @@ -13,12 +13,12 @@ export const appConfig: ApplicationConfig = { { provide: APP_INITIALIZER, useFactory: configInitializer, - deps: [FirebirdConfigService], + deps: [ServerConfigService], multi: true } ] }; -export function configInitializer(configService: FirebirdConfigService): () => Promise { +export function configInitializer(configService: ServerConfigService): () => Promise { return () => configService.loadConfig(); } diff --git a/firebird-ng/src/app/input-config/input-config.component.ts b/firebird-ng/src/app/input-config/input-config.component.ts index 1efd165..e742baa 100644 --- a/firebird-ng/src/app/input-config/input-config.component.ts +++ b/firebird-ng/src/app/input-config/input-config.component.ts @@ -14,7 +14,7 @@ import {MatAutocomplete, MatAutocompleteTrigger, MatOption} from "@angular/mater import {AsyncPipe, NgForOf} from "@angular/common"; import {MatTooltip} from "@angular/material/tooltip"; import {ResourceSelectComponent} from "../resource-select/resource-select.component"; -import {defaultFirebirdConfig, FirebirdConfig, FirebirdConfigService} from "../firebird-config.service"; +import {defaultFirebirdConfig, ServerConfig, ServerConfigService} from "../server-config.service"; import {MatAccordion, MatExpansionPanel, MatExpansionPanelTitle, MatExpansionPanelHeader} from "@angular/material/expansion"; @@ -34,7 +34,7 @@ export class InputConfigComponent implements OnInit, AfterViewInit { serverUseApi: FormControl = new FormControl(false); serverApiHost = new FormControl('localhost'); serverApiPort: FormControl = new FormControl(5454); - firebirdConfig: FirebirdConfig = defaultFirebirdConfig; + firebirdConfig: ServerConfig = defaultFirebirdConfig; @ViewChild('geometrySelect') @@ -107,7 +107,7 @@ export class InputConfigComponent implements OnInit, AfterViewInit { constructor(private userConfigService: UserConfigService, - private firebirdConfigService: FirebirdConfigService) { + private firebirdConfigService: ServerConfigService) { } diff --git a/firebird-ng/src/app/main-display/main-display.component.html b/firebird-ng/src/app/main-display/main-display.component.html index 3f31819..0720628 100644 --- a/firebird-ng/src/app/main-display/main-display.component.html +++ b/firebird-ng/src/app/main-display/main-display.component.html @@ -117,4 +117,4 @@
{{currentGeometry}}
-
+
diff --git a/firebird-ng/src/app/main-display/main-display.component.scss b/firebird-ng/src/app/main-display/main-display.component.scss index 09d4adc..06b478f 100644 --- a/firebird-ng/src/app/main-display/main-display.component.scss +++ b/firebird-ng/src/app/main-display/main-display.component.scss @@ -5,3 +5,7 @@ padding-left: 13px; padding-right: 0; } + +#eventDisplay { + height: auto; +} diff --git a/firebird-ng/src/app/model/data-exchange.ts b/firebird-ng/src/app/model/data-exchange.ts new file mode 100644 index 0000000..ea8c673 --- /dev/null +++ b/firebird-ng/src/app/model/data-exchange.ts @@ -0,0 +1,32 @@ + +import {Entry} from "./entry"; + +export class DataExchange { + + version: string = "0.01" + origin: any = {} + entries: Entry[] = [] + + + toObj() { + let objEntries:any[] = []; + for(const entry of this.entries) { + objEntries.push(entry.toObj()); + } + return { + version: this.version, + origin: this.origin, + entries: objEntries + } + } + + static fromFirebirdEventObj(obj: any): DataExchange { + let result = new DataExchange(); + result.version = obj["version"]; + result.origin = obj["origin"]; + for(const objEntry of obj["entries"]) { + result.entries.push(Entry.fromFirebirdEventObj(objEntry)); + } + return result; + } +} diff --git a/firebird-ng/src/app/model/entry-component.ts b/firebird-ng/src/app/model/entry-component.ts new file mode 100644 index 0000000..e520b18 --- /dev/null +++ b/firebird-ng/src/app/model/entry-component.ts @@ -0,0 +1,16 @@ +export abstract class EntryComponent { + + name: string; + type: string; + originType?: string; + + constructor(name: string, type: string, originType?: string) { + this.name = name; + this.type = type; + this.originType = originType; + } + + // Instance method to serialize the object + abstract toSpecialObject(): any; + +} diff --git a/firebird-ng/src/app/model/entry.ts b/firebird-ng/src/app/model/entry.ts new file mode 100644 index 0000000..bf1e480 --- /dev/null +++ b/firebird-ng/src/app/model/entry.ts @@ -0,0 +1,13 @@ +export class Entry +{ + id: string = ""; + components: Component = []; + + toObj() { + return {} + } + + static fromFirebirdEventObj(obj: any): void { + throw new Error("Method not implemented."); + } +} diff --git a/firebird-ng/src/app/model/event-component.ts b/firebird-ng/src/app/model/event-component.ts new file mode 100644 index 0000000..e69de29 diff --git a/firebird-ng/src/app/model/object-serializable.interface.ts b/firebird-ng/src/app/model/object-serializable.interface.ts new file mode 100644 index 0000000..c69ffda --- /dev/null +++ b/firebird-ng/src/app/model/object-serializable.interface.ts @@ -0,0 +1,14 @@ + +export interface ToFirebirdObject { + /** Serialize to Firebird event object */ + toObj():any; +} + +export interface + +export function from( + ctor: IObjectSerializable, + data: any +): ClockInterface { + return new ctor(hour, minute); +} diff --git a/firebird-ng/src/app/model/tracker-hit-box.ts b/firebird-ng/src/app/model/tracker-hit-box.ts new file mode 100644 index 0000000..e69de29 diff --git a/firebird-ng/src/app/firebird-config.service.spec.ts b/firebird-ng/src/app/server-config.service.spec.ts similarity index 80% rename from firebird-ng/src/app/firebird-config.service.spec.ts rename to firebird-ng/src/app/server-config.service.spec.ts index a0d06d7..d7c002e 100644 --- a/firebird-ng/src/app/firebird-config.service.spec.ts +++ b/firebird-ng/src/app/server-config.service.spec.ts @@ -1,18 +1,18 @@ import { TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; -import { FirebirdConfigService } from './firebird-config.service'; +import { ServerConfigService } from './server-config.service'; import * as jsoncParser from 'jsonc-parser'; describe('FirebirdConfigService', () => { - let service: FirebirdConfigService; + let service: ServerConfigService; let httpMock: HttpTestingController; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], - providers: [FirebirdConfigService] + providers: [ServerConfigService] }); - service = TestBed.inject(FirebirdConfigService); + service = TestBed.inject(ServerConfigService); httpMock = TestBed.inject(HttpTestingController); }); @@ -50,14 +50,14 @@ describe('FirebirdConfigService', () => { // import { TestBed } from '@angular/core/testing'; // -// import { FirebirdConfigService } from './firebird-config.service'; +// import { ServerConfigService } from './firebird-config.service'; // -// describe('FirebirdConfigService', () => { -// let service: FirebirdConfigService; +// describe('ServerConfigService', () => { +// let service: ServerConfigService; // // beforeEach(() => { // TestBed.configureTestingModule({}); -// service = TestBed.inject(FirebirdConfigService); +// service = TestBed.inject(ServerConfigService); // }); // // it('should be created', () => { diff --git a/firebird-ng/src/app/firebird-config.service.ts b/firebird-ng/src/app/server-config.service.ts similarity index 87% rename from firebird-ng/src/app/firebird-config.service.ts rename to firebird-ng/src/app/server-config.service.ts index 4559b8c..667fa00 100644 --- a/firebird-ng/src/app/firebird-config.service.ts +++ b/firebird-ng/src/app/server-config.service.ts @@ -5,7 +5,7 @@ import {deepCopy} from "./utils/deep-copy"; import {BehaviorSubject, Observable, catchError, map, of, firstValueFrom} from "rxjs"; -export interface FirebirdConfig { +export interface ServerConfig { serverPort: number; serverHost: string; servedByPyrobird: boolean; @@ -14,7 +14,7 @@ export interface FirebirdConfig { logLevel: string; } -export const defaultFirebirdConfig: FirebirdConfig = { +export const defaultFirebirdConfig: ServerConfig = { serverPort: 5454, serverHost: "localhost", apiAvailable: false, @@ -27,7 +27,7 @@ export const defaultFirebirdConfig: FirebirdConfig = { @Injectable({ providedIn: 'root' }) -export class FirebirdConfigService { +export class ServerConfigService { private configUrl = 'assets/config.jsonc'; // URL to the JSONC config file private _config = deepCopy(defaultFirebirdConfig); @@ -35,7 +35,7 @@ export class FirebirdConfigService { constructor(private http: HttpClient) {} - get config(): FirebirdConfig { + get config(): ServerConfig { if (!this.triedLoading) { this.triedLoading = true; console.error("Client called config while config is not loaded.") @@ -61,7 +61,7 @@ export class FirebirdConfigService { } } - private parseConfig(jsoncData: string): Partial { + private parseConfig(jsoncData: string): Partial { try { return jsoncParser.parse(jsoncData); } catch (parseError) { @@ -74,7 +74,7 @@ export class FirebirdConfigService { * Sets the configuration - intended for use in unit tests only. * This method is safeguarded to be operational only in non-production environments. */ - public setUnitTestConfig(value: Partial) { + public setUnitTestConfig(value: Partial) { this.triedLoading = true; this._config = {...defaultFirebirdConfig, ...value}; } diff --git a/firebird-ng/src/app/url.service.spec.ts b/firebird-ng/src/app/url.service.spec.ts index fabe3a7..5f18776 100644 --- a/firebird-ng/src/app/url.service.spec.ts +++ b/firebird-ng/src/app/url.service.spec.ts @@ -2,13 +2,13 @@ import { TestBed } from '@angular/core/testing'; import {resolveProtocolAlias, UrlService} from './url.service'; import { UserConfigService } from './user-config.service'; -import { FirebirdConfigService } from './firebird-config.service'; +import { ServerConfigService } from './server-config.service'; import {BehaviorSubject} from "rxjs"; xdescribe('UrlService', () => { let service: UrlService; let userConfigService: jasmine.SpyObj; - let firebirdConfigService: jasmine.SpyObj; + let firebirdConfigService: jasmine.SpyObj; beforeEach(() => { const userConfigSpy = jasmine.createSpyObj('UserConfigService', ['localServerHost', 'localServerPort', 'localServerUseApi']); @@ -22,12 +22,12 @@ xdescribe('UrlService', () => { providers: [ UrlService, { provide: UserConfigService, useValue: userConfigSpy }, - { provide: FirebirdConfigService, useValue: firebirdConfigSpy } + { provide: ServerConfigService, useValue: firebirdConfigSpy } ] }); userConfigService = TestBed.inject(UserConfigService) as any; - firebirdConfigService = TestBed.inject(FirebirdConfigService) as any; + firebirdConfigService = TestBed.inject(ServerConfigService) as any; service = TestBed.inject(UrlService); }); diff --git a/firebird-ng/src/app/url.service.ts b/firebird-ng/src/app/url.service.ts index 935bc0a..f8a3ef7 100644 --- a/firebird-ng/src/app/url.service.ts +++ b/firebird-ng/src/app/url.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import {UserConfigService} from "./user-config.service"; -import {FirebirdConfigService} from "./firebird-config.service"; +import {ServerConfigService} from "./server-config.service"; let defaultProtocolAliases = [ {"local://": "http://localhost/" }, @@ -60,7 +60,7 @@ export class UrlService { constructor(private userConfigService: UserConfigService, - private firebirdConfigService: FirebirdConfigService) { + private firebirdConfigService: ServerConfigService) { // Track user config changes this.userConfigService.localServerHost.subject.subscribe((value)=>{this.userConfigHost = value}); diff --git a/firebird-ng/src/app/user-config.service.ts b/firebird-ng/src/app/user-config.service.ts index 9e6e09a..5787ba3 100644 --- a/firebird-ng/src/app/user-config.service.ts +++ b/firebird-ng/src/app/user-config.service.ts @@ -22,6 +22,5 @@ export class UserConfigService { this.localServerUseApi = new ConfigProperty("server.useApi", false); this.localServerHost = new ConfigProperty("server.host", "localhost"); this.localServerPort = new ConfigProperty("server.port", 5454); - } } diff --git a/pyrobird/src/pyrobird/edm4eic.py b/pyrobird/src/pyrobird/edm4eic.py index 9710cae..ae838dc 100644 --- a/pyrobird/src/pyrobird/edm4eic.py +++ b/pyrobird/src/pyrobird/edm4eic.py @@ -193,5 +193,5 @@ def edm4eic_to_dict(tree, entry_ids, origin_info=None): "origin": origin_info, "entries": entries_data } - + return result