/* This is a convenient way to add a block, if you're using standard demodulation * configurations. This method is thread-safe. */ //public void AddBlock(Block b, string[] demodulationConfigs) //{ // log("Adding block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"]); // BlockDemodulator blockDemodulator = new BlockDemodulator(); // foreach (string dcName in demodulationConfigs) // { // DemodulationConfig dc = DemodulationConfig.GetStandardDemodulationConfig(dcName, b); // //DemodulatedBlock dBlock = blockDemodulator.DemodulateBlockNL(b, dc); // DemodulatedBlock dBlock = blockDemodulator.DemodulateBlock(b, dc); // blockStore.AddDBlock(dBlock); // } //} public void AddBlock(Block b) { BlockDemodulator blockDemodulator = new BlockDemodulator(); log("Demodulating block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"]); DemodulatedBlock db = blockDemodulator.DemodulateBlock(b, DemodulationConfig.MakeStandardDemodulationConfig()); blockStore.AddDBlock(db); TimeSpan ts2 = DateTime.Now.Subtract(threadManager.GetCurrentAnalysisStart()); log("Added block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"] + " after " + ts2.TotalSeconds.ToString() + " seconds."); }
/* This is a convenient way to add a block, if you're using standard demodulation * configurations. This method is thread-safe. */ public void AddBlock(Block b, string[] demodulationConfigs) { log("Adding block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"]); BlockDemodulator blockDemodulator = new BlockDemodulator(); foreach (string dcName in demodulationConfigs) { DemodulationConfig dc = DemodulationConfig.GetStandardDemodulationConfig(dcName, b); DemodulatedBlock dBlock = blockDemodulator.DemodulateBlockNL(b, dc); blockStore.AddDBlock(dBlock); } }
public void MagDataAcquisitionFinished(Block b) { this.Block = b; mainWindow.AppendToTextArea("Demodulating magnetic data block."); DemodulationConfig dc = DemodulationConfig.GetStandardDemodulationConfig("magnetometers", b); DBlock = blockDemodulator.DemodulateMagDataBlock(b, dc); // liveViewer.AddDBlock(DBlock); haveBlock = true; appState = AppState.stopped; mainWindow.AppendToTextArea("Acquisition finished"); SetStatusReady(); }
public void AcquisitionFinished(Block b) { this.Block = b; mainWindow.AppendToTextArea("Demodulating block."); // "cgate11Fixed" for Ar, "centreFixedKr" for Kr DemodulationConfig dc = DemodulationConfig.GetStandardDemodulationConfig("wgate5", b); // was cgate11fixed DBlock = blockDemodulator.DemodulateBlock(b, dc); // blockDemodulator.DemodulateBlock(b, dc); liveViewer.AddDBlock(DBlock); //config.g haveBlock = true; appState = AppState.stopped; mainWindow.AppendToTextArea("Acquisition finished"); SetStatusReady(); }
//public void TOFDemodulateBlocks(string[] blockFiles, string savePath) //{ // // first of all test that the save location exists to avoid later disappointment. // if (!Directory.Exists(Path.GetDirectoryName(savePath))) // { // log("Save path does not exist!!"); // return; // } // // initialise the accumulator // tcsga = new TOFChannelSetGroupAccumulator(); // // queue the blocks - the last block analysed will take care of saving the results. // foreach (string blockFile in blockFiles) // { // tofDemodulateParams tdp = new tofDemodulateParams(); // tdp.blockPath = blockFile; // tdp.savePath = savePath; // threadManager.AddToQueue(TOFDemodulateThreadWrapper, tdp); // } //} //private void TOFDemodulateBlock(string blockPath, string savePath) //{ // BlockSerializer bs = new BlockSerializer(); // string[] splitPath = blockPath.Split('\\'); // log("Loading block " + splitPath[splitPath.Length - 1]); // Block b = bs.DeserializeBlockFromZippedXML(blockPath, "block.xml"); // log("Demodulating block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"]); // BlockTOFDemodulator btd = new BlockTOFDemodulator(); // TOFChannelSet tcs = btd.TOFDemodulateBlock(b, 0, true); // log("Accumulating block " + b.Config.Settings["cluster"] + " - " + b.Config.Settings["clusterIndex"]); // lock (accumulatorLock) tcsga.Add(tcs); // // are we the last block to be added? If so, it's our job to save the results // if (threadManager.RemainingJobs == 1) // { // // this lock should not be needed // lock(accumulatorLock) // { // TOFChannelSetGroup tcsg = tcsga.GetResult(); // Stream fileStream = new FileStream(savePath, FileMode.Create); // (new BinaryFormatter()).Serialize(fileStream, tcsg); // fileStream.Close(); // } // } //} //private void TOFDemodulateThreadWrapper(object parametersIn) //{ // threadManager.QueueItemWrapper(delegate(object parms) // { // tofDemodulateParams parameters = (tofDemodulateParams)parms; // TOFDemodulateBlock(parameters.blockPath, parameters.savePath); // }, // parametersIn // ); //} //private struct tofDemodulateParams //{ // public string blockPath; // public string savePath; // // this struct has a ToString method defined for error reporting porpoises. // public override string ToString() // { // return blockPath; // } //} #endregion #region Testing // Somewhere for SirCachealot to store test results that's accessible by Mathematica. // Makes debugging easier and is needed as a workaround for the constant Mathematica // NET/Link errors. // public TOFChannelSetGroup ChanSetGroup; // workarounds for NET/Link bugs //public TOFChannelSet GetAveragedChannelSet(bool eSign, bool bSign, bool rfSign) //{ // return ChanSetGroup.AverageChannelSetSignedByMachineState(eSign, bSign, rfSign); //} //public void LoadChannelSetGroup(string path) //{ // BinaryFormatter bf = new BinaryFormatter(); // FileStream fs = new FileStream(path, FileMode.Open); // ChanSetGroup = (TOFChannelSetGroup)bf.Deserialize(fs); // fs.Close(); //} public void Test1() { BlockSerializer bs = new BlockSerializer(); Block b = bs.DeserializeBlockFromZippedXML( "C:\\Users\\jony\\Files\\Data\\SEDM\\v3\\2009\\October2009\\01Oct0900_0.zip", "block.xml"); BlockDemodulator bd = new BlockDemodulator(); DemodulatedBlock db = bd.DemodulateBlockNL(b, DemodulationConfig.GetStandardDemodulationConfig("cgate11Fixed", b)); //JsonSerializer serializer = new JsonSerializer(); //using (StreamWriter sw = new StreamWriter("c:\\Users\\jony\\Desktop\\test.json")) //using (JsonWriter writer = new JsonTextWriter(sw)) //{ // serializer.Serialize(writer, b.Config); //} //bs.SerializeBlockAsJSON("c:\\Users\\jony\\Desktop\\test.json", b); }
private void AddBlock(string path, string normConfig) { Monitor.JobStarted(); string fileName = path.Split('\\').Last(); try { Controller.log("Adding block " + fileName); using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext()) { BlockSerializer bls = new BlockSerializer(); Block b = bls.DeserializeBlockFromZippedXML(path, "block.xml"); Controller.log("Loaded " + fileName); // at the moment the block data is normalized by dividing each "top" TOF through // by the integral of the corresponding "norm" TOF over the gate in the function below. // TODO: this could be improved! b.Normalise(DemodulationConfig.GetStandardDemodulationConfig(normConfig, b).GatedDetectorExtractSpecs["norm"]); // add some of the single point data to the Shot TOFs so that it gets analysed string[] spvsToTOFulise = new string[] { "NorthCurrent", "SouthCurrent", "MiniFlux1", "MiniFlux2", "MiniFlux3", "ProbePD", "PumpPD" }; b.TOFuliseSinglePointData(spvsToTOFulise); // extract the metadata and config into a DB object DBBlock dbb = new DBBlock(); dbb.cluster = (string)b.Config.Settings["cluster"]; dbb.clusterIndex = (int)b.Config.Settings["clusterIndex"]; dbb.include = false; dbb.eState = (bool)b.Config.Settings["eState"]; dbb.bState = (bool)b.Config.Settings["bState"]; try { dbb.rfState = (bool)b.Config.Settings["rfState"]; } catch (Exception) { // blocks from the old days had no rfState recorded in them. dbb.rfState = true; } dbb.ePlus = (double)b.Config.Settings["ePlus"]; dbb.eMinus = (double)b.Config.Settings["eMinus"]; dbb.blockTime = (DateTime)b.TimeStamp; byte[] bts = serializeAsByteArray(b.Config); dbb.configBytes = bts; // extract the TOFChannelSets List <string> detectorsToExtract = new List <string> { "top", "norm", "magnetometer", "gnd", "battery", "topNormed", "NorthCurrent", "SouthCurrent", "MiniFlux1", "MiniFlux2", "MiniFlux3", "ProbePD", "PumpPD" }; foreach (string detector in detectorsToExtract) { BlockTOFDemodulator demod = new BlockTOFDemodulator(); TOFChannelSet tcs = demod.TOFDemodulateBlock(b, b.detectors.IndexOf(detector), true); byte[] tcsBytes = serializeAsByteArray(tcs); DBTOFChannelSet t = new DBTOFChannelSet(); t.tcsData = tcsBytes; t.detector = detector; t.FileID = Guid.NewGuid(); dbb.DBTOFChannelSets.Add(t); } Controller.log("Demodulated " + fileName); // add to the database dc.DBBlocks.InsertOnSubmit(dbb); dc.SubmitChanges(); Controller.log("Added " + fileName); } } catch (Exception e) { Controller.errorLog("Error adding " + fileName); Controller.errorLog("Error adding block " + path + "\n" + e.StackTrace); } finally { Monitor.JobFinished(); } }