private void OKBtn_Click(object sender, EventArgs e) { NCCReporter.LMLoggers.LognLM applog = NC.App.Logger(NCCReporter.LMLoggers.AppSection.App); string dest = UIIntegration.GetUsersFolder("Select Destination", string.Empty); if (string.IsNullOrEmpty(dest)) { return; } if (DetectorCurrentRadioButton.Checked) { List <Detector> l = new List <Detector>(); l.Add(Integ.GetCurrentAcquireDetector()); INCCInitialDataDetectorFile iddf = INCCKnew.FromDetectors(l); iddf.Save(dest); } else if (DetectorAllRadioButton.Checked) { List <Detector> l = NC.App.DB.Detectors; INCCInitialDataDetectorFile iddf = INCCKnew.FromDetectors(l); iddf.Save(dest); } else if (CalibrationCurrentRadioButton.Checked) { List <Detector> l = new List <Detector>(); l.Add(Integ.GetCurrentAcquireDetector()); List <INCCInitialDataCalibrationFile> lidcf = INCCKnew.CalibFromDetectors(l); if (lidcf.Count > 0) { if (!lidcf[0].Save(dest)) { applog.TraceEvent(NCCReporter.LogLevels.Warning, 33154, "No calibration parameters for " + lidcf[0].Name); } } } else if (CalibrationAllRadioButton.Checked) { List <Detector> l = NC.App.DB.Detectors; List <INCCInitialDataCalibrationFile> lidcf = INCCKnew.CalibFromDetectors(l); foreach (INCCInitialDataCalibrationFile idcf in lidcf) { if (!idcf.Save(dest)) { applog.TraceEvent(NCCReporter.LogLevels.Warning, 33154, "No calibration parameters for " + idcf.Name); } } } Close(); }
public virtual INCCTransferBase Restore() { // current file INCCTransferBase result = null; switch (mft) { case eFileType.eInitialDataDetector: { INCCInitialDataDetectorFile idd = new INCCInitialDataDetectorFile(mlogger, mpath); bool good = idd.Restore(mpath); if (good) result = idd; // this now has the structs ready } break; case eFileType.eInitialDataCalibration: { INCCInitialDataCalibrationFile idcal = new INCCInitialDataCalibrationFile(mlogger, mpath); bool good = idcal.Restore(mpath); if (good) result = idcal; // this now has the structs ready } break; case eFileType.eTransfer: { INCCTransferFile idt = new INCCTransferFile(mlogger, mpath); bool good = idt.Restore(mpath); if (good) result = idt; // this now has the structs ready } break; case eFileType.eNCC: { INCCReviewFile irf = new INCCReviewFile(mlogger, mpath); bool good = irf.Restore(mpath); if (good) result = irf; // this now has the structs ready } break; case eFileType.eUnknown: mlogger.TraceEvent(LogLevels.Info, 34007, "Skipping {0}", mpath); break; default: // for future expansion // dev note: NOP and COP files are just CSV or Tab-delimited text files, so no binary matching is needed, so I am moving the handling of these to another class (OPfiles) mlogger.TraceEvent(LogLevels.Info, 34008, "Not processing the unsupported file {0}", mpath); break; }; return result; }
public unsafe void BuildDetector(INCCInitialDataDetectorFile iddf, int num) { INCCDB DB = NC.App.DB; detector_rec d = iddf.Detector[0]; sr_parms_rec sr = iddf.SRParms[0]; bkg_parms_rec bkh = iddf.BKGParms[0]; norm_parms_rec norm = iddf.NormParms[0]; tm_bkg_parms_rec tmbkg = iddf.TMBKGParms[0]; add_a_source_setup_rec aass = iddf.AASParms[0]; InstrType srtype = (InstrType)sr.sr_type; bool overwrite = NC.App.AppContext.OverwriteImportedDefs; mlogger.TraceEvent(LogLevels.Verbose, 34100, "Building '{0}' detector '{1}' from {2} {3}", srtype.ToString(), TransferUtils.str(d.detector_id, INCC.MAX_DETECTOR_ID_LENGTH), num, iddf.Path); // if the detector is not known internally, then // add the detector to the list of detectors in memory, and // associate a new set of SR, Bkg and Norm and AB params with the new detector // todo: What are the HV Params from INCC5, and once that is known, can they be transferred to the INCC6 HV Param and results tables Detector det = new Detector(); if (srtype.IsListMode()) det.Id.FullConnInfo = new LMConnectionInfo(); try { // this transfer should be a method in this class, it will be used elsewhere too det.Id.DetectorId = TransferUtils.str(d.detector_id, INCC.MAX_DETECTOR_ID_LENGTH); det.Id.SRType = srtype; det.Id.Type = TransferUtils.str(d.detector_type, INCC.DETECTOR_TYPE_LENGTH); det.Id.ElectronicsId = TransferUtils.str(d.electronics_id, INCC.ELECTRONICS_ID_LENGTH); det.Id.ConnInfo = sr.sr_port_number.ToString(); det.Id.source = ConstructedSource.INCCTransferCopy; det.MultiplicityParams.FA = srtype.DefaultFAFor(); det.MultiplicityParams.gateWidthTics = (ulong)(sr.gate_length * 10.0); // shift down to tics from microseconds det.SRParams.deadTimeCoefficientAinMicroSecs = sr.coeff_a_deadtime; det.SRParams.deadTimeCoefficientBinPicoSecs = sr.coeff_b_deadtime; det.SRParams.deadTimeCoefficientCinNanoSecs = sr.coeff_c_deadtime; det.SRParams.deadTimeCoefficientMultiplicityinNanoSecs = sr.multiplicity_deadtime; det.SRParams.dieAwayTime = sr.die_away_time * 10.0; // shift down to tics from microseconds det.SRParams.doublesGateFraction = sr.doubles_gate_fraction; det.SRParams.efficiency = sr.efficiency; det.SRParams.gateLength = (ulong)(sr.gate_length * 10.0); // shift down to tics from microseconds //det.SRParams.gateLength2 = sr.gate_length2; det.SRParams.highVoltage = sr.high_voltage; det.SRParams.predelay = (ulong)(sr.predelay * 10.0); // shift down to tics from microseconds det.SRParams.triplesGateFraction = sr.triples_gate_fraction; // = sr.sr_type , sr.sr_port_number, sr.sr_detector_id these are in the Id now, not the SRparams, but they travel together. if (NC.App.AppContext.OverwriteImportedDefs) DB.Detectors.Replace(det); else DB.Detectors.AddOnlyIfNotThere(det); DetectorIndex = DB.Detectors.Count - 1; BackgroundParameters bkg = new BackgroundParameters(); bkg.DeadtimeCorrectedRates.Singles.v = bkh.curr_passive_bkg_singles_rate; bkg.DeadtimeCorrectedRates.Doubles.v = bkh.curr_passive_bkg_doubles_rate; bkg.DeadtimeCorrectedRates.Triples.v = bkh.curr_passive_bkg_triples_rate; bkg.DeadtimeCorrectedRates.Singles.err = bkh.curr_passive_bkg_singles_err; bkg.DeadtimeCorrectedRates.Doubles.err = bkh.curr_passive_bkg_doubles_err; bkg.DeadtimeCorrectedRates.Triples.err = bkh.curr_passive_bkg_triples_err; bkg.Scaler1.v = bkh.curr_passive_bkg_scaler1_rate; bkg.Scaler2.v = bkh.curr_passive_bkg_scaler2_rate; bkg.INCCActive.Singles.v = bkh.curr_active_bkg_singles_rate; bkg.INCCActive.Singles.err = bkh.curr_active_bkg_singles_err; bkg.INCCActive.Scaler1Rate = bkh.curr_active_bkg_scaler1_rate; bkg.INCCActive.Scaler2Rate = bkh.curr_active_bkg_scaler2_rate; bkg.TMBkgParams.Singles.v = tmbkg.tm_singles_bkg; bkg.TMBkgParams.Ones.v = tmbkg.tm_ones_bkg; bkg.TMBkgParams.Twos.v = tmbkg.tm_twos_bkg; bkg.TMBkgParams.Zeros.v = tmbkg.tm_zeros_bkg; bkg.TMBkgParams.Singles.err = tmbkg.tm_singles_bkg_err; bkg.TMBkgParams.Ones.err = tmbkg.tm_ones_bkg_err; bkg.TMBkgParams.Twos.err = tmbkg.tm_twos_bkg_err; bkg.TMBkgParams.Zeros.err = tmbkg.tm_zeros_bkg_err; bkg.TMBkgParams.ComputeTMBkg = (tmbkg.tm_bkg == 0 ? false : true); if (DB.BackgroundParameters.Get(det.Id.DetectorName) == null) { DB.BackgroundParameters.GetMap().Add(det, bkg); // saved to DB at below } else if (overwrite) { bkg.modified = true; NC.App.DB.BackgroundParameters.GetMap().Remove(det); NC.App.DB.BackgroundParameters.GetMap().Add(det, bkg); NC.App.DB.BackgroundParameters.Set(det, bkg); } // save the params listed here using the detector as the key NormParameters normp = new NormParameters(); normp.acceptanceLimitPercent = norm.acceptance_limit_percent; normp.acceptanceLimitStdDev = norm.acceptance_limit_std_dev; normp.amliRefSinglesRate = norm.amli_ref_singles_rate; normp.biasMode = OldToNewBiasTestId(norm.bias_mode); normp.biasPrecisionLimit = norm.bias_precision_limit; normp.biasTestAddasrcPosition = norm.bias_test_addasrc_position; normp.biasTestUseAddasrc = (norm.bias_test_use_addasrc == 0 ? false : true); normp.cf252RefDoublesRate.v = norm.cf252_ref_doubles_rate; normp.currNormalizationConstant.v = norm.curr_normalization_constant; normp.currNormalizationConstant.err = norm.curr_normalization_constant_err; normp.initSrcPrecisionLimit = norm.init_src_precision_limit; normp.measRate.v = norm.meas_rate; normp.measRate.err = norm.meas_rate_err; normp.refDate = INCC.DateFrom(TransferUtils.str(norm.ref_date, INCC.DATE_TIME_LENGTH)); normp.sourceId = TransferUtils.str(norm.source_id, INCC.SOURCE_ID_LENGTH); normp.yieldRelativeToMrc95 = norm.yield_relative_to_mrc_95; if (DB.NormParameters.Get(det.Id.DetectorName) == null) { DB.NormParameters.GetMap().Add(det, normp); // saved to DB at end } else if (overwrite) { normp.modified = true; DB.NormParameters.GetMap().Remove(det); DB.NormParameters.GetMap().Add(det, normp); // the in-memory map DB.NormParameters.Set(det, normp); // the DB table } AddASourceSetup aassp = new AddASourceSetup(); aassp.type = OldToNewAASId(aass.ad_type); aassp.port_number = aass.ad_port_number; aassp.forward_over_travel = aass.ad_forward_over_travel; aassp.reverse_over_travel = aass.ad_reverse_over_travel; aassp.number_positions = aass.ad_number_positions; aassp.dist_to_move = TransferUtils.Copy(aass.ad_dist_to_move, INCC.MAX_ADDASRC_POSITIONS); aassp.cm_steps_per_inch = aass.cm_steps_per_inch; aassp.cm_forward_mask = aass.cm_forward_mask; aassp.cm_reverse_mask = aass.cm_reverse_mask; aassp.cm_axis_number = aass.cm_axis_number; aassp.cm_over_travel_state = aass.cm_over_travel_state; aassp.cm_step_ratio = aass.cm_step_ratio; aassp.cm_slow_inches = aass.cm_slow_inches; aassp.plc_steps_per_inch = aass.plc_steps_per_inch; aassp.scale_conversion_factor = aass.scale_conversion_factor; aassp.cm_rotation = (aass.cm_rotation == 0 ? false : true); if (!DB.AASSParameters.GetMap().ContainsKey(det)) { DB.AASSParameters.GetMap().Add(det, aassp); } else if (overwrite) { aassp.modified = true; DB.AASSParameters.GetMap().Remove(det); DB.AASSParameters.GetMap().Add(det, aassp); // todo: in-memory and db } if (!DB.UnattendedParameters.GetMap().ContainsKey(det)) { DB.UnattendedParameters.GetMap().Add(det, new UnattendedParameters()); } else if (overwrite) { DB.UnattendedParameters.GetMap().Remove(det); DB.UnattendedParameters.GetMap().Add(det, new UnattendedParameters()); } // the alpha beta arrays must be sized here, for first use by the calc_alpha_beta code in the cycle conditioning code Multiplicity mkey = new Multiplicity(srtype.DefaultFAFor()); mkey.SR = new ShiftRegisterParameters(det.SRParams); MultiplicityCountingRes mcr = new MultiplicityCountingRes(srtype.DefaultFAFor(), 0); ABKey abkey = new ABKey(mkey, 512); // NEXT: maxbins is arbitrary LMRawAnalysis.SDTMultiplicityCalculator.SetAlphaBeta(abkey, det.AB); mcr.AB.TransferIntermediates(det.AB); } catch (Exception e) { mlogger.TraceEvent(LogLevels.Warning, 34064, "Detector transfer processing error {0} {1} ({2})", det.Id.DetectorName, e.Message, System.IO.Path.GetFileName(iddf.Path)); } }
public static unsafe INCCInitialDataDetectorFile FromDetectors(List<Detector> dets) { INCCInitialDataDetectorFile iddf = new INCCInitialDataDetectorFile(NC.App.Loggers.Logger(LMLoggers.AppSection.Control), null); foreach(Detector det in dets) { detector_rec dr = new detector_rec(); byte[] b = new byte[INCC.MAX_DETECTOR_ID_LENGTH]; char[] a = det.Id.DetectorId.ToCharArray(0, Math.Min(det.Id.DetectorId.Length, INCC.MAX_DETECTOR_ID_LENGTH)); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,dr.detector_id); b = new byte[INCC.DETECTOR_TYPE_LENGTH]; a = det.Id.Type.ToCharArray(0, Math.Min(det.Id.Type.Length, INCC.DETECTOR_TYPE_LENGTH)); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,dr.detector_type); b = new byte[INCC.ELECTRONICS_ID_LENGTH]; a = det.Id.ElectronicsId.ToCharArray(0, Math.Min(det.Id.ElectronicsId.Length, INCC.ELECTRONICS_ID_LENGTH)); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,dr.electronics_id); iddf.Detector.Add(dr); sr_parms_rec sr = new sr_parms_rec(); b = new byte[INCC.MAX_DETECTOR_ID_LENGTH]; a = det.Id.DetectorId.ToCharArray(0, Math.Min(det.Id.DetectorId.Length, INCC.MAX_DETECTOR_ID_LENGTH)); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,sr.sr_detector_id); sr.sr_type = (short)det.Id.SRType; sr.sr_port_number = (short)det.Id.SerialPort; sr.predelay = det.SRParams.predelayMS; sr.die_away_time = det.SRParams.dieAwayTimeMS; sr.gate_length = det.SRParams.gateLengthMS; sr.coeff_a_deadtime = det.SRParams.deadTimeCoefficientAinMicroSecs; sr.coeff_b_deadtime = det.SRParams.deadTimeCoefficientBinPicoSecs; sr.coeff_c_deadtime = det.SRParams.deadTimeCoefficientCinNanoSecs; sr.multiplicity_deadtime = det.SRParams.deadTimeCoefficientMultiplicityinNanoSecs; sr.doubles_gate_fraction = det.SRParams.doublesGateFraction; sr.triples_gate_fraction = det.SRParams.triplesGateFraction; sr.efficiency = det.SRParams.efficiency; sr.high_voltage = det.SRParams.highVoltage; iddf.SRParms.Add(sr); BackgroundParameters bkgp = NC.App.DB.BackgroundParameters.Get(det); bkg_parms_rec bkg = new bkg_parms_rec(); bkg.curr_active_bkg_scaler1_rate = bkgp.INCCActive.Scaler1Rate; bkg.curr_active_bkg_scaler2_rate = bkgp.INCCActive.Scaler2Rate; bkg.curr_active_bkg_singles_err = bkgp.INCCActive.Singles.err; bkg.curr_active_bkg_singles_rate = bkgp.INCCActive.Singles.v; bkg.curr_passive_bkg_doubles_err = bkgp.DeadtimeCorrectedRates.Doubles.err; bkg.curr_passive_bkg_doubles_rate = bkgp.DeadtimeCorrectedRates.Doubles.v; bkg.curr_passive_bkg_scaler1_rate = bkgp.Scaler1.v; bkg.curr_passive_bkg_scaler2_rate = bkgp.Scaler2.v; bkg.curr_passive_bkg_singles_err = bkgp.DeadtimeCorrectedRates.Singles.err; bkg.curr_passive_bkg_singles_rate = bkgp.DeadtimeCorrectedRates.Singles.v; bkg.curr_passive_bkg_triples_err = bkgp.DeadtimeCorrectedRates.Triples.err; bkg.curr_passive_bkg_triples_rate = bkgp.DeadtimeCorrectedRates.Triples.v; iddf.BKGParms.Add(bkg); tm_bkg_parms_rec tm = new tm_bkg_parms_rec(); tm.tm_singles_bkg = bkgp.TMBkgParams.Singles.v; tm.tm_ones_bkg = bkgp.TMBkgParams.Ones.v; tm.tm_twos_bkg = bkgp.TMBkgParams.Twos.v; tm.tm_zeros_bkg = bkgp.TMBkgParams.Zeros.v; tm.tm_singles_bkg_err = bkgp.TMBkgParams.Singles.err; tm.tm_ones_bkg_err = bkgp.TMBkgParams.Ones.err; tm.tm_twos_bkg_err = bkgp.TMBkgParams.Twos.err; tm.tm_zeros_bkg_err = bkgp.TMBkgParams.Zeros.err; tm.tm_bkg = (bkgp.TMBkgParams.ComputeTMBkg ? (byte)0x1 : (byte)0x0); iddf.TMBKGParms.Add(tm); NormParameters normp = NC.App.DB.NormParameters.Get(det); norm_parms_rec norm = new norm_parms_rec(); norm.acceptance_limit_percent = normp.acceptanceLimitPercent; norm.acceptance_limit_std_dev = normp.acceptanceLimitStdDev; norm.amli_ref_singles_rate = normp.amliRefSinglesRate; norm.bias_mode = NewToOldBiasTestId(normp.biasMode); norm.bias_precision_limit = normp.biasPrecisionLimit; norm.bias_test_addasrc_position = normp.biasTestAddasrcPosition; norm.bias_test_use_addasrc = (byte)(normp.biasTestUseAddasrc ? 1 : 0); norm.cf252_ref_doubles_rate = normp.cf252RefDoublesRate.v; norm.cf252_ref_doubles_rate_err = normp.cf252RefDoublesRate.v; norm.curr_normalization_constant = normp.currNormalizationConstant.v; norm.curr_normalization_constant_err = normp.currNormalizationConstant.err; norm.init_src_precision_limit = normp.initSrcPrecisionLimit; norm.meas_rate = normp.measRate.v; norm.meas_rate_err = normp.measRate.err; norm.yield_relative_to_mrc_95 = normp.yieldRelativeToMrc95; b = new byte[INCC.DATE_TIME_LENGTH]; a = normp.refDate.ToString("yy.MM.dd").ToCharArray(); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,norm.ref_date); b = new byte[INCC.SOURCE_ID_LENGTH]; a = normp.sourceId.ToCharArray(0, Math.Min(normp.sourceId.Length, INCC.SOURCE_ID_LENGTH)); Encoding.ASCII.GetBytes(a, 0, a.Length, b, 0); TransferUtils.Copy(b,norm.source_id); iddf.NormParms.Add(norm); AddASourceSetup aasp = NC.App.DB.AASSParameters.Get(det); add_a_source_setup_rec aas = new add_a_source_setup_rec(); TransferUtils.CopyDbls(aasp.dist_to_move, aas.ad_dist_to_move); aas.ad_forward_over_travel = aasp.forward_over_travel; aas.ad_number_positions = aasp.number_positions; aas.ad_port_number = aasp.port_number; aas.ad_reverse_over_travel = aasp.reverse_over_travel; aas.ad_type = NewToOldAASId(aasp.type); aas.cm_axis_number = aasp.cm_axis_number; aas.cm_forward_mask = aasp.cm_forward_mask; aas.cm_over_travel_state = aasp.cm_over_travel_state; aas.cm_reverse_mask = aasp.cm_reverse_mask; aas.cm_rotation = (byte)(aasp.cm_rotation ? 1 : 0); aas.cm_slow_inches = aasp.cm_slow_inches; aas.cm_steps_per_inch = aasp.cm_steps_per_inch; aas.cm_step_ratio = aasp.cm_step_ratio; aas.plc_steps_per_inch = aasp.plc_steps_per_inch; aas.scale_conversion_factor = aasp.scale_conversion_factor; iddf.AASParms.Add(aas); } return iddf; }
public virtual INCCTransferBase Restore() { // current file INCCTransferBase result = null; switch (mft) { case eFileType.eInitialDataDetector: { INCCInitialDataDetectorFile idd = new INCCInitialDataDetectorFile(mlogger, mpath); bool good = idd.Restore(mpath); if (good) { result = idd; // this now has the structs ready } } break; case eFileType.eInitialDataCalibration: { INCCInitialDataCalibrationFile idcal = new INCCInitialDataCalibrationFile(mlogger, mpath); bool good = idcal.Restore(mpath); if (good) { result = idcal; // this now has the structs ready } } break; case eFileType.eTransfer: { INCCTransferFile idt = new INCCTransferFile(mlogger, mpath); bool good = idt.Restore(mpath); if (good) { result = idt; // this now has the structs ready } } break; case eFileType.eNCC: { INCCReviewFile irf = new INCCReviewFile(mlogger, mpath); bool good = irf.Restore(mpath); if (good) { result = irf; // this now has the structs ready } } break; case eFileType.eUnknown: mlogger.TraceEvent(LogLevels.Info, 34007, "Skipping {0}", mpath); break; default: // for future expansion // dev note: NOP and COP files are just CSV or Tab-delimited text files, so no binary matching is needed, so I am moving the handling of these to another class (OPfiles) mlogger.TraceEvent(LogLevels.Info, 34008, "Not processing the unsupported file {0}", mpath); break; } ; return(result); }