コード例 #1
0
 public TDState(UInt16 acquire_num_runs)
 {
     gl_take_data_status   = SR.SUCCESS;
     this.acquire_num_runs = acquire_num_runs;
     initial_num_runs      = acquire_num_runs;
     timeout = new Com_h.com_timeout(); timeout.start = timeout.total = 0;
     run     = new run_rec_ext();
 }
コード例 #2
0
        unsafe void AddReviewFileCycle(int i, run_rec_ext run, INCCReviewFile.run_rec_ext_plus rrep, Measurement meas, string fn)
        {
            Cycle cycle = new Cycle(datalog);

            try
            {
                cycle.UpdateDataSourceId(ConstructedSource.ReviewFile, meas.Detector.Id.SRType,
                                         rrep.dt, fn);
                cycle.seq = (run.run_number > 0 ? run.run_number : i); // INCC run record sequence numbers start at 1
                cycle.TS  = TimeSpan.FromSeconds(run.run_count_time);

                /* init run tests */
                cycle.SetQCStatus(meas.Detector.MultiplicityParams, QCTestStatus.Pass, run.run_high_voltage); // APluralityOfMultiplicityAnalyzers: creates entry if not found, expand from the single mult key from detector here
                meas.Add(cycle);
                /* singles, reals + accidentals, accidentals */
                cycle.Totals = (ulong)run.run_singles;
                MultiplicityCountingRes mcr = new MultiplicityCountingRes(meas.Detector.MultiplicityParams.FA, cycle.seq); // APluralityOfMultiplicityAnalyzers: expand when detector has multiple analyzers
                cycle.CountingAnalysisResults.Add(meas.Detector.MultiplicityParams, mcr);                                  // APluralityOfMultiplicityAnalyzers: expand when detector has multiple analyzers
                mcr.AB.TransferIntermediates(meas.Detector.AB);                                                            // copy alpha beta onto the cycle's results
                mcr.Totals        = cycle.Totals;
                mcr.TS            = cycle.TS;
                mcr.ASum          = run.run_acc;
                mcr.RASum         = run.run_reals_plus_acc;
                mcr.Scaler1.v     = run.run_scaler1;
                mcr.Scaler2.v     = run.run_scaler2;
                cycle.SinglesRate = run.run_singles / run.run_count_time;

                // assign the hits to a single channel (0)
                cycle.HitsPerChannel[0] = cycle.Totals;

                mcr.RawSinglesRate.v = cycle.SinglesRate;

                // now back-compute the actual limits of the bins
                for (int n = rrep.n_mult - 1; n >= 0; n--)
                {
                    if ((run.run_mult_reals_plus_acc[n] > 0.0) || (run.run_mult_acc[n] > 0.0))
                    {
                        mcr.MinBins = mcr.MaxBins = (ulong)(n + 1);
                        break;
                    }
                }
                mcr.RAMult      = new ulong[mcr.MaxBins];
                mcr.NormedAMult = new ulong[mcr.MaxBins];
                mcr.UnAMult     = new ulong[mcr.MaxBins]; // todo: compute this

                // copy the bin values, if any
                for (ushort j = 0; j < mcr.MaxBins; j++)
                {
                    mcr.RAMult[j]      = (ulong)run.run_mult_reals_plus_acc[j];
                    mcr.NormedAMult[j] = (ulong)run.run_mult_acc[j];
                }
                ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString() + (rrep.n_mult > 0 ? " n_:" + rrep.n_mult.ToString() + " max:" + mcr.MaxBins.ToString() : " *"));
            }
            catch (Exception e)
            {
                ctrllog.TraceEvent(LogLevels.Warning, 33085, "Cycle processing error {0} {1}", run, e.Message);
            }
        }
