Skip to content

Commit

Permalink
[ng] Exchange format definition
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Sep 18, 2024
1 parent d237b89 commit dc51d9f
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 29 deletions.
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

6 changes: 3 additions & 3 deletions firebird-ng/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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<any> {
export function configInitializer(configService: ServerConfigService): () => Promise<any> {
return () => configService.loadConfig();
}
6 changes: 3 additions & 3 deletions firebird-ng/src/app/input-config/input-config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand All @@ -34,7 +34,7 @@ export class InputConfigComponent implements OnInit, AfterViewInit {
serverUseApi: FormControl<boolean | null> = new FormControl(false);
serverApiHost = new FormControl('localhost');
serverApiPort: FormControl<number | null> = new FormControl(5454);
firebirdConfig: FirebirdConfig = defaultFirebirdConfig;
firebirdConfig: ServerConfig = defaultFirebirdConfig;


@ViewChild('geometrySelect')
Expand Down Expand Up @@ -107,7 +107,7 @@ export class InputConfigComponent implements OnInit, AfterViewInit {


constructor(private userConfigService: UserConfigService,
private firebirdConfigService: FirebirdConfigService) {
private firebirdConfigService: ServerConfigService) {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
<div style="color: darkgray">{{currentGeometry}}</div>
</div>

<div id="eventDisplay"></div>
<div id="eventDisplay" ></div>
4 changes: 4 additions & 0 deletions firebird-ng/src/app/main-display/main-display.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
padding-left: 13px;
padding-right: 0;
}

#eventDisplay {
height: auto;
}
32 changes: 32 additions & 0 deletions firebird-ng/src/app/model/data-exchange.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions firebird-ng/src/app/model/entry-component.ts
Original file line number Diff line number Diff line change
@@ -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;

}
13 changes: 13 additions & 0 deletions firebird-ng/src/app/model/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Entry
{
id: string = "";
components: Component = [];

toObj() {
return {}
}

static fromFirebirdEventObj(obj: any): void {
throw new Error("Method not implemented.");
}
}
Empty file.
14 changes: 14 additions & 0 deletions firebird-ng/src/app/model/object-serializable.interface.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -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);
});

Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +14,7 @@ export interface FirebirdConfig {
logLevel: string;
}

export const defaultFirebirdConfig: FirebirdConfig = {
export const defaultFirebirdConfig: ServerConfig = {
serverPort: 5454,
serverHost: "localhost",
apiAvailable: false,
Expand All @@ -27,15 +27,15 @@ 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);

private triedLoading = false;

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.")
Expand All @@ -61,7 +61,7 @@ export class FirebirdConfigService {
}
}

private parseConfig(jsoncData: string): Partial<FirebirdConfig> {
private parseConfig(jsoncData: string): Partial<ServerConfig> {
try {
return jsoncParser.parse(jsoncData);
} catch (parseError) {
Expand All @@ -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<FirebirdConfig>) {
public setUnitTestConfig(value: Partial<ServerConfig>) {
this.triedLoading = true;
this._config = {...defaultFirebirdConfig, ...value};
}
Expand Down
8 changes: 4 additions & 4 deletions firebird-ng/src/app/url.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserConfigService>;
let firebirdConfigService: jasmine.SpyObj<FirebirdConfigService>;
let firebirdConfigService: jasmine.SpyObj<ServerConfigService>;

beforeEach(() => {
const userConfigSpy = jasmine.createSpyObj('UserConfigService', ['localServerHost', 'localServerPort', 'localServerUseApi']);
Expand All @@ -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);
});

Expand Down
4 changes: 2 additions & 2 deletions firebird-ng/src/app/url.service.ts
Original file line number Diff line number Diff line change
@@ -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/" },
Expand Down Expand Up @@ -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});
Expand Down
1 change: 0 additions & 1 deletion firebird-ng/src/app/user-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
2 changes: 1 addition & 1 deletion pyrobird/src/pyrobird/edm4eic.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ def edm4eic_to_dict(tree, entry_ids, origin_info=None):
"origin": origin_info,
"entries": entries_data
}

return result

0 comments on commit dc51d9f

Please sign in to comment.