public void CreateDB_test1(int frameCountToWrite)
        {
            DataReaderTests.DataReaderTests.PrintMethodName(System.Reflection.MethodBase.GetCurrentMethod());

            var fiTarget = new FileInfo(FileRefs.WriterTest10Frames);

            if (fiTarget.Exists)
            {
                fiTarget.Delete();
            }

            var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            using (var writer = new DataWriter(fiTarget.FullName, executingAssembly))
            {
                writer.CreateTables("int");

                var globalParameters = new GlobalParams();

                globalParameters.AddUpdateValue(GlobalParamKeyType.Bins, 400000)
                .AddUpdateValue(GlobalParamKeyType.BinWidth, 0.25)
                .AddUpdateValue(GlobalParamKeyType.DateStarted, DateTime.Now)
                .AddUpdateValue(GlobalParamKeyType.NumFrames, frameCountToWrite)
                .AddUpdateValue(GlobalParamKeyType.TOFIntensityType, "ADC");

                writer.InsertGlobal(globalParameters)
                .AddUpdateGlobalParameter(GlobalParamKeyType.TimeOffset, 1)
                .AddUpdateGlobalParameter(GlobalParamKeyType.InstrumentName, "IMS_Test");

                Console.WriteLine("Adding frame 1");

                const float SECONDS_PER_FRAME = 1.25f;

                var randGenerator = new Random();

                for (var frameNum = 1; frameNum <= frameCountToWrite; frameNum++)
                {
                    var fp = new FrameParams();

                    fp.AddUpdateValue(FrameParamKeyType.FrameType, (int)UIMFData.FrameType.MS1)
                    .AddUpdateValue(FrameParamKeyType.CalibrationSlope, 0.3476349957054481)
                    .AddUpdateValue(FrameParamKeyType.CalibrationIntercept, 0.03434148864746093)
                    .AddUpdateValue(FrameParamKeyType.AverageTOFLength, 163366.6666666667)
                    .AddUpdateValue(FrameParamKeyType.StartTimeMinutes, frameNum * SECONDS_PER_FRAME)
                    .AddUpdateValue(FrameParamKeyType.Scans, 600);

                    writer.InsertFrame(frameNum, fp);

                    for (var scanNumber = 1; scanNumber <= 600; scanNumber++)
                    {
                        if (scanNumber == 1 | scanNumber % 100 == 0)
                        {
                            Console.WriteLine("Adding frame " + frameNum + ", scan " + scanNumber);
                        }

                        var intensities = new int[148000];

                        for (var i = 0; i < intensities.Length; i++)
                        {
                            var nextRandom = randGenerator.Next(0, 255);
                            if (nextRandom < 250)
                            {
                                intensities[i] = 0;
                            }
                            else
                            {
                                intensities[i] = nextRandom;
                            }
                        }

                        writer.InsertScan(frameNum, fp, scanNumber, intensities, globalParameters.BinWidth);
                    }
                }

                writer.UpdateGlobalStats();

                Console.WriteLine("Wrote 10 frames of data to " + fiTarget.FullName);
            }
        }
示例#2
0
        private static void WriterTest()
        {
            var fiTestFile = new FileInfo("TestOutput.uimf");

            try
            {
                if (fiTestFile.Exists)
                {
                    fiTestFile.Delete();
                }
            }
            catch (IOException)
            {
                Console.WriteLine("Existing " + fiTestFile.Name + " file exists and cannot be deleted (locked)");
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Existing " + fiTestFile.Name + " file exists and cannot be deleted: " + ex.Message);
                return;
            }

            try
            {
                Console.WriteLine("Creating " + fiTestFile.FullName);

                using (var writer = new DataWriter(fiTestFile.FullName))
                {
                    writer.CreateTables();

                    var globalParameters = new GlobalParams();
                    globalParameters.AddUpdateValue(GlobalParamKeyType.Bins, 400000)
                    .AddUpdateValue(GlobalParamKeyType.BinWidth, 0.25)
                    .AddUpdateValue(GlobalParamKeyType.DateStarted, DateTime.Now)
                    .AddUpdateValue(GlobalParamKeyType.TOFIntensityType, "ADC")
                    .AddUpdateValue(GlobalParamKeyType.TOFCorrectionTime, 0.0);

                    writer.InsertGlobal(globalParameters);

                    globalParameters = writer.GetGlobalParams();

                    writer.AddUpdateGlobalParameter(GlobalParamKeyType.TimeOffset, 1)
                    .AddUpdateGlobalParameter(GlobalParamKeyType.InstrumentName, "IMS_Test")
                    .FlushUimf();

                    const float SECONDS_PER_FRAME = 1.25f;

                    var randGenerator = new Random();

                    for (var frameNum = 1; frameNum <= 5; frameNum++)
                    {
                        var fp = new FrameParams();

                        fp.AddUpdateValue(FrameParamKeyType.FrameType, (int)UIMFLibrary.DataReader.FrameType.MS1)
                        .AddUpdateValue(FrameParamKeyType.CalibrationSlope, 0.3476349957054481)
                        .AddUpdateValue(FrameParamKeyType.CalibrationIntercept, 0.03434148864746093)
                        .AddUpdateValue(FrameParamKeyType.AverageTOFLength, 163366.6666666667)
                        .AddUpdateValue(FrameParamKeyType.StartTimeMinutes, frameNum * SECONDS_PER_FRAME);

                        writer.InsertFrame(frameNum, fp)
                        .AddUpdateFrameParameter(frameNum, FrameParamKeyType.Accumulations, "18")
                        .AddUpdateFrameParameter(frameNum, FrameParamKeyType.TOFLosses, randGenerator.Next(0, 150).ToString());

                        for (var scanNumber = 1; scanNumber < 600; scanNumber++)
                        {
                            if (scanNumber == 1 | scanNumber % 100 == 0)
                            {
                                Console.WriteLine("Adding frame " + frameNum + ", scan " + scanNumber);
                            }

                            var intensities = new int[148000];

                            for (var i = 0; i < intensities.Length; i++)
                            {
                                var nextRandom = randGenerator.Next(0, 255);
                                if (nextRandom < 250)
                                {
                                    intensities[i] = 0;
                                }
                                else
                                {
                                    intensities[i] = nextRandom;
                                }
                            }

                            writer.InsertScan(frameNum, fp, scanNumber, intensities, globalParameters.BinWidth);
                        }
                    }
                }

                Console.WriteLine("Wrote 5 frames of data to \n" + fiTestFile.FullName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error testing the writer: " + ex.Message);
            }
        }