示例#1
0
        public UInt32 AddDBlock(DemodulatedBlock db)
        {
            lock (dbAddLock)
            {
                mySqlComm = mySql.CreateCommand();
                // extract the data that we're going to put in the sql database
                string clusterName  = db.Config.Settings["cluster"] as string;
                int    clusterIndex = (int)db.Config.Settings["clusterIndex"];
                string aTag         = "";
                bool   eState       = (bool)db.Config.Settings["eState"];
                bool   bState       = (bool)db.Config.Settings["bState"];
                bool   rfState      = (bool)db.Config.Settings["rfState"];
                // for some blocks, no mw state config
                bool mwState = true;
                if (db.Config.Settings.StringKeyList.Contains("mwState"))
                {
                    mwState = (bool)db.Config.Settings["mwState"];
                }

                DateTime timeStamp   = db.TimeStamp;
                double   ePlus       = (double)db.Config.Settings["ePlus"];
                double   eMinus      = (double)db.Config.Settings["eMinus"];
                byte[]   dBlockBytes = serializeDBlockAsByteArray(db);

                mySqlComm             = mySql.CreateCommand();
                mySqlComm.CommandText =
                    "INSERT INTO DBLOCKS " +
                    "VALUES(?uint, ?cluster, ?clusterIndex, ?aTag, ?eState, ?bState, ?rfState, ?mwState, ?ts, " +
                    "?ePlus, ?eMinus);";
                // the uid column is defined auto_increment
                mySqlComm.Parameters.AddWithValue("?uint", null);
                mySqlComm.Parameters.AddWithValue("?cluster", clusterName);
                mySqlComm.Parameters.AddWithValue("?clusterIndex", clusterIndex);
                mySqlComm.Parameters.AddWithValue("?aTag", aTag);
                mySqlComm.Parameters.AddWithValue("?eState", eState);
                mySqlComm.Parameters.AddWithValue("?bState", bState);
                mySqlComm.Parameters.AddWithValue("?rfState", rfState);
                mySqlComm.Parameters.AddWithValue("?mwState", mwState);
                mySqlComm.Parameters.AddWithValue("?ts", timeStamp);
                mySqlComm.Parameters.AddWithValue("?ePlus", ePlus);
                mySqlComm.Parameters.AddWithValue("?eMinus", eMinus);

                mySqlComm.ExecuteNonQuery();
                mySqlComm.Parameters.Clear();

                UInt32 uid = (UInt32)mySqlComm.LastInsertedId;
                mySqlComm             = mySql.CreateCommand();
                mySqlComm.CommandText =
                    "INSERT INTO DBLOCKDATA VALUES(?uint, ?dblock);";
                mySqlComm.Parameters.AddWithValue("?uint", uid);
                mySqlComm.Parameters.AddWithValue("?dblock", dBlockBytes);

                mySqlComm.ExecuteNonQuery();
                mySqlComm.Parameters.Clear();

                return(uid);
            }
        }
示例#2
0
        public ChannelSet <TOFWithError> TOFAccumulate(uint[] uids, string detector)
        {
            TOFChannelSetAccumulator tcsa = new TOFChannelSetAccumulator();

            for (uint i = 0; i < uids.Length; i++)
            {
                DemodulatedBlock db = (DemodulatedBlock)blockStore.GetDBlock(uids[i]);
                tcsa.Add((ChannelSet <TOFWithError>)db.GetTOFChannelSet(detector));
            }

            return(tcsa.GetResult());
        }
