예제 #1
0
        protected void PTRFilePairAssay()
        {

            List<string> ext = new List<string>() { ".chn", ".bin" };
            FileList<PTRFilePair> hdlr = new FileList<PTRFilePair>();
            FileList<PTRFilePair> files = null;
            hdlr.Init(ext, datalog);

            // initialize operation timer here
            NC.App.Opstate.ResetTimer(0, filegather, files, 170, (int)NC.App.AppContext.StatusTimerMilliseconds);
            FireEvent(EventType.ActionPrep, this);
            NC.App.Opstate.StampOperationStartTime();


            // get the list of files from the named folder, or use the supplied list
            if (NC.App.AppContext.FileInputList == null)
                files = (FileList<PTRFilePair>)hdlr.BuildFileList(NC.App.AppContext.FileInput, NC.App.AppContext.Recurse, false);
            else
                files = (FileList<PTRFilePair>)hdlr.BuildFileList(NC.App.AppContext.FileInputList);
            if (files == null || files.Count() < 1)
            {
                NC.App.Opstate.StopTimer(0);
                return;
            }
            int removed = files.RemoveAll(f => f.PairEntryFileExtension(".chn"));
            if (files.Count() < 1)
            {
                NC.App.Opstate.StopTimer(0);
                return;
            }

            Measurement meas = NC.App.Opstate.Measurement;

            PseudoInstrument = new LMDAQ.LMInstrument(meas.Detectors[0]);  // psuedo LM until we can map from user or deduce from file content at run-time
            PseudoInstrument.selected = true;
            if (!Instruments.Active.Contains(PseudoInstrument))
                Instruments.Active.Add(PseudoInstrument); // add to global runtime list

            // Force RDT.State to be a LM ptrFile file RDT, this shows a design failure, so need to rework the entire scheme, (like there is still time . . .)
            LMRawDataTransform rdt = (PseudoInstrument as LMDAQ.LMInstrument).RDT;
            rdt.SetLMState(((LMConnectionInfo)(PseudoInstrument.id.FullConnInfo)).NetComm);
            PTRFileProcessingState c = new PTRFileProcessingState(rdt.State.maxValuesInBuffer * 2, (LMProcessingState)PseudoInstrument.RDT.State);  // expects 8 bytes, we only use 4
            PseudoInstrument.RDT.State = c;
            rdt.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis));
            rdt.RawDataBuff = null;// free it back up, don't need it

            NC.App.Opstate.ResetTimer(0, this.neutronCountingPrep, 0, 170, (int)NC.App.AppContext.StatusTimerMilliseconds / 4);
            DataSourceIdentifier did = meas.Detectors[0].Id;
            rdt.SetupCountingAnalyzerHandler(NC.App.Config, did.source.TimeBase(did.SRType), // 1e-8 expected here
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Verbose, 439, "Neutron counting processing complete: '" + s + "'");
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 438, "Neutron counting processing stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 437, "Neutron counting processing [Block] stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        }
                    );


            meas.AcquireState.num_runs = (ushort)files.Count(); // RequestedRepetitions

            rdt.PrepareAndStartCountingAnalyzers(meas.AnalysisParams);
            NC.App.Opstate.StopTimer(0);

            FireEvent(EventType.ActionStart, this);

            meas.CurrentRepetition = 0;
            NC.App.Opstate.ResetTimer(0, filerawprocessing, PseudoInstrument, 250, (int)NC.App.AppContext.StatusTimerMilliseconds);

            PTRFileProcessingState pps = PseudoInstrument.RDT.State as PTRFileProcessingState;
            foreach (var ptrFile in files)
            {
                if (NC.App.Opstate.IsQuitRequested)  // cancellation occurs here and at selected steps in the internal file and analyzer processing 
                    break;
                if (!ptrFile.OpenForReading())
                    continue;
                PseudoInstrument.PendingReset();
                if (meas.CurrentRepetition == 0)
                {
                    meas.MeasDate = new DateTimeOffset(ptrFile.DTO.Ticks, ptrFile.DTO.Offset);
                    meas.Detectors[0].Id.source = ConstructedSource.PTRFile;
                    PseudoInstrument.id.source = ConstructedSource.PTRFile;
                }

                Cycle cycle = new Cycle(ctrllog);
                cycle.UpdateDataSourceId(ConstructedSource.PTRFile, InstrType.PTR32 /* revisit this, it could be from any source */,
                                         ptrFile.DTO, ptrFile.Filename);
                meas.Add(cycle);
                rdt.StartCycle(cycle);
                meas.CurrentRepetition++;
                pps.Reset();
                NC.App.Opstate.SOH = NCC.OperatingState.Living;
                PseudoInstrument.id.FileName = ptrFile.Filename;

                ctrllog.TraceEvent(LogLevels.Info, 3335, "Assaying with {0}", ptrFile.Filename);
                /// unique here
                UInt32 deltaTime = 0;
                Double ShakeTime; // like pulse files 10^e-8

                int maxValuesInBuffer = (int)pps.maxValuesInBuffer;
                try
                {

                    UInt32[] chnmask = new UInt32[32];
                    for (int i = 0; i < 32; i++)
                    {
                        chnmask[i] = (uint)1 << i;
                    }

                    rdt.NumProcessedRawDataBuffers = 0;
                    string issue = String.Empty;

                    //read the header from the BIN file
                    ptrFile.Events.ReadHeader();
                    ShakeTime = 0;
                    //Add this as check. We should have this count - big T as final count rate
                    pps.PTRReportedCountTime += ptrFile.Events.ReportedCountTime;
                    if (!ptrFile.Channels.Active)
                    {
                        ptrFile.Channels.fulllen = ptrFile.Events.stream.Length;
                    }
                    while (ptrFile.Channels.read < ptrFile.Channels.fulllen && String.IsNullOrEmpty(issue))
                    {
                        rdt.NumProcessedRawDataBuffers++;

                        // divide file size into discrete lengths of a reasonable size, say 50Mb or a 128 Mb default
                        int elen = (ptrFile.Events.eventsectionlen > pps.eventBufferLength ? (int)pps.eventBufferLength : (int)ptrFile.Events.eventsectionlen);
                        int clen = (ptrFile.Channels.fulllen > maxValuesInBuffer ? maxValuesInBuffer : (int)ptrFile.Channels.fulllen);

                        // read the times up to the buffer limit
                        int events = Math.Min(maxValuesInBuffer, elen / sizeof(UInt32));
                        events = Math.Min(events, ptrFile.Events.EventsYetToRead());  // might be at the last buffers-worth, check and constrain
                        ptrFile.Events.thisread = ptrFile.Events.ReadUInt32Array(pps.timeInBuffer, 0, events);
                        ptrFile.Events.read += ptrFile.Events.thisread;

                        // read or simulate the channel bytes
                        if (ptrFile.Channels.Active)
                        {
                            ptrFile.Channels.thisread = ptrFile.Channels.reader.Read(pps.chnInBuffer, 0, clen);
                            ptrFile.Channels.read += ptrFile.Channels.thisread;
                        }
                        else  // fake it with a single channel, an empty channel mask means channel 1
                        {
                            ptrFile.Channels.read += clen;
                        }

                        // Todo: fix this because could be or'ing over the buffer end, so this will blow
                        int edi = -1;  // actual events
                        for (int ec = 0; ec < events; ec++) // raw event counts
                        {
                            deltaTime = pps.timeInBuffer[ec];
                            if (deltaTime == 0) // or the channel mask                            
                            {
                                pps.channels[edi] |= chnmask[pps.chnInBuffer[ec]];
                                ptrFile.Log.TraceEvent(LogLevels.Verbose, 3246, "multiple hits {0:x8} at {1} ({2} {3})", pps.channels[edi], ShakeTime, edi, ec);
                                continue;
                            }

                            edi++;  // the next event
                            ShakeTime += deltaTime; // accumulate total time

                            //set the neutron event with the new neutron
                            pps.channels[edi] = chnmask[pps.chnInBuffer[ec]];
                            //set the event time with the new neutron time
                            pps.times[edi] = ShakeTime;

                            if (pps.channels[edi] == 0)
                                ptrFile.Log.TraceEvent(LogLevels.Warning, 3334, "0 event at {0}", ShakeTime);

                            // ptrFile.Log.TraceEvent(LogLevels.Verbose, 777, "{0} {1} [{2:x8}]", ae, pps.times[ae], pps.channels[ae]);
                        }
                        int counted = edi + 1;
                        ptrFile.Log.TraceEvent(LogLevels.Verbose, 3336, "constructed buffer {0} of {1} hits for {2} neutrons", rdt.NumProcessedRawDataBuffers, counted, events);

                        // push the time doubles through the pipeline
                        StreamStatusBlock ssb = rdt.PassBufferToTheCounters(counted);
                        if (ssb != null)
                        {
                            rdt.ParseStatusBlock(ssb, cycle);
                            ctrllog.TraceEvent(LogLevels.Verbose, 412, "End of stream, status message at byte {0}, len {1}", ssb.index, ssb.msglen);
                        }

                        rdt.StartNewBuffer();

                        ctrllog.TraceEvent(LogLevels.Verbose, 411, "[{0}] Counted {1} triggers, {2} hits, over {3} secs", rdt.NumProcessedRawDataBuffers, cycle.TotalEvents, cycle.Totals, cycle.TS.TotalSeconds);
                        NC.App.Loggers.Flush();

                        if (NC.App.Opstate.IsQuitRequested)  // cancellation in between buffers
                        {
                            ctrllog.TraceEvent(LogLevels.Warning, 428, "Processing cancelled, stopped at " + BufferStateSnapshot(PseudoInstrument));
                            break;
                        }
                    }
                }
                catch (FatalNeutronCountingException e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e);
                    ctrllog.TraceEvent(LogLevels.Warning, 429, "Neutron counting incomplete: {0}, processing stopped at {1}", e.Message, BufferStateSnapshot(PseudoInstrument));
                }
                catch (Exception e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e, true);
					ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + BufferStateSnapshot(PseudoInstrument));
                }
                finally
                {
                    ptrFile.CloseReader();
                    if (meas.CurrentRepetition == 1)// this is the first file, create the results before they get used 
                    {
                        meas.PrepareINCCResults();
                        meas.Persist();
                    }
                    rdt.EndOfCycleProcessing(meas);
                    rdt.FlushCycleSummaryResults();
                    NC.App.Loggers.Flush();
                }
                FireEvent(EventType.ActionInProgress, this);
            } // loop over each PTR-32 file (pair)
            rdt.EndOfCycleProcessing(meas, last:true);

            PseudoInstrument.selected = false;

            FireEvent(EventType.ActionInProgress, this);

            NC.App.Opstate.StopTimer(0);

            if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available
            { 
                //if (meas.HasReportableData)
                //{
                // if we have more than one cycle (one per file), and the cycles are combined into a 'measurement', then do the meta-processing across the results cycle list here
                NC.App.Opstate.ResetTimer(1, postprocessing, meas, 50, (int)NC.App.AppContext.StatusTimerMilliseconds);

                meas.CalculateMeasurementResults();

                NC.App.Opstate.StopTimer(1);
                FireEvent(EventType.ActionInProgress, this);

                ReportMangler rm = new ReportMangler(ctrllog);
                rm.GenerateReports(meas);

                meas.SaveMeasurementResults();
            }

            NC.App.Opstate.ResetTokens();
            Instruments.All.Remove(PseudoInstrument);

            NC.App.Opstate.SOH = NCC.OperatingState.Stopping;
            NC.App.Opstate.StampOperationStopTime();
            FireEvent(EventType.ActionStop, this);

        }
예제 #2
0
        /// <summary>
        /// Process a list of NCD files
        /// </summary>
        void NCDFileAssay()
        {
            if (!NC.App.Opstate.Measurement.Detectors[0].ListMode)
                ctrllog.TraceEvent(LogLevels.Warning, 439, NC.App.Opstate.Measurement.Detectors[0].Id.DetectorName + " is not a list mode detector.");

            List<string> ext = new List<string>() { ".ncd" };
            FileList<NCDFile> hdlr = new FileList<NCDFile>();
            hdlr.Init(ext, ctrllog);
            FileList<NCDFile> files = null;

            /// this section now occurs in the caller, the state is set up earlier
            Measurement meas = NC.App.Opstate.Measurement;

            PseudoInstrument = new LMDAQ.LMInstrument(meas.Detectors[0]);  // psuedo LM until we can map from user or deduce from file content at run-time
            PseudoInstrument.selected = true;
            if (!Instruments.Active.Contains(PseudoInstrument))
                Instruments.Active.Add(PseudoInstrument); // add to global runtime list
            DataSourceIdentifier did = meas.Detectors[0].Id;
            LMRawDataTransform rdt = (LMRawDataTransform)PseudoInstrument.RDT;
            rdt.SetLMState(((LMConnectionInfo)(PseudoInstrument.id.FullConnInfo)).NetComm);

            // initialize operation timer here
            NC.App.Opstate.ResetTimer(0, filegather, files, 170, (int)NC.App.AppContext.StatusTimerMilliseconds);
            FireEvent(EventType.ActionPrep, this);
            NC.App.Opstate.StampOperationStartTime();

            // get the list of files from the named folder, or use the supplied list
            if (NC.App.AppContext.FileInputList == null)
                files = (FileList<NCDFile>)hdlr.BuildFileList(NC.App.AppContext.FileInput, NC.App.AppContext.Recurse, false);
            else
                files = (FileList<NCDFile>)hdlr.BuildFileList(NC.App.AppContext.FileInputList);
            if (files == null || files.Count() < 1)
            {
                NC.App.Opstate.StopTimer(0);
                return;
            }

            NC.App.Opstate.ResetTimer(0, this.neutronCountingPrep, 0, 170, (int)NC.App.AppContext.StatusTimerMilliseconds / 4);

            rdt.SetupCountingAnalyzerHandler(NC.App.Config, did.source.TimeBase(did.SRType),
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Verbose, 439, "Neutron counting processing complete: '" + s + "'");
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 438, "Neutron counting processing stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 437, "Neutron counting processing [Block] stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        }
                    );


            meas.AcquireState.num_runs = (ushort)files.Count(); // RequestedRepetitions

            rdt.PrepareAndStartCountingAnalyzers(meas.AnalysisParams);
            NC.App.Opstate.StopTimer(0);

            FireEvent(EventType.ActionStart, this);

            meas.CurrentRepetition = 0;
            NC.App.Opstate.ResetTimer(0, filerawprocessing, PseudoInstrument, 250, (int)NC.App.AppContext.StatusTimerMilliseconds);
            foreach (var ncd in files)
            {
                if (NC.App.Opstate.IsQuitRequested)  // cancellation occurs here and at selected steps in the internal file and analyzer processing 
                    break;
                if (!ncd.OpenForReading())
                    continue;
                PseudoInstrument.PendingReset();
                if (meas.CurrentRepetition == 0)
                {
                    meas.MeasDate = ncd.DTO;
                    meas.Detectors[0].Id.source = ConstructedSource.NCDFile;
                    PseudoInstrument.id.source = ConstructedSource.NCDFile;
                }

                Cycle cycle = new Cycle(ctrllog);
                cycle.UpdateDataSourceId(ConstructedSource.NCDFile, InstrType.LMMM /* revisit this, it could be from any source */,
                                         ncd.DTO, ncd.Filename);
                meas.Add(cycle);
                rdt.StartCycle(cycle);
                meas.CurrentRepetition++;
                rdt.NumProcessedRawDataBuffers = 0;
                int thisread = 0;
                long read = 0, fulllen = ncd.stream.Length;
                NC.App.Opstate.SOH = NCC.OperatingState.Living;
                PseudoInstrument.id.FileName = ncd.Filename;

                ctrllog.TraceEvent(LogLevels.Info, 3335, "Assaying with {0}", ncd.Filename);

                try
                {
                    while (read < fulllen)
                    {
                        rdt.NumProcessedRawDataBuffers++;
                        // divide file size into discrete lengths of a reasonable size, say 50Mb or a 128 Mb default
                        int len = (fulllen > (int)rdt.CurEventBuffLen ? (int)rdt.CurEventBuffLen : (int)fulllen);

                        thisread = ncd.reader.Read(rdt.RawDataBuff, 0, len);
                        read += thisread;

                        ctrllog.TraceEvent(LogLevels.Verbose, 410, "Processing buffer {0} of {1} bytes", rdt.NumProcessedRawDataBuffers, len);

                        // push the bytes through the pipeline
                        StreamStatusBlock res = rdt.PassBufferToTheCounters(thisread);
                        if (res != null)
                        {
                            rdt.ParseStatusBlock(res, cycle);
                            // assert read >= fullen here, because we found a valid status block at the end of the file
                            ctrllog.TraceEvent(LogLevels.Verbose, 412, "End of stream, status message at byte {0}, len {1}", res.index, res.msglen);
                        }

                        rdt.StartNewBuffer();

                        ctrllog.TraceEvent(LogLevels.Verbose, 411, "[{0}] Counted {1} triggers, {2} hits, over {3} secs", rdt.NumProcessedRawDataBuffers, cycle.TotalEvents, cycle.Totals, cycle.TS.TotalSeconds);
                        NC.App.Loggers.Flush();

                        if (NC.App.Opstate.IsQuitRequested)  // cancellation in between buffers
                        {
                            ctrllog.TraceEvent(LogLevels.Warning, 428, "Processing cancelled, stopped at " + BufferStateSnapshot(PseudoInstrument));
                            break;
                        }

                    }
                }
                catch (FatalNeutronCountingException e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e);
                    ctrllog.TraceEvent(LogLevels.Warning, 429, "Neutron counting incomplete: {0}, processing stopped at {1}", e.Message, BufferStateSnapshot(PseudoInstrument));
                }
                catch (Exception e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e, true);
					ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + BufferStateSnapshot(PseudoInstrument));
                }
                finally
                {
                    ncd.CloseReader();
                    if (meas.CurrentRepetition == 1)// this is the first file, create the results before they get used 
                    {
                        meas.PrepareINCCResults();
                        meas.Persist();
                    }
                    rdt.EndOfCycleProcessing(meas);
                    NC.App.Loggers.Flush();
                }
                FireEvent(EventType.ActionInProgress, this);
            } // loop over each NCD file

            PseudoInstrument.selected = false;
            rdt.EndOfCycleProcessing(meas, last: true);

            FireEvent(EventType.ActionInProgress, this);

            NC.App.Opstate.StopTimer(0);
            if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available
            {
                //if (meas.HasReportableData)
                //{
                // if we have more than one cycle (one per file), and the cycles are combined into a 'measurement', then do the meta-processing across the results cycle list here
                NC.App.Opstate.ResetTimer(1, postprocessing, meas, 50, (int)NC.App.AppContext.StatusTimerMilliseconds);

                meas.CalculateMeasurementResults();

                NC.App.Opstate.StopTimer(1);
                FireEvent(EventType.ActionInProgress, this);

                ReportMangler rm = new ReportMangler(ctrllog);
                rm.GenerateReports(meas);

                meas.SaveMeasurementResults();
                //}
            }

            NC.App.Opstate.ResetTokens();
            Instruments.All.Remove(PseudoInstrument);

            NC.App.Opstate.SOH = NCC.OperatingState.Stopping;
            NC.App.Opstate.StampOperationStopTime();
            FireEvent(EventType.ActionStop, this);

        }
예제 #3
0
        void PassThru(Measurement m) // preserve existing measurement without re-computing it
        {
            ctrllog.TraceEvent(LogLevels.Info, 34072, "Preserve this: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'");
            NC.App.Opstate.Measurement = m;
            m.AcquireState.comment += " pass-through";
            MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults.First().Value;
            // need to get alpha beta onto the summary too.
            mcr.AB.TransferIntermediates(m.Detectors[0].AB);

            // sum per-cycle channel hits
            m.CycleSummary(false);

            ReportMangler rm = new ReportMangler(ctrllog);
            rm.GenerateReports(m);

            m.PersistFileNames();
        }
예제 #4
0
        void Replay(Measurement m, ConstructedSource src)
        {
            ctrllog.TraceEvent(LogLevels.Info, 34071, "Replay this: '" + m.MeasurementId.MeasDateTime.ToString() + ", " + m.MeasOption.PrintName() + "'");
            m.AcquireState.comment += " replay";
            // todo: make sure assay type on measurement is not overridden by cmd line artifacts 
            NC.App.Opstate.Measurement = m;
            SRInstrument PseudoInstrument = new SRInstrument(m.Detectors[0]);  // psuedo LM until we can map from user or deduce from file content at run-time
            PseudoInstrument.id.source = ConstructedSource.INCCTransfer;
            // remove PseudoInstrument.id.SetSRType(PseudoInstrument.id.Type); // hack, the SR type should be pre-defined by an earlier import of a INCCInitialDataDetectorFile
            PseudoInstrument.selected = true;
            if (!Instruments.Active.Contains(PseudoInstrument))
                Instruments.Active.Add(PseudoInstrument); // add to global runtime list

            m.CurrentRepetition = 0;
            NC.App.Opstate.SOH = NCC.OperatingState.Living;
            try
            {
                MultiplicityCountingRes mcr = (MultiplicityCountingRes)m.CountingAnalysisResults.First().Value;
                for (int i = 0; i < mcr.RAMult.Length; i++)  // count again using the per-cycle accumulation of summary results
                    mcr.RAMult[i] = 0;
                for (int i = 0; i < mcr.NormedAMult.Length; i++)
                    mcr.NormedAMult[i] = 0;
                m.Detectors[0].Id.source = src;
                // need to get alpha beta onto the summary too.
                mcr.AB.TransferIntermediates(m.Detectors[0].AB);

                foreach (AnalysisDefs.Cycle cycle in m.Cycles)
                {
                    if (NC.App.Opstate.IsCancellationRequested)  // cancellation occurs here and at selected steps in the internal file and analyzer processing 
                        break;
                    m.CurrentRepetition++;
                    CycleProcessing.ApplyTheCycleConditioningSteps(cycle, m);
                    m.CycleStatusTerminationCheck(cycle);
                }
            }
            catch (Exception e)
            {
                NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                ctrllog.TraceException(e, true);
				ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + m.CurrentRepetition);
            }
            finally
            {
                NC.App.Loggers.Flush();
            }
			// todo: 			if (meas.HasReportableData)
            m.CalculateMeasurementResults();

            ReportMangler rm = new ReportMangler(ctrllog);
            rm.GenerateReports(m);

            m.SaveMeasurementResults();

            Instruments.All.Remove(PseudoInstrument);
        }
