Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/model/event-group.ts is written in an unsupported language. File is not indexed.

0001 /**
0002  * The EventGroup class is an abstract base class for all entry components.
0003  */
0004 export abstract class EventGroup {
0005 
0006   /**
0007    * The name of the component, intended to be a unique identifier in UI menus and such.
0008    */
0009   name: string;
0010 
0011   /**
0012    * The type of the component, used to identify the component class
0013    * and facilitate deserialization and factory lookup.
0014    */
0015   type: string;
0016 
0017   /**
0018    * An optional string indicating the origin type of the component,
0019    * such as the original EDM4EIC/EDM4HEP/C++ data type from which it was derived.
0020    */
0021   origin?: string;
0022 
0023 
0024 
0025   /**
0026    * The constructor is protected to prevent direct instantiation of the abstract class.
0027    * Only derived classes can call this constructor when they implement their own constructors.
0028    *
0029    * @param name - The name of the component.
0030    * @param type - The type of the component.
0031    * @param origin - Optional origin type of the component.
0032    */
0033   protected constructor(name: string, type: string, origin?: any) {
0034     this.name = name;
0035     this.type = type;
0036     this.origin = origin;
0037   }
0038 
0039   /**
0040    * Abstract method that must be implemented by derived classes.
0041    * This method should serialize the component instance into a JSON-compatible object
0042    * following the Data Exchange format (DexObject).
0043    *
0044    * @returns A JSON-compatible object representing the serialized component.
0045    */
0046   abstract toDexObject(): any;
0047 
0048   /** min and max time of the EventGroup
0049    * null means the component doesn't need time and shows as is
0050    *
0051    * @returns [min, max] range of times or null if it is not available for the component
0052    *
0053    * */
0054   abstract get timeRange(): [number, number] | null;
0055 }
0056 
0057 /**
0058  * The EventGroupFactory interface defines the structure for factory classes
0059  * that are responsible for creating instances of EventGroup subclasses.
0060  */
0061 export interface EventGroupFactory {
0062 
0063   /**
0064    * The type of the component that this factory creates.
0065    * This should match the `type` property of the components it creates.
0066    */
0067   type: string;
0068 
0069   /**
0070    * Method to create an instance of an EventGroup subclass from a deserialized object.
0071    * The method takes a generic object (typically parsed from JSON) and returns an instance
0072    * of the corresponding EventGroup subclass.
0073    *
0074    * @param obj - The deserialized object from which to create the component.
0075    * @returns An instance of an EventGroup subclass.
0076    */
0077   fromDexObject(obj: any): EventGroup;
0078 }
0079 
0080 /**
0081  * The componentRegistry is a mapping from component type strings to their corresponding factories.
0082  * It is used to look up the appropriate factory when deserializing components from JSON data.
0083  * This registry enables the system to support multiple component types dynamically.
0084  */
0085 const componentRegistry: { [type: string]: EventGroupFactory } = {};
0086 
0087 /**
0088  * Registers a new component factory in the registry.
0089  * This allows the factory to be used during deserialization to create instances
0090  * of the component it represents.
0091  *
0092  * @param factory - The factory to register.
0093  */
0094 export function registerEventGroupFactory(factory: EventGroupFactory): void {
0095   componentRegistry[factory.type] = factory;
0096 }
0097 
0098 /**
0099  * Retrieves a component factory from the registry based on the component type.
0100  *
0101  * @param type - The type of the component.
0102  * @returns The corresponding EventGroupFactory, or undefined if not found.
0103  */
0104 export function getEventGroupFactory(type: string): EventGroupFactory | undefined {
0105   return componentRegistry[type];
0106 }
0107 
0108 /**
0109  * Resets the component registry.
0110  * This function is intended for internal use during testing.
0111  *
0112  * @internal
0113  */
0114 export function _resetEventGroupRegistry(): void {
0115   for (const key in componentRegistry) {
0116     delete componentRegistry[key];
0117   }
0118 }