Exemplo n.º 1
0
        /// <summary>
        /// Save a detector and its related class instances on the in-memory collections to the database
        /// </summary>
        /// <param name="newdet">The detector to persist</param>
        public static void PersistDetectorAndAssociations(Detector newdet)
        {
            // write detector essentials to DB, detector must be in DB before related insertions
            try
            {
                CentralizedState.App.DB.UpdateDetector(newdet); // write detector and related sr_parms to database

                BackgroundParameters bp = CentralizedState.App.DB.BackgroundParameters.Get(newdet);
                CentralizedState.App.DB.BackgroundParameters.Set(newdet, bp);

                NormParameters np = CentralizedState.App.DB.NormParameters.Get(newdet);
                CentralizedState.App.DB.NormParameters.Set(newdet, np);

                UnattendedParameters unp = CentralizedState.App.DB.UnattendedParameters.Get(newdet);
                CentralizedState.App.DB.UnattendedParameters.Set(newdet, unp);

                AddASourceSetup aass = CentralizedState.App.DB.AASSParameters.Get(newdet);
                CentralizedState.App.DB.AASSParameters.Set(newdet, aass);

                HVCalibrationParameters hv = CentralizedState.App.DB.HVParameters.Get(newdet);
                CentralizedState.App.DB.HVParameters.Set(newdet, hv);
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new detector in-memory, with the related classes.
        /// Emulates the INCC relationship constructor, caller must insert new det into global list, then update to DB later for persistence
        /// </summary>
        /// <param name="model">detector to copy</param>
        /// <param name="newId">New detector name</param>
        /// <param name="elecId">Electronics id (just a string)</param>
        /// <param name="typeDesc">Type description (just a string)</param>
        /// <param name="srType">Actual instrument type</param>
        /// <returns>The newly created in-memory Detector class instance</returns>
        static public Detector CreateDetectorWithAssociations(Detector model, string newId, string elecId, string typeDesc, InstrType srType = InstrType.AMSR)
        {
            if (model != null)
            {
                Detector det = new Detector(model); // copies the SR too
                det.Id.SetIdDetails(newId, elecId, typeDesc, model.Id.SRType);

                // copy the model detector's related parameters (skips stratum)
                NormParameters          n          = CentralizedState.App.DB.NormParameters.Get(model);
                NormParameters          Norm       = new NormParameters(n);
                BackgroundParameters    b          = CentralizedState.App.DB.BackgroundParameters.Get(model);
                BackgroundParameters    Background = new BackgroundParameters(b);
                UnattendedParameters    u          = CentralizedState.App.DB.UnattendedParameters.Get(model);
                UnattendedParameters    Unatt      = new UnattendedParameters(u);
                AddASourceSetup         a          = CentralizedState.App.DB.AASSParameters.Get(model);
                AddASourceSetup         Aass       = new AddASourceSetup(a);
                HVCalibrationParameters h          = CentralizedState.App.DB.HVParameters.Get(model);
                HVCalibrationParameters Hv         = new HVCalibrationParameters(h);

                // add copied param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, Norm);
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, Unatt);
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, Background);
                CentralizedState.App.DB.AASSParameters.Map.Add(det, Aass);
                CentralizedState.App.DB.HVParameters.Map.Add(det, Hv);

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return(det);
            }
            else
            {
                Detector det = new Detector();
                det.Id.SetIdDetails(newId, elecId, typeDesc, srType);

                if (srType.IsListMode())
                {
                    det.Id.FullConnInfo = new LMConnectionInfo();
                }

                // add fresh param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, new NormParameters());
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, new UnattendedParameters());
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, new BackgroundParameters());
                CentralizedState.App.DB.AASSParameters.Map.Add(det, new AddASourceSetup());
                CentralizedState.App.DB.HVParameters.Map.Add(det, new HVCalibrationParameters());

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return(det);
            }

            /*  * todo: create analysis selector (or it happens automatically when first referenced?)
             * creating a stratum association
             * */
        }
Exemplo n.º 3
0
        /// <summary>
        /// Imprint a new measurement with as much information as possible from a results_rec.
        /// Might need to bring the Item Id into the test soon.
        /// </summary>
        /// <param name="rec">The results_rec with the measurement details</param>
        /// <param name="meaId">Unique id for the measurement, from the results_rec fields</param>
        /// <param name="logger">logger handle</param>
        /// <returns>A new measurement</returns>
        public Measurement(INCCResults.results_rec rec, MeasId meaId, NCCReporter.LMLoggers.LognLM logger)
        {
            HVCalibrationParameters hv = NCC.IntegrationHelpers.GetCurrentHVCalibrationParams(rec.det);
            MeasurementTuple        mt = new MeasurementTuple(new DetectorList(rec.det), rec.tests, rec.norm, rec.bkg, rec.iso, rec.acq, hv);

            this.mt     = mt;
            this.logger = logger;
            mid         = meaId;
            InitMisc();
        }