示例#3
0
        /* 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.");
        }
示例#4
0
        /* 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);
            }
        }
示例#5
0
        private byte[] serializeDBlockAsByteArray(DemodulatedBlock db)
        {
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream    ms = new MemoryStream();

            bf.Serialize(ms, db);
            byte[] buffer = new Byte[ms.Length];
            ms.Seek(0, SeekOrigin.Begin);
            ms.Read(buffer, 0, (int)ms.Length);
            ms.Close();
            return(buffer);
        }
示例#6
0
        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();
        }
示例#7
0
        public void AcquisitionFinished(Block b)
        {
            this.Block = b;
            mainWindow.AppendToTextArea("Demodulating block.");
            b.AddDetectorsToBlock();
            DBlock         = blockDemodulator.QuickDemodulateBlock(b);
            AnalysedDBlock = QuickEDMAnalysis.AnalyseDBlock(DBlock);
            liveViewer.AddAnalysedDBlock(AnalysedDBlock);

            //config.g
            haveBlock = true;
            appState  = AppState.stopped;
            mainWindow.AppendToTextArea("Acquisition finished");
            SetStatusReady();
        }
示例#8
0
        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();
        }
示例#9
0
        public uint[] GetUIDsByPredicate(PredicateFunction func, uint[] fromUIDs)
        {
            QueryCount++;
            mySqlComm             = mySql.CreateCommand();
            mySqlComm.CommandText = "SELECT UID FROM DBLOCKS WHERE UID IN " + MakeSQLArrayString(fromUIDs);
            UInt32[]      uids        = GetUIDsFromCommand(mySqlComm);
            List <UInt32> matchedUIDs = new List <UInt32>();

            foreach (UInt32 uid in uids)
            {
                DemodulatedBlock db = GetDBlock(uid);
                if (func(db))
                {
                    matchedUIDs.Add(uid);
                }
            }
            return(matchedUIDs.ToArray());
        }
示例#10
0
        //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);
        }
示例#11
0
        //public void Clear()
        //{
        //}

        public void AddDBlock(DemodulatedBlock dblock)
        {
            QuickEDMAnalysis analysis = QuickEDMAnalysis.AnalyseDBlock(dblock);

            //Append LiveViewer text with edm errors, B, DB & DB/SIG
            AppendStatusText(
                (Math.Pow(10, 26) * analysis.RawEDMErr).ToString("G3")
                + "\t" + (Math.Pow(10, 26) * analysis.RawEDMErrNormed).ToString("G3")
                + "\t\t" + (analysis.BValAndErr[0]).ToString("N2")
                + "\t" + (analysis.DBValAndErr[0]).ToString("N2")
                + "\t" + (analysis.DBValAndErr[0] / analysis.SIGValAndErr[0]).ToString("N3")
                + Environment.NewLine);

            // Rollings values of edm error
            clusterVariance =
                ((clusterVariance * (blockCount - 1)) + analysis.RawEDMErr * analysis.RawEDMErr) / blockCount;
            double edmPerDay = Math.Sqrt(clusterVariance / blocksPerDay);

            clusterVarianceNormed =
                ((clusterVarianceNormed * (blockCount - 1))
                 + analysis.RawEDMErrNormed * analysis.RawEDMErrNormed) / blockCount;
            double edmPerDayNormed = Math.Sqrt(clusterVarianceNormed / blocksPerDay);

            UpdateClusterStatusText(
                "errorPerDay: " + edmPerDay.ToString("E3")
                + "\terrorPerDayNormed: " + edmPerDayNormed.ToString("E3")
                + Environment.NewLine + "block count: " + blockCount);

            //Update Plots
            AppendToSigScatter(new double[] { blockCount }, new double[] { analysis.SIGValAndErr[0] });
            AppendToSigNoiseScatter(new double[] { blockCount }, new double[] { analysis.SIGValAndErr[1] });
            AppendToBScatter(new double[] { blockCount }, new double[] { analysis.BValAndErr[0] });
            AppendToDBScatter(new double[] { blockCount }, new double[] { analysis.DBValAndErr[0] });
            AppendToEDMScatter(new double[] { blockCount },
                               new double[] { Math.Pow(10, 26) * analysis.RawEDMErr });
            AppendToEDMNormedScatter(new double[] { blockCount },
                                     new double[] { Math.Pow(10, 26) * analysis.RawEDMErrNormed });
            AppendSigmaToSIGScatter(new double[] { blockCount },
                                    new double[] { analysis.SIGValAndErr[0] + analysis.SIGValAndErr[1] },
                                    new double[] { analysis.SIGValAndErr[0] - analysis.SIGValAndErr[1] });
            AppendSigmaToBScatter(new double[] { blockCount },
                                  new double[] { analysis.BValAndErr[0] + analysis.BValAndErr[1] },
                                  new double[] { analysis.BValAndErr[0] - analysis.BValAndErr[1] });
            AppendSigmaToDBScatter(new double[] { blockCount },
                                   new double[] { analysis.DBValAndErr[0] + analysis.DBValAndErr[1] },
                                   new double[] { analysis.DBValAndErr[0] - analysis.DBValAndErr[1] });
            AppendToNorthLeakageScatter(new double[] { blockCount },
                                        new double[] { analysis.NorthCurrentValAndError[0] });
            AppendToSouthLeakageScatter(new double[] { blockCount },
                                        new double[] { analysis.SouthCurrentValAndError[0] });
            AppendToNorthLeakageErrorScatter(new double[] { blockCount },
                                             new double[] { analysis.NorthCurrentValAndError[1] });
            AppendToSouthLeakageErrorScatter(new double[] { blockCount },
                                             new double[] { analysis.SouthCurrentValAndError[1] });
            AppendToNorthECorrLeakageScatter(new double[] { blockCount },
                                             new double[] { analysis.NorthECorrCurrentValAndError[0] });
            AppendToSouthECorrLeakageScatter(new double[] { blockCount },
                                             new double[] { analysis.SouthECorrCurrentValAndError[0] });
            AppendToMagNoiseScatter(new double[] { blockCount },
                                    new double[] { analysis.MagValandErr[1] });
            AppendToRfCurrentScatter(new double[] { blockCount },
                                     new double[] { analysis.rfCurrent[0] });
            AppendToLF1Scatter(new double[] { blockCount }, new double[] { analysis.LFValandErr[0] });
            AppendToLF1NoiseScatter(new double[] { blockCount }, new double[] { analysis.LFValandErr[1] });
            AppendToRF1AScatter(new double[] { blockCount }, new double[] { analysis.rf1AmpAndErr[0] });
            AppendToRF2AScatter(new double[] { blockCount }, new double[] { analysis.rf2AmpAndErr[0] });
            AppendToRF1FScatter(new double[] { blockCount }, new double[] { analysis.rf1FreqAndErr[0] });
            AppendToRF2FScatter(new double[] { blockCount }, new double[] { analysis.rf2FreqAndErr[0] });

            if (blockCount == 1)
            {
                initProbePD = analysis.probePD[0];
                initPumpPD  = analysis.pumpPD[0];
            }
            AppendTopProbePDScatter(new double[] { blockCount }, new double[] { analysis.probePD[0] / initProbePD });
            AppendTopPumpPDScatter(new double[] { blockCount }, new double[] { analysis.pumpPD[0] / initPumpPD });

            AppendToLF1DBDBScatter(new double[] { blockCount }, new double[] { analysis.LF1DBDB[0] });
            AppendToLF2DBDBScatter(new double[] { blockCount }, new double[] { analysis.LF2DBDB[0] });
            AppendSigmaToLF1Scatter(new double[] { blockCount },
                                    new double[] { analysis.LF1DBDB[0] + analysis.LF1DBDB[1] },
                                    new double[] { analysis.LF1DBDB[0] - analysis.LF1DBDB[1] });
            AppendSigmaToLF2Scatter(new double[] { blockCount },
                                    new double[] { analysis.LF2DBDB[0] + analysis.LF2DBDB[1] },
                                    new double[] { analysis.LF2DBDB[0] - analysis.LF2DBDB[1] });

            blockCount = blockCount + 1;
        }