コード例 #3
0
        unsafe static void RunValuesToResults(run_rec_ext run, Cycle cycle, Multiplicity key, MultiplicityCountingRes mcr)
        {
            cycle.seq = run.run_number;
            cycle.TS  = TimeSpan.FromSeconds(run.run_count_time); // is not always whole seconds hn 10-1.

            cycle.Totals      = (ulong)run.run_singles;
            cycle.SinglesRate = run.run_singles / run.run_count_time;

            // table lookup on the strings, so test status is correct
            string       s    = TransferUtils.str(run.run_tests, INCC.MAX_RUN_TESTS_LENGTH);
            QCTestStatus qcts = QCTestStatusExtensions.FromString(s);

            cycle.SetQCStatus(key, qcts); // creates entry if not found


            mcr.Totals = cycle.Totals;
            mcr.TS     = cycle.TS;

            mcr.DeadtimeCorrectedSinglesRate.v = run.run_singles_rate;
            mcr.DeadtimeCorrectedDoublesRate.v = run.run_doubles_rate;
            mcr.DeadtimeCorrectedTriplesRate.v = run.run_triples_rate;

            mcr.RASum = (ulong)run.run_reals_plus_acc;
            mcr.ASum  = (ulong)run.run_acc;

            mcr.efficiency     = run.run_multiplicity_efficiency;
            mcr.mass           = run.run_mass;
            mcr.multiAlpha     = run.run_multiplicity_alpha;
            mcr.multiplication = run.run_multiplicity_mult;
            cycle.HighVoltage  = run.run_high_voltage;

            // assign the hits to a single channel (0)
            cycle.HitsPerChannel[0] = run.run_singles;
            mcr.RawSinglesRate.v    = run.run_singles_rate;
            mcr.RawDoublesRate.v    = run.run_doubles_rate;
            mcr.RawTriplesRate.v    = run.run_triples_rate;

            mcr.Scaler1.v     = run.run_scaler1;
            mcr.Scaler2.v     = run.run_scaler2;
            mcr.Scaler1Rate.v = run.run_scaler1_rate;
            mcr.Scaler2Rate.v = run.run_scaler2_rate;

            long index = 0;

            for (ulong i = 0; i < INCC.SR_EX_MAX_MULT; i++)
            {
                if (run.run_mult_acc[i] > 0 || run.run_mult_reals_plus_acc[i] > 0)
                {
                    index = (long)i;
                }
            }

            mcr.MaxBins = (ulong)index + 1;
            mcr.MinBins = (ulong)index + 1;

            mcr.NormedAMult = new ulong[mcr.MaxBins];
            mcr.RAMult      = new ulong[mcr.MaxBins];
            mcr.UnAMult     = new ulong[mcr.MaxBins];

            // was not setting these to the right values hn 10-2
            for (ulong i = 0; i < (ulong)mcr.MaxBins; i++)
            {
                mcr.RAMult[i]      = (ulong)run.run_mult_reals_plus_acc[i];
                mcr.NormedAMult[i] = (ulong)run.run_mult_acc[i];
            }
            mcr.RASum = run.run_reals_plus_acc;
            mcr.ASum  = run.run_acc;
            mcr.AB.Resize((int)mcr.MaxBins);
        }