Exemplo n.º 4
0
        public IDDHighVoltagePlateau()
        {
            InitializeComponent();

            Integ.GetCurrentAcquireDetectorPair(ref acq, ref det);
            hvp = Integ.GetCurrentHVCalibrationParams(det);

            Text += " for detector " + det.Id.DetectorName;
            MinimumVoltageTextBox.Text  = hvp.MinHV.ToString();
            MaximumVoltageTextBox.Text  = hvp.MaxHV.ToString();
            VoltageStepSizeTextBox.Text = hvp.Step.ToString();
            CountTimeTextBox.Text       = hvp.HVDuration.ToString();
            HVStepDelay.Text            = hvp.DelayMS.ToString();
            OpenInExcel.Checked         = acq.lm.HVX;
            OpenInExcel.Enabled         = DAQ.HVExcel.ExcelPresent();
        }
Exemplo n.º 5
0
        public IDDHighVoltagePlateau()
        {
            InitializeComponent();

            Integ.GetCurrentAcquireDetectorPair(ref acq, ref det);
            hvp = Integ.GetCurrentHVCalibrationParams(det);

            Text += " for detector " + det.Id.DetectorName;
            MinimumVoltageTextBox.Text = hvp.MinHV.ToString();
            MaximumVoltageTextBox.Text = hvp.MaxHV.ToString();
            VoltageStepSizeTextBox.Text = hvp.Step.ToString();
            CountTimeTextBox.Text = hvp.HVDuration.ToString();
            HVStepDelay.Text = hvp.DelayMS.ToString();
            OpenInExcel.Checked = acq.lm.HVX;
            OpenInExcel.Enabled = DAQ.HVExcel.ExcelPresent();
        }
Exemplo n.º 6
0
        public static HVCalibrationParameters GetCurrentHVCalibrationParams(Detector det)
        {
            HVCalibrationParameters bp = new HVCalibrationParameters();

            if (det != null)
            {
                if (CentralizedState.App.DB.HVParameters.Map.ContainsKey(det))
                {
                    bp.Copy(CentralizedState.App.DB.HVParameters.Map[det]);
                }
                else if (det.ListMode)
                {
                    AcquireParameters acq = GetCurrentAcquireParamsFor(det);
                    bp = new HVCalibrationParameters(acq.lm);
                }
            }
            return(bp);
        }
Exemplo n.º 7
0
 public static HVCalibrationParameters GetCurrentHVCalibrationParams(Detector det)
 {
     HVCalibrationParameters bp = new HVCalibrationParameters();
     if (det != null)
     {
         if (CentralizedState.App.DB.HVParameters.Map.ContainsKey(det))
             bp.Copy(CentralizedState.App.DB.HVParameters.Map[det]);
         else if (det.ListMode)
         {
             AcquireParameters acq = GetCurrentAcquireParamsFor(det);
             bp = new HVCalibrationParameters(acq.lm);
         }
     }
     return bp;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new detector in-memory, with the related classes.
        /// Emulates the INCC relationship constructor, caller must insert new det into global list, then update to DB later for persistence
        /// </summary>
        /// <param name="model">detector to copy</param>
        /// <param name="newId">New detector name</param>
        /// <param name="elecId">Electronics id (just a string)</param>
        /// <param name="typeDesc">Type description (just a string)</param>
        /// <param name="srType">Actual instrument type</param>
        /// <returns>The newly created in-memory Detector class instance</returns>
        public static Detector CreateDetectorWithAssociations(Detector model, string newId, string elecId, string typeDesc, InstrType srType = InstrType.AMSR)
        {
            if (model != null)
            {
                Detector det = new Detector(model); // copies the SR too
                det.Id.SetIdDetails(newId, elecId, typeDesc, model.Id.SRType);

                // copy the model detector's related parameters (skips stratum)
                NormParameters n = CentralizedState.App.DB.NormParameters.Get(model);
                NormParameters Norm = new NormParameters(n);
                BackgroundParameters b = CentralizedState.App.DB.BackgroundParameters.Get(model);
                BackgroundParameters Background = new BackgroundParameters(b);
                UnattendedParameters u = CentralizedState.App.DB.UnattendedParameters.Get(model);
                UnattendedParameters Unatt = new UnattendedParameters(u);
                AddASourceSetup a = CentralizedState.App.DB.AASSParameters.Get(model);
                AddASourceSetup Aass = new AddASourceSetup(a);
                HVCalibrationParameters h = CentralizedState.App.DB.HVParameters.Get(model);
                HVCalibrationParameters Hv = new HVCalibrationParameters(h);

                // add copied param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, Norm);
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, Unatt);
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, Background);
                CentralizedState.App.DB.AASSParameters.Map.Add(det, Aass);
                CentralizedState.App.DB.HVParameters.Map.Add(det, Hv);

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return det;
            }
            else
            {
                Detector det = new Detector();
                det.Id.SetIdDetails(newId, elecId, typeDesc,srType);

                if (srType.IsListMode())
                    det.Id.FullConnInfo = new LMConnectionInfo();

                // add fresh param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, new NormParameters());
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, new UnattendedParameters());
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, new BackgroundParameters());
                CentralizedState.App.DB.AASSParameters.Map.Add(det, new AddASourceSetup());
                CentralizedState.App.DB.HVParameters.Map.Add(det, new HVCalibrationParameters());

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return det;
            }

            /*  * todo: create analysis selector (or it happens automatically when first referenced?)
                * creating a stratum association
             * */
        }
