Example #1
0
 public Measurement(MeasurementTuple newMT, AssaySelector.MeasurementOption at, NCCReporter.LMLoggers.LognLM logger)
 {
     mt          = newMT;
     this.logger = logger;
     mid         = new MeasId(at);
     InitMisc();
 }
Example #2
0
 /// <summary>
 /// Constructs a new Measurement object with default values
 /// </summary>
 /// <param name="at">The measurement method or goal</param>
 /// <param name="logger">the logger handle</param>
 public Measurement(AssaySelector.MeasurementOption at, LMLoggers.LognLM logger)
 {
     mt          = new MeasurementTuple();
     this.logger = logger;
     mid         = new MeasId(at);
     InitMisc();
 }
Example #3
0
 public Measurement(AssaySelector.MeasurementOption at)
 {
     mt          = new MeasurementTuple();
     this.logger = null;
     mid         = new MeasId(at);
     InitMisc();
 }
Example #4
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();
        }
Example #5
0
 private void OKBtn_Click(object sender, EventArgs e)
 {
     ListViewItem lvi = null;
     if (listView1.SelectedItems.Count > 0)
     { 
         lvi = listView1.SelectedItems[0];
         measurementId = (MeasId)lvi.Tag;
         this.DialogResult = DialogResult.OK;
     }
     else
         this.DialogResult = DialogResult.Ignore;
     this.Close();
 }
Example #6
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            ListViewItem lvi = null;

            if (listView1.SelectedItems.Count > 0)
            {
                lvi           = listView1.SelectedItems[0];
                measurementId = ((Measurement)lvi.Tag).MeasurementId;
                DialogResult  = DialogResult.OK;
            }
            else
            {
                DialogResult = DialogResult.Ignore;
            }
            Close();
        }
Example #7
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            bool notify = true;

            NCCReporter.LMLoggers.LognLM ctrllog = N.App.Loggers.Logger(NCCReporter.LMLoggers.AppSection.Control);
            foreach (ListViewItem lvi in MeasurementView.Items)
            {
                if (lvi.Selected)
                {
                    int lvIndex = 0;
                    if (!int.TryParse(lvi.SubItems[5].Text, out lvIndex))                     // 5 has the original mlist index of this sorted row element
                    {
                        continue;
                    }
                    MeasId mid = mlist[lvIndex].MeasurementId;
                    ctrllog.TraceEvent(NCCReporter.LogLevels.Info, 22222,
                                       "Deleting " + mid.MeasOption.PrintName() + " " + mid.MeasDateTime.ToString("yy.MM.dd HH:mm:ss") + ", #" + mid.UniqueId + " for " + det.Id.DetectorId);
                    N.App.DB.DeleteMeasurement(mlist[lvIndex].MeasurementId);
                    notify = false;
                }
            }
            LoadList(notify);
        }