コード例 #4
0
        //* <f> */
        //*============================================================================
        //*
        //* function name: sr_get_data()
        //*
        //* purpose: check for shift register stopped, and if so read the data and
        //*	    put it in the database run record.
        //*
        //* return value: SR_SUCCESS/SR_NOT_FINISHED/ZERO_COUNT_TIME/SR_TRY_AGAIN/FAIL
        //*
        //* special notes: if there is a failure, the shift register port is closed.
        //*
        //* revision history:
        //*
        //*  date	author		revision
        //*  ----	------		--------
        //*  11/30/93	Bill Harker	created
        //*
        //*============================================================================*/

        public unsafe int sr_get_data(ref run_rec_ext run_ptr)
        {
            sr_h.sr_rdout       rdout = new sr_h.sr_rdout(); /* sr scaler data */
            sr_h.sr_mult_rdout  mult_rdout;                  /* sr multiplicity data */
            sr_h.sr_mult_rdout2 mult_rdout2;                 /* sr multiplicity data */
            int    bincount = sr_h.SR_MAX_MULT;
            byte   sr_status;
            int    status, mult_status;
            ushort num_trys;
            ushort i, j;

            /* check for shift register stopped */
            sr_status = 0;
            status    = SRLib.Control(dsid.SerialPort, sr_h.SR_GET_STATUS, ref sr_status);
            if (status != sr_h.SR_SUCCESS)
            {
                status = sr_restart();
                if (status == SUCCESS)
                {
                    return(SR_TRY_AGAIN);
                }
                else
                {
                    return(FAIL);
                }
            }
            if ((sr_status & sr_h.SR_S_FAULT) != 0)
            {
                status = sr_restart();
                if (status == SUCCESS)
                {
                    return(SR_TRY_AGAIN);
                }
                else
                {
                    return(FAIL);
                }
            }
            if (((sr_status & sr_h.SR_S_TIMEOUT) == 0) && ((sr_status & sr_h.SR_S_STOPPED) == 0))
            {
                return(SR_NOT_FINISHED);
            }
            log.TraceEvent(LogLevels.Info, 0x4f32E, "Getting data from the shift register");
            /* get a set of scaler data from the shift register */
            num_trys = 0;
            do
            {
                status = SRLib.Control(dsid.SerialPort, sr_h.SR_GET_RDOUT, ref rdout);
                num_trys++;
            } while ((status == sr_h.SR_TIMEOUT) && (num_trys <= SR_NUM_TRYS));

            /* get a set of multiplicity data from the shift register */
            if ((dsid.SRType == InstrType.MSR4A) ||
                (dsid.SRType == InstrType.PSR) || AMSRFerSher)
            {
                mult_rdout = new sr_h.sr_mult_rdout();  /* sr multiplicity data */
                num_trys   = 0;
                do
                {
                    Thread.Sleep(100);          /* allow windows system to execute */
                    mult_status = SRLib.Control(dsid.SerialPort, sr_h.SR_GET_MULT_RDOUT, ref mult_rdout);
                    num_trys++;
                } while ((mult_status == sr_h.SR_TIMEOUT) && (num_trys <= SR_NUM_TRYS));
            }
            else if (JSR15orUNAPMasqueradingAsAMSR || dsid.SRType == InstrType.JSR15 || dsid.SRType == InstrType.UNAP)
            {
                bincount    = sr_h.SR_MAX_MULT2;
                mult_rdout2 = new sr_h.sr_mult_rdout2();        /* 512 sr multiplicity data */
                num_trys    = 0;
                do
                {
                    Thread.Sleep(100);          /* allow windows system to execute */
                    mult_status = SRLib.Control(dsid.SerialPort, sr_h.SR_GET_MULT_RDOUT2, ref mult_rdout2);
                    num_trys++;
                } while ((mult_status == sr_h.SR_TIMEOUT) && (num_trys <= SR_NUM_TRYS));
            }
            else
            {
                mult_rdout   = new sr_h.sr_mult_rdout();
                mult_status  = sr_h.SR_SUCCESS;
                mult_rdout.n = bincount;
                for (j = 0; j < bincount; j++)
                {
                    mult_rdout.rpa[j] = 0;
                    mult_rdout.a[j]   = 0;
                }
            }

            if ((status != sr_h.SR_SUCCESS) || (mult_status != sr_h.SR_SUCCESS))
            {
                status = sr_restart();
                if (status == SUCCESS)
                {
                    return(SR_TRY_AGAIN);
                }
                else
                {
                    return(FAIL);
                }
            }
            else if (rdout.time <= 0)
            {
                return(ZERO_COUNT_TIME);
            }

            /* read high voltage */
            if (dsid.SRType == InstrType.JSR12)
            {
                SRLib.Ioctl(dsid.SerialPort, sr_h.SR_JSR12_GET_HV,
                            ref run_ptr.run_high_voltage);
            }
            else if ((dsid.SRType == InstrType.PSR) ||
                     (dsid.SRType == InstrType.AMSR) || (dsid.SRType == InstrType.UNAP))
            {
                SRLib.Ioctl(dsid.SerialPort, sr_h.SR_PSR_GET_HV,
                            ref run_ptr.run_high_voltage);
            }
            else if (dsid.SRType == InstrType.JSR15) // HHMR
            {
                SRLib.Ioctl(dsid.SerialPort, sr_h.SR_HHMR_GET_HV,
                            ref run_ptr.run_high_voltage);
            }
            else if (dsid.SRType == InstrType.DGSR)
            {
                SRLib.Ioctl(dsid.SerialPort, sr_h.SR_DGSR_GET_HV,
                            ref run_ptr.run_high_voltage);
            }
            else
            {
                run_ptr.run_high_voltage = 0.0;
            }

            /* put shift register data in run record */
            /* use current date and time */
            string dt = String.Empty;
            int    x  = NCCTransfer.INCC.Gen32.gen_date_time(NCCTransfer.INCC.Gen32.GEN_DTF_IAEA, ref dt);

            //gen_date_time (GEN_DTF_IAEA, &string_addr);
            //strcpy (run_date_time_string, string_addr);
            Byte[] dtba = Encoding.ASCII.GetBytes(dt);
            fixed(byte *rd = run_ptr.run_date,
                  rt       = run_ptr.run_time,
                  tst      = run_ptr.run_tests)
            {
                TransferUtils.Copy(dtba, 0, rd, 0, INCC.DATE_TIME_LENGTH);
                TransferUtils.Copy(dtba, 9, rt, 0, INCC.DATE_TIME_LENGTH); // ? index?
                TransferUtils.PassPack(tst);

                run_ptr.run_count_time     = rdout.time;
                run_ptr.run_singles        = rdout.totals;
                run_ptr.run_scaler1        = rdout.totals2;
                run_ptr.run_scaler2        = rdout.totals3;
                run_ptr.run_reals_plus_acc = rdout.rpa;
                if (dsid.SRType == InstrType.DGSR)  // todo: gate_length2, but no-one will ever need it
                {
                    run_ptr.run_acc = rdout.a * (sr_parms.gateLengthMS / sr_parms.gateLengthMS);
                    //  sr_parms.gate_length2);
                }
                else
                {
                    run_ptr.run_acc = rdout.a;
                }

                fixed(double *RA = run_ptr.run_mult_reals_plus_acc, A = run_ptr.run_mult_acc)
                {
                    for (i = 0; i < bincount; i++)
                    {
                        if (bincount == sr_h.SR_MAX_MULT)
                        {
                            RA[i] = mult_rdout.rpa[i];
                            A[i]  = mult_rdout.a[i];
                        }
                        else if (bincount == sr_h.SR_MAX_MULT2)
                        {
                            RA[i] = mult_rdout2.rpa[i];
                            A[i]  = mult_rdout2.a[i];
                        }
                    }
                }
            }

            return(sr_h.SR_SUCCESS);
        }