/// <summary> /// cancel then wait for the bitter end /// </summary> /// <param name="inst"></param> public void StopThread(SRInstrument inst, bool wait) { SRControlThread srct = null; foreach (KeyValuePair<DataSourceIdentifier, SRControlThread> kvp in threads) { if (kvp.Key.Equals(inst.id)) { kvp.Value.CancelMe(); // doing the cancel in two ways! srct = kvp.Value; break; } } int counter = 0; while (srct != null & srct.IsBusy & wait & counter < 10) { counter++; NC.App.Logger(LMLoggers.AppSection.Collect).TraceEvent(LogLevels.Verbose, 87233, "Waiting for thread {0} to terminate", srct.SRCtrl.identifyingNumber); Thread.Sleep(500); } }
// assumes initalized measurement with at least one cycle, and at least one defined counting analysis result indexed by the detector's mult params, including VSRs fror LM void ComputeFromINCC5SRData(Measurement m) { string pre = (m.AcquireState.data_src == ConstructedSource.Reanalysis ? "Rec" : "C"); ctrllog.TraceEvent(LogLevels.Info, 34071, pre + "omputing: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); if (m.Cycles.Count < 1) { ctrllog.TraceEvent(LogLevels.Error, 34830, "Skipping, no cycles on '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); return; } if (m.CountingAnalysisResults.Count < 1 || !m.CountingAnalysisResults.HasMultiplicity) { ctrllog.TraceEvent(LogLevels.Error, 34831, "Bad match between detector and this file type." + (!m.CountingAnalysisResults.HasMultiplicity ? " No Multiplicity counter defined." : "")); return; //bad match between detector and this file type. } SRInstrument PseudoInstrument = new SRInstrument(m.Detector); PseudoInstrument.selected = true; if (!Instruments.Active.Contains(PseudoInstrument)) Instruments.Active.Add(PseudoInstrument); // add to global runtime list m.CurrentRepetition = 0; NC.App.Opstate.SOH = OperatingState.Living; try { MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults[m.Detector.MultiplicityParams]; // APluralityOfMultiplicityAnalyzers: check for use of multiple analyzers // start counting using the per-cycle accumulation of summary results Array.Clear(mcr.RAMult, 0, mcr.RAMult.Length); Array.Clear(mcr.NormedAMult, 0, mcr.NormedAMult.Length); Array.Clear(mcr.UnAMult, 0, mcr.UnAMult.Length); mcr.AB.TransferIntermediates(src: m.Detector.AB); // remove, redundant copy in most cases CycleList cl = m.Cycles; m.Cycles = new CycleList(); foreach (Cycle cycle in cl) // process incrementally to match expected outlier processing behavior from INCC { if (NC.App.Opstate.IsQuitRequested) // exit via abort or quit/save, follow-on code decides to continue with processing { ctrllog.TraceEvent(LogLevels.Warning, 430, "Cycle first-pass processing " + NC.App.Opstate.CancelStopAbortStateRep + " at sequence #" + cycle.seq + ", " + m.CurrentRepetition); break; } m.CurrentRepetition++; m.Cycles.Add(cycle); m.SetQCStatus(cycle); CycleProcessing.ApplyTheCycleConditioningSteps(cycle, m); m.CycleStatusTerminationCheck(cycle); ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString()); if (m.CurrentRepetition % 8 == 0) FireEvent(EventType.ActionInProgress, this); } FireEvent(EventType.ActionInProgress, this); // trim any None's that were not processed (occurs during a cancel/stop intervention) m.Cycles.Trim(m.Detector.MultiplicityParams); // APluralityOfMultiplicityAnalyzers: expand when detector has multiple analyzers } catch (Exception e) { NC.App.Opstate.SOH = OperatingState.Trouble; ctrllog.TraceException(e, true); ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + m.CurrentRepetition); } finally { NC.App.Loggers.Flush(); } if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available { if (m.HasReportableData) { m.CalculateMeasurementResults(); new ReportMangler(ctrllog).GenerateReports(m); m.SaveMeasurementResults(); } } NC.App.Opstate.ResetTokens(); Instruments.All.Remove(PseudoInstrument); }
protected void ShiftRegisterRuntimeInit() { Detector det = NC.App.Opstate.Measurement.Detector; if (det.ListMode) return; SRInstrument sri = new SRInstrument(det); sri.selected = true; sri.Init(datalog, NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) Instruments.All.Add(sri); // add to global runtime list }
private void OKBtn_Click(object sender, EventArgs e) { if (hvp.modified) { DialogResult = System.Windows.Forms.DialogResult.OK; HVCalibrationParameters c = NC.App.DB.HVParameters.Get(det.Id.DetectorName); if (c != null) c.Copy(hvp); // copy changes back to original on user affirmation else { c = hvp; NC.App.DB.HVParameters.GetMap().Add(det, c); } NC.App.DB.HVParameters.Set(det,c); // dev note: LM HV vals on LM Acquire record, but SR uses separate DB table so move HV vals so unify the scheme } else DialogResult = System.Windows.Forms.DialogResult.Ignore; // The acquire is set to occur, build up the measurement state Integ.BuildMeasurement(acq, det, AssaySelector.MeasurementOption.unspecified); if (acq.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AcquireParametersMap().Add(sel, acq); // it's a new one, not the existing one modified NC.App.DB.UpdateAcquireParams(acq, det.ListMode); } UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (NC.App.Opstate.Measurement.Detectors[0].ListMode) { if (NC.App.Opstate.Measurement.Detectors[0].Id.SRType == InstrType.PTR32) { Ptr32Instrument instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detectors[0]); instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.Active.Contains(instrument)) { Instruments.Active.Add(instrument); } } else { // if ok, the analyzers are set up, so can kick it off now. LMInstrument lm = new LMInstrument(NC.App.Opstate.Measurement.Detectors[0]); lm.DAQState = DAQInstrState.Offline; // these are manually initiated as opposed to auto-pickup lm.selected = false; //must broadcast first to get it selected if (!Instruments.All.Contains(lm)) Instruments.All.Add(lm); // add to global runtime list } } else { SRInstrument sri = new SRInstrument(NC.App.Opstate.Measurement.Detectors[0]); sri.selected = true; sri.Init(null, null); if (!Instruments.All.Contains(sri)) Instruments.All.Add(sri); // add to global runtime list } UIIntegration.Controller.SetHVCalib(); // tell the controller to do an HV operation using the current measurement state UIIntegration.Controller.Perform(); // start the HV DAQ thread this.Close(); }
// need to call this AFTER the instruments are identified from the sys config internal void ConnectSRInstruments() { // start the control thread for each SR and and make sure it is waiting for a command IEnumerator iter = Instruments.Active.GetSREnumerator(); while (iter.MoveNext()) { SRInstrument sri = (SRInstrument)iter.Current; bool found = false; try // Fix case where crashes because COM port doesn't exist any more..... hn 5.15.2015 { if (sri.id.SRType.IsCOMPortBasedSR()) // always true if code gets you here { if (!CheckCOMPortExistence(sri.id.SerialPort)) // if not found then emit error { collog.TraceInformation("The COM port {0} is no longer available. Instrument {1} cannot be connected. Please set a valid COM port.", sri.id.SerialPort.ToString(), sri.id.DetectorId); string[] ports = System.IO.Ports.SerialPort.GetPortNames(); // "COMnnn" string ps = string.Empty; if (ports.Length == 0) { ps = "No COM ports found"; } else { ps = "These COM ports are available:"; foreach (string p in ports) { ps += (" " + p + ","); } } collog.TraceInformation(ps); sri.selected = false; } else { found = true; } } } catch (Exception ex) { collog.TraceException(ex); } if (!found) { Instruments.Active.RemoveAll(i => i.selected == false); return; } sri.SRCtrl = SRWrangler.StartSRControl(sri, pceh: (sender, args) => // the report progress eh { SRControl srctrl = args.UserState as SRControl; if (srctrl.IsInitialized) { SRWrangler.Logger.TraceEvent(LogLevels.Verbose, 383, "{0}, SRControl {1}: SR status '{2}', SR Control Status '{3}' ({4})", args.ProgressPercentage, srctrl.Identifier, INCCSR.SRAPIReturnStatusCode(srctrl.LastSRStatus), INCCSR.SRAPIReturnStatusCode(srctrl.LastMeasStatus), srctrl.fraction); } else { SRWrangler.Logger.TraceEvent(LogLevels.Verbose, 384, "{0}, SRControl {1}", args.ProgressPercentage, srctrl.Identifier); } }, // the operation complete eh opeh: SREventHandler ); } iter = Instruments.Active.GetSREnumerator(); // associate each new SR thread with the current measurement while (iter.MoveNext()) { SRInstrument sri = (SRInstrument)iter.Current; SRWrangler.StartSRActionAndWait(sri.id, SRTakeDataHandler.SROp.InitializeContext); } // devnote: the attempt to connect occurs in StartLMCAssay }
public SRControl StartSRControl(SRInstrument sr, ProgressChangedEventHandler pceh, SROpCompletedEventHandler opeh) { SRControlThread srct; if (threads.ContainsKey(sr.id)) { srct = threads[sr.id]; return srct.SRCtrl; // what? } // lookup the associated detector for the SRInstrument (match on DSID) Detector det = meas.Detectors.GetIt(sr.id); // must be there! srct = new SRControlThread(threads.Count + 1, logger, meas, det); srct.sri = sr; threads[sr.id] = srct; srct.WorkerReportsProgress = true; srct.WorkerSupportsCancellation = true; srct.DoWork += new DoWorkEventHandler(ThreadOp); srct.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Done); srct.ProgressChanged += new ProgressChangedEventHandler(pceh); srct.SROpCompleted += new SROpCompletedEventHandler(opeh); srct.RunWorkerAsync(sr); return srct.SRCtrl; }
//// BUTTONCLICK HANDLERS /////////////////////////////////////////////// public DialogResult OKButton_Click(object sender, EventArgs e) { DialogResult dr = DialogResult.Cancel; if (ap.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, ap.item_type, DateTime.Now); ap.MeasDateTime = sel.TimeStamp; ap.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AcquireParametersMap().Add(sel, ap); // it's a new one, not the existing one modified NC.App.DB.UpdateAcquireParams(ap, det.ListMode); } // The acquire is set to occur, build up the measurement state AnalysisWizard.ResetMeasurement(); Integ.BuildMeasurement(ap, det, mo); switch (ap.data_src) { case ConstructedSource.Live: // set up the instrument list for the action controller UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (det.ListMode) { // patch override lm.Interval with run_count_time from dialog NC.App.Opstate.Measurement.AcquireState.lm.Interval = NC.App.Opstate.Measurement.AcquireState.run_count_time; // Check NC.App.Opstate.Measurement.AnalysisParams for at least one VSR // If not present, inform and pop up the wizard // If present, inform with new dialog, do not pop up the wizard if (NC.App.Opstate.Measurement.AnalysisParams.HasMultiplicity()) { dr = DialogResult.OK; } else { AnalysisWizard awl = new AnalysisWizard(AnalysisWizard.AWSteps.Step2B, ap, det); // analyzers are created in here, placed on global measurement dr = awl.ShowDialog(); if (dr == DialogResult.OK) { NC.App.DB.UpdateAcquireParams(ap); //update it again NC.App.DB.UpdateDetector(det); } } if (dr == DialogResult.OK) { // if ok, the analyzers are set up, so can kick it off now. UIIntegration.Controller.ActivateDetector(det); } } else { SRInstrument sri = new SRInstrument(det); sri.selected = true; sri.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) { Instruments.All.Add(sri); // add to global runtime list } dr = DialogResult.OK; } break; case ConstructedSource.DB: NC.App.AppContext.DBDataAssay = true; UIIntegration.Controller.file = true; IDDAcquireDBMeas dbdlg = new IDDAcquireDBMeas(this); if (dbdlg.HasItems()) { dr = dbdlg.ShowDialog(); if (dr == DialogResult.OK) { DateTimeOffset dto = dbdlg.measurementId.MeasDateTime; DateTimeOffset cur = new DateTimeOffset(dto.Ticks, dto.Offset); NC.App.Logger(NCCReporter.LMLoggers.AppSection.App).TraceEvent(NCCReporter.LogLevels.Info, 87654, "Using " + dto.ToString("MMM dd yyy HH:mm:ss.ff K")); // get the cycles for the selected measurement from the database, and add them to the current measurement CycleList cl = NC.App.DB.GetCycles(det, dbdlg.measurementId); foreach (Cycle cycle in cl) // add the necessary meta-data to the cycle identifier instance { cycle.UpdateDataSourceId(ap.data_src, det.Id.SRType, cur.AddTicks(cycle.TS.Ticks), det.Id.FileName); cur = cycle.DataSourceId.dt; } NC.App.Opstate.Measurement.Add(cl); // TODO: for Reanalysis, a full reconstruction of the measurement state based on the ResultsRec state and the method parameter map contents (for Calib and Verif) } } else { MessageBox.Show("No items found in database matching these parameters", "WARNING"); } break; case ConstructedSource.Manual: UIIntegration.Controller.file = true; NC.App.AppContext.DBDataAssay = true; IDDManualDataEntry mdlg = new IDDManualDataEntry(); mdlg.AH = this; dr = mdlg.ShowDialog(); if (dr == DialogResult.OK) { // the work is done in the dialog class } break; case ConstructedSource.CycleFile: NC.App.AppContext.TestDataFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select a test data (disk) file", NC.App.AppContext.FileInput, "INCC5 Test data (disk)", "dat"); break; case ConstructedSource.ReviewFile: NC.App.AppContext.ReviewFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select an NCC file", NC.App.AppContext.FileInput, "INCC5 Review", "NCC"); break; case ConstructedSource.NCDFile: NC.App.AppContext.NCDFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select NCD files or folder", NC.App.AppContext.FileInput, "LMMM NCD", "ncd"); } break; case ConstructedSource.SortedPulseTextFile: NC.App.AppContext.PulseFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw1 = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw1.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select pulse files or folder", NC.App.AppContext.FileInput, "pulse", "txt"); } break; case ConstructedSource.PTRFile: NC.App.AppContext.PTRFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw2 = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw2.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select PTR-32 files or folder", NC.App.AppContext.FileInput, "PTR-32", "bin", "chn"); } break; case ConstructedSource.NILAFile: NC.App.AppContext.NILAFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFilesFolder("Select NILA files or folder", NC.App.AppContext.FileInput, "MTS NILA", "dat"); //dr = DialogResult.Cancel; break; default: break; } return(dr); }
// assumes initalized measurement with at least one cycle, and at least one defined counting analysis result indexed by the detector's mult params // NEXT: implement for LM results void ComputeFromINCC5SRData(Measurement m) { ctrllog.TraceEvent(LogLevels.Info, 34071, "Recomputing: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); if (m.Cycles.Count < 1) { ctrllog.TraceEvent(LogLevels.Error, 34830, "Skipping, no cycles on '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); return; } if (m.CountingAnalysisResults.Count < 1 || !m.CountingAnalysisResults.HasMultiplicity) { ctrllog.TraceEvent(LogLevels.Error, 34831, "Bad match between detector and this file type." + (!m.CountingAnalysisResults.HasMultiplicity ? " No Multiplicity counter defined." : "")); return; //bad match between detector and this file type. } SRInstrument PseudoInstrument = new SRInstrument(m.Detectors[0]); PseudoInstrument.selected = true; if (!Instruments.Active.Contains(PseudoInstrument)) Instruments.Active.Add(PseudoInstrument); // add to global runtime list m.CurrentRepetition = 0; NC.App.Opstate.SOH = NCC.OperatingState.Living; try { // urgent: there is more work to do for the bins and AB here, AB can be copied from the detector values MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults[m.Detectors[0].MultiplicityParams]; // multmult // start counting using the per-cycle accumulation of summary results Array.Clear(mcr.RAMult, 0, mcr.RAMult.Length); Array.Clear(mcr.NormedAMult, 0, mcr.NormedAMult.Length); mcr.AB.TransferIntermediates(src: m.Detectors[0].AB); foreach (AnalysisDefs.Cycle cycle in m.Cycles) { if (NC.App.Opstate.IsQuitRequested) // exit via abort or quit/save, follow-on code decides to continue with processing { ctrllog.TraceEvent(LogLevels.Warning, 430, "Cycle first-pass processing " + NC.App.Opstate.CancelStopAbortStateRep + " at sequence #" + cycle.seq + ", " + m.CurrentRepetition); break; } m.CurrentRepetition++; cycle.SetQCStatus(m.Detectors[0].MultiplicityParams, QCTestStatus.Pass, cycle.HighVoltage); // multmult prep for analyis one by one CycleProcessing.ApplyTheCycleConditioningSteps(cycle, m); m.CycleStatusTerminationCheck(cycle); ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString()); if (m.CurrentRepetition % 8 == 0) FireEvent(EventType.ActionInProgress, this); } FireEvent(EventType.ActionInProgress, this); // trim any None's that were not processed (occurs during a cancel/stop intervention) m.Cycles.Trim(m.Detectors[0].MultiplicityParams); // multmult } catch (Exception e) { NC.App.Opstate.SOH = NCC.OperatingState.Trouble; ctrllog.TraceException(e, true); ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + m.CurrentRepetition); } finally { NC.App.Loggers.Flush(); } if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available { // todo: if (meas.HasReportableData) m.CalculateMeasurementResults(); new ReportMangler(ctrllog).GenerateReports(m); m.SaveMeasurementResults(); } NC.App.Opstate.ResetTokens(); Instruments.All.Remove(PseudoInstrument); }
private void AnalysisWizardClick(object sender, RoutedEventArgs e) { AcquireParameters acq = null; Detector det = null; NC.App.DB.ResetAcquireParametersMap(); // force read from DB to get as-is default acquire state // NEXT: do a refresh of the specific acquire instance, not the entire list Integ.GetCurrentAcquireDetectorPair(ref acq, ref det); if (!det.ListMode) { System.Windows.Forms.MessageBox.Show("'" + det.ToString() + "' is not a List Mode detector,\r\ncreate or select a List Mode detector\r\n with Setup > Facility/Inspection...", "List Mode Acquire"); return; } LMAcquire a = new LMAcquire(acq, det); a.ShowDialog(); if (a.DialogResult == System.Windows.Forms.DialogResult.OK) { if (acq.modified || acq.lm.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AddAcquireParams(sel, acq); // it's a new one, not the existing one modified } switch (NC.App.Opstate.Measurement.AcquireState.data_src) // global access to latest acq here, same as acq set in wizard { case ConstructedSource.Live: UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (NC.App.Opstate.Measurement.Detector.ListMode) { // if ok, the analyzers are set up, so can kick it off now. if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.PTR32) { Ptr32Instrument instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detector); instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); // redundant now instrument.RDT.ResetRawDataBuffer(); instrument.RDT.SetLMStateFlags(((LMConnectionInfo)(instrument.id.FullConnInfo)).NetComm); if (!Instruments.Active.Contains(instrument)) { Instruments.Active.Add(instrument); } } else if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.MCA527) { MCA527Instrument mca = new MCA527Instrument(NC.App.Opstate.Measurement.Detector); mca.DAQState = DAQInstrState.Offline; // these are manually initiated as opposed to auto-pickup mca.selected = true; mca.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); // redundant now? if (!Instruments.Active.Contains(mca)) { Instruments.Active.Add(mca); } } else // LMMM { LMInstrument lm = new LMInstrument(NC.App.Opstate.Measurement.Detector); lm.DAQState = DAQInstrState.Offline; // these are manually initiated as opposed to auto-pickup lm.selected = false; //must broadcast first to get it selected if (!Instruments.All.Contains(lm)) { Instruments.All.Add(lm); // add to global runtime list } } } else { SRInstrument sri = new SRInstrument(NC.App.Opstate.Measurement.Detector); sri.selected = true; sri.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) { Instruments.All.Add(sri); // add to global runtime list } } break; case ConstructedSource.DB: UIIntegration.Controller.file = true; return; //break; case ConstructedSource.Manual: UIIntegration.Controller.file = true; return; //break; case ConstructedSource.CycleFile: case ConstructedSource.ReviewFile: UIIntegration.Controller.file = true; string xs = UIIntegration.GetUsersFolder("Select Input Folder", NC.App.AppContext.FileInput); if (!string.IsNullOrEmpty(xs)) { NC.App.AppContext.FileInput = xs; NC.App.AppContext.FileInputList = null; // no explicit file list } SRInstrument sri2 = new SRInstrument(NC.App.Opstate.Measurement.Detector); sri2.selected = true; sri2.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri2)) { Instruments.All.Add(sri2); // add to global runtime list } break; case ConstructedSource.NCDFile: NC.App.AppContext.NCDFileAssay = true; // suntoucher, this is right here how we're flowing now UIIntegration.Controller.file = true; break; case ConstructedSource.SortedPulseTextFile: NC.App.AppContext.PulseFileAssay = true; UIIntegration.Controller.file = true; break; case ConstructedSource.PTRFile: NC.App.AppContext.PTRFileAssay = true; UIIntegration.Controller.file = true; break; case ConstructedSource.MCA527File: NC.App.AppContext.MCA527FileAssay = true; UIIntegration.Controller.file = true; break; default: break; } NC.App.Opstate.Measurement.Detector.Id.source = NC.App.Opstate.Measurement.AcquireState.data_src; // set the detector overall data source value here UIIntegration.Controller.SetAssay(); // tell the controller to do an assay operation using the current measurement state UIIntegration.Controller.Perform(); // start the measurement file or DAQ thread } }
private void OKBtn_Click(object sender, EventArgs e) { if (hvp.modified) { DialogResult = DialogResult.OK; HVCalibrationParameters c = NC.App.DB.HVParameters.Get(det.Id.DetectorName); if (c != null) { c.Copy(hvp); // copy changes back to original on user affirmation } else { c = hvp; NC.App.DB.HVParameters.GetMap().Add(det, c); } NC.App.DB.HVParameters.Set(det, c); // dev note: LM HV vals on LM Acquire record, but SR uses separate DB table so move HV vals so unify the scheme } else { DialogResult = DialogResult.Ignore; } acq.data_src = ConstructedSource.Live; if (OpenInExcel.Checked != acq.lm.HVX) { acq.lm.HVX = OpenInExcel.Checked; NC.App.DB.UpdateAcquireParams(acq, det.ListMode); } // The acquire is set to occur, build up the measurement state Integ.BuildMeasurement(acq, det, AssaySelector.MeasurementOption.unspecified); NC.App.Opstate.Measurement.Detector.Id.source = ConstructedSource.Live; if (acq.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AddAcquireParams(sel, acq); // it's a new one, not the existing one modified } UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag Instrument instrument = null; if (NC.App.Opstate.Measurement.Detector.ListMode) { if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.PTR32) { instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detector); } else if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.MCA527) { instrument = new MCA527Instrument(NC.App.Opstate.Measurement.Detector); ((Analysis.MCA527ProcessingState)instrument.RDT.State).writingFile = false; // force this } else if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.LMMM) { instrument = new LMInstrument(NC.App.Opstate.Measurement.Detector); } instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.Active.Exists(i => instrument.id.Equals(i.id))) { Instruments.Active.Add(instrument); } } else { instrument = new SRInstrument(NC.App.Opstate.Measurement.Detector); instrument.selected = true; instrument.Init(null, null); if (!Instruments.Active.Exists(i => instrument.id.Equals(i))) { Instruments.All.Add(instrument); // add to global runtime list } } UIIntegration.Controller.SetHVCalib(); // tell the controller to do an HV operation using the current measurement state UIIntegration.Controller.Perform(); // start the HV DAQ thread Close(); }
private void OKBtn_Click(object sender, EventArgs e) { if (hvp.modified) { DialogResult = DialogResult.OK; HVCalibrationParameters c = NC.App.DB.HVParameters.Get(det.Id.DetectorName); if (c != null) c.Copy(hvp); // copy changes back to original on user affirmation else { c = hvp; NC.App.DB.HVParameters.GetMap().Add(det, c); } NC.App.DB.HVParameters.Set(det,c); // dev note: LM HV vals on LM Acquire record, but SR uses separate DB table so move HV vals so unify the scheme } else DialogResult = DialogResult.Ignore; acq.data_src = ConstructedSource.Live; if (OpenInExcel.Checked != acq.lm.HVX) { acq.lm.HVX = OpenInExcel.Checked; NC.App.DB.UpdateAcquireParams(acq, det.ListMode); } // The acquire is set to occur, build up the measurement state Integ.BuildMeasurement(acq, det, AssaySelector.MeasurementOption.unspecified); NC.App.Opstate.Measurement.Detector.Id.source = ConstructedSource.Live; if (acq.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AddAcquireParams(sel, acq); // it's a new one, not the existing one modified } UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag Instrument instrument = null; if (NC.App.Opstate.Measurement.Detector.ListMode) { if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.PTR32) { instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detector); } else if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.MCA527) { instrument = new MCA527Instrument(NC.App.Opstate.Measurement.Detector); ((Analysis.MCA527ProcessingState)instrument.RDT.State).writingFile = false; // force this } else if (NC.App.Opstate.Measurement.Detector.Id.SRType == InstrType.LMMM) { instrument = new LMInstrument(NC.App.Opstate.Measurement.Detector); } instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.Active.Exists(i => instrument.id.Equals(i.id))) Instruments.Active.Add(instrument); } else { instrument = new SRInstrument(NC.App.Opstate.Measurement.Detector); instrument.selected = true; instrument.Init(null, null); if (!Instruments.Active.Exists(i => instrument.id.Equals(i))) Instruments.All.Add(instrument); // add to global runtime list } UIIntegration.Controller.SetHVCalib(); // tell the controller to do an HV operation using the current measurement state UIIntegration.Controller.Perform(); // start the HV DAQ thread Close(); }
//// BUTTONCLICK HANDLERS /////////////////////////////////////////////// public DialogResult OKButton_Click(object sender, EventArgs e) { DialogResult dr = DialogResult.Cancel; if (ap.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, ap.item_type, DateTime.Now); ap.MeasDateTime = sel.TimeStamp; ap.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AcquireParametersMap().Add(sel, ap); // it's a new one, not the existing one modified NC.App.DB.UpdateAcquireParams(ap, det.ListMode); } // The acquire is set to occur, build up the measurement state AnalysisWizard.ResetMeasurement(); Integ.BuildMeasurement(ap, det, mo); switch (ap.data_src) { case ConstructedSource.Live: // set up the instrument list for the action controller UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (det.ListMode) { // patch override lm.Interval with run_count_time from dialog NC.App.Opstate.Measurement.AcquireState.lm.Interval = NC.App.Opstate.Measurement.AcquireState.run_count_time; // Check NC.App.Opstate.Measurement.AnalysisParams for at least one VSR // If not present, inform and pop up the wizard // If present, inform with new dialog, do not pop up the wizard if (NC.App.Opstate.Measurement.AnalysisParams.HasMultiplicity()) { dr = DialogResult.OK; } else { AnalysisWizard awl = new AnalysisWizard(AnalysisWizard.AWSteps.Step2B, ap, det); // analyzers are created in here, placed on global measurement dr = awl.ShowDialog(); if (dr == DialogResult.OK) { NC.App.DB.UpdateAcquireParams(ap); //update it again NC.App.DB.UpdateDetector(det); } } if (dr == DialogResult.OK) { // if ok, the analyzers are set up, so can kick it off now. UIIntegration.Controller.ActivateDetector(det); } } else { SRInstrument sri = new SRInstrument(det); sri.selected = true; sri.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) Instruments.All.Add(sri); // add to global runtime list dr = DialogResult.OK; } break; case ConstructedSource.DB: NC.App.AppContext.DBDataAssay = true; UIIntegration.Controller.file = true; IDDAcquireDBMeas dbdlg = new IDDAcquireDBMeas(this); if (dbdlg.HasItems()) { dr = dbdlg.ShowDialog(); if (dr == DialogResult.OK) { DateTimeOffset dto = dbdlg.measurementId.MeasDateTime; DateTimeOffset cur = new DateTimeOffset(dto.Ticks, dto.Offset); NC.App.Logger(NCCReporter.LMLoggers.AppSection.App).TraceEvent(NCCReporter.LogLevels.Info, 87654, "Using " + dto.ToString("MMM dd yyy HH:mm:ss.ff K")); // get the cycles for the selected measurement from the database, and add them to the current measurement CycleList cl = NC.App.DB.GetCycles(det, dbdlg.measurementId); foreach(Cycle cycle in cl) // add the necessary meta-data to the cycle identifier instance { cycle.UpdateDataSourceId(ap.data_src, det.Id.SRType, cur.AddTicks(cycle.TS.Ticks), det.Id.FileName); cur = cycle.DataSourceId.dt; } NC.App.Opstate.Measurement.Add(cl); // TODO: for Reanalysis, a full reconstruction of the measurement state based on the ResultsRec state and the method parameter map contents (for Calib and Verif) } } else MessageBox.Show("No items found in database matching these parameters", "WARNING"); break; case ConstructedSource.Manual: UIIntegration.Controller.file = true; NC.App.AppContext.DBDataAssay = true; IDDManualDataEntry mdlg = new IDDManualDataEntry(); mdlg.AH = this; dr = mdlg.ShowDialog(); if (dr == DialogResult.OK) { // the work is done in the dialog class } break; case ConstructedSource.CycleFile: NC.App.AppContext.TestDataFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select a test data (disk) file", NC.App.AppContext.FileInput, "INCC5 Test data (disk)", "dat"); break; case ConstructedSource.ReviewFile: NC.App.AppContext.ReviewFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select an NCC file", NC.App.AppContext.FileInput, "INCC5 Review", "NCC"); break; case ConstructedSource.NCDFile: NC.App.AppContext.NCDFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select NCD files or folder", NC.App.AppContext.FileInput, "LMMM NCD", "ncd"); } break; case ConstructedSource.SortedPulseTextFile: NC.App.AppContext.PulseFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw1 = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw1.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select pulse files or folder", NC.App.AppContext.FileInput, "pulse", "txt"); } break; case ConstructedSource.PTRFile: NC.App.AppContext.PTRFileAssay = true; UIIntegration.Controller.file = true; if (NC.App.Opstate.Measurement.MeasOption == AssaySelector.MeasurementOption.unspecified) { AnalysisWizard aw2 = new AnalysisWizard(AnalysisWizard.AWSteps.Step2A, ap, det); dr = aw2.ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select PTR-32 files or folder", NC.App.AppContext.FileInput, "PTR-32", "bin", "chn"); } break; case ConstructedSource.NILAFile: NC.App.AppContext.NILAFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFilesFolder("Select NILA files or folder", NC.App.AppContext.FileInput, "MTS NILA", "dat"); //dr = DialogResult.Cancel; break; default: break; } return dr; }
/// <summary> /// Start an assay on every instrument connected, this is for a single interval only /// The LMMM does just one assay from it's POV, and needs to be retold by DAQ here to do the next interval /// </summary> private int StartLM_SRAssay() { collog.TraceEvent(LogLevels.Info, 0, "Starting assay..."); CurState.Measurement.CurrentRepetition++; CurState.State = DAQInstrState.ReceivingData; numTotalBytes = 0; collectingFileData = NC.App.AppContext.LiveFileWrite; CurState.StampAssayTime(); CurState.GenDateTimePrefix(NC.App.AppContext.RootLoc); foreach (Instrument active in Instruments.Active) { if (active is SRInstrument) { ctrllog.TraceEvent(LogLevels.Verbose, 999333, "Got SR {0} here", (active as SRInstrument).id.Identifier()); } active.DAQState = DAQInstrState.ReceivingData; Cycle cycle = new Cycle(ctrllog); cycle.SetUpdatedDataSourceId(active.id); // where the cycle came from, but with updated timestamp CurState.Measurement.Add(cycle); // todo: this mixes the cycles from the different instruments onto one list, gotta change this now that we are at more than one instrument, well you can simply write iterators that select on specific instrument Ids, over the entire list, or use LINQ select * where dsid == whatever syntax on the list ctrllog.TraceEvent(LogLevels.Verbose, 93939, "Cycle {0} init", cycle.seq); // devnote: file writing is selectable via the UI, and raw analysis should be independently // start the file capture if (active is LMInstrument) { NCCFile.INeutronDataFile f = (active as LMInstrument).PrepOutputFile(CurState.currentDataFilenamePrefix, Instruments.Active.IndexOf(active), collog); active.RDT.StartCycle(cycle, f); // internal handler needs access to the file handle for PTR-32 and MCA-527, but not for LMMM ctrllog.TraceEvent(LogLevels.Verbose, 93939, "Cycle {0}, {1}", cycle.seq, string.IsNullOrEmpty(f.Filename) ? string.Empty: "output file name " + f.Filename); } else { active.RDT.StartCycle(cycle); } if (CurState.Measurement.CurrentRepetition == 1) { // devnote: with more than one active, these need to be revisited if (active is LMInstrument) { (active as LMInstrument).RDT.SetupCountingAnalyzerHandler(NC.App.Config, active.id.source.TimeBase(active.id.SRType)); (active as LMInstrument).RDT.PrepareAndStartCountingAnalyzers(CurState.Measurement.AnalysisParams); } // todo: Measurement Detector List exists but is not integrated with associated Instrument objects here if (active is SRInstrument) { // kick off the thread to try and init the SR SRWrangler.StartSRActionAndWait((active as SRInstrument).id, SRTakeDataHandler.SROp.InitializeSR); } else if (active is LMInstrument && active.id.SRType == InstrType.LMMM) { LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.prep, 0, Instruments.All.IndexOf(active)); // send this config message to this LMMM } // devnote: index might be wrong if some of multiple LMs are disabled via UI. This will require a revisit at integration time } } NC.App.Loggers.Flush(); FireEvent(EventType.ActionInProgress, this); Thread.Sleep(250); // LMMM only: wait for last send to finish, todo could we use EventHandler<SocketAsyncEventArgs> Completed here? // PTR-32/MCA-527 // This loop works for PTR-32 and MCA-527) instruments, based on an improved instrument and control design // devnote: rewrite SR and LMMM sections below to use the StartAssay virtual method abstraction for measurement control foreach (Instrument instrument in Instruments.Active) { try { instrument.StartAssay(CurState.Measurement); } catch (Exception ex) { collog.TraceException(ex); } } // The following sections are for SR and LMMM // LMMM if (Instruments.Active.HasLMMM()) // send to a plurality of thresholding units, err, I mean, LMMM Instruments { if (CurState.broadcastGo) // send go { // this has to be sent separately, because linux control is looking for the Arm alone. LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.arm); // send to all active Thread.Sleep(250); // allow linux code to setup waiting socket. // broadcast go message to all NCC.App.Config.Net.Subnet addresses. This is the instrument group. LMMMComm.PostLMMMCommand(LMMMLingo.Tokens.go, true); } else { LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.go); // send to all active } } // SR bool srgood = false, hasSR = false; // send the start DAQ to every active SR, probably better to do this in the event handler not here IEnumerator iter = Instruments.Active.GetSREnumerator(); while (iter.MoveNext()) { hasSR = true; SRInstrument sri = (SRInstrument)iter.Current; int srStatus = 0, measStatus = 0; SRWrangler.GetLastStatus(sri.id, ref srStatus, ref measStatus); if (measStatus != INCCSR.SUCCESS) // failure means we cannot see or use the SR, so go to the next one, whereas success means it initialized correctly in the InitializeSR step { sri.DAQState = DAQInstrState.Offline; continue; } int status = SRWrangler.StartSRActionAndWait(sri.id, SRTakeDataHandler.SROp.StartSRDAQ); // NEXT: check if pending here is going to be an issue if (status == INCCSR.MEAS_CONTINUE) // the SR started { srgood = true; SRWrangler.SetAction(sri.id, SRTakeDataHandler.SROp.WaitForResults); // event handler will pick up results when the internal timer polling in the thread detects results and fires the event } } // need a better test in here to skip all this startup stuff when the SR/LM/cycle init failed if (Instruments.Active.Count < 1) { CurState.Measurement.CurrentRepetition--; ctrllog.TraceEvent(LogLevels.Warning, 46, "No active instruments available now"); } else if (hasSR && !srgood) { CurState.Measurement.CurrentRepetition--; ctrllog.TraceEvent(LogLevels.Warning, 46, "No Shift Register is available now"); } else { if (CurState.Measurement.CurrentRepetition == 1) { if (Instruments.Active.Count > 1) { if (Instruments.Active.Count != Instruments.All.Count) { ctrllog.TraceInformation("Using " + Instruments.Active.Count + " of " + Instruments.All.Count + " instruments"); } else { ctrllog.TraceInformation("Using " + Instruments.Active.Count + " instruments"); } } else { ctrllog.TraceInformation("Using one instrument"); } } string str = "Assay cycle " + CurState.Measurement.CurrentRepetition + " of "; if (CurState.Measurement.RequestedRepetitions == 0) { str += "a continuous assay starting"; } else { str += (CurState.Measurement.RequestedRepetitions + " cycles starting"); } ctrllog.TraceInformation(str); } if (Instruments.Active.Count > 0) { FireEvent(EventType.ActionInProgress, this); collog.TraceEvent(LogLevels.Verbose, 0, "Started assay with {0} instrument{1}", Instruments.Active.Count, (Instruments.Active.Count > 1 ? "s" : "")); } return(Instruments.Active.Count); }
void Replay(Measurement m, ConstructedSource src) { ctrllog.TraceEvent(LogLevels.Info, 34071, "Replay this: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); m.AcquireState.comment += " replay"; // todo: make sure assay type on measurement is not overridden by cmd line artifacts NC.App.Opstate.Measurement = m; SRInstrument PseudoInstrument = new SRInstrument(m.Detectors[0]); // psuedo LM until we can map from user or deduce from file content at run-time PseudoInstrument.id.source = ConstructedSource.INCCTransfer; // remove PseudoInstrument.id.SetSRType(PseudoInstrument.id.Type); // hack, the SR type should be pre-defined by an earlier import of a INCCInitialDataDetectorFile PseudoInstrument.selected = true; if (!Instruments.Active.Contains(PseudoInstrument)) Instruments.Active.Add(PseudoInstrument); // add to global runtime list m.CurrentRepetition = 0; NC.App.Opstate.SOH = NCC.OperatingState.Living; try { MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults.First().Value; for (int i = 0; i < mcr.RAMult.Length; i++) // count again using the per-cycle accumulation of summary results mcr.RAMult[i] = 0; for (int i = 0; i < mcr.NormedAMult.Length; i++) mcr.NormedAMult[i] = 0; m.Detectors[0].Id.source = src; // need to get alpha beta onto the summary too. mcr.AB.TransferIntermediates(m.Detectors[0].AB); foreach (AnalysisDefs.Cycle cycle in m.Cycles) { if (NC.App.Opstate.IsCancellationRequested) // cancellation occurs here and at selected steps in the internal file and analyzer processing break; m.CurrentRepetition++; CycleProcessing.ApplyTheCycleConditioningSteps(cycle, m); m.CycleStatusTerminationCheck(cycle); } } catch (Exception e) { NC.App.Opstate.SOH = NCC.OperatingState.Trouble; ctrllog.TraceException(e, true); ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + m.CurrentRepetition); } finally { NC.App.Loggers.Flush(); } // todo: if (meas.HasReportableData) m.CalculateMeasurementResults(); ReportMangler rm = new ReportMangler(ctrllog); rm.GenerateReports(m); m.SaveMeasurementResults(); Instruments.All.Remove(PseudoInstrument); }
private void OKBtn_Click(object sender, EventArgs e) { if (hvp.modified) { DialogResult = System.Windows.Forms.DialogResult.OK; HVCalibrationParameters c = NC.App.DB.HVParameters.Get(det.Id.DetectorName); if (c != null) { c.Copy(hvp); // copy changes back to original on user affirmation } else { c = hvp; NC.App.DB.HVParameters.GetMap().Add(det, c); } NC.App.DB.HVParameters.Set(det, c); // dev note: LM HV vals on LM Acquire record, but SR uses separate DB table so move HV vals so unify the scheme } else { DialogResult = System.Windows.Forms.DialogResult.Ignore; } // The acquire is set to occur, build up the measurement state Integ.BuildMeasurement(acq, det, AssaySelector.MeasurementOption.unspecified); if (acq.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AcquireParametersMap().Add(sel, acq); // it's a new one, not the existing one modified NC.App.DB.UpdateAcquireParams(acq, det.ListMode); } UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (NC.App.Opstate.Measurement.Detectors[0].ListMode) { if (NC.App.Opstate.Measurement.Detectors[0].Id.SRType == InstrType.PTR32) { Ptr32Instrument instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detectors[0]); instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.Active.Contains(instrument)) { Instruments.Active.Add(instrument); } } else { // if ok, the analyzers are set up, so can kick it off now. LMInstrument lm = new LMInstrument(NC.App.Opstate.Measurement.Detectors[0]); lm.DAQState = DAQInstrState.Offline; // these are manually initiated as opposed to auto-pickup lm.selected = false; //must broadcast first to get it selected if (!Instruments.All.Contains(lm)) { Instruments.All.Add(lm); // add to global runtime list } } } else { SRInstrument sri = new SRInstrument(NC.App.Opstate.Measurement.Detectors[0]); sri.selected = true; sri.Init(null, null); if (!Instruments.All.Contains(sri)) { Instruments.All.Add(sri); // add to global runtime list } } UIIntegration.Controller.SetHVCalib(); // tell the controller to do an HV operation using the current measurement state UIIntegration.Controller.Perform(); // start the HV DAQ thread this.Close(); }
//// BUTTONCLICK HANDLERS /////////////////////////////////////////////// public DialogResult OKButton_Click(object sender, EventArgs e) { DialogResult dr = DialogResult.Cancel; if (ap.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, ap.item_type, DateTime.Now); ap.MeasDateTime = sel.TimeStamp; ap.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AddAcquireParams(sel, ap); // it's a new one, not the existing one modified } // The acquire is set to occur if (ap.data_src != ConstructedSource.Reanalysis) // Reanalysis is a bit backwards, the correct measurement is fully constructed before this point LMAcquire.ResetMeasurement(); switch (ap.data_src) { case ConstructedSource.Live: // set up the instrument list for the action controller Integ.BuildMeasurement(ap, det, mo); UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (det.ListMode) { // patch override lm.Interval with run_count_time from dialog // the acquire dialogs field values, as seen and modified by the user, override the LM-only acquire settings for virtual SR measurements NC.App.Opstate.Measurement.AcquireState.lm.Interval = NC.App.Opstate.Measurement.AcquireState.run_count_time; NC.App.Opstate.Measurement.AcquireState.lm.Cycles = NC.App.Opstate.Measurement.AcquireState.num_runs; // Check NC.App.Opstate.Measurement.AnalysisParams for at least one VSR // If not present, inform and pop up the wizard // If present, inform with new dialog, do not pop up the wizard if (NC.App.Opstate.Measurement.AnalysisParams.HasMatchingVSR(det.MultiplicityParams)) { dr = DialogResult.OK; } else { dr = (new LMAcquire(ap, det, fromINCC5Acq: true)).ShowDialog();// analyzers are created in here, placed on global measurement if (dr == DialogResult.OK) { NC.App.DB.UpdateAcquireParams(ap); //update it again NC.App.DB.UpdateDetector(det); } } if (dr == DialogResult.OK) { // if ok, the analyzers are set up, so can kick it off now. UIIntegration.Controller.ActivateDetector(det); } } else { SRInstrument sri = new SRInstrument(det); sri.selected = true; sri.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) Instruments.All.Add(sri); // add to global runtime list dr = DialogResult.OK; } break; case ConstructedSource.DB: NC.App.AppContext.DBDataAssay = true; UIIntegration.Controller.file = true; IDDAcquireDBMeas dbdlg = new IDDAcquireDBMeas(this); if (dbdlg.HasItems()) { dr = dbdlg.ShowDialog(); if (dr == DialogResult.OK) { Integ.BuildMeasurement(ap, det, mo); DateTimeOffset dto = dbdlg.measurementId.MeasDateTime; NC.App.Logger(LMLoggers.AppSection.App).TraceEvent(LogLevels.Info, 87654, "Using " + dto.ToString("MMM dd yyy HH:mm:ss.ff K")); NC.App.Opstate.Measurement.MeasDate = dto; // get the cycles for the selected measurement from the database, and add them to the current measurement CycleList cl = NC.App.DB.GetCycles(det, dbdlg.measurementId, ap.data_src); // APluralityOfMultiplicityAnalyzers: // URGENT: get all the cycles associated with each analyzer, restoring into the correct key->result pair NC.App.Opstate.Measurement.Add(cl); // use the cycle time interval as found in the data, taking the first entry because equal intervals are assumed if (cl.Count > 0) NC.App.Opstate.Measurement.AcquireState.lm.Interval = NC.App.Opstate.Measurement.AcquireState.run_count_time = cl[0].TS.TotalSeconds; NC.App.DB.UpdateAcquireParams(ap); //update it again } } else MessageBox.Show("No items found in database matching these parameters", "WARNING"); break; case ConstructedSource.Manual: UIIntegration.Controller.file = true; NC.App.AppContext.DBDataAssay = true; IDDManualDataEntry mdlg = new IDDManualDataEntry(); mdlg.AH = this; dr = mdlg.ShowDialog(); // the work constructing the measurement is done in the dialog class break; case ConstructedSource.Reanalysis: UIIntegration.Controller.file = true; NC.App.AppContext.DBDataAssay = true; dr = DialogResult.OK; // the measurement re-creation work is done in the IDDReanalysisAssay dialog class prior to reaching this point break; case ConstructedSource.CycleFile: Integ.BuildMeasurementMinimal(ap, det, mo); // the measurement is reconstructed before each test data file processing, so this is meant as a carrier for certain kick-off values NC.App.AppContext.TestDataFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select a test data (disk) file", NC.App.AppContext.FileInput, "INCC5 Test data (disk)", "dat", "cnn"); break; case ConstructedSource.ReviewFile: Integ.BuildMeasurementMinimal(ap, det, mo); // acquire type and measurement option are read from each NCC file itself, so this instance is an acquire state kick-off carrier value NC.App.AppContext.ReviewFileAssay = true; UIIntegration.Controller.file = true; dr = UIIntegration.GetUsersFile("Select an NCC file", NC.App.AppContext.FileInput, "INCC5 Review", "NCC"); break; case ConstructedSource.NCDFile: Integ.BuildMeasurement(ap, det, mo); NC.App.AppContext.NCDFileAssay = true; UIIntegration.Controller.file = true; if (det.ListMode || NC.App.Opstate.Measurement.MeasOption.IsListMode()) { dr = (new LMAcquire(ap, det, fromINCC5Acq: true)).ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select NCD files or folder", NC.App.AppContext.FileInput, "LMMM NCD", "ncd"); } break; case ConstructedSource.SortedPulseTextFile: Integ.BuildMeasurement(ap, det, mo); NC.App.AppContext.PulseFileAssay = true; UIIntegration.Controller.file = true; if (det.ListMode || NC.App.Opstate.Measurement.MeasOption.IsListMode()) { dr = (new LMAcquire(ap, det, fromINCC5Acq: true)).ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select pulse files or folder", NC.App.AppContext.FileInput, "pulse", "txt"); } break; case ConstructedSource.PTRFile: Integ.BuildMeasurement(ap, det, mo); NC.App.AppContext.PTRFileAssay = true; UIIntegration.Controller.file = true; if (det.ListMode || NC.App.Opstate.Measurement.MeasOption.IsListMode()) { dr = (new LMAcquire(ap, det, fromINCC5Acq: true)).ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select PTR-32 files or folder", NC.App.AppContext.FileInput, "PTR-32", "bin", "chn"); } break; case ConstructedSource.MCA527File: Integ.BuildMeasurement(ap, det, mo); NC.App.AppContext.MCA527FileAssay = true; UIIntegration.Controller.file = true; if (det.ListMode || NC.App.Opstate.Measurement.MeasOption.IsListMode()) { dr = (new LMAcquire(ap, det, fromINCC5Acq: true)).ShowDialog(); // show LM-relevant acquire-style settings for modification or confirmation } else { dr = UIIntegration.GetUsersFilesFolder("Select MCA files or folder", NC.App.AppContext.FileInput, "MCA527", "mca"); } break; default: break; } return dr; }
/////////////////// // MOUSER MENU // /////////////////// private void AnalysisWizardClick(object sender, RoutedEventArgs e) { AcquireParameters acq = null; Detector det = null; Integ.GetCurrentAcquireDetectorPair(ref acq, ref det); if (!det.ListMode) { MessageBox.Show("'" + det.ToString() + "' is not a List Mode detector,\r\ncreate or select a List Mode detector\r\n with Setup > Facility/Inspection...", "List Mode Acquire"); return; } NewUI.AnalysisWizard f = new NewUI.AnalysisWizard(NewUI.AnalysisWizard.AWSteps.Step1, acq, det); System.Windows.Forms.DialogResult dr = f.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { if (acq.modified || acq.lm.modified) { INCCDB.AcquireSelector sel = new INCCDB.AcquireSelector(det, acq.item_type, DateTime.Now); acq.MeasDateTime = sel.TimeStamp; acq.lm.TimeStamp = sel.TimeStamp; NC.App.DB.AcquireParametersMap().Add(sel, acq); // it's a new one, not the existing one modified NC.App.DB.UpdateAcquireParams(acq, det.ListMode); } switch (NC.App.Opstate.Measurement.AcquireState.data_src) // global access to latest acq here, same as acq set in wizard { case ConstructedSource.Live: UIIntegration.Controller.file = false; // make sure to use the DAQ controller, not the file controller NC.App.AppContext.FileInput = null; // reset the cmd line file input flag if (NC.App.Opstate.Measurement.Detectors[0].ListMode) { // NC.App.DB.UpdateAcquireParams(ap, det.ListMode); //update it again // NC.App.DB.UpdateDetector(det); // if ok, the analyzers are set up, so can kick it off now. if (NC.App.Opstate.Measurement.Detectors[0].Id.SRType == InstrType.PTR32) { Ptr32Instrument instrument = new Ptr32Instrument(NC.App.Opstate.Measurement.Detectors[0]); instrument.DAQState = DAQInstrState.Offline; instrument.selected = true; instrument.Init(NC.App.Logger(LMLoggers.AppSection.Data), NC.App.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.Active.Contains(instrument)) { Instruments.Active.Add(instrument); } } else { LMInstrument lm = new LMInstrument(NC.App.Opstate.Measurement.Detectors[0]); lm.DAQState = DAQInstrState.Offline; // these are manually initiated as opposed to auto-pickup lm.selected = false; //must broadcast first to get it selected if (!Instruments.All.Contains(lm)) Instruments.All.Add(lm); // add to global runtime list } } else { SRInstrument sri = new SRInstrument(NC.App.Opstate.Measurement.Detectors[0]); sri.selected = true; sri.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri)) Instruments.All.Add(sri); // add to global runtime list } break; case ConstructedSource.DB: UIIntegration.Controller.file = true; return; //break; case ConstructedSource.Manual: UIIntegration.Controller.file = true; return; //break; case ConstructedSource.CycleFile: case ConstructedSource.ReviewFile: UIIntegration.Controller.file = true; string xs = UIIntegration.GetUsersFolder("Select Input Folder", NC.App.AppContext.FileInput); if (!String.IsNullOrEmpty(xs)) { NC.App.AppContext.FileInput = xs; NC.App.AppContext.FileInputList = null; // no explicit file list } SRInstrument sri2 = new SRInstrument(NC.App.Opstate.Measurement.Detectors[0]); sri2.selected = true; sri2.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis)); if (!Instruments.All.Contains(sri2)) Instruments.All.Add(sri2); // add to global runtime list break; case ConstructedSource.NCDFile: NC.App.AppContext.NCDFileAssay = true; // suntoucher, this is right here how we're flowing now UIIntegration.Controller.file = true; break; case ConstructedSource.SortedPulseTextFile: NC.App.AppContext.PulseFileAssay = true; UIIntegration.Controller.file = true; break; case ConstructedSource.PTRFile: NC.App.AppContext.PTRFileAssay = true; UIIntegration.Controller.file = true; break; default: break; } NC.App.Opstate.Measurement.Detectors[0].Id.source = NC.App.Opstate.Measurement.AcquireState.data_src; // set the detector overall data source value here UIIntegration.Controller.SetAssay(); // tell the controller to do an assay operation using the current measurement state UIIntegration.Controller.Perform(); // start the measurement file or DAQ thread } }
/// <summary> /// Checks control state for DAQ continuation, then /// If at the end of a cycle /// 1) finishes cycle processing (get results, summarize counts, cycle conditioning steps) /// a) starts the next assay cycle, or /// b) notifies controller of DAQ measurement completion /// </summary> /// <param name="activeInstr">instrument object associated with the current DAQ state</param> /// <param name="sb">status block object indicating end of a cycle</param> static void HandleEndOfCycleProcessing(SRInstrument activeInstr) { //activeInstr.RDT.PlaceStatusTextOnCurrentCycle(sb); //activeInstr.RDT.Cycle.ApplyTheCycleConditioningSteps(CurState.Measurement); bool done = true; // assume done for all instruments activeInstr.DAQState = DAQInstrState.Offline; IEnumerator iter = Instruments.Active.GetSREnumerator(); while (iter.MoveNext()) { SRInstrument sri = (SRInstrument)iter.Current; if (sri.DAQState == DAQInstrState.ReceivingData || sri.DAQState == DAQInstrState.Online) done = false; break; } if (done) // all are done { CurState.State = DAQInstrState.Online; activeInstr.RDT.logger.TraceInformation("Assay cycle " + CurState.Measurement.CurrentRepetition + " complete"); if ((CurState.Measurement.CurrentRepetition < CurState.Measurement.RequestedRepetitions) || (CurState.Measurement.RequestedRepetitions == 0) && !CurState.IsQuitRequested) { bool ok = activeInstr.RDT.EndOfCycleProcessing(CurState.Measurement); if (gControl != null) { if (ok) gControl.StartLM_SRAssay(); else gControl.MajorOperationCompleted(); // the overall pend handle used by cmd line } } else { activeInstr.RDT.logger.TraceInformation("All assay cycles completed"); activeInstr.RDT.EndOfCycleProcessing(CurState.Measurement); if (gControl != null) { gControl.MajorOperationCompleted(); // the overall pend handle used by cmd line } } } }
// assumes initalized measurement with at least one cycle, and at least one defined counting analysis result indexed by the detector's mult params // NEXT: implement for LM results void ComputeFromINCC5SRData(Measurement m) { ctrllog.TraceEvent(LogLevels.Info, 34071, "Recomputing: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); if (m.Cycles.Count < 1) { ctrllog.TraceEvent(LogLevels.Error, 34830, "Skipping, no cycles on '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'"); return; } if (m.CountingAnalysisResults.Count < 1 || !m.CountingAnalysisResults.HasMultiplicity) { ctrllog.TraceEvent(LogLevels.Error, 34831, "Bad match between detector and this file type." + (!m.CountingAnalysisResults.HasMultiplicity ? " No Multiplicity counter defined." : "")); return; //bad match between detector and this file type. } SRInstrument PseudoInstrument = new SRInstrument(m.Detectors[0]); PseudoInstrument.selected = true; if (!Instruments.Active.Contains(PseudoInstrument)) { Instruments.Active.Add(PseudoInstrument); // add to global runtime list } m.CurrentRepetition = 0; NC.App.Opstate.SOH = NCC.OperatingState.Living; try { // urgent: there is more work to do for the bins and AB here, AB can be copied from the detector values MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults[m.Detectors[0].MultiplicityParams]; // multmult // start counting using the per-cycle accumulation of summary results Array.Clear(mcr.RAMult, 0, mcr.RAMult.Length); Array.Clear(mcr.NormedAMult, 0, mcr.NormedAMult.Length); mcr.AB.TransferIntermediates(src: m.Detectors[0].AB); foreach (AnalysisDefs.Cycle cycle in m.Cycles) { if (NC.App.Opstate.IsQuitRequested) // exit via abort or quit/save, follow-on code decides to continue with processing { ctrllog.TraceEvent(LogLevels.Warning, 430, "Cycle first-pass processing " + NC.App.Opstate.CancelStopAbortStateRep + " at sequence #" + cycle.seq + ", " + m.CurrentRepetition); break; } m.CurrentRepetition++; cycle.SetQCStatus(m.Detectors[0].MultiplicityParams, QCTestStatus.Pass, cycle.HighVoltage); // multmult prep for analyis one by one CycleProcessing.ApplyTheCycleConditioningSteps(cycle, m); m.CycleStatusTerminationCheck(cycle); ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString()); if (m.CurrentRepetition % 8 == 0) { FireEvent(EventType.ActionInProgress, this); } } FireEvent(EventType.ActionInProgress, this); // trim any None's that were not processed (occurs during a cancel/stop intervention) m.Cycles.Trim(m.Detectors[0].MultiplicityParams); // multmult } catch (Exception e) { NC.App.Opstate.SOH = NCC.OperatingState.Trouble; ctrllog.TraceException(e, true); ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + m.CurrentRepetition); } finally { NC.App.Loggers.Flush(); } if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available { // todo: if (meas.HasReportableData) m.CalculateMeasurementResults(); new ReportMangler(ctrllog).GenerateReports(m); m.SaveMeasurementResults(); } NC.App.Opstate.ResetTokens(); Instruments.All.Remove(PseudoInstrument); }