Files

119 lines
4.9 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
using DTS.Common.Utilities.Logging;
using DTS.DASLib.Service;
namespace DTS.Serialization
{
public class EventInfoAggregate
{
public string EventId { get; set; }
public string EventDescription { get; set; }
public double DurationSeconds { get; set; }
public string GUID { get; set; }
public bool HasBeenDownloaded { get; set; }
public bool WasTriggered { get; set; }
public int NumberOfChannels { get; set; }
public UInt64 NumberOfSamples { get; set; }
public UInt64 NumberOfBytes { get; set; }
public bool Faulted { get; set; }
public int EventNumber { get; set; }
private readonly Dictionary<IDASCommunication, int> _eventIndices = new Dictionary<IDASCommunication, int>();
private List<IDASCommunication> _das = null;
private Slice.Control.Event _event;
public Slice.Control.Event GetEvent(bool bClear)
{
if (bClear) { _event = null; }
return GetEvent();
}
public Slice.Control.Event GetEvent()
{
if (null == _event)
{
_event = new Slice.Control.Event(GetDasList(), this);
}
return _event;
}
public int GetEventIndex(IDASCommunication idas)
{
if (!_eventIndices.ContainsKey(idas)) { throw new NotImplementedException(string.Format("ERROR in GetEventIndex for {0}", idas.SerialNumber)); }
return _eventIndices[idas];
}
public List<IDASCommunication> GetDasList()
{
if (null == _das)
{
_das = new List<IDASCommunication>();
_das.AddRange(_eventIndices.Keys.ToArray());
}
return _das;
}
public EventInfoAggregate(DownloadReport.EventInfo newEvent)
{
EventId = newEvent.TestID;
EventDescription = newEvent.Description;
DurationSeconds = newEvent.Modules[0].PreTriggerSeconds + newEvent.Modules[0].PostTriggerSeconds;
GUID = newEvent.TestGUID.ToString();
HasBeenDownloaded = newEvent.HasBeenDownloaded;
WasTriggered = newEvent.WasTriggered;
NumberOfChannels = newEvent.Modules.Sum(s => s.Channels.Length);
NumberOfSamples = newEvent.Modules[0].NumberOfSamples;
NumberOfBytes = NumberOfSamples * (ulong)NumberOfChannels * (ulong)2;
Faulted = 0 != newEvent.FaultFlags;
EventNumber = newEvent.EventNumber;
_eventIndices.Add(newEvent.Modules[0].OwningDAS, newEvent.EventNumber);
}
public void Add(DownloadReport.EventInfo newEvent)
{
if (newEvent.TestID != EventId)
{
APILogger.Log("Warning, expected matching test ids: ", newEvent.TestID, EventId);
}
if (newEvent.Description != EventDescription)
{
APILogger.Log("Warning, expected matching test descriptions: ", newEvent.Description);
}
var duration = newEvent.Modules[0].PreTriggerSeconds + newEvent.Modules[0].PostTriggerSeconds;
if (duration != DurationSeconds)
{
APILogger.Log("Warning, durations don't match: ", duration, DurationSeconds);
DurationSeconds = Math.Min(DurationSeconds, duration);
}
if (newEvent.TestGUID.ToString() != GUID)
{
APILogger.Log("Warning, expected test GUIDs to match,", GUID, newEvent.TestGUID.ToString());
}
if (newEvent.HasBeenDownloaded != HasBeenDownloaded)
{
APILogger.Log("Warning, event has been downloaded from one unit, but not another");
}
if (newEvent.WasTriggered != WasTriggered)
{
APILogger.Log("Warning, one unit has triggered, but another has not");
}
var faulted = 0 != newEvent.FaultFlags;
Faulted = Faulted || faulted;
if (newEvent.Modules[0].NumberOfSamples != NumberOfSamples)
{
APILogger.Log("Warning, expected number of samples to match", NumberOfSamples, newEvent.Modules[0].NumberOfSamples);
NumberOfSamples = Math.Min(NumberOfSamples, newEvent.Modules[0].NumberOfSamples);
}
if (newEvent.EventNumber != EventNumber)
{
APILogger.Log("Warning, expected event numbers to match", EventNumber, newEvent.EventNumber);
}
NumberOfChannels += newEvent.Modules.Sum(s => s.Channels.Length);
NumberOfBytes = (ulong)2 * (ulong)NumberOfChannels * NumberOfSamples;
_eventIndices.Add(newEvent.Modules[0].OwningDAS, newEvent.EventNumber);
}
}
}