protected Event(EventDictionaryEntry entry) { ede = entry; m_name = entry.Name; //Lookup and allocate space for ancillary data, if needed if (entry.ancillarySize > 0) ancillary = new byte[entry.ancillarySize]; else ancillary = null; }
public CreateEventWindow(EventDictionaryEntry ede) { InitializeComponent(); Title = "Create " + ede.Name + " Event"; Time.Tag = true; if (ede.GroupVars != null) foreach (GroupVarDictionary.GVEntry gve in ede.GroupVars) { StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; Label l = new Label(); l.Content = gve.Name; l.Width = 120D; sp.Children.Add(l); if (gve.GVValueDictionary == null) { TextBox tb = new TextBox(); tb.Text = "0"; tb.Tag = true; tb.Width = 120D; sp.Children.Add(tb); } else { ComboBox cb = new ComboBox(); cb.Width = 120D; foreach (string s in gve.GVValueDictionary.Keys) cb.Items.Add(s); cb.SelectedIndex = 0; sp.Children.Add(cb); } GVEntries.Children.Add(sp); } else { GVBox.Visibility = Visibility.Collapsed; } }
internal OutputEvent(EventDictionaryEntry entry) : base(entry) { m_time = (double)(DateTime.Now.Ticks) / 1E7; // Get time immediately if (entry.GroupVars != null && entry.GroupVars.Count > 0) GVValue = new string[entry.GroupVars.Count]; //allocate correct number of group variable value entries else GVValue = null; }
/// <summary> /// Stand-alone constructor for use creating naked events based on BDF /// </summary> /// <param name="entry">EventDictionaryEntry describing the Event</param> /// <param name="time">time of Event, seconds since start of BDF file</param> public OutputEvent(EventDictionaryEntry entry, double time) : base(entry) { if (!entry.BDFBased) throw new Exception("OutputEvent constructor(EDE, double) only for BDF-based Events"); ede = entry; m_time = time; GVValue = null; }
/// <summary> /// Stand-alone constructor for use creating simulated events (not real-time); no checking is performed /// </summary> /// <param name="entry">EventDictionaryEntry describing the Event</param> /// <param name="time">time of Event, ticks since 0CE</param> /// <param name="index">assigned index of Event</param> public OutputEvent(EventDictionaryEntry entry, long time, int index) : base(entry) { ede = entry; m_time = (double)(time) / 1E7; if (entry.IsCovered) { m_index = (uint)index; m_gc = EventFactory.grayCode(m_index); } GVValue = null; }
public string[] GVValue; //stored as strings #endregion Fields #region Constructors /// <summary> /// Stand-alone constructor for use creating simulated events (not real-time); no checking is performed /// </summary> /// <param name="entry">EventDictionaryEntry describing the Event</param> /// <param name="time">DateTime of Event</param> /// <param name="index">assigned index of Event: cannot = 0 unless Event is naked</param> public OutputEvent(EventDictionaryEntry entry, DateTime time, int index = 0) : base(entry) { ede = entry; m_time = (double)(time.Ticks) / 1E7; if (entry.IsCovered) { if (index == 0) throw new Exception("Event.OutputEvent: attempt to create a covered OutputEvent with GC = 0"); m_index = (uint)index; m_gc = EventFactory.grayCode(m_index); } GVValue = null; }
public InputEvent(EventDictionaryEntry entry) : base(entry) { if (ede.GroupVars != null && ede.GroupVars.Count > 0) GVValue = new string[ede.GroupVars.Count]; }
private void Finish_Click(object sender, RoutedEventArgs e) { if (MarkerCanvas.markedRegions.Count != 0) { EventDictionaryEntry ede1; EventDictionaryEntry ede2; //Determine how many artifact files in existence to create unique name string[] files = Directory.GetFiles(directory, "*_artifact*.hdr", SearchOption.TopDirectoryOnly); int maxFileIndex = -1; for (int i = 0; i < files.Length; i++) { Match m = Regex.Match(files[i], @"^.+_artifact(-\d+)*-(?<number>\d+)\.[hH][dD][rR]$"); if(m.Success) //has to match naming convention maxFileIndex = Math.Max(maxFileIndex, Convert.ToInt32(m.Groups["number"].Value)); } string newFileName; StringBuilder sb = new StringBuilder(header.Comment); //Add comment to HDR file documenting artifact marking if (sb.Length > 0) sb.Append(Environment.NewLine); sb.Append("Artifacts marked on " + DateTime.Today.ToShortDateString() + " by " + Environment.UserName); header.Comment = sb.ToString(); if (updateFlag) //then, this dataset is based on another one; need to find out if this is an update of current dataset only, or if a new file is to be created { if (!header.Events.TryGetValue("**ArtifactBegin", out ede1) || !header.Events.TryGetValue("**ArtifactEnd", out ede2) || !ede1.BDFBased || !ede2.BDFBased) throw new Exception("Error in attempted update of previously marked dataset; may be update of old-form dataset"); Window3 w = new Window3(); w.Owner = this; w.ShowDialog(); if (dialogReturn == 1) return; if (dialogReturn == 2) //replace current files only newFileName = System.IO.Path.GetFileNameWithoutExtension(header.EventFile); //Use old name; only update Comment else //create new file set from old { newFileName = System.IO.Path.GetFileNameWithoutExtension(header.EventFile) + "-" + (maxFileIndex + 1).ToString("0"); header.EventFile = newFileName + ".evt"; } } else //this is based on a previously unmarked dataset; add new Event types to HDR { //Modify header with new "naked" Events and file names ede1 = new EventDictionaryEntry(); ede1.intrinsic = null; ede1.BDFBased = true; //Use BDF-based clocking ede1.Description = "Beginning of artifact region"; ede2 = new EventDictionaryEntry(); ede2.intrinsic = null; ede2.BDFBased = true; //Use BDF-based clocking ede2.Description = "End of artifact region"; header.Events.Add("**ArtifactBegin", ede1); header.Events.Add("**ArtifactEnd", ede2); newFileName = System.IO.Path.GetFileNameWithoutExtension(header.BDFFile) + @"_artifact-" + (maxFileIndex + 1).ToString("0"); ; //create new filename header.EventFile = newFileName + ".evt"; //and write new header out } header.Comment += (header.Comment == "" ? "" : Environment.NewLine) + "Artefact Events marked on " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss") + " by " + Environment.UserName; FileStream fs = new FileStream(System.IO.Path.Combine(directory, newFileName + ".hdr"), FileMode.OpenOrCreate, FileAccess.Write); new HeaderFileWriter(fs, header); //write out new header foreach (MarkerRectangle mr in MarkerCanvas.markedRegions) //update Event file to include new artifact marks { double eventTime = mr.leftEdge; OutputEvent newOE = new OutputEvent(ede1, eventTime); int index = events.FindIndex(ev => bdf.timeFromBeginningOfFileTo(ev) >= eventTime); if (index < 0) //must be after last Event or no Events events.Add(newOE); else events.Insert(index, newOE); eventTime = mr.rightEdge; newOE = new OutputEvent(ede2, eventTime); index = events.FindIndex(ev => bdf.timeFromBeginningOfFileTo(ev) > eventTime); if (index < 0) events.Add(newOE); else events.Insert(index, newOE); } EventFileWriter efw = new EventFileWriter( new FileStream(System.IO.Path.Combine(directory, header.EventFile), FileMode.OpenOrCreate, FileAccess.Write)); foreach (OutputEvent ev in events) efw.writeRecord(ev); efw.Close(); Log.writeToLog(" Created/updated to dataset " + newFileName); } this.Close(); }
/// <summary> /// Adds new Event to EventDictionary /// </summary> /// <param name="name">Event Name</param> /// <param name="description">Event Description</param> /// <param name="GVList">List or array of GV entries</param> /// <returns>New EventDictionaryEntry</returns> /// <remarks>EDE returned has default assumptions: intrinsic Event with Absolute clock time</remarks> public EventDictionaryEntry AddNewEvent(string name, string description, IEnumerable<GVEntry> GVList) { EventDictionaryEntry ede = new EventDictionaryEntry(); ede.Description = description; if (GVList != null) { ede.GroupVars = new List<GVEntry>(); foreach (GVEntry gve in GVList) { if (!this.GroupVars.ContainsKey(gve.Name)) throw new Exception("Attempt to create Event entry \"" + name + "\"with GV \"" + gve.Name + "\" not in GV dictionary"); ede.GroupVars.Add(gve); } } Events.Add(name, ede); //will throw exception if duplicate return ede; }
public Header.Header read() { Header.Header header = new Header.Header(); try { xr.ReadStartElement("ExperimentDescription", nameSpace); xr.ReadStartElement("SoftwareVersion", nameSpace); header.SoftwareVersion = xr.ReadContentAsString(); xr.ReadEndElement(/* SoftwareVersion */); xr.ReadStartElement("Title", nameSpace); header.Title = xr.ReadContentAsString(); xr.ReadEndElement(/* Title */); xr.ReadStartElement("LongDescription", nameSpace); header.LongDescription = xr.ReadContentAsString(); xr.ReadEndElement(/* LongDescription */); header.Experimenter = new List<string>(); while (xr.Name == "Experimenter") { xr.ReadStartElement(/* Experimenter */); header.Experimenter.Add(xr.ReadContentAsString()); xr.ReadEndElement(/* Experimenter */); } xr.ReadStartElement("Status", nameSpace); header.Status = xr.ReadContentAsInt(); xr.ReadEndElement(/* Status */); if (xr.Name == "Other") { header.OtherExperimentInfo = new Dictionary<string, string>(); do { string name = xr["Name"]; xr.ReadStartElement(/* Other */); string value = xr.ReadContentAsString(); header.OtherExperimentInfo.Add(name, value); xr.ReadEndElement(/* Other */); } while (xr.Name == "Other"); } if (xr.Name == "GroupVar") { header.GroupVars = new GroupVarDictionary.GroupVarDictionary(); do { xr.ReadStartElement(/* GroupVar */); GroupVarDictionary.GVEntry gve = new GVEntry(); xr.ReadStartElement("Name", nameSpace); string name = xr.ReadContentAsString(); if (name.Length > 24) throw new Exception("name too long for GV " + name); xr.ReadEndElement(/* Name */); xr.ReadStartElement("Description", nameSpace); gve.Description = xr.ReadContentAsString(); xr.ReadEndElement(/* Description */); if (xr.Name == "GV") { gve.GVValueDictionary = new Dictionary<string, int>(); do { string key = xr["Desc", nameSpace]; xr.ReadStartElement(/* GV */); int val = xr.ReadContentAsInt(); if (val > 0) gve.GVValueDictionary.Add(key, val); else throw new Exception("invalid value for GV "+ name); xr.ReadEndElement(/* GV */); } while (xr.Name == "GV"); } header.GroupVars.Add(name, gve); xr.ReadEndElement(/* GroupVar */); } while (xr.Name == "GroupVar"); } if (xr.Name == "Event") { header.Events = new EventDictionary.EventDictionary(header.Status); do { EventDictionaryEntry ede = new EventDictionaryEntry(); if (xr.MoveToAttribute("Type")) { string s = xr.ReadContentAsString(); if (s == "*") ede.intrinsic = null; else ede.intrinsic = s != "extrinsic"; } //else Type is intrinsic by default if (xr.MoveToAttribute("Clock")) //is there a Clock attribute? { string s = xr.ReadContentAsString(); if (s == "Absolute") ede.BDFBased = false; else if (s == "BDF-based") { if (ede.IsCovered) throw new Exception("Incompatible Type and Clock attributes in Event"); ede.BDFBased = true; } else throw new Exception("Invalid Clock attribute in Event"); } //else clock is Absolute by default xr.ReadStartElement(/* Event */); xr.ReadStartElement("Name", nameSpace); string name = xr.ReadContentAsString(); xr.ReadEndElement(/* Event */); xr.ReadStartElement("Description", nameSpace); ede.Description = xr.ReadContentAsString(); xr.ReadEndElement(/* Description */); if (ede.IsCovered && !(bool)ede.intrinsic) { xr.ReadStartElement("Channel", nameSpace); ede.channelName = xr.ReadContentAsString(); xr.ReadEndElement(/* Channel */); xr.ReadStartElement("Edge", nameSpace); ede.rise = xr.ReadContentAsString() == "rising"; xr.ReadEndElement(/* Edge */); ede.location = (xr.Name == "Location" ? (xr.ReadElementContentAsString() == "after") : false); //leads by default ede.channelMax = xr.Name == "Max" ? xr.ReadElementContentAsDouble() : 0D; //zero by default ede.channelMin = xr.Name == "Min" ? xr.ReadElementContentAsDouble() : 0D; //zero by default if (ede.channelMax < ede.channelMin) throw new Exception("invalid max/min signal values in extrinsic Event " + name); //Note: Max and Min are optional; if neither is specified, 0.0 will always be used as threshold } if (xr.Name == "Ancillary") { xr.ReadStartElement(/* Ancillary */); ede.ancillarySize = xr.ReadContentAsInt(); xr.ReadEndElement(/* Ancillary */); } if (xr.Name == "GroupVar") { ede.GroupVars = new List<GVEntry>(); do { string gvName = xr["Name", nameSpace]; bool isEmpty = xr.IsEmptyElement; xr.ReadStartElement(/* GroupVar */); GVEntry gve; if (header.GroupVars.TryGetValue(gvName, out gve)) ede.GroupVars.Add(gve); else throw new Exception("invalid GroupVar " + gvName + " in Event " + name); if(!isEmpty) xr.ReadEndElement(/* GroupVar */); } while (xr.Name == "GroupVar"); } header.Events.Add(name, ede); xr.ReadEndElement(/* Event */); } while (xr.Name == "Event"); } xr.ReadEndElement(/* ExperimentDescription */); xr.ReadStartElement("SessionDescription", nameSpace); xr.ReadStartElement("Date", nameSpace); header.Date = xr.ReadContentAsString(); xr.ReadEndElement(/* Date */); xr.ReadStartElement("Time", nameSpace); header.Time = xr.ReadContentAsString(); xr.ReadEndElement(/* Time */); xr.ReadStartElement("Subject", nameSpace); header.Subject = xr.ReadContentAsInt(); xr.ReadEndElement(/* Subject */); if (xr.Name == "Agent") { xr.ReadStartElement(/* Agent */); header.Agent = xr.ReadContentAsInt(); xr.ReadEndElement(/* Agent */); } header.Technician = new List<string>(); while (xr.Name == "Technician") { xr.ReadStartElement(/* Technician */); header.Technician.Add(xr.ReadContentAsString()); xr.ReadEndElement(/* Technician */); } if (xr.Name == "Other") { header.OtherSessionInfo = new Dictionary<string, string>(); do { string name = xr["Name"]; xr.ReadStartElement(/* Other */); string value = xr.ReadContentAsString(); xr.ReadEndElement(/* Other */); header.OtherSessionInfo.Add(name, value); } while (xr.Name == "Other"); } xr.ReadStartElement("BDFFile", nameSpace); header.BDFFile = xr.ReadContentAsString(); xr.ReadEndElement(/* BDFFile */); xr.ReadStartElement("EventFile", nameSpace); header.EventFile = xr.ReadContentAsString(); xr.ReadEndElement(/* EventFile */); xr.ReadStartElement("ElectrodeFile", nameSpace); header.ElectrodeFile = xr.ReadContentAsString(); xr.ReadEndElement(/* ElectrodeFile */); if (xr.Name == "Comment") { xr.ReadStartElement(/* Comment */); header.Comment = xr.ReadContentAsString(); //Optional comment xr.ReadEndElement(/* Comment */); } xr.ReadEndElement(/* SessionDescription */); return header; } catch (Exception e) { XmlNodeType nodeType = xr.NodeType; string name = xr.Name; throw new Exception("HeaderFileReader.read: Error processing " + nodeType.ToString() + " named " + name + ": " + e.Message); } }