Example #8
0
        /// <summary>
        /// Process one or more .NCC Review measurement data files, with related .NOP/.COP files.
        /// Presence of NOP/COP files is optional
        /// See Import Operator Declarations from Operator Review and Measurements from Radiation Review p. 24,
        /// See Operator Declaration File Format p. 87,
        /// See Operator Declaration File Format for Curium Ratio Measurements p. 88,
        /// See Radiation Review Measurement Data File Format p. 93, INCC Software Users Manual, March 29, 2009
        /// </summary>
        void INCCReviewFileProcessing()
        {
            FireEvent(EventType.ActionPrep, this);
            NC.App.Opstate.StampOperationStartTime();
            // This code would be the same for an interactive version of this operation
            //  > Start here
            // first find and process and .NOP files
            List <string> exts = new List <string>()
            {
                ".nop", ".cop"
            };
            FileList <CSVFile> hdlr = new FileList <CSVFile>();

            hdlr.Init(exts, ctrllog);
            FileList <CSVFile> files   = null;
            OPFiles            opfiles = new OPFiles();

            // The INCC5 semantics
            if (NC.App.AppContext.FileInputList == null)
            {
                files = (FileList <CSVFile>)hdlr.BuildFileList(NC.App.AppContext.FileInput, NC.App.AppContext.Recurse, true);
            }
            else
            {
                files = (FileList <CSVFile>)hdlr.BuildFileList(NC.App.AppContext.FileInputList);
            }
            if (files != null && files.Count > 0)
            {
                // construct lists of isotopics and items from the NOP and COP files
                opfiles.Process(files);
                ctrllog.TraceEvent(LogLevels.Verbose, 33085, "NOP items " + opfiles.Results.ItemIds.Count);
                //ctrllog.TraceEvent(LogLevels.Verbose, 33085, "COP entries " + opfiles.Results.COPRatioRecs.Count);
            }
            else
            {
                ctrllog.TraceEvent(LogLevels.Warning, 33085, "No operator declarations available, continuing with default values");
            }

            // process the NCC files only
            INCCFileOrFolderInfo foo = new INCCFileOrFolderInfo(ctrllog, "*.NCC");

            if (NC.App.AppContext.FileInputList == null)
            {
                foo.SetPath(NC.App.AppContext.FileInput);
            }
            else
            {
                foo.SetFileList(NC.App.AppContext.FileInputList);
            }
            foo.eh += new TransferEventHandler((s, e) => { FireEvent(EventType.ActionInProgress, e); });
            List <INCCTransferBase> res = foo.Restore();
            // use RemoveAll to cull those NCC files that reference a non-existent detector
            DetectorList dl = NC.App.DB.Detectors;

            foreach (INCCReviewFile rf in res)
            {
                List <Detector> tdk = dl.FindAll(d => 0 == string.Compare(d.Id.DetectorName, rf.detector, true));
                if (tdk.Count < 1)
                {
                    rf.skip = true;
                    ctrllog.TraceEvent(LogLevels.Warning, 33085, "No detector " + rf.detector + " defined, cannot complete processing NCC review file " + System.IO.Path.GetFileName(rf.Path));
                }
            }
            res.RemoveAll(rf => (rf as INCCReviewFile).skip);
            res.Sort((rf1, rf2) => // sort chronologically
            {
                return(DateTime.Compare((rf1 as INCCReviewFile).dt, (rf2 as INCCReviewFile).dt));
            });
            /// end here > The sorted, filtered and processed list here would be returned to the UI for display and interactive selection
            if (res == null || res.Count < 1)
            {
                NC.App.Opstate.StopTimer();
                NC.App.Opstate.StampOperationStopTime();
                FireEvent(EventType.ActionStop, this);
                ctrllog.TraceEvent(LogLevels.Warning, 33085, "No usable NCC review files found in " + System.IO.Path.GetFullPath(foo.GetPath()));
                return;
            }

            AcquireParameters orig_acq = new AcquireParameters(NC.App.Opstate.Measurement.AcquireState);

            // Each NCC file is a separate measurement
            foreach (INCCReviewFile irf in res)
            {
                ResetMeasurement();
                if (NC.App.Opstate.IsQuitRequested)
                {
                    break;
                }
                // Find the detector named in the NCC file (existence shown in earlier processing above)
                Detector curdet = NC.App.DB.Detectors.Find(d => string.Compare(d.Id.DetectorName, irf.detector, true) == 0);

                if (curdet.AB.Unset)
                {
                    ABKey abkey = new ABKey(curdet.MultiplicityParams, 512);                      // NEXT: maxbins is arbitrary, just the first of many for VSR
                    LMRawAnalysis.SDTMultiplicityCalculator.SetAlphaBeta(abkey, curdet.AB);
                }

                // set up acquire state based on the NCC file content
                AcquireParameters newacq = ConfigureAcquireState(curdet, orig_acq, irf);

                AssaySelector.MeasurementOption mo = NCCMeasOption(irf);
                // make a temp MeasId
                MeasId thisone = new MeasId(mo, newacq.MeasDateTime);
                // get the list of measurement Ids for this detector
                List <MeasId> list    = NC.App.DB.MeasurementIds(curdet.Id.DetectorName, mo.PrintName());
                MeasId        already = list.Find(mid => mid.Equals(thisone));
                if (already != null)
                {
                    // URGENT: do the replacement as it says
                    ctrllog.TraceEvent(LogLevels.Warning, 33085, "Replacing the matching {0} measurement, timestamp {1} (in a future release)", already.MeasOption.PrintName(), already.MeasDateTime.ToString());
                }

                IntegrationHelpers.BuildMeasurement(newacq, curdet, mo);
                Measurement meas = NC.App.Opstate.Measurement;
                meas.MeasDate = newacq.MeasDateTime; // use the date and time from the NCC file content

                meas.Persist();                      // preserve the basic results record
                if (AssaySelector.ForMass(meas.MeasOption) && !meas.INCCAnalysisState.Methods.AnySelected())
                {
                    ctrllog.TraceEvent(LogLevels.Warning, 437, "No mass methods for " + meas.INCCAnalysisState.Methods.selector.ToString());
                }

                try
                {
                    ushort total_number_runs     = 0;
                    double run_count_time        = 0;
                    double total_good_count_time = 0;

                    if (irf.num_runs == 0)
                    {
                        ctrllog.TraceEvent(LogLevels.Error, 440, "This measurement has no good cycles.");
                        continue;
                    }
                    if (meas.MeasOption == AssaySelector.MeasurementOption.holdup)
                    {
                        continue;
                    }

                    /* convert to total count time */
                    total_number_runs     = irf.num_runs;
                    total_good_count_time = irf.num_runs *
                                            run_count_time;
                    meas.RequestedRepetitions = total_number_runs;

                    // convert runs to cycles
                    for (int i = 0; i < irf.num_runs; i++)
                    {
                        /* run date and time (IAEA format) */
                        AddReviewFileCycle(i, irf.runs[i], irf.times[i], meas, irf.Path);
                        if (i % 8 == 0)
                        {
                            FireEvent(EventType.ActionInProgress, this);
                        }
                    }
                    FireEvent(EventType.ActionInProgress, this);

                    // NEXT: handle true AAS cycles as in INCC5
                    if (meas.MeasOption == AssaySelector.MeasurementOption.verification &&
                        meas.INCCAnalysisState.Methods.Has(AnalysisMethod.AddASource) &&
                        meas.AcquireState.well_config == WellConfiguration.Passive)
                    {
                        ctrllog.TraceEvent(LogLevels.Error, 440, "No add-a-source data processed because the implementation is incomplete. AAS");
                        //AddASourceSetup aass = IntegrationHelpers.GetCurrentAASSParams(meas.Detector);
                        //for (int n = 1; n <= aass.number_positions; n++)
                        //{
                        //    /* number of good runs */
                        //    string l = td.reader.ReadLine();
                        //    if (td.reader.EndOfStream)
                        //    {
                        //        ctrllog.TraceEvent(LogLevels.Error, 440, "No add-a-source data found in disk file. " + "AAS p" + n.ToString());

                        //    }
                        //}
                    }
                }
                catch (Exception e)
                {
                    NC.App.Opstate.SOH = OperatingState.Trouble;
                    ctrllog.TraceException(e, true);
                    ctrllog.TraceEvent(LogLevels.Error, 437, "NCC file processing stopped with error: '" + e.Message + "'");
                }
                finally
                {
                    NC.App.Loggers.Flush();
                }
                FireEvent(EventType.ActionInProgress, this);
                ComputeFromINCC5SRData(meas);
                FireEvent(EventType.ActionInProgress, this);
            }


            NC.App.Opstate.ResetTokens();
            NC.App.Opstate.SOH = OperatingState.Stopping;
            NC.App.Opstate.StampOperationStopTime();
            FireEvent(EventType.ActionFinished, this);
        }