Exemplo n.º 9
0
        /// <summary>
        /// Imprint a new measurement with as much information as possible from a results_rec.
        /// </summary>
        /// <param name="rec">The results_rec with the measurement details</param>
        /// <param name="meaId">Unique id for the measurement, from the results_rec fields</param>
        /// <param name="logger">logger handle</param>
        /// <returns>A new measurement</returns>
        public Measurement(INCCResults.results_rec rec, MeasId meaId, LMLoggers.LognLM logger)
        {
            HVCalibrationParameters hv = NCC.IntegrationHelpers.GetCurrentHVCalibrationParams(rec.det);
            MeasurementTuple        mt = new MeasurementTuple(new DetectorList(rec.det), rec.tests, rec.norm, rec.bkg, rec.iso, rec.acq, hv);

            this.mt     = mt;
            this.logger = logger;
            mid         = meaId;
            InitMisc();

            if (rec.det.ListMode)
            {
                AnalysisParams = NC.App.LMBD.CountingParameters(rec.det, applySRFromDetector: true);
                if (meaId.MeasOption.IsListMode()) // pure List Mode, not INCC5
                {
                    // for a list-mode-only measurement with a multiplicity analyzer the detector SR params must match at least one of the multiplicity analyzer SR params
                    NCC.IntegrationHelpers.ApplyVSRChangesToDefaultDetector(this);
                }
                else // it is an INCC5 analysis driven with LM data
                {
                    // prepare or identify an active CA entry with matching CA gatewidth and FA, with remaining SR params as the detector
                    AnalysisParams.PrepareMatchingVSR(rec.det.MultiplicityParams);
                }
            }
            else
            {
                // prepare analyzer params from detector SR params
                AnalysisParams = NC.App.LMBD.CountingParameters(rec.det, applySRFromDetector: false);
                if (!AnalysisParams.Exists(w => { return((w is Multiplicity) && (w as Multiplicity).Equals(rec.det.MultiplicityParams)); }))
                {
                    AnalysisParams.Add(rec.det.MultiplicityParams);
                }
            }

            // get the INCC5 analysis methods
            INCCAnalysisState = new INCCAnalysisState();
            INCCSelector    sel = new INCCSelector(rec.acq.detector_id, rec.acq.item_type);
            AnalysisMethods am;
            bool            found = NC.App.DB.DetectorMaterialAnalysisMethods.TryGetValue(sel, out am);

            if (found)
            {
                am.selector = sel; // gotta do this so that the equality operator is correct
                INCCAnalysisState.Methods = am;
            }
            else
            {
                INCCAnalysisState.Methods = new AnalysisMethods(sel);
            }
            InitializeContext(clearCounterResults: true);
            PrepareINCCResults();
            // a list mode measurement may not have a multiplicity analyzer at all, create on results, copying the current values
            if (CountingAnalysisResults.ContainsKey(rec.det.MultiplicityParams))
            {
                MultiplicityCountingRes mcr = (MultiplicityCountingRes)CountingAnalysisResults[rec.det.MultiplicityParams];
                if (rec.mcr.AB.Unset)
                {
                    SDTMultiplicityCalculator.SetAlphaBeta(rec.det.MultiplicityParams, rec.mcr); // works only if MaxBins is set
                }
                mcr.CopyFrom(rec.mcr);                                                           // copy the mcr results onto the first moskey entry
                // the same results are copied to the full results structure
                MeasOptionSelector mos    = new MeasOptionSelector(MeasOption, rec.det.MultiplicityParams);
                INCCResult         result = INCCAnalysisState.Lookup(mos);
                result.CopyFrom(rec.mcr);
            }

            Stratum = new Stratum(rec.st);             // the stratum from the results rec
        }
Exemplo n.º 10
0
        public static Measurement BuildMeasurementTemp(AcquireParameters acq, Detector det, AssaySelector.MeasurementOption mo, TestParameters tp, BackgroundParameters bkg, NormParameters np, AnalysisDefs.Isotopics iso, HVCalibrationParameters hvp)
        {
            // gather it all together
            MeasurementTuple mt = new MeasurementTuple(new DetectorList(det),
                                                       tp,
                                                       np,
                                                       bkg,
                                                       iso,
                                                       acq,
                                                       hvp);

            det.Id.source = acq.data_src;  // set the detector overall data source value here

            // create the context holder for the measurement. Everything is rooted here ...
            Measurement meas = new Measurement(mt, mo);

            FillInMeasurementDetails(meas);
            // ready for insertion of methods and processing start
            return(meas);
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        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();
        }