Example #1
0
        public void Run(CSeriesLinac linac, IElectrometer el, I1DScanner scan1D, Logger logger = null)
        {
            ServiceModeSession.Instance.Logger = logger;

            foreach (var job in RowJobs)
            {
                var measurementsLeft = job.Item1.NumberOfMeasurementsDesired - job.Item1.Measurements.Length;
                if (measurementsLeft > 0)
                {
                    linac.SetMachineState(job.Item1.MachineStateRun);
                }
                if (scan1D != null)
                {
                    scan1D.GoToDepth(job.Item1.DepthOfMeasurentMM).Wait();
                }
                if (el != null && measurementsLeft > 0)
                {
                    for (int i = 0; i < measurementsLeft; i++)
                    {
                        el.StartMeasurement();
                        linac.BeamOn();
                        el.StopMeasurement();
                        var val = el.GetValue();
                        job.Item1.AddMeasurement(val.Measurement);
                    }
                    SaveAction();
                }
            }
        }
Example #2
0
        public void Run()
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mulinearity.txt");
            }
            ;

            //Move to Scanning Depth
            Logger.Log("Moving scanning chamber...\n");
            _scan1D.GoToDepth(ScanningDepthMM).Wait();

            var ms = MachineState.InitNew();

            ms.X1 = ms.X2 = ms.Y1 = ms.Y2 = 5;

            foreach (var en in energiesToTest)
            {
                foreach (var mu in musToTest)
                {
                    var movingMs = ms.Copy();
                    movingMs.Energy = en;
                    movingMs.MU     = mu;
                    var jr = new Job(movingMs);
                    jr.DepthOfMeasurentMM = ScanningDepthMM;
                    for (int n = 0; n < RepeatMeasurements; n++)
                    {
                        Logger.Log($"Working on {en}, {mu} MU, Measurement {n + 1}\n");

                        _linac.SetMachineState(movingMs);

                        //Start measuring
                        _el.Reset();
                        _el.StartMeasurement();

                        if (n == 0)
                        {
                            _linac.BeamOn();
                        }
                        else
                        {
                            _linac.RepeatBeam();
                        }

                        Thread.Sleep(_linac.WaitMsForMU(mu));

                        //Stop and get measurement
                        _el.StopMeasurement();
                        var measured = _el.GetValue().Measurement;
                        Logger?.Log($"Measured : {measured}\n");

                        //Save results
                        jr.AddMeasurement(_el.GetValue().Measurement);
                    }
                    JobWriter.AppendResult(SavePath, jr);
                }
            }
        }
Example #3
0
        public void Run()
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "edwFactors.txt");
            }
            ;

            var states = BuildMeasurementList();

            foreach (var m in states)
            {
                var jr = new Job(m);
                jr.DepthOfMeasurentMM = DepthOfMeasurementMM;
                if (Math.Abs(_scan1D.LastKnowPositionMM - DepthOfMeasurementMM) > 0.1)
                {
                    Logger.Log($"Changing depth to {DepthOfMeasurementMM} mm\n");
                    _scan1D.GoToDepth(jr.DepthOfMeasurentMM);
                }

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    var fov = EnergyHelper.IsPhoton(m.Energy) ? $"{m.X1 * 2} x {m.Y1 * 2}" : m.Accessory;
                    Logger.Log($"Working on {m.Energy}, Depth {jr.DepthOfMeasurentMM}, {m.Accessory} ,  Measurement {n + 1}\n\n");

                    _linac.SetMachineState(m);

                    //Start measuring
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    var waitTime = _linac.WaitMsForMU(m.MU, true);
                    using (var t = new TimerLogger("Waiting on beam completion", waitTime, 1000, this.Logger))
                    {
                        Thread.Sleep(waitTime);
                    }
                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }
                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }
Example #4
0
        public void Run(bool photons = true, bool electrons = true)
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "outputFactors.txt");
            }
            ;

            var measurementList = BuildMeasurementList(photons, electrons);

            foreach (var m in measurementList)
            {
                var jr = new Job(m);
                jr.DepthOfMeasurentMM = energyDepths[m.Energy];
                _scan1D.GoToDepth(jr.DepthOfMeasurentMM);

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    var fov = EnergyHelper.IsPhoton(m.Energy) ? $"{m.X1 * 2} x {m.Y1 * 2}" : m.Accessory;
                    Logger.Log($"Working on {m.Energy}, Depth {jr.DepthOfMeasurentMM}, {fov} ,  Measurement {n + 1}");

                    var state = _linac.GetMachineStateCopy();
                    //Check for cone change
                    if (_linac.GetMachineStateCopy().Accessory != m.Accessory)
                    {
                        Console.Beep(4000, 1000);
                        Logger.Log($"Please change the cone to {m.Accessory}\n");
                        Logger.Log($"Press ENTER when complete\n");
                        while (Console.ReadKey().Key != ConsoleKey.Enter)
                        {
                        }
                        Logger.Log($"{m.Accessory} inserted! Continuing...\n");
                    }

                    _linac.SetMachineState(m);

                    //Start measuring
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    Thread.Sleep(_linac.WaitMsForMU(m.MU));

                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }

                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }
Example #5
0
        public void Run()
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "outputs.txt");
            }
            ;

            var measurementList = BuildMeasurementList();

            BeamManager.SetFixed();
            BeamManager.SetEnergy(Energy._6X);
            BeamManager.SetDoseRate(measurementList.First().MachineStateRun.DoseRate);

            foreach (var jr in measurementList)
            {
                Task depthTask = Task.Run(() => { });
                if (_scan1D.GetCurrentDepthMM() != jr.DepthOfMeasurentMM)
                {
                    depthTask = _scan1D.GoToDepth(jr.DepthOfMeasurentMM);
                }

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    Logger.Log($"Working on {jr.MachineStateRun.Energy}, Depth {jr.DepthOfMeasurentMM},  Measurement {n + 1}\n");

                    var state = _linac.GetMachineStateCopy();
                    //Check for cone change
                    if (_linac.GetMachineStateCopy().Accessory != jr.MachineStateRun.Accessory)
                    {
                        Console.Beep(4000, 1000);
                        Logger.Log($"Please change the cone to {jr.MachineStateRun.Accessory}\n");
                        Logger.Log($"Press ENTER when complete\n");
                        while (Console.ReadKey().Key != ConsoleKey.Enter)
                        {
                        }
                        Logger.Log($"{jr.MachineStateRun.Accessory} inserted! Continuing...\n");
                    }

                    _linac.SetMachineState(jr.MachineStateRun);

                    //Start measuring
                    depthTask.Wait();
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    Thread.Sleep(_linac.WaitMsForMU(jr.MachineStateRun.MU));

                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }

                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }