public void GivenVideoEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var videos = dataFaker.FakeVideo.Generate(count: 10);

            // Assert
            videos.ForEach(video =>
            {
                Assert.That(video.Id, Is.Not.Null);
                Assert.That(video.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(video.ChannelId, Is.Not.Null);
                Assert.That(video.ChannelId, Is.GreaterThanOrEqualTo(1));
                Assert.That(video.Title, Is.Not.Null);
                Assert.That(video.Title, Is.Not.Empty);
                Assert.That(video.Title.Length, Is.InRange(1, 50));
                Assert.That(video.Length, Is.Not.Null);
                Assert.That(video.Length, Is.InRange(1, 3600));
                Assert.That(video.Thumbnail, Is.Not.Null);
                Assert.That(video.Thumbnail, Is.Not.Empty);
                Assert.That(video.AccessType, Is.Not.Null);
                Assert.That(video.AccessType, Is.TypeOf <VideoAccessType>());
                Assert.That(video.Url, Is.Not.Null);
                Assert.That(video.Url, Is.Not.Empty);
                Assert.That(video.PublishDate, Is.Not.Null);
                Assert.That(video.PublishDate, Is.GreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)));
                Assert.That(video.PublishDate, Is.LessThanOrEqualTo(DateTime.UtcNow));
                Assert.That(video.IsDeleted, Is.Not.Null);
                Assert.That(video.IsDeleted, Is.TypeOf <bool>());
            });
        }
Ejemplo n.º 2
0
        internal void GivenPlaylistEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var playlists = dataFaker.FakePlaylist.Generate(count: 10);

            // Assert
            playlists.ForEach(
                playlist => playlist.ShouldSatisfyAllConditions(
                    () => playlist.Id.ShouldNotBe(Guid.Empty),
                    () => playlist.Name.ShouldNotBeNullOrEmpty(),
                    () => playlist.Name.Length.ShouldBeInRange(1, 50),
                    () => playlist.Description.ShouldNotBeNullOrEmpty(),
                    () => playlist.Description.Length.ShouldBeInRange(1, 100),
                    () => playlist.AccessType.ShouldBeOfType <PlaylistAccessType>(),
                    () => playlist.CreatedAt.ShouldBeGreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)),
                    () => playlist.CreatedAt.ShouldBeLessThanOrEqualTo(DateTime.UtcNow),
                    () => playlist.Videos.ShouldNotBeNull(),
                    () => playlist.Videos.ShouldNotBeEmpty(),
                    () => playlist.Videos.ShouldBeAssignableTo <IEnumerable <Video> >(),
                    () => playlist.Videos.Count().ShouldBe(3),
                    () => playlist.IsDeleted.ShouldBeOneOf(true, false)));
        }
Ejemplo n.º 3
0
        internal void GivenVideoEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var videos = dataFaker.FakeVideo.Generate(count: 10);

            // Assert
            videos.ForEach(video =>
            {
                Assert.NotEqual(Guid.Empty, video.Id);
                Assert.InRange(video.ChannelId, 1, int.MaxValue);
                Assert.NotNull(video.Title);
                Assert.NotEmpty(video.Title);
                Assert.InRange(video.Title.Length, 1, 50);
                Assert.InRange(video.Length, 1, 3600);
                Assert.NotNull(video.Thumbnail);
                Assert.NotEmpty(video.Thumbnail);
                Assert.IsType <VideoAccessType>(video.AccessType);
                Assert.NotNull(video.Url);
                Assert.NotEmpty(video.Url);
                Assert.InRange(video.PublishDate, DateTime.UtcNow.AddDays(-365), DateTime.UtcNow);
                Assert.IsType <bool>(video.IsDeleted);
            });
        }
        internal void GivenPlaylistEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var playlists = dataFaker.FakePlaylist.Generate(count: 10);

            // Assert
            playlists.ForEach(playlist =>
            {
                Assert.NotEqual(Guid.Empty, playlist.Id);
                Assert.NotNull(playlist.Name);
                Assert.NotEmpty(playlist.Name);
                Assert.InRange(playlist.Name.Length, 1, 50);
                Assert.NotNull(playlist.Description);
                Assert.NotEmpty(playlist.Description);
                Assert.InRange(playlist.Description.Length, 1, 100);
                Assert.IsType <PlaylistAccessType>(playlist.AccessType);
                Assert.InRange(playlist.CreatedAt, DateTime.UtcNow.AddDays(-365), DateTime.UtcNow);
                Assert.NotNull(playlist.Videos);
                Assert.IsAssignableFrom <IEnumerable <Video> >(playlist.Videos);
                Assert.NotEmpty(playlist.Videos);
                Assert.Equal(3, playlist.Videos.Count());
                Assert.IsType <bool>(playlist.IsDeleted);
            });
        }
Ejemplo n.º 5
0
        internal void GivenChannelEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var channels = dataFaker.FakeChannel.Generate(count: 10);

            // Assert
            channels.ForEach(
                channel => channel.ShouldSatisfyAllConditions(
                    () => channel.Id.ShouldBeGreaterThanOrEqualTo(1),
                    () => channel.Name.ShouldNotBeNullOrEmpty(),
                    () => channel.Name.Length.ShouldBeInRange(1, 50),
                    () => channel.Description.ShouldNotBeNullOrEmpty(),
                    () => channel.Description.Length.ShouldBeInRange(1, 100),
                    () => channel.Avatar.ShouldNotBeNull(),
                    () => channel.Avatar.ShouldNotBeEmpty(),
                    () => channel.OwnerEmail.ShouldNotBeNullOrEmpty(),
                    () => channel.OwnerEmail.ShouldContain('@'),
                    () => channel.Subscriptions.ShouldNotBeNull(),
                    () => channel.Subscriptions.ShouldBeAssignableTo <IEnumerable <Subscription> >(),
                    () => channel.Subscriptions.ShouldNotBeEmpty(),
                    () => channel.Subscriptions.Count().ShouldBe(3),
                    () => channel.Videos.ShouldNotBeNull(),
                    () => channel.Videos.ShouldBeAssignableTo <IEnumerable <Video> >(),
                    () => channel.Videos.ShouldNotBeEmpty(),
                    () => channel.Videos.Count().ShouldBe(3),
                    () => channel.IsDeleted.ShouldBeOneOf(true, false)));
        }
Ejemplo n.º 6
0
        public void GivenPlaylistEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var playlists = dataFaker.FakePlaylist.Generate(count: 10);

            // Assert
            playlists.ForEach(playlist =>
            {
                Assert.That(playlist.Id, Is.Not.Null);
                Assert.That(playlist.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(playlist.Name, Is.Not.Null);
                Assert.That(playlist.Name, Is.Not.Empty);
                Assert.That(playlist.Name.Length, Is.InRange(1, 50));
                Assert.That(playlist.Description, Is.Not.Null);
                Assert.That(playlist.Description, Is.Not.Empty);
                Assert.That(playlist.Description.Length, Is.InRange(1, 100));
                Assert.That(playlist.AccessType, Is.Not.Null);
                Assert.That(playlist.AccessType, Is.TypeOf <PlaylistAccessType>());
                Assert.That(playlist.CreatedAt, Is.Not.Null);
                Assert.That(playlist.CreatedAt, Is.GreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)));
                Assert.That(playlist.CreatedAt, Is.LessThanOrEqualTo(DateTime.UtcNow));
                Assert.That(playlist.Videos, Is.Not.Null);
                Assert.That(playlist.Videos, Is.InstanceOf <IEnumerable <Video> >());
                Assert.That(playlist.Videos, Is.Not.Empty);
                Assert.That(playlist.Videos, Has.Count.EqualTo(3));
                Assert.That(playlist.IsDeleted, Is.Not.Null);
                Assert.That(playlist.IsDeleted, Is.TypeOf <bool>());
            });
        }
        public void GivenSubscriptionEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var subscriptions = dataFaker.FakeSubscription.Generate(count: 10);

            // Assert
            subscriptions.ForEach(subscription =>
            {
                Assert.That(subscription.Id, Is.Not.Null);
                Assert.That(subscription.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(subscription.ChannelId, Is.Not.Null);
                Assert.That(subscription.ChannelId, Is.GreaterThanOrEqualTo(1));
                Assert.That(subscription.UserEmail, Is.Not.Null);
                Assert.That(subscription.UserEmail, Is.Not.Empty);
                Assert.That(subscription.UserEmail, Does.Contain("@"));
                Assert.That(subscription.SubscribedAt, Is.Not.Null);
                Assert.That(subscription.SubscribedAt, Is.GreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)));
                Assert.That(subscription.SubscribedAt, Is.LessThanOrEqualTo(DateTime.UtcNow));
                Assert.That(subscription.IsDeleted, Is.Not.Null);
                Assert.That(subscription.IsDeleted, Is.TypeOf <bool>());
            });
        }
Ejemplo n.º 8
0
        internal void GivenChannelEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var channels = dataFaker.FakeChannel.Generate(count: 10);

            // Assert
            channels.ForEach(channel =>
            {
                Assert.InRange(channel.Id, 1, int.MaxValue);
                Assert.NotNull(channel.Name);
                Assert.NotEmpty(channel.Name);
                Assert.InRange(channel.Name.Length, 1, 50);
                Assert.NotNull(channel.Description);
                Assert.NotEmpty(channel.Description);
                Assert.InRange(channel.Description.Length, 1, 100);
                Assert.NotNull(channel.Avatar);
                Assert.NotEmpty(channel.Avatar);
                Assert.NotNull(channel.OwnerEmail);
                Assert.NotEmpty(channel.OwnerEmail);
                Assert.Contains('@', channel.OwnerEmail);
                Assert.NotNull(channel.Subscriptions);
                Assert.IsAssignableFrom <IEnumerable <Subscription> >(channel.Subscriptions);
                Assert.NotEmpty(channel.Subscriptions);
                Assert.Equal(3, channel.Subscriptions.Count());
                Assert.NotNull(channel.Videos);
                Assert.IsAssignableFrom <IEnumerable <Video> >(channel.Videos);
                Assert.NotEmpty(channel.Videos);
                Assert.Equal(3, channel.Videos.Count());
                Assert.IsType <bool>(channel.IsDeleted);
            });
        }
        internal void GivenSubscriptionEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var subscriptions = dataFaker.FakeSubscription.Generate(count: 10);

            // Assert
            subscriptions.ForEach(subscription =>
            {
                subscription.Id.Should().NotBeEmpty();
                subscription.ChannelId.Should().NotBe(null).And.BeGreaterOrEqualTo(1);
                subscription.UserEmail.Should().NotBeNullOrEmpty().And.Contain("@");
                subscription.SubscribedAt.Should().BeOnOrAfter(DateTime.UtcNow.AddDays(-365));
                subscription.SubscribedAt.Should().BeOnOrBefore(DateTime.UtcNow);
            });
        }
Ejemplo n.º 10
0
        internal void GivenSubscriptionEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var subscriptions = dataFaker.FakeSubscription.Generate(count: 10);

            // Assert
            subscriptions.ForEach(
                subscription => subscription.ShouldSatisfyAllConditions(
                    () => subscription.Id.ShouldNotBe(Guid.Empty),
                    () => subscription.ChannelId.ShouldBeGreaterThanOrEqualTo(1),
                    () => subscription.UserEmail.ShouldNotBeNullOrEmpty(),
                    () => subscription.UserEmail.ShouldContain('@'),
                    () => subscription.SubscribedAt.ShouldBeGreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)),
                    () => subscription.SubscribedAt.ShouldBeLessThanOrEqualTo(DateTime.UtcNow),
                    () => subscription.IsDeleted.ShouldBeOneOf(true, false)));
        }
Ejemplo n.º 11
0
        internal void GivenSubscriptionEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var subscriptions = dataFaker.FakeSubscription.Generate(count: 10);

            // Assert
            subscriptions.ForEach(subscription =>
            {
                Assert.NotEqual(Guid.Empty, subscription.Id);
                Assert.InRange(subscription.ChannelId, 1, int.MaxValue);
                Assert.NotNull(subscription.UserEmail);
                Assert.NotEmpty(subscription.UserEmail);
                Assert.Contains('@', subscription.UserEmail);
                Assert.InRange(subscription.SubscribedAt, DateTime.UtcNow.AddDays(-365), DateTime.UtcNow);
                Assert.IsType <bool>(subscription.IsDeleted);
            });
        }
Ejemplo n.º 12
0
        internal void GivenVideoEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var videos = dataFaker.FakeVideo.Generate(count: 10);

            // Assert
            videos.ForEach(video =>
            {
                video.Id.Should().NotBeEmpty();
                video.ChannelId.Should().NotBe(null).And.BeGreaterOrEqualTo(1);
                video.Title.Should().NotBeNullOrEmpty();
                video.Title.Length.Should().BeInRange(1, 50);
                video.Length.Should().BeInRange(1, 3600);
                video.Thumbnail.Should().NotBeNullOrEmpty();
                video.AccessType.Should().NotBeNull().And.BeOfType <VideoAccessType>();
                video.Url.Should().NotBeNullOrEmpty();
                video.PublishDate.Should().BeOnOrAfter(DateTime.UtcNow.AddDays(-365));
                video.PublishDate.Should().BeOnOrBefore(DateTime.UtcNow);
            });
        }
Ejemplo n.º 13
0
        internal void GivenPlaylistEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var playlists = dataFaker.FakePlaylist.Generate(count: 10);

            // Assert
            playlists.ForEach(playlist =>
            {
                playlist.Id.Should().NotBeEmpty();
                playlist.Name.Should().NotBeNullOrEmpty();
                playlist.Name.Length.Should().BeInRange(1, 50);
                playlist.Description.Should().NotBeNullOrEmpty();
                playlist.Description.Length.Should().BeInRange(1, 100);
                playlist.AccessType.Should().NotBeNull().And.BeOfType <PlaylistAccessType>();
                playlist.CreatedAt.Should().BeOnOrAfter(DateTime.UtcNow.AddDays(-365));
                playlist.CreatedAt.Should().BeOnOrBefore(DateTime.UtcNow);
                playlist.Videos.Should().NotBeNull().And.BeAssignableTo <IEnumerable <Video> >();
                playlist.Videos.Should().NotBeEmpty().And.HaveCount(3);
            });
        }
Ejemplo n.º 14
0
        internal void GivenVideoEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var videos = dataFaker.FakeVideo.Generate(count: 10);

            // Assert
            videos.ForEach(
                video => video.ShouldSatisfyAllConditions(
                    () => video.Id.ShouldNotBe(Guid.Empty),
                    () => video.ChannelId.ShouldBeGreaterThanOrEqualTo(1),
                    () => video.Title.ShouldNotBeNullOrEmpty(),
                    () => video.Title.Length.ShouldBeInRange(1, 50),
                    () => video.Length.ShouldBeInRange(1, 3600),
                    () => video.Thumbnail.ShouldNotBeNull(),
                    () => video.Thumbnail.ShouldNotBeEmpty(),
                    () => video.AccessType.ShouldBeOfType <VideoAccessType>(),
                    () => video.Url.ShouldNotBeNullOrEmpty(),
                    () => video.PublishDate.ShouldBeGreaterThanOrEqualTo(DateTime.UtcNow.AddDays(-365)),
                    () => video.PublishDate.ShouldBeLessThanOrEqualTo(DateTime.UtcNow),
                    () => video.IsDeleted.ShouldBeOneOf(true, false)));
        }
Ejemplo n.º 15
0
        public void GivenChannelEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var channels = dataFaker.FakeChannel.Generate(count: 10);

            // Assert
            channels.ForEach(channel =>
            {
                Assert.That(channel.Id, Is.Not.Null);
                Assert.That(channel.Id, Is.GreaterThanOrEqualTo(1));
                Assert.That(channel.Name, Is.Not.Null);
                Assert.That(channel.Name, Is.Not.Empty);
                Assert.That(channel.Name.Length, Is.InRange(1, 50));
                Assert.That(channel.Description, Is.Not.Null);
                Assert.That(channel.Description, Is.Not.Empty);
                Assert.That(channel.Description.Length, Is.InRange(1, 100));
                Assert.That(channel.Avatar, Is.Not.Null);
                Assert.That(channel.Avatar, Is.Not.Empty);
                Assert.That(channel.OwnerEmail, Is.Not.Null);
                Assert.That(channel.OwnerEmail, Is.Not.Empty);
                Assert.That(channel.OwnerEmail, Does.Contain("@"));
                Assert.That(channel.Subscriptions, Is.Not.Null);
                Assert.That(channel.Subscriptions, Is.InstanceOf <IEnumerable <Subscription> >());
                Assert.That(channel.Subscriptions, Is.Not.Empty);
                Assert.That(channel.Subscriptions, Has.Count.EqualTo(3));
                Assert.That(channel.Videos, Is.Not.Null);
                Assert.That(channel.Videos, Is.InstanceOf <IEnumerable <Video> >());
                Assert.That(channel.Videos, Is.Not.Empty);
                Assert.That(channel.Videos, Has.Count.EqualTo(3));
                Assert.That(channel.IsDeleted, Is.Not.Null);
                Assert.That(channel.IsDeleted, Is.TypeOf <bool>());
            });
        }
Ejemplo n.º 16
0
        internal void GivenChannelEntityWhenGeneratedWithDataFakerThenVerifyAllProperties()
        {
            // Arrange
            IDataFaker dataFaker = new DataFaker();

            // Act
            var channels = dataFaker.FakeChannel.Generate(count: 10);

            // Assert
            channels.ForEach(channel =>
            {
                channel.Id.Should().NotBe(null).And.BeGreaterOrEqualTo(1);
                channel.Name.Should().NotBeNullOrEmpty();
                channel.Name.Length.Should().BeInRange(1, 50);
                channel.Description.Should().NotBeNullOrEmpty();
                channel.Description.Length.Should().BeInRange(1, 100);
                channel.Avatar.Should().NotBeNullOrEmpty();
                channel.OwnerEmail.Should().NotBeNullOrEmpty().And.Contain("@");
                channel.Subscriptions.Should().NotBeNull().And.BeAssignableTo <IEnumerable <Subscription> >();
                channel.Subscriptions.Should().NotBeEmpty().And.HaveCount(3);
                channel.Videos.Should().NotBeNull().And.BeAssignableTo <IEnumerable <Video> >();
                channel.Videos.Should().NotBeEmpty().And.HaveCount(3);
            });
        }
Ejemplo n.º 17
0
        private void schonClicked(object sender, EventArgs e)
        {
            MenuItem item = (MenuItem)sender;

            Controller.GetController().LoadData(DataFaker.GetFakeDataPath(item.Text));
        }
Ejemplo n.º 18
0
        // this is the method that actually takes the data. It is called by Start() and shouldn't
        // be called directly
        public void Acquire()
        {
            // lock onto something that the front end can see
            Monitor.Enter(MonitorLockObject);

            scanMaster         = new ScanMaster.Controller();
            phaseLock          = new EDMPhaseLock.MainForm();
            hardwareController = new EDMHardwareControl.Controller();

            // map modulations to physical channels
            MapChannels();

            // map the analog inputs
            MapAnalogInputs();

            Block b = new Block();

            b.Config = config;
            b.SetTimeStamp();
            foreach (ScannedAnalogInput channel in inputs.Channels)
            {
                b.detectors.Add(channel.Channel.Name);
            }

            try
            {
                // get things going
                AcquisitionStarting();

                // enter the main loop
                for (int point = 0; point < (int)config.Settings["numberOfPoints"]; point++)
                {
                    // set the switch states and impose the appropriate wait times
                    ThrowSwitches(point);

                    // take a point
                    Shot     s;
                    EDMPoint p;
                    if (Environs.Debug)
                    {
                        // just stuff a made up shot in
                        //Thread.Sleep(10);
                        s = DataFaker.GetFakeShot(1900, 50, 10, 3, 3);
                        ((TOF)s.TOFs[0]).Calibration = ((ScannedAnalogInput)inputs.Channels[0]).Calibration;
                        p      = new EDMPoint();
                        p.Shot = s;
                        //Thread.Sleep(20);
                    }
                    else
                    {
                        // everything should be ready now so start the analog
                        // input task (it will wait for a trigger)
                        inputTask.Start();

                        // get the raw data
                        double[,] analogData = inputReader.ReadMultiSample(inputs.GateLength);
                        inputTask.Stop();


                        // extract the data for each scanned channel and put it in a TOF
                        s = new Shot();
                        for (int i = 0; i < inputs.Channels.Count; i++)
                        {
                            // extract the raw data
                            double[] rawData = new double[inputs.GateLength];
                            for (int q = 0; q < inputs.GateLength; q++)
                            {
                                rawData[q] = analogData[i, q];
                            }

                            ScannedAnalogInput ipt = (ScannedAnalogInput)inputs.Channels[i];
                            // reduce the data
                            double[] data = ipt.Reduce(rawData);
                            TOF      t    = new TOF();
                            t.Calibration = ipt.Calibration;
                            // the 1000000 is because clock period is in microseconds;
                            t.ClockPeriod   = 1000000 / ipt.CalculateClockRate(inputs.RawSampleRate);
                            t.GateStartTime = inputs.GateStartTime;
                            // this is a bit confusing. The chop is measured in points, so the gate
                            // has to be adjusted by the number of points times the clock period!
                            if (ipt.ReductionMode == DataReductionMode.Chop)
                            {
                                t.GateStartTime += (ipt.ChopStart * t.ClockPeriod);
                            }
                            t.Data = data;
                            // the 1000000 is because clock period is in microseconds;
                            t.ClockPeriod = 1000000 / ipt.CalculateClockRate(inputs.RawSampleRate);

                            s.TOFs.Add(t);
                        }

                        p      = new EDMPoint();
                        p.Shot = s;
                    }
                    // do the "SinglePointData" (i.e. things that are measured once per point)
                    // We'll save the leakage monitor until right at the end.
                    // keep an eye on what the phase lock is doing
                    p.SinglePointData.Add("PhaseLockFrequency", phaseLock.OutputFrequency);
                    p.SinglePointData.Add("PhaseLockError", phaseLock.PhaseError);
                    // scan the analog inputs
                    double[] spd;
                    // fake some data if we're in debug mode
                    if (Environs.Debug)
                    {
                        spd    = new double[7];
                        spd[0] = 1;
                        spd[1] = 2;
                        spd[2] = 3;
                        spd[3] = 4;
                        spd[4] = 5;
                        spd[5] = 6;
                        spd[6] = 7;
                    }
                    else
                    {
                        singlePointInputTask.Start();
                        spd = singlePointInputReader.ReadSingleSample();
                        singlePointInputTask.Stop();
                    }
                    p.SinglePointData.Add("ProbePD", spd[0]);
                    p.SinglePointData.Add("PumpPD", spd[1]);
                    p.SinglePointData.Add("MiniFlux1", spd[2]);
                    p.SinglePointData.Add("MiniFlux2", spd[3]);
                    p.SinglePointData.Add("MiniFlux3", spd[4]);
                    //p.SinglePointData.Add("CplusV", spd[5]);
                    //p.SinglePointData.Add("CminusV", spd[6]);

                    //hardwareController.UpdateVMonitor();
                    //p.SinglePointData.Add("CplusV", hardwareController.CPlusMonitorVoltage);
                    //hardwareController.UpdateLaserPhotodiodes();
                    //p.SinglePointData.Add("ProbePD", hardwareController.ProbePDVoltage);
                    //p.SinglePointData.Add("PumpPD", hardwareController.PumpPDVoltage);
                    //hardwareController.UpdateMiniFluxgates();
                    //p.SinglePointData.Add("MiniFlux1", hardwareController.MiniFlux1Voltage);
                    //p.SinglePointData.Add("MiniFlux2", hardwareController.MiniFlux2Voltage);
                    //p.SinglePointData.Add("MiniFlux3", hardwareController.MiniFlux3Voltage);
                    hardwareController.ReadIMonitor();
                    p.SinglePointData.Add("NorthCurrent", hardwareController.NorthCurrent);
                    p.SinglePointData.Add("SouthCurrent", hardwareController.SouthCurrent);
                    //hardwareController.UpdatePiMonitor();
                    //p.SinglePointData.Add("piMonitor", hardwareController.PiFlipMonVoltage);
                    //p.SinglePointData.Add("CminusV", hardwareController.CMinusMonitorVoltage);

                    // Hopefully the leakage monitors will have finished reading by now.
                    // We join them, read out the data, and then launch another asynchronous
                    // acquisition. [If this is the first shot of the block, the leakage monitor
                    // measurement will have been launched in AcquisitionStarting() ].
                    //hardwareController.WaitForIMonitorAsync();
                    //p.SinglePointData.Add("NorthCurrent", hardwareController.NorthCurrent);
                    //p.SinglePointData.Add("SouthCurrent", hardwareController.SouthCurrent);
                    //hardwareController.UpdateIMonitorAsync();

                    // randomise the Ramsey phase
                    // TODO: check whether the .NET rng is good enough
                    // TODO: reference where this number comes from
                    //double d = 2.3814 * (new Random().NextDouble());
                    //hardwareController.SetScramblerVoltage(d);

                    b.Points.Add(p);

                    // update the front end
                    Controller.GetController().GotPoint(point, p);

                    if (CheckIfStopping())
                    {
                        // release hardware
                        AcquisitionStopping();
                        // signal anybody waiting on the lock that we're done
                        Monitor.Pulse(MonitorLockObject);
                        Monitor.Exit(MonitorLockObject);
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                // try and stop the experiment gracefully
                try
                {
                    AcquisitionStopping();
                }
                catch (Exception) {}                                            // about the best that can be done at this stage
                Monitor.Pulse(MonitorLockObject);
                Monitor.Exit(MonitorLockObject);
                throw e;
            }

            AcquisitionStopping();

            // hand the new block back to the controller
            Controller.GetController().AcquisitionFinished(b);

            // signal anybody waiting on the lock that we're done
            Monitor.Pulse(MonitorLockObject);
            Monitor.Exit(MonitorLockObject);
        }
Ejemplo n.º 19
0
        public void AcquireAndStepTarget()
        {
            // lock onto something that the front end can see
            Monitor.Enter(MonitorLockObject);

            scanMaster         = new ScanMaster.Controller();
            phaseLock          = new EDMPhaseLock.MainForm();
            hardwareController = new EDMHardwareControl.Controller();

            // map modulations to physical channels
            MapChannels();

            // map the analog inputs
            MapAnalogInputs();

            Block b = new Block();

            b.Config = config;
            b.SetTimeStamp();



            foreach (ScannedAnalogInput channel in inputs.Channels)
            {
                b.detectors.Add(channel.Channel.Name);
            }

            try
            {
                // get things going
                AcquisitionStarting();
                int point = 0;
                // enter the main loop
                for (point = 0; point < (int)config.Settings["maximumNumberOfTimesToStepTarget"]; point++)
                {
                    // take a point
                    Shot     s;
                    EDMPoint p;
                    if (Environs.Debug)
                    {
                        // just stuff a made up shot in
                        //Thread.Sleep(10);
                        s = DataFaker.GetFakeShot(1900, 50, 10, 3, 3);
                        ((TOF)s.TOFs[0]).Calibration = ((ScannedAnalogInput)inputs.Channels[0]).Calibration;
                        p      = new EDMPoint();
                        p.Shot = s;
                        //Thread.Sleep(20);
                    }
                    else
                    {
                        // everything should be ready now so start the analog
                        // input task (it will wait for a trigger)
                        inputTask.Start();

                        // get the raw data
                        double[,] analogData = inputReader.ReadMultiSample(inputs.GateLength);
                        inputTask.Stop();


                        // extract the data for each scanned channel and put it in a TOF
                        s = new Shot();
                        for (int i = 0; i < inputs.Channels.Count; i++)
                        {
                            // extract the raw data
                            double[] rawData = new double[inputs.GateLength];
                            for (int q = 0; q < inputs.GateLength; q++)
                            {
                                rawData[q] = analogData[i, q];
                            }

                            ScannedAnalogInput ipt = (ScannedAnalogInput)inputs.Channels[i];
                            // reduce the data
                            double[] data = ipt.Reduce(rawData);
                            TOF      t    = new TOF();
                            t.Calibration = ipt.Calibration;
                            // the 1000000 is because clock period is in microseconds;
                            t.ClockPeriod   = 1000000 / ipt.CalculateClockRate(inputs.RawSampleRate);
                            t.GateStartTime = inputs.GateStartTime;
                            // this is a bit confusing. The chop is measured in points, so the gate
                            // has to be adjusted by the number of points times the clock period!
                            if (ipt.ReductionMode == DataReductionMode.Chop)
                            {
                                t.GateStartTime += (ipt.ChopStart * t.ClockPeriod);
                            }
                            t.Data = data;
                            // the 1000000 is because clock period is in microseconds;
                            t.ClockPeriod = 1000000 / ipt.CalculateClockRate(inputs.RawSampleRate);

                            s.TOFs.Add(t);
                        }

                        p      = new EDMPoint();
                        p.Shot = s;
                    }
                    // do the "SinglePointData" (i.e. things that are measured once per point)
                    // We'll save the leakage monitor until right at the end.
                    // keep an eye on what the phase lock is doing
                    p.SinglePointData.Add("PhaseLockFrequency", phaseLock.OutputFrequency);
                    p.SinglePointData.Add("PhaseLockError", phaseLock.PhaseError);
                    // scan the analog inputs
                    double[] spd;
                    // fake some data if we're in debug mode
                    if (Environs.Debug)
                    {
                        spd    = new double[7];
                        spd[0] = 1;
                        spd[1] = 2;
                        spd[2] = 3;
                        spd[3] = 4;
                        spd[4] = 5;
                        spd[5] = 6;
                        spd[6] = 7;
                    }
                    else
                    {
                        singlePointInputTask.Start();
                        spd = singlePointInputReader.ReadSingleSample();
                        singlePointInputTask.Stop();
                    }
                    p.SinglePointData.Add("ProbePD", spd[0]);
                    p.SinglePointData.Add("PumpPD", spd[1]);
                    p.SinglePointData.Add("MiniFlux1", spd[2]);
                    p.SinglePointData.Add("MiniFlux2", spd[3]);
                    p.SinglePointData.Add("MiniFlux3", spd[4]);
                    //p.SinglePointData.Add("CplusV", spd[5]);
                    //p.SinglePointData.Add("CminusV", spd[6]);

                    //hardwareController.UpdateVMonitor();
                    //p.SinglePointData.Add("CplusV", hardwareController.CPlusMonitorVoltage);
                    //hardwareController.UpdateLaserPhotodiodes();
                    //p.SinglePointData.Add("ProbePD", hardwareController.ProbePDVoltage);
                    //p.SinglePointData.Add("PumpPD", hardwareController.PumpPDVoltage);
                    //hardwareController.UpdateMiniFluxgates();
                    //p.SinglePointData.Add("MiniFlux1", hardwareController.MiniFlux1Voltage);
                    //p.SinglePointData.Add("MiniFlux2", hardwareController.MiniFlux2Voltage);
                    //p.SinglePointData.Add("MiniFlux3", hardwareController.MiniFlux3Voltage);
                    hardwareController.ReadIMonitor();
                    p.SinglePointData.Add("NorthCurrent", hardwareController.NorthCurrent);
                    p.SinglePointData.Add("SouthCurrent", hardwareController.SouthCurrent);

                    b.Points.Add(p);

                    // update the front end
                    Controller.GetController().GotPoint(point, p);


                    // Integrate the first toff and stop the sequence if the signal is sufficiently high
                    TOF detectorATOF = new TOF();
                    detectorATOF = (TOF)s.TOFs[0];
                    double sig = detectorATOF.Integrate((double)config.Settings["targetStepperGateStartTime"], (double)config.Settings["targetStepperGateEndTime"]);
                    if (sig > (double)config.Settings["minimumSignalToRun"])
                    {
                        Controller.GetController().TargetHealthy = true;
                        Stop();
                        point = (int)config.Settings["maximumNumberOfTimesToStepTarget"] + 1;
                    }
                    else
                    {
                        Controller.GetController().TargetHealthy = false;
                        hardwareController.StepTarget(2);
                    }
                    //if (CheckIfStopping())
                    //{
                    // release hardware
                    //    AcquisitionStopping();
                    // signal anybody waiting on the lock that we're done
                    //    Monitor.Pulse(MonitorLockObject);
                    //    Monitor.Exit(MonitorLockObject);
                    //    point = (int)config.Settings["maximumNumberOfTimesToStepTarget"];
                    //    return;
                    //}
                }
                AcquisitionStopping();

                // hand the new block back to the controller
                Controller.GetController().IntelligentAcquisitionFinished();

                // signal anybody waiting on the lock that we're done
                Monitor.Pulse(MonitorLockObject);
                Monitor.Exit(MonitorLockObject);
            }
            catch (Exception e)
            {
                // try and stop the experiment gracefully
                try
                {
                    AcquisitionStopping();
                }
                catch (Exception) { }                           // about the best that can be done at this stage
                Monitor.Pulse(MonitorLockObject);
                Monitor.Exit(MonitorLockObject);
                throw e;
            }
        }