예제 #5
0
        protected void SortedPulseFileAssay()
        {

            List<string> ext = new List<string>() { ".pulse.sorted", ".txt.sorted" };
            FileList<SortedPulseFile> hdlr = new FileList<SortedPulseFile>();
            hdlr.Init(ext, ctrllog);
            FileList<SortedPulseFile> files = null;

            // initialize operation timer here
            NC.App.Opstate.ResetTimer(0, filegather, files, 170, (int)NC.App.AppContext.StatusTimerMilliseconds);
            FireEvent(EventType.ActionPrep, this);
            NC.App.Opstate.StampOperationStartTime();

            // get the list of files from the named folder
            files = (FileList<SortedPulseFile>)hdlr.BuildFileList(NC.App.AppContext.FileInput, NC.App.AppContext.Recurse, true);
            if (files == null || files.Count() < 1)
            {
                NC.App.Opstate.StopTimer(0);
                return;
            }

            Measurement meas = NC.App.Opstate.Measurement;

            PseudoInstrument = new LMDAQ.LMInstrument(meas.Detectors[0]);  // psuedo LM until we can map from user or deduce from file content at run-time
            PseudoInstrument.selected = true;
            if (!Instruments.Active.Contains(PseudoInstrument))
                Instruments.Active.Add(PseudoInstrument); // add to global runtime list

            // Force RDT.State To be a pulse file RDT, this shows a design failure, so need to rework the entire scheme
            LMRawDataTransform rdt = (PseudoInstrument as LMDAQ.LMInstrument).RDT;
            PulseProcessingState c = new PulseProcessingState(rdt.State.maxValuesInBuffer);
            PseudoInstrument.RDT.State = null;
            PseudoInstrument.RDT.State = c;
            rdt.Init(NC.App.Loggers.Logger(LMLoggers.AppSection.Data), NC.App.Loggers.Logger(LMLoggers.AppSection.Analysis));
            rdt.SetLMState(((LMConnectionInfo)(PseudoInstrument.id.FullConnInfo)).NetComm);
            rdt.RawDataBuff = null;// free it back up, don't need it

            NC.App.Opstate.ResetTimer(0, this.neutronCountingPrep, 0, 170, (int)NC.App.AppContext.StatusTimerMilliseconds / 4);
            DataSourceIdentifier did = meas.Detectors[0].Id;
            rdt.SetupCountingAnalyzerHandler(NC.App.Config, did.source.TimeBase(did.SRType), // 1e-8 expected here
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Verbose, 439, "Neutron counting processing complete: '" + s + "'");
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 438, "Neutron counting processing stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        },
                        (string s) =>
                        {
                            PseudoInstrument.PendingComplete();
                            ctrllog.TraceEvent(LogLevels.Error, 437, "Neutron counting processing [Block] stopped with error: '" + s + "'");
                            rdt.EndAnalysisImmediately();
                            throw new FatalNeutronCountingException(s);  // emergency exit, caught and noted in file processing loop below
                        }
                    );


            meas.AcquireState.num_runs = (ushort)files.Count(); // RequestedRepetitions

            rdt.PrepareAndStartCountingAnalyzers(meas.AnalysisParams);
            NC.App.Opstate.StopTimer(0);

            FireEvent(EventType.ActionStart, this);

            meas.CurrentRepetition = 0;
            NC.App.Opstate.ResetTimer(0, filerawprocessing, PseudoInstrument, 250, (int)NC.App.AppContext.StatusTimerMilliseconds);

            Random rand = new Random();
            int a = rand.Next(0, 3);
            byte byt = (byte)(1 << (byte)rand.Next(1, 7));
            PulseProcessingState pps = PseudoInstrument.RDT.State as PulseProcessingState;
            foreach (var sortedpulse in files)
            {
                if (NC.App.Opstate.IsQuitRequested)  // cancellation occurs here and at selected steps in the internal file and analyzer processing 
                    break;
                if (!sortedpulse.OpenForReading())
                    continue;
                PseudoInstrument.PendingReset();
                if (meas.CurrentRepetition == 0)
                {
                    meas.MeasDate = new DateTimeOffset(sortedpulse.DTO.Ticks, sortedpulse.DTO.Offset);
                    meas.Detectors[0].Id.source = ConstructedSource.SortedPulseTextFile;
                    PseudoInstrument.id.source = ConstructedSource.SortedPulseTextFile;
                }

                Cycle cycle = new Cycle(ctrllog);
                cycle.UpdateDataSourceId(ConstructedSource.SortedPulseTextFile, InstrType.LMMM, // MCNPX is common source of pulse files, but we need an explicit LM type here /* revisit this, it could be from any source */,
                          sortedpulse.DTO, sortedpulse.Filename);
                meas.Add(cycle);
                rdt.StartCycle(cycle);
                meas.CurrentRepetition++;
                pps.Reset();
                NC.App.Opstate.SOH = NCC.OperatingState.Living;
                PseudoInstrument.id.FileName = sortedpulse.Filename;

                ctrllog.TraceEvent(LogLevels.Info, 3335, "Assaying with {0}", sortedpulse.Filename);
                try
                {
                    pps.chnbytes[a] = byt;  // use the same rand value for all these files, makes for consistent per-channel rates counting
                    rdt.NumProcessedRawDataBuffers = 0;
                    string issue = String.Empty;
                    while (!sortedpulse.reader.EndOfStream && String.IsNullOrEmpty(issue))
                    {
                        string s;
                        int rb = 0;
                        rdt.NumProcessedRawDataBuffers++;
                        do
                        {
                            s = sortedpulse.reader.ReadLine();
                            double res = 0;
                            if (Double.TryParse(s, out res))
                            {
                                pps.timeInBuffer[rb++] = res;
                            }
                        } while (!sortedpulse.reader.EndOfStream && rb < pps.maxValuesInBuffer);
                        // now transform the doubles list and assay at the same time

                        ctrllog.TraceEvent(LogLevels.Verbose, 410, "Processing buffer {0} of {1} times", rdt.NumProcessedRawDataBuffers, rb);

                        // push the time doubles through the pipeline
                        StreamStatusBlock ssb = rdt.PassBufferToTheCounters(rb);
                        if (ssb != null)
                        {
                            rdt.ParseStatusBlock(ssb, cycle);
                            // assert read >= fullen here, because we found a valid status block at the end of the file
                            ctrllog.TraceEvent(LogLevels.Verbose, 412, "End of stream, status message at byte {0}, len {1}", ssb.index, ssb.msglen);
                        }

                        rdt.StartNewBuffer();

                        ctrllog.TraceEvent(LogLevels.Verbose, 411, "[{0}] Counted {1} triggers, {2} hits, over {3} secs", rdt.NumProcessedRawDataBuffers, cycle.TotalEvents, cycle.Totals, cycle.TS.TotalSeconds);
                        NC.App.Loggers.Flush();

                        if (NC.App.Opstate.IsQuitRequested)  // cancellation in between buffers
                        {
                            ctrllog.TraceEvent(LogLevels.Warning, 428, "Processing cancelled, stopped at " + BufferStateSnapshot(PseudoInstrument));
                            break;
                        }

                    }
                    // Analysis.StreamStatusBlock sb = NCDFile.CustomStatusBlock("Pulse", NC.App.name + " " + NC.App.Config.VersionString, pf.Filename, issue);

                }
                catch (FatalNeutronCountingException e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e);
                    ctrllog.TraceEvent(LogLevels.Warning, 429, "Neutron counting incomplete: {0}, processing stopped at {1}", e.Message, BufferStateSnapshot(PseudoInstrument));
                }
                catch (Exception e)
                {
                    NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                    ctrllog.TraceException(e, true);
					ctrllog.TraceEvent(LogLevels.Warning, 430, "Processing stopped at cycle " + BufferStateSnapshot(PseudoInstrument));
                }
                finally
                {
                    sortedpulse.CloseReader();
                    if (meas.CurrentRepetition == 1)// this is the first file, create the results before they get used 
                    {
                        meas.PrepareINCCResults();
                        meas.Persist();
                    }
                    rdt.EndOfCycleProcessing(meas);
                    NC.App.Loggers.Flush();
                }
                FireEvent(EventType.ActionInProgress, this);
            } // loop over each NCD file
            rdt.EndOfCycleProcessing(meas, last: true);
            PseudoInstrument.selected = false;

            FireEvent(EventType.ActionInProgress, this);

            NC.App.Opstate.StopTimer(0);
            if (!NC.App.Opstate.IsAbortRequested) // stop/quit means continue with what is available
            {
                //if (meas.HasReportableData)
                //{ 
                // if we have more than one cycle (one per file), and the cycles are combined into a 'measurement', then do the meta-processing across the results cycle list here
                NC.App.Opstate.ResetTimer(1, postprocessing, meas, 50, (int)NC.App.AppContext.StatusTimerMilliseconds);

                meas.CalculateMeasurementResults();

                NC.App.Opstate.StopTimer(1);
                FireEvent(EventType.ActionInProgress, this);

                ReportMangler rm = new ReportMangler(ctrllog);
                rm.GenerateReports(meas);
                meas.SaveMeasurementResults();
                //}
            }

            NC.App.Opstate.ResetTokens();
            Instruments.All.Remove(PseudoInstrument);

            NC.App.Opstate.SOH = NCC.OperatingState.Stopping;
            NC.App.Opstate.StampOperationStopTime();
            FireEvent(EventType.ActionStop, this);

        }
예제 #6
0
파일: Collect.cs 프로젝트: hnordquist/INCC6
        public void OutputResults(NCC.NCCAction action = NCC.NCCAction.Nothing)
        {
            if (action == NCCAction.Nothing)
                action = NC.App.Opstate.Action;
            switch (action)  // these are the actions available from the command line only
            {
                case NCCAction.HVCalibration:
                    if (ctrlHVCalib != null)
                    {
                        collog.TraceInformation("Producing HV Calib results output file");
                        ctrlHVCalib.GenerateReport();
                    }
                    break;

                case NCCAction.Assay:
                    collog.TraceInformation("Producing Assay results output file");
                    ReportMangler rm = new ReportMangler(ctrllog);
                    rm.GenerateReports(CurState.Measurement);
                    NC.App.DB.AddResultsFileNames(CurState.Measurement);
                    break;
            }
        }