Наследование: System.Data.Linq.DataContext
Пример #1
0
        private BlockStoreDetectorResponse processDetectorQueryAverage(BlockStoreDetectorQuery query, int[] blockIDs)
        {
            BlockStoreDetectorResponse dr = new BlockStoreDetectorResponse();

            dr.Channels = new Dictionary <string, TOFChannel>();
            using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
            {
                IEnumerable <DBTOFChannelSet> tcss = from DBTOFChannelSet tcs in dc.DBTOFChannelSets
                                                     where (tcs.detector == query.Detector) &&
                                                     blockIDs.Contains(tcs.blockID)
                                                     select tcs;
                // accumulate the average TCS
                TOFChannelSetAccumulator tcsa = new TOFChannelSetAccumulator();
                foreach (DBTOFChannelSet dbTcs in tcss)
                {
                    TOFChannelSet t = deserializeTCS(dbTcs.tcsData.ToArray());
                    tcsa.Add(t);
                }
                // TODO: Handle special channels
                TOFChannelSet averageTCS = tcsa.GetResult();
                foreach (string channel in query.Channels)
                {
                    dr.Channels.Add(channel, (TOFChannel)averageTCS.GetChannel(channel));
                }
            }
            return(dr);
        }
Пример #2
0
 public void SetIncluded(string cluster, int clusterIndex, bool included)
 {
     using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
     {
         IEnumerable<DBBlock> b = from DBBlock dbb in dc.DBBlocks
                                  where (dbb.cluster == cluster)
                                  && (dbb.clusterIndex == clusterIndex)
                                  select dbb;
         foreach (DBBlock dbb in b) dbb.include = included;
         dc.SubmitChanges();
     }
 }
Пример #3
0
 public void SetIncluded(string cluster, int clusterIndex, bool included)
 {
     using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
     {
         IEnumerable <DBBlock> b = from DBBlock dbb in dc.DBBlocks
                                   where (dbb.cluster == cluster) &&
                                   (dbb.clusterIndex == clusterIndex)
                                   select dbb;
         foreach (DBBlock dbb in b)
         {
             dbb.include = included;
         }
         dc.SubmitChanges();
     }
 }
Пример #4
0
        private BlockConfig getBlockConfig(int blockID)
        {
            BlockConfig bc = new BlockConfig();

            using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
            {
                IEnumerable <DBBlock> bs = from DBBlock dbb in dc.DBBlocks
                                           where (dbb.blockID == blockID)
                                           select dbb;
                // there should only be one item - better to check or not?
                DBBlock dbbb = bs.First();
                bc = deserializeBC(dbbb.configBytes.ToArray());
            }
            return(bc);
        }
Пример #5
0
        private BlockStoreDetectorResponse processDetectorQuery(BlockStoreDetectorQuery query, int blockID)
        {
            BlockStoreDetectorResponse dr = new BlockStoreDetectorResponse();

            dr.Channels = new Dictionary <string, TOFChannel>();
            using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
            {
                IEnumerable <DBTOFChannelSet> tcss = from DBTOFChannelSet tcs in dc.DBTOFChannelSets
                                                     where (tcs.detector == query.Detector) &&
                                                     (tcs.blockID == blockID)
                                                     select tcs;
                // there should only be one item - better to check or not?
                DBTOFChannelSet tc = tcss.First();
                TOFChannelSet   t  = deserializeTCS(tc.tcsData.ToArray());
                // TODO: Handle special channels
                foreach (string channel in query.Channels)
                {
                    dr.Channels.Add(channel, (TOFChannel)t.GetChannel(channel));
                }
            }
            return(dr);
        }
Пример #6
0
        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)
                    {
                        BlockDemodulator demod    = new BlockDemodulator();
                        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();
            }
        }
Пример #7
0
 private BlockStoreDetectorResponse processDetectorQueryAverage(BlockStoreDetectorQuery query, int[] blockIDs)
 {
     BlockStoreDetectorResponse dr = new BlockStoreDetectorResponse();
     dr.Channels = new Dictionary<string, TOFChannel>();
     using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
     {
         IEnumerable<DBTOFChannelSet> tcss = from DBTOFChannelSet tcs in dc.DBTOFChannelSets
                                             where (tcs.detector == query.Detector)
                                             && blockIDs.Contains(tcs.blockID)
                                             select tcs;
         // accumulate the average TCS
         TOFChannelSetAccumulator tcsa = new TOFChannelSetAccumulator();
         foreach (DBTOFChannelSet dbTcs in tcss)
         {
             TOFChannelSet t = deserializeTCS(dbTcs.tcsData.ToArray());
             tcsa.Add(t);
         }
         // TODO: Handle special channels
         TOFChannelSet averageTCS = tcsa.GetResult();
         foreach (string channel in query.Channels)
             dr.Channels.Add(channel, (TOFChannel)averageTCS.GetChannel(channel));
     }
     return dr;
 }
Пример #8
0
        private BlockStoreDetectorResponse processDetectorQuery(BlockStoreDetectorQuery query, int blockID)
        {
            BlockStoreDetectorResponse dr = new BlockStoreDetectorResponse();
            dr.Channels = new Dictionary<string, TOFChannel>();
            using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
            {
                IEnumerable<DBTOFChannelSet> tcss = from DBTOFChannelSet tcs in dc.DBTOFChannelSets
                                                    where (tcs.detector == query.Detector)
                                                    && (tcs.blockID == blockID)
                                                    select tcs;
                // there should only be one item - better to check or not?
                DBTOFChannelSet tc = tcss.First();
                TOFChannelSet t = deserializeTCS(tc.tcsData.ToArray());
                // TODO: Handle special channels
                foreach (string channel in query.Channels)
                    dr.Channels.Add(channel, (TOFChannel)t.GetChannel(channel));

            }
            return dr;
        }
Пример #9
0
 private BlockConfig getBlockConfig(int blockID)
 {
     BlockConfig bc = new BlockConfig();
     using (BlockDatabaseDataContext dc = new BlockDatabaseDataContext())
     {
         IEnumerable<DBBlock> bs = from DBBlock dbb in dc.DBBlocks
                                   where (dbb.blockID == blockID)
                                   select dbb;
         // there should only be one item - better to check or not?
         DBBlock dbbb = bs.First();
         bc = deserializeBC(dbbb.configBytes.ToArray());
     }
     return bc;
 }
Пример #10
0
        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();
            }
        }