Example #9
0
        /// <summary>
        /// Process one or more .NCC Review measurement data files, with related .NOP/.COP files.
        /// see Import Operator Declarations from Operator Review and Measurements from Radiation Review p. 24,
        /// See Operator Declaration File Format p. 87, 
        /// See Operator Declaration File Format for Curium Ratio Measurements p. 88, 
        /// See Radiation Review Measurement Data File Format p. 93, INCC Software Users Manual, March 29, 2009
        /// </summary>
        void INCCReviewFileProcessing()
        {

            FireEvent(EventType.ActionPrep, this);
            NC.App.Opstate.StampOperationStartTime();
            // This code would be the same for an interactive version of this operation
            //  > Start here
            // first find and process and .NOP files 
            List<string> exts = new List<string>() { ".nop", ".cop" };
            FileList<CSVFile> hdlr = new FileList<CSVFile>();
            hdlr.Init(exts, ctrllog);
            FileList<CSVFile> files = null;

            // The INCC5 semantics
            if (NC.App.AppContext.FileInputList == null)
                files = (FileList<CSVFile>)hdlr.BuildFileList(NC.App.AppContext.FileInput, NC.App.AppContext.Recurse, true);
            else
                files = (FileList<CSVFile>)hdlr.BuildFileList(NC.App.AppContext.FileInputList);

            // construct lists of isotopics and items from the NOP and COP files
            OPFiles opfiles = new OPFiles();
            opfiles.Process(files);

            ctrllog.TraceEvent(LogLevels.Verbose, 33085, "NOP items " + opfiles.NOPItemIds.Count);

            // process the NCC files only
            INCCFileOrFolderInfo foo = new INCCFileOrFolderInfo(ctrllog, "*.NCC");
            if (NC.App.AppContext.FileInputList == null)
                foo.SetPath(NC.App.AppContext.FileInput);
            else
                foo.SetFileList(NC.App.AppContext.FileInputList);
            List<INCCTransferBase> res = foo.Restore();
            // use RemoveAll to cull those NCC files that reference a non-existent detector
            DetectorList dl = NC.App.DB.Detectors;
            foreach (INCCReviewFile rf in res)
            {
                List<Detector> tdk = dl.FindAll(d => 0 == string.Compare(d.Id.DetectorName, rf.detector, true));
                if (tdk.Count < 1)
                {
                    rf.skip = true;
                    ctrllog.TraceEvent(LogLevels.Warning, 33085, "No detector " + rf.detector + " defined, cannot complete processing NCC review file " + System.IO.Path.GetFileName(rf.Path));
                }
            }
            res.RemoveAll(rf => (rf as INCCReviewFile).skip);
            res.Sort((rf1, rf2) => // sort chronologically
            {
                return DateTime.Compare((rf1 as INCCReviewFile).dt, (rf2 as INCCReviewFile).dt);
            });
            /// end here > The sorted, filtered and processed list here would be returned to the UI for display and interactive selection

            if (res == null || res.Count < 1)
            {
                NC.App.Opstate.StopTimer(0);
                NC.App.Opstate.StampOperationStopTime();
                FireEvent(EventType.ActionStop, this);
                ctrllog.TraceEvent(LogLevels.Warning, 33085, "No useable NCC review files found in " + System.IO.Path.GetFullPath(foo.GetPath()));
                return;
            }

            AcquireParameters orig_acq = new AcquireParameters(NC.App.Opstate.Measurement.AcquireState);

            // Each NCC file is a separate measurement 
            foreach (INCCReviewFile irf in res)
            {
                ResetMeasurement();
                if (NC.App.Opstate.IsQuitRequested)
                    break;
                // Find the detector named in the NCC file (existence shown in earlier processing above)
                Detector curdet = NC.App.DB.Detectors.Find(d => string.Compare(d.Id.DetectorName, irf.detector, true) == 0);

                // set up acquire state based on the NCC file content
                AcquireParameters newacq = ConfigureAcquireState(curdet, orig_acq, irf);

                AssaySelector.MeasurementOption mo = NCCMeasOption(irf);
                // make a temp MeasId
                MeasId thisone = new MeasId(mo, newacq.MeasDateTime);
                // get the list of measurement Ids for this detector
                List<MeasId> list = NC.App.DB.MeasurementIds(curdet.Id.DetectorName, mo.PrintName());
                MeasId already = list.Find(mid => mid.Equals(thisone));
                if (already != null)
                {
                    // URGENT: do the replacement as it says 
                    ctrllog.TraceEvent(LogLevels.Warning, 33085, "Replacing the matching {0} measurement, timestamp {1} (in a future release)", already.MeasOption.PrintName(), already.MeasDateTime.ToString());
                }

                IntegrationHelpers.BuildMeasurement(newacq, curdet, mo);
                Measurement meas = NC.App.Opstate.Measurement;
                meas.MeasDate = newacq.MeasDateTime; // use the date and time from the NCC file content      

                meas.Persist();  // preserve the basic results record
                if (AssaySelector.ForMass(meas.MeasOption) && !meas.INCCAnalysisState.Methods.AnySelected())
                    ctrllog.TraceEvent(LogLevels.Warning, 437, "No mass methods for " + meas.INCCAnalysisState.Methods.selector.ToString());

                try
                {

                    UInt16 total_number_runs = 0;
                    double run_count_time = 0;
                    double total_good_count_time = 0;

                    if (irf.num_runs == 0)
                    {
                        ctrllog.TraceEvent(LogLevels.Error, 440, "This measurement has no good cycles.");
                        continue;
                    }
                    if (meas.MeasOption == AssaySelector.MeasurementOption.holdup)
                        continue;

                    /* convert to total count time */
                    total_number_runs = irf.num_runs;
                    total_good_count_time = (double)irf.num_runs *
                        run_count_time;
                    meas.RequestedRepetitions = total_number_runs;

                    // convert runs to cycles
                    for (int i = 0; i < irf.num_runs; i++)
                    {
                        /* run date and time (IAEA format) */
                        AddReviewFileCycle(i, irf.runs[i], irf.times[i], meas, irf.Path);
                        if (i % 8 == 0)
                            FireEvent(EventType.ActionInProgress, this);
                    }
                    FireEvent(EventType.ActionInProgress, this);

                    // NEXT: handle true AAS cycles as in INCC5
                    if (meas.MeasOption == AssaySelector.MeasurementOption.verification &&
                        meas.INCCAnalysisState.Methods.Has(AnalysisMethod.AddASource) &&
                        meas.AcquireState.well_config == WellConfiguration.Passive)
                    {
                        ctrllog.TraceEvent(LogLevels.Error, 440, "No add-a-source data processed because I am lame. " + "AAS ");
                        //AddASourceSetup aass = IntegrationHelpers.GetCurrentAASSParams(meas.Detectors[0]);
                        //for (int n = 1; n <= aass.number_positions; n++)
                        //{
                        //    /* number of good runs */
                        //    string l = td.reader.ReadLine();
                        //    if (td.reader.EndOfStream)
                        //    {
                        //        ctrllog.TraceEvent(LogLevels.Error, 440, "No add-a-source data found in disk file. " + "AAS p" + n.ToString());

                        //    }
                        //}
                    }
                }
                catch (Exception e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e, true);
                    ctrllog.TraceEvent(LogLevels.Error, 437, "NCC file processing stopped with error: '" + e.Message + "'");
                }
                finally
                {
                    NC.App.Loggers.Flush();
                }
                FireEvent(EventType.ActionInProgress, this);
                ComputeFromINCC5SRData(meas);
                FireEvent(EventType.ActionInProgress, this);
            }


            NC.App.Opstate.ResetTokens();
            NC.App.Opstate.SOH = NCC.OperatingState.Stopping;
            NC.App.Opstate.StampOperationStopTime();
            FireEvent(EventType.ActionStop, this);
        }
Example #10
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
        }