예제 #1
0
        public string PrepRawStreams(ulong num, bool combineDuplicateHits = false)
        {
            const UInt64 RollOverShakes = UInt64.MaxValue;

            string issue = String.Empty;
            ulong  dups = 0, events = 0;

            Double lasttime = 0;
            UInt64 timeUI8B4 = 0;
            UInt64 timeUI8Shakes = 0, circuits = 0;
            double firstread = 0;

            try
            {
                uint chann_els = 0;
                foreach (double time in times)
                {
                    events++;

                    if (events > num)
                    {
                        events--;
                        break;
                    }

                    timeUI8Shakes = Convert.ToUInt64(time);

                    if (events == 1)
                    {
                        if (FirstEventTimeInShakes == 0)
                        {
                            FirstEventTimeInShakes = timeUI8Shakes;
                        }
                        firstread = time;
                    }

                    if (timeUI8Shakes >= RollOverShakes)  // first 184467440737.09551615 ... secs are handled quickly, but here we must do a moddiv
                    {
                        throw new Exception("Sorry, relative event times greater 184467440737 seconds are unsupported");
                    }
                    if (lasttime > time) // ooops!
                    {
                        throw new Exception(String.Format("{0}, {1} ({2}, {3}) out-of-order, you forgot to sort", lasttime, time, timeUI8B4, timeUI8Shakes));
                    }
                    else if (timeUI8B4 == timeUI8Shakes) // found a duplicate!
                    {
                        dups++;
                        if (combineDuplicateHits)
                        {
                            if (0 != (chann_els & channels[events]))
                            {
                                logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate channel hit event {0} [{1:x8}] at time {2}", events, channels[events], timeUI8B4);
                            }
                            else
                            {
                                chann_els |= channels[events];
                                logger.TraceEvent(LogLevels.Verbose, 3331, "Combining hits [{0:x8}] from duplicate event {1} ({2})[{3:x8}] at time {4}", chann_els, NumValuesParsed, events, channels[events], timeUI8B4);
                            }
                        }
                        else
                        {
                            logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate event {0} [{1:x8}] at time {2} (due to rounding)", events, channels[events], timeUI8B4);
                        }
                        continue;
                    }

                    timeUI8B4 = timeUI8Shakes;

                    // fill in the arrays for the analyzers
                    chann_els |= channels[NumValuesParsed];
                    neutronEventArray[(int)NumValuesParsed] = chann_els;

                    // todo: can use the skipchannels single channel flag to optimize this loop to a single increment in hitsPerChn
                    for (short i = 0; i < NC.ChannelCount; i++)  // count channel hits here
                    {
                        if ((neutronEventArray[(int)NumValuesParsed] & chnmask[i]) != 0)
                        {
                            hitsPerChn[i]++;
                            NumTotalsEncountered++;
                        }
                    }

                    timeArray[(int)NumValuesParsed] = timeUI8B4;
                    chann_els = 0;

                    if (!usingStreamRawAnalysis) // drop them in, one by one
                    {
                        Sup.HandleANeutronEvent(timeArray[(int)NumValuesParsed], neutronEventArray[(int)NumValuesParsed]);
                    }

                    NumValuesParsed++;
                    lasttime = time;
                }

                logger.TraceEvent(LogLevels.Verbose, 3338, "Converted {0} hits ({1} events) between {2} and {3} shakes ({4} rollovers) ({5} duplicates skipped)({6})", events, NumValuesParsed, firstread, lasttime, circuits, dups, num);
            }
            catch (Exception e)
            {
                logger.TraceEvent(LogLevels.Verbose, 3339, "Converted {0} hits ({1} events) between {2} and {3} shakes ({4} rollovers) ({5} duplicates skipped)({6})", events, NumValuesParsed, firstread, lasttime, circuits, dups, num);
                logger.TraceEvent(LogLevels.Warning, 3363, "Error parsing pulses encountered '{0}'", e.Message);
                NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                issue = e.Message;
            }
            TotalEvents     += events;
            TotalDups       += dups;
            LastTimeInShakes = timeUI8Shakes;
            return(issue);
        }
예제 #2
0
        public string PrepRawStreams(ulong num, byte[] chnbytes, bool combineDuplicateHits = false)
        {
            UInt64 ROllOverShakes = UInt64.MaxValue;

            string issue = String.Empty;
            ulong  dups = 0, events = 0;
            uint   channels = NCCFile.ByteArray.ToUInt32(chnbytes);


            Double lasttime = 0;
            UInt64 timeUI8B4 = 0;
            UInt64 timeUI8Shakes = 0, circuits = 0;
            double firstread = 0;

            try
            {
                foreach (double time in timeInBuffer)
                {
                    events++;

                    if (events > num)
                    {
                        events--;
                        break;
                    }

                    timeUI8Shakes = Convert.ToUInt64(time);

                    if (events == 1)
                    {
                        if (FirstEventTimeInShakes == 0)
                        {
                            FirstEventTimeInShakes = timeUI8Shakes;
                        }
                        firstread = time;
                    }

                    if (timeUI8Shakes >= ROllOverShakes)  // first 184467440737... secs are handled quickly, but here we must do a moddiv
                    {
                        throw new Exception("Sorry, times greater 184467440737 seconds (about 5.8K years) are unsupported, but soon will be!");
                    }
                    if (lasttime > time) // ooops!
                    {
                        throw new Exception(String.Format("{0}, {1} ({2}, {3}) out-of-order, you forgot to sort", lasttime, time, timeUI8B4, timeUI8Shakes));
                    }
                    else if (timeUI8B4 == timeUI8Shakes) // a duplicate !
                    {
                        dups++;
                        logger.TraceEvent(LogLevels.Verbose, 3337, "Skipping duplicate event {0} at time {1} (due to hit within the same shake)", events, timeUI8B4);
                        continue;
                    }

                    timeUI8B4 = timeUI8Shakes;

                    // fill in the arrays for the analyzers
                    if (skipchannels)
                    {
                        neutronEventArray[(int)NumValuesParsed] = channels;
                    }
                    else
                    {
                        channels = NCCFile.ByteArray.ToUInt32(chnbytes);
                    }

                    // todo: can use the skipchannels single channel flag to optimize this loop to a single increment in hitsPerChn
                    for (short i = 0; i < NC.ChannelCount; i++)  // count channel hits here
                    {
                        if ((channels & chnmask[i]) != 0)
                        {
                            hitsPerChn[i]++;
                            NumTotalsEncountered++;
                        }
                    }

                    timeArray[(int)NumValuesParsed] = timeUI8B4;

                    if (!usingStreamRawAnalysis) // drop them in, one by one
                    {
                        Sup.HandleANeutronEvent(timeArray[(int)NumValuesParsed], neutronEventArray[(int)NumValuesParsed]);
                    }

                    NumValuesParsed++;

                    lasttime = time;
                }

                logger.TraceEvent(LogLevels.Verbose, 3338, "Converted {0} events between {1} and {2} shakes ({3} rollovers) ({4} duplicates skipped)", events, firstread, lasttime, circuits, dups);
            }
            catch (Exception e)
            {
                logger.TraceEvent(LogLevels.Verbose, 3339, "Converted {0} events between {1} and {2} shakes ({3} rollovers) ({4} duplicates skipped)", events, firstread, lasttime, circuits, dups);
                logger.TraceEvent(LogLevels.Warning, 3363, "Error parsing pulses encountered '{0}'", e.Message);
                NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                issue = e.Message;
            }
            TotalEvents     += events;
            TotalDups       += dups;
            LastTimeInShakes = timeUI8Shakes;
            return(issue);
        }