Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkovalchik committed Jun 18, 2020
1 parent 03cf2a5 commit 14cf109
Show file tree
Hide file tree
Showing 31 changed files with 1,726 additions and 0 deletions.
25 changes: 25 additions & 0 deletions RealTimeOrbiWiz.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RealTimeOrbiWiz", "RealTimeOrbiWiz\RealTimeOrbiWiz.csproj", "{15718988-0ACF-4602-B940-FFD087DD2CFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{15718988-0ACF-4602-B940-FFD087DD2CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15718988-0ACF-4602-B940-FFD087DD2CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15718988-0ACF-4602-B940-FFD087DD2CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15718988-0ACF-4602-B940-FFD087DD2CFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D615DC5-AF45-4853-9643-2B76F8AE7342}
EndGlobalSection
EndGlobal
153 changes: 153 additions & 0 deletions RealTimeOrbiWiz/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.IO;
using System.Security.Permissions;
using System.Threading.Tasks;
using ThermoFisher.CommonCore.Data.Business;
using ThermoFisher.CommonCore.Data;
using System.Linq;

namespace RealTimeOrbiWiz
{
class Program
{
public static void Main(string[] args)
{
Run(args);
}

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] // I don't remember why this is here. I think something to do with watching the filesystem, but maybe try deleting it and see if things still work.
private static void Run(string[] args)
{

// If a directory is not specified, exit program.
if (args.Length != 1)
{
// Display the proper way to call the program.
Console.WriteLine("Usage: RealTimeOrbiWiz.exe (directory)");
return;
}

// Create a new FileSystemWatcher and set its properties.
using (FileSystemWatcher watcher = new FileSystemWatcher())
{
watcher.Path = args[0];

// Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.FileName
| NotifyFilters.CreationTime;

// Only watch .raw files.
watcher.Filter = "*.raw";

// Add event handlers.
//watcher.Changed += OnChanged;
watcher.Created += OnCreated;
//watcher.Deleted += OnChanged;
//watcher.Renamed += OnRenamed;

// Begin watching.
watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program.
// Console.WriteLine("Press 'q' to quit the sample.");
Console.WriteLine("Running. Waiting for new files to show up... Press 'q' to quit");
while (Console.Read() != 'q') { };
}
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e) =>
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");

private static void OnRenamed(object source, RenamedEventArgs e) =>
// Specify what is done when a file is renamed.
Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");

private static void OnCreated(object source, FileSystemEventArgs e)
{
Console.WriteLine($"File: {e.FullPath} created");
Task.Run(() => WatchFile(e.FullPath)).Wait();
}

private static void WatchFile(string pathToRawFile)
{
using (var f = new StreamWriter("rawFileAcquisitionInfo.txt", append: true))
{
using (var rawFile = RawFileReaderFactory.CreateThreadManager(pathToRawFile).CreateThreadAccessor())
{
rawFile.SelectMsData();

DateTime created = DateTime.Now;

f.WriteLine($"{pathToRawFile} created at {created}");
f.WriteLine($"InAcquisition: {rawFile.InAcquisition}");
f.WriteLine($"Run header: {rawFile.RunHeader.ToString()}");
f.WriteLine($"Spectra count: {rawFile.RunHeaderEx.SpectraCount}");

Console.WriteLine($"{pathToRawFile} created at {created}");
Console.WriteLine($"InAcquisition: {rawFile.InAcquisition}");
Console.WriteLine($"Run header: {rawFile.RunHeader.ToString()}");
Console.WriteLine($"Spectra count: {rawFile.RunHeaderEx.SpectraCount}");

int lastSpectrum = rawFile.RunHeader.LastSpectrum;
int spectraCount = rawFile.RunHeaderEx.SpectraCount;

while (spectraCount == rawFile.RunHeaderEx.SpectraCount || lastSpectrum == rawFile.RunHeader.LastSpectrum)
{
Console.WriteLine($"Waiting for a spectrum to be recorded. {(DateTime.Now - created).TotalSeconds} seconds elapsed.");
f.WriteLine($"Waiting for a spectrum to be recorded. {(DateTime.Now - created).TotalSeconds} seconds elapsed.");
Task.Delay(5000).Wait();
rawFile.RefreshViewOfFile();
}

Console.WriteLine("A spectrum has been recorded.");
f.WriteLine("A spectrum has been recorded.");

var firstRecordedSpec = rawFile.RunHeader.FirstSpectrum;
var rtInSecBeforeFirstScan = rawFile.RetentionTimeFromScanNumber(firstRecordedSpec) * 60;

var deadTime = (DateTime.Now - created).TotalSeconds - rtInSecBeforeFirstScan;
Console.WriteLine($"Dead time: {deadTime}");
f.WriteLine($"Dead time: {deadTime}");

Console.WriteLine("Now watching the file as new spectra are recorded.");
f.WriteLine("Now watching the file as new spectra are recorded.");

while (rawFile.InAcquisition)
{
rawFile.RefreshViewOfFile();

lastSpectrum = rawFile.RunHeader.LastSpectrum;
spectraCount = rawFile.RunHeaderEx.SpectraCount;
var scan = rawFile.GetScanEventForScanNumber(lastSpectrum);

Console.WriteLine($"Seconds since file creation: {(DateTime.Now - created).TotalSeconds}");
Console.WriteLine($"Current retention time: {rawFile.RetentionTimeFromScanNumber(lastSpectrum)}");
Console.WriteLine($"Estimated time until end of run: {rawFile.RunHeader.ExpectedRuntime - rawFile.RetentionTimeFromScanNumber(lastSpectrum)}");
Console.WriteLine($"Latest spectrum: {lastSpectrum}\tTotal spectra: {spectraCount}");
Console.WriteLine($"Base intensity of latest scan: {rawFile.GetSegmentedScanFromScanNumber(lastSpectrum, null).Intensities.Max()}");
Console.WriteLine($"MS order of latest scan: {scan.MSOrder}");
Console.WriteLine();

f.WriteLine($"Seconds since file creation: {(DateTime.Now - created).TotalSeconds}");
f.WriteLine($"Current retention time: {rawFile.RetentionTimeFromScanNumber(lastSpectrum)}");
f.WriteLine($"Estimated time until end of run: {rawFile.RunHeader.ExpectedRuntime - rawFile.RetentionTimeFromScanNumber(lastSpectrum)}");
f.WriteLine($"Latest spectrum: {lastSpectrum}\tTotal spectra: {spectraCount}");
f.WriteLine($"Base intensity of latest scan: {rawFile.GetSegmentedScanFromScanNumber(lastSpectrum, null).Intensities.Max()}");
f.WriteLine($"MS order of latest scan: {scan.MSOrder}");
f.WriteLine();

Task.Delay(30000).Wait();
}

f.WriteLine($"{rawFile.FileName} reports it is done being acquired!");
Console.WriteLine($"{rawFile.FileName} reports it is done being acquired! Press any key to exit.");
Console.ReadKey();
Environment.Exit(0);
}
}
}
}
}
8 changes: 8 additions & 0 deletions RealTimeOrbiWiz/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"RealTimeOrbiWiz": {
"commandName": "Project",
"commandLineArgs": "C:\\"
}
}
}
16 changes: 16 additions & 0 deletions RealTimeOrbiWiz/RealTimeOrbiWiz.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Security.Permissions" Version="4.6.0" />
<PackageReference Include="ThermoFisher.CommonCore.BackgroundSubtraction" Version="5.0.0.7" />
<PackageReference Include="ThermoFisher.CommonCore.Data" Version="5.0.0.7" />
<PackageReference Include="ThermoFisher.CommonCore.MassPrecisionEstimator" Version="5.0.0.7" />
<PackageReference Include="ThermoFisher.CommonCore.RawFileReader" Version="5.0.0.7" />
</ItemGroup>

</Project>
Loading

0 comments on commit 14cf109

Please sign in to comment.