Beispiel #1
0
 public ArchiveData(EventLoggerAccess log, Calibration calibration)
 {
     _log = log;
     _calibration = calibration;
     _pxeWriteAccess = new PxeWriteAccess();
 }
        private void LoadStoredData()
        {
            PxeWriteAccess pxeWriteAccess = new PxeWriteAccess();

            LINAC_ENERGY_TYPE_VALUE energy;
            PulseWidth pulseWidth;

            try 
            {
                string fileName;

                energy = LINAC_ENERGY_TYPE_VALUE.Dual;
                pulseWidth = PulseWidth.PulseWidth1;
                
                fileName = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                if (File.Exists(fileName) && pxeWriteAccess.OpenPXEFile(fileName) == true)
                {
                    ReadStoredEnergyData(pxeWriteAccess, energy, pulseWidth);
                    pxeWriteAccess.ClosePXE();
                    _logger.LogInfo("Calibration: Read " + fileName + " successfully.");
                }
                else
                {
                    _logger.LogError("Calibration: reading of " + fileName + " failed");
                    _allCalibrationDataFound = false;
                }

                energy = LINAC_ENERGY_TYPE_VALUE.High;
                pulseWidth = PulseWidth.PulseWidth2;

                fileName = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                if (File.Exists(fileName) && pxeWriteAccess.OpenPXEFile(fileName) == true)
                {
                    ReadStoredEnergyData(pxeWriteAccess, energy, pulseWidth);
                    pxeWriteAccess.ClosePXE();
                    _logger.LogInfo("Calibration: Read " + fileName + " successfully.");
                }
                else
                {
                    _logger.LogError("Calibration: reading of " + fileName + " failed");
                    _allCalibrationDataFound = false;
                }

                energy = LINAC_ENERGY_TYPE_VALUE.Low;
                pulseWidth = PulseWidth.PulseWidth3;

                fileName = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                if (File.Exists(fileName) && pxeWriteAccess.OpenPXEFile(fileName) == true)
                {
                    ReadStoredEnergyData(pxeWriteAccess, energy, pulseWidth);
                    pxeWriteAccess.ClosePXE();
                    _logger.LogInfo("Calibration: Read " + fileName + " successfully.");
                }
                else
                {
                    _logger.LogError("Calibration: reading of " + fileName + " failed");
                    _allCalibrationDataFound = false;
                }

#if LinacLowDose
                energy = LINAC_ENERGY_TYPE_VALUE.LowDose;
                pulseWidth = PulseWidth.PulseWidth3;

                fileName = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                if (File.Exists(fileName) && pxeWriteAccess.OpenPXEFile(fileName) == true)
                {
                    ReadStoredEnergyData(pxeWriteAccess, energy, pulseWidth);
                    pxeWriteAccess.ClosePXE();
                    _logger.LogInfo("Calibration: Read " + fileName + " successfully.");
                }
                else
                {
                    _logger.LogError("Calibration: reading of " + fileName + " failed");
                    _allCalibrationDataFound = false;
                }
#endif

                _allCalibrationDataFound = true;
            }
            catch (Exception e)
            {
                _logger.LogError("Exception during reading Calibration files: " + e.Message);
                _allCalibrationDataFound = false;
            }


            /*
            //foreach (PulseWidth pulseWidth in Enum.GetValues(typeof(PulseWidth)))
            //{
            int index = 1;

            foreach (LINAC_ENERGY_TYPE_VALUE energy in Enum.GetValues(typeof(LINAC_ENERGY_TYPE_VALUE)))
            {
                PulseWidth pulseWidth = (PulseWidth)(index - 1);

                string fileName = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                if (File.Exists(fileName) && pxeWriteAccess.OpenPXEFile(fileName) == true)
                {
                    ReadStoredEnergyData(pxeWriteAccess, energy, pulseWidth);
                    pxeWriteAccess.ClosePXE();
                }
                else
                {
                    _logger.LogError("Calibration: reading of " + fileName + " failed");
                    _allCalibrationDataFound = false;
                }

                index++;
            }
            }
            */

            LoadBadDetectorsInfo();
            _calibrationLoaded = true;
        }
        private void ReadStoredEnergyData(PxeWriteAccess pxeWriteAccess, LINAC_ENERGY_TYPE_VALUE energy, PulseWidth pulseWidth)
        {
            long bufferSize = _dataAccess.Detectors.PixelsPerColumn;
            CalibrationDataCollection collection = GetCalibrationCollection(energy, pulseWidth);
            if (energy == LINAC_ENERGY_TYPE_VALUE.High)
            {
                float[] airHighDataBuffer = new float[bufferSize];
                float[] darkHighDataBuffer = new float[bufferSize];
                float[] normScaleHighDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadHighEngDarkSample(darkHighDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(darkHighDataBuffer));
                }

                if (pxeWriteAccess.ReadHighEngAirSample(airHighDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(airHighDataBuffer));
                }
            }
            if (energy == LINAC_ENERGY_TYPE_VALUE.Low)
            {
                float[] airLowDataBuffer = new float[bufferSize];
                float[] normScaleLowDataBuffer = new float[bufferSize];
                float[] darkLowDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadLowEngDarkSample(darkLowDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(darkLowDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngAirSample(airLowDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(airLowDataBuffer));
                }
            }
            if (energy == LINAC_ENERGY_TYPE_VALUE.Dual)
            {
                float[] airHighDataBuffer = new float[bufferSize];
                float[] darkHighDataBuffer = new float[bufferSize];
                float[] normScaleHighDataBuffer = new float[bufferSize];
                float[] airLowDataBuffer = new float[bufferSize];
                float[] normScaleLowDataBuffer = new float[bufferSize];
                float[] darkLowDataBuffer = new float[bufferSize];
                if (pxeWriteAccess.ReadHighEngDarkSample(darkHighDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(darkHighDataBuffer));
                }

                if (pxeWriteAccess.ReadHighEngAirSample(airHighDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.HighEnergy, PixelConverter.Convert(airHighDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngDarkSample(darkLowDataBuffer))
                {
                    collection.AddDarkData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(darkLowDataBuffer));
                }

                if (pxeWriteAccess.ReadLowEngAirSample(airLowDataBuffer))
                {
                    collection.AddAirData(XRayEnergyEnum.LowEnergy, PixelConverter.Convert(airLowDataBuffer));
                }
            }
        }
        private void SaveDataToPXE()
        {
            _logger.LogInfo("Calibration saving data to pxe...");

            PxeWriteAccess pxeWriteAccess = new PxeWriteAccess();

            if (!Directory.Exists(_calibrationStorageLocation))
            {
                Directory.CreateDirectory(_calibrationStorageLocation);
            }

            //foreach (PulseWidth pulseWidth in Enum.GetValues(typeof(PulseWidth)))
            //{
                foreach (LINAC_ENERGY_TYPE_VALUE energy in Enum.GetValues(typeof(LINAC_ENERGY_TYPE_VALUE)))
                {
                    try
                    {
                        if (energy == LINAC_ENERGY_TYPE_VALUE.LowDose)
                            continue;

                        PulseWidth pulseWidth;

                        switch(energy)
                        {
                            case LINAC_ENERGY_TYPE_VALUE.Dual:
                                pulseWidth = PulseWidth.PulseWidth1;
                                break;
                            case LINAC_ENERGY_TYPE_VALUE.High:
                                pulseWidth = PulseWidth.PulseWidth2;
                                break;
                            case LINAC_ENERGY_TYPE_VALUE.Low:
                                pulseWidth = PulseWidth.PulseWidth3;
                                break;
#if LinacLowDose
                            case LINAC_ENERGY_TYPE_VALUE.LowDose:
                                pulseWidth = PulseWidth.PulseWidth3;
                                break;
#endif
                            default:
                                pulseWidth = PulseWidth.PulseWidth1;
                                break;
                        }

                        string pxeFile = Path.Combine(_calibrationStorageLocation, "Calibration_" + energy.ToString() + "_" + pulseWidth.ToString() + ".pxe");

                        if (File.Exists(pxeFile))
                        {
                            File.Delete(pxeFile);
                        }

                        pxeWriteAccess.CreatePXE(pxeFile);

                        if (energy == LINAC_ENERGY_TYPE_VALUE.Dual || energy == LINAC_ENERGY_TYPE_VALUE.High)
                        {
                            pxeWriteAccess.CreateHiPXEHeader(1, (uint)GetCalibrationCollection(energy, pulseWidth).GetScaleFactor(XRayEnergyEnum.HighEnergy).Length);
                            pxeWriteAccess.WriteHighEngDarkSample(PixelConverter.Convert(GetCalibrationCollection(energy, pulseWidth).GetDarkData(XRayEnergyEnum.HighEnergy)));
                            pxeWriteAccess.WriteHighEngAirSample(PixelConverter.Convert(GetCalibrationCollection(energy, pulseWidth).GetAirData(XRayEnergyEnum.HighEnergy)));
                        }

                        if (energy == LINAC_ENERGY_TYPE_VALUE.Dual
                                || energy == LINAC_ENERGY_TYPE_VALUE.Low
#if LinacLowDose
                                || energy == LINAC_ENERGY_TYPE_VALUE.LowDose
#endif
                            )
                        {
                            pxeWriteAccess.CreateLoPXEHeader(1, (uint)GetCalibrationCollection(energy, pulseWidth).GetScaleFactor(XRayEnergyEnum.LowEnergy).Length);
                            pxeWriteAccess.WriteLowEngDarkSample(PixelConverter.Convert(GetCalibrationCollection(energy, pulseWidth).GetDarkData(XRayEnergyEnum.LowEnergy)));
                            pxeWriteAccess.WriteLowEngAirSample(PixelConverter.Convert(GetCalibrationCollection(energy, pulseWidth).GetAirData(XRayEnergyEnum.LowEnergy)));
                        }

                        pxeWriteAccess.ClosePXEWrite();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex);
                    }
                //}
            }

            _logger.LogInfo("Calibration saving data to pxe done.");
        }
Beispiel #5
0
        private void XRayDataStateStopBtn_Checked(object sender, RoutedEventArgs eventArguments)
        {
            try { AccessDetectorsData.Detectors.SetDataTransferMode(dataTransferMode.Stop); }
            catch (Exception ex) { AnomalyShow(ex); }

            try
            {
                PxeWriteAccess pxeAccess = new PxeWriteAccess();
                pxeAccess.CreatePXE("Test" + DateTime.Now.Ticks.ToString() + ".pxe");
                pxeAccess.CreatePXEHeader(1, (uint)AccessDetectorsData.Detectors.RawDataCollection.Count, (uint)AccessDetectorsData.Detectors.PixelsPerColumn);
                while (AccessDetectorsData.Detectors.RawDataCollection.Count > 0)
                {
                    DataInfo information = AccessDetectorsData.Detectors.RawDataCollection.Take();
                    float[] data = PixelConverter.Convert(information.LineData);
                    pxeAccess.WriteDataLines(1, data, 1);
                }
                pxeAccess.ClosePXEWrite();
            }
            catch (Exception ex) { AnomalyShow(ex); }
        }