Exemple #1
0
 protected void SetParameterStatus(RdmParameters parameter, ParameterStatus status)
 {
     parameterStatus[parameter] = status;
 }
Exemple #2
0
        private void FillSpectrum(byte[] sdata, ISpectrum spectrum, ParameterStatus status)
        {
            //read group
            uint size;

            using (MemoryStream stream = new MemoryStream(sdata)) {
                BinaryReader reader = new BinaryReader(stream);
                try {
                    size = reader.ReadUInt32();
                    reader.ReadString();
                    //int position = sizeof(byte) + BitConverter.ToInt16(sdata, 0);
                    float fit = reader.ReadSingle();
                    if (status > 0)
                    {
                        spectrum.Fit = fit; // ReadSingle(sdata, ref position);
                    }
                    byte g, c, p, cc, cs;
                    while (stream.Position < size)
                    {
                        g = reader.ReadByte(); // sdata[position++];
                        if (spectrum.Parameters[g] is ContributedGroup)
                        {
                            ReadParameter(reader, ((ContributedGroup)spectrum.Parameters[g]).contribution, status);
                        }
                        else
                        {
                            ReadParameter(reader, null, 0);
                        }
                        cc = reader.ReadByte();
                        cs = reader.ReadByte();

                        //resize spectrum if neccessary
                        if (spectrum.Parameters[g].Components.Size != cc &&
                            spectrum.Parameters[g].Definition.componentCount == 0 ||
                            spectrum.Parameters[g].Components.Size != spectrum.Parameters[g].Definition.componentCount)
                        {
                            spectrum.Parameters[g].Components.Size = cc;
                        }

                        if (spectrum.Parameters[g].Components.Size > 0)
                        {
                            for (c = 0; c < cc; c++)
                            {
                                for (p = 0; p < cs; p++)
                                {
                                    if (c < spectrum.Parameters[g].Components.Size && p < spectrum.Parameters[g].Components[0].Size)
                                    {
                                        ReadParameter(reader, spectrum.Parameters[g].Components[c][p], status);
                                    }
                                    else
                                    {
                                        ReadParameter(reader, null, 0);
                                    }
                                }
                            }
                        }
                        else
                        {
                            reader.ReadBytes(6 * cc * cs);
                            //position += (sizeof(float) + sizeof(byte) + sizeof(byte)) * cc * cs;
                        }
                    }
                } catch (EndOfStreamException) {
                } finally {
                    reader.Close();
                }
            }
        }
Exemple #3
0
 public abstract void RestoreSpectrumStartingValues(ISpectrum spectrum, ParameterStatus status);
Exemple #4
0
 internal void FillSpectrum(ISpectrum spectrum, int dataId, ParameterStatus status)
 {
     FillSpectrum(this.data[dataId], spectrum, status);
 }
Exemple #5
0
 public void FillSpectrum(ISpectrum spectrum, ParameterStatus status)
 {
     this.FillSpectrum(spectrum, FindSpectrum(spectrum.Name), status);
 }
Exemple #6
0
        public virtual int setparams(IParameterSet ps, IParameter[] a, bool[] ai, bool[] f, ParameterStatus status, ISpectrum spectrum)
        {
            int        g, c, p;
            int        pc        = 0;
            int        bufferpos = ps.BufferStart;
            bool       commonf   = (status & (ParameterStatus.Common | ParameterStatus.Free)) == (ParameterStatus.Common | ParameterStatus.Free);
            IParameter ip;

            for (g = 1; g < ps.GroupCount; g++)
            {
                for (c = 0; c < ps[g].Components.Size; c++)
                {
                    for (p = 0; p < ps[g].Components[c].Size; p++)
                    {
                        ip = ps[g].Components[c][p];
                        if ((p == 0 && c == 0) || (ip.Definition.Properties & ParameterProperties.Unsearchable) == ParameterProperties.Unsearchable)
                        {
                            continue;
                        }
                        else
                        {
                            checkParameter(ip, spectrum, CheckOptions.RefreshDelta | CheckOptions.SetDefaultValues);
                            pc++;
                            if (a != null)
                            {
                                a[bufferpos] = ip;
                            }
                            if (ai != null && f != null)
                            {
                                if (ai[bufferpos] = (ip.Status & status) == status && !ip.HasReferenceValue)  //if parameter doesnt have desired status then it is out of search
                                //ai[bufferpos] = (p == 0) && (f[0] || ps[g].Definition.kind == 3 || commonf) || //if intensity and either: includeints OR prompt intensity OR common intensity
                                //    (f[0] && p == 3 && ps[g].Definition.kind == 4); //or include ints and background is the analysing parameter
                                {
                                    ai[bufferpos] = f[0] && (p == 0 || ps[g].Definition.kind == 4) || //if intensity or background with included intensities se to true
                                                    ps[g].Definition.kind == 3 ||                     //prompt always included
                                                    !f[0] && p > 0 && ps[g].Definition.kind < 4;
                                }
                            }
                            bufferpos++;
                        }
                    }
                }
                if (ps[g].Definition.kind == 2)   //only source contribution may be putted into search
                {
                    ip = ((ContributedGroup)ps[g]).contribution;
                    if ((ip.Definition.Properties & ParameterProperties.Unsearchable) != ParameterProperties.Unsearchable)
                    {
                        checkParameter(ip, spectrum, CheckOptions.RefreshDelta | CheckOptions.SetDefaultValues);
                        pc++;
                        if (a != null)
                        {
                            a[bufferpos] = ip;
                        }
                        if (ai != null && f != null)
                        {
                            if (ai[bufferpos] = (ip.Status & status) == status && !ip.HasReferenceValue) //if parameter doesnt have defined status then it is out of search
                            {
                                ai[bufferpos] = f[0] || f[1];                                            // (f[1] && commonf);
                            }
                        }
                        bufferpos++;
                    }
                }
            }
            return(pc);
        }
Exemple #7
0
 public StatusChangeEventArgs(IGroup group, ISpectrum spectrum, List <ISpectrum> spectra, IParameter parameter, ParameterStatus status)
     : base()
 {
     this.group     = group;
     this.spectrum  = spectrum;
     this.parameter = parameter;
     this.status    = status;
     this.spectra   = spectra;
 }
Exemple #8
0
 public ParameterDefinition(string Name, ParameterStatus DefaultStatus, ParameterProperties Properties)
     : this(Name, Name, ParameterStatus.None, DefaultStatus, null, Properties)
 {
 }
Exemple #9
0
 public ParameterDefinition(string Name, string Header, ParameterStatus BindedStatus, ParameterStatus DefaultStatus,
                            CalculateParameterValueHandler CalculateParameterValue, ParameterProperties properties)
 {
     this.Name = Name;
     if (Header == Name)
     {
         this.Header = String.Format("[p text='{0}']", Name);
     }
     else
     {
         this.Header = Header;
     }
     this.BindedStatus            = BindedStatus;
     this.CalculateParameterValue = CalculateParameterValue;
     this.DefaultStatus           = DefaultStatus;
     this.Properties = properties;
 }
Exemple #10
0
 public ParameterDefinition(string Name, ParameterProperties Properties, ParameterStatus BindedStatus)
     : this(Name, Name, BindedStatus, BindedStatus, null, Properties)
 {
 }
Exemple #11
0
 public ParameterDefinition(string Name, ParameterProperties properties, ParameterStatus BindedStatus, CalculateParameterValueHandler CalculateParameterValue)
     : this(Name, Name, BindedStatus, ParameterStatus.Local | ParameterStatus.Fixed, CalculateParameterValue, properties)
 {
 }
Exemple #12
0
 public ParameterDefinition(string Name, string Header, ParameterStatus DefaultStatus)
     : this(Name, Header, ParameterStatus.None, DefaultStatus, null, 0)
 {
 }
Exemple #13
0
        public override void normalizeAfterSearch(SearchLevel sl, PrepareOptions po, bool flagOnly)
        {
            int             gid, cid;
            double          sum, ifree;
            ParameterStatus status = ParameterStatus.Free;

            switch (sl)
            {
            case SearchLevel.Local: status |= ParameterStatus.Local; break;

            case SearchLevel.Global: status |= ParameterStatus.Common; break;
                //case SearchLevel.Preliminary: status |= ParameterStatus.Local | ParameterStatus.Common; break;
            }
            //sample, source, prompt
            for (gid = 1; gid < 4; gid++)
            {
                if (_parameters[gid].Components.Size == 0)
                {
                    continue;
                }
                if (gid < 3 && (po & PrepareOptions.ComponentIntensities) == 0)
                {
                    continue;
                }
                if (gid == 3 && (po & PrepareOptions.PromptIntensities) == 0)
                {
                    continue;
                }
                sum   = 1;
                ifree = 1;
                if (_parameters[gid].Components.IntensitiesState == ComponentIntsState.PreparedToSearch)
                {
                    if ((_parameters[gid].Components[0][0].Status & status) == status)
                    {
                        if (!flagOnly)
                        {
                            for (cid = 1; cid < _parameters[gid].Components.Size; cid++)
                            {
                                if ((_parameters[gid].Components[cid][0].Status & ParameterStatus.Fixed) > 0)
                                {
                                    ifree -= _parameters[gid].Components[cid][0].Value;
                                }
                                else
                                {
                                    sum += _parameters[gid].Components[cid][0].Value * _parameters[gid].Components[cid][0].Value;
                                }
                            }
                            for (cid = 0; cid < _parameters[gid].Components.Size; cid++)
                            {
                                if (((_parameters[gid].Components[cid][0].Status & ParameterStatus.Free) > 0)) // && !_parameters[gid].Components[cid][0].HasReferenceValue)
                                {
                                    _parameters[gid].Components[cid][0].Value = ifree * _parameters[gid].Components[cid][0].Value * _parameters[gid].Components[cid][0].Value / sum;
                                }
                            }
                        }
                        _parameters[gid].Components.IntensitiesState = ComponentIntsState.Normed;
                    }
                }
            }
            if ((po & PrepareOptions.ComponentIntensities) > 0)
            {
                if ((((ContributedGroup)_parameters[2]).contribution.Status & status) == status && !((ContributedGroup)_parameters[2]).contribution.HasReferenceValue)
                {
                    ((ContributedGroup)_parameters[2]).contribution.Value = Math.Abs(((ContributedGroup)_parameters[2]).contribution.Value) / (1 + Math.Abs(((ContributedGroup)_parameters[2]).contribution.Value));
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Procedura przygotowująca parametry widma do odpowiedniego typu procedury minimalizacyjnej
        /// - Pole pod krzywą w zależności od wybranego zakresu
        /// - Intensywności funkcji zdolności rozdzielczej
        /// </summary>
        /// <param name="sm"></param>
        public override void prepareToSearch(SearchLevel sl, PrepareOptions po)
        {
            int             i, c, g;
            ParameterStatus status = ParameterStatus.Free;

            switch (sl)
            {
            case SearchLevel.Local: status |= ParameterStatus.Local; break;

            case SearchLevel.Global: status |= ParameterStatus.Common; break;
            }
            if ((po & PrepareOptions.GlobalArea) == PrepareOptions.GlobalArea)
            {
                //pole pod krzywą eksperymentalną w wybranym zakresie
                this._rangeArea = 0;
                //for (i = 0; i < this._experimentalSpectrum.Length-1; i++)
                //    this._rangeArea += this._experimentalSpectrum[i];
                //this._rangeArea -= (int)((this._experimentalSpectrum.Length - 2) * _parameters[4].Components[0][3].Value);

                for (i = this._dataBufferStart; i <= this._dataBufferStop; i++)
                {
                    this._rangeArea += this._container.Data[i];
                }
                this._rangeArea -= (int)(this._dataLength * _parameters[4].Components[0][3].Value);
            }
            if ((po & PrepareOptions.ComponentIntensities) == PrepareOptions.ComponentIntensities)
            {
                for (g = 1; g < 3; g++)
                {
                    if (_parameters[g].Components.Size > 0)
                    {
                        if ((_parameters[g].Components[0][0].Status & status) == status && _parameters[g].Components.IntensitiesState != ComponentIntsState.PreparedToSearch)
                        {
                            _parameters[g].Components.IntensitiesState = ComponentIntsState.PreparedToSearch;
                            for (c = 1; c < _parameters[g].Components.Size; c++)
                            {
                                if ((_parameters[g].Components[c][0].Status & status) == status) // && !_parameters[g].Components[c][0].HasReferenceValue)
                                {
                                    _parameters[g].Components[c][0].Value = Math.Sqrt(Math.Abs(_parameters[g].Components[c][0].Value / _parameters[g].Components[0][0].Value));
                                }
                            }
                        }
                        //if ((_parameters[g].Components[0][0].Status & status) == status)
                        _parameters[g].Components[0][0].Value = 1.0;
                    }
                }
                if ((((ContributedGroup)_parameters[2]).contribution.Status & status) == status && !((ContributedGroup)_parameters[2]).contribution.HasReferenceValue)
                {
                    ((ContributedGroup)_parameters[2]).contribution.Value = 1 / (1 / ((ContributedGroup)_parameters[2]).contribution.Value - 1);
                }
            }
            if ((po & PrepareOptions.PromptIntensities) == PrepareOptions.PromptIntensities)
            {
                //intensywności funkcji zdolności rozdzielczej. Muszą być tak przekonwertowane, by
                //pierwszy wyraz był równy 1
                if (_parameters[3].Components.Size > 0)
                {
                    if ((_parameters[3].Components[0][0].Status & status) == status && _parameters[3].Components.IntensitiesState != ComponentIntsState.PreparedToSearch)
                    {
                        _parameters[3].Components.IntensitiesState = ComponentIntsState.PreparedToSearch;
                        for (c = 1; c < _parameters[3].Components.Size; c++)
                        {
                            if ((_parameters[3].Components[c][0].Status & status) == status) // && !_parameters[3].Components[c][0].HasReferenceValue)
                            {
                                _parameters[3].Components[c][0].Value = Math.Sqrt(_parameters[3].Components[c][0].Value / _parameters[3].Components[0][0].Value);
                            }
                        }
                    }
                    //if ((_parameters[3].Components[0][0].Status & status) == status)
                    _parameters[3].Components[0][0].Value = 1.0;
                }
            }
        }
Exemple #15
0
 protected bool IsParameterStatus(RdmParameters parameter, ParameterStatus status)
 {
     return(GetParameterStatus(parameter) == status);
 }
Exemple #16
0
        public static async Task <(BackendMessageObject msg, Int32 msgSize)> ReadBackendMessageAsync(
            MessageIOArgs ioArgs,
            ResizableArray <ResettableTransformable <Int32?, Int32> > columnSizes
            )
        {
            var args   = ioArgs.Item1;
            var stream = ioArgs.Item2;
            var token  = ioArgs.Item3;
            var buffer = ioArgs.Item4;
            var code   = (BackendMessageCode)(await args.ReadByte(stream, buffer, token));
            var length = await args.ReadInt32(stream, buffer, token);

            var remaining = length - sizeof(Int32);

            if (code != BackendMessageCode.DataRow && code != BackendMessageCode.CopyData)
            {
                // Just read the whole message at once for everything else except DataRow and CopyData messages
                buffer.CurrentMaxCapacity = remaining;
                await stream.ReadSpecificAmountAsync(buffer.Array, 0, remaining, token);

                remaining = 0;
            }
            var array    = buffer.Array;
            var encoding = args.Encoding.Encoding;

            BackendMessageObject result;

            switch (code)
            {
            case BackendMessageCode.AuthenticationRequest:
                result = new AuthenticationResponse(array, length);
                break;

            case BackendMessageCode.ErrorResponse:
                result = new PgSQLErrorObject(array, encoding, true);
                break;

            case BackendMessageCode.NoticeResponse:
                result = new PgSQLErrorObject(array, encoding, false);
                break;

            case BackendMessageCode.RowDescription:
                result = new RowDescription(array, encoding);
                break;

            case BackendMessageCode.DataRow:
                (result, remaining) = await DataRowObject.ReadDataRow(args, stream, token, array, columnSizes, remaining);

                break;

            case BackendMessageCode.ParameterDescription:
                result = new ParameterDescription(array);
                break;

            case BackendMessageCode.ParameterStatus:
                result = new ParameterStatus(array, encoding);
                break;

            case BackendMessageCode.ReadyForQuery:
                result = new ReadyForQuery(array);
                break;

            case BackendMessageCode.BackendKeyData:
                result = new BackendKeyData(array);
                break;

            case BackendMessageCode.CommandComplete:
                result = new CommandComplete(array, encoding);
                break;

            case BackendMessageCode.NotificationResponse:
                result = new NotificationMessage(array, encoding);
                break;

            case BackendMessageCode.CopyInResponse:
                result = new CopyInOrOutMessage(array, true);
                break;

            case BackendMessageCode.CopyOutResponse:
                result = new CopyInOrOutMessage(array, false);
                break;

            case BackendMessageCode.CopyData:
                result = new CopyDataMessage(length);
                break;

            case BackendMessageCode.ParseComplete:
                result = MessageWithNoContents.PARSE_COMPLETE;
                break;

            case BackendMessageCode.BindComplete:
                result = MessageWithNoContents.BIND_COMPLETE;
                break;

            case BackendMessageCode.EmptyQueryResponse:
                result = MessageWithNoContents.EMPTY_QUERY;
                break;

            case BackendMessageCode.NoData:
                result = MessageWithNoContents.NO_DATA;
                break;

            case BackendMessageCode.CopyDone:
                result = MessageWithNoContents.COPY_DONE;
                break;

            case BackendMessageCode.CloseComplete:
                result = MessageWithNoContents.CLOSE_COMPLETE;
                break;

            default:
                throw new NotSupportedException("Not supported backend response: " + code);
            }

            return(result, remaining);
        }
Exemple #17
0
        public string GetParameterValue(IsoluctionParameterDto isoluctionParameterDto, DataBaseProvider baseProvider,
                                        string connectionString, out ParameterStatus exists)
        {
            IDbConnection dbConnection = null;

            exists = ParameterStatus.DoesNotExist;

            try
            {
                var theSelect = "select " + isoluctionParameterDto.ColumnOrField + " from " +
                                isoluctionParameterDto.Table +
                                (string.IsNullOrEmpty(isoluctionParameterDto.Where)
                                    ? ""
                                    : " where " + isoluctionParameterDto.Where);

                DbCommand dbCommand;
                switch (baseProvider)
                {
                case DataBaseProvider.Oracle:
                    dbConnection = new OracleConnection(connectionString);
                    dbConnection.Open();
                    dbCommand = new OracleCommand(theSelect,
                                                  (OracleConnection)dbConnection);
                    break;

                case DataBaseProvider.SqlServer:
                    dbConnection = new SqlConnection(connectionString);
                    dbConnection.Open();
                    dbCommand = new SqlCommand(theSelect, (SqlConnection)dbConnection);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(baseProvider), baseProvider, null);
                }

                var dataTable = new DataTable();
                dataTable.Load(dbCommand.ExecuteReader());

                foreach (DataRow row in dataTable.Rows)
                {
                    if (DBNull.Value.Equals(row[isoluctionParameterDto.ColumnOrField]))
                    {
                        exists = ParameterStatus.NullOrEmpty;
                        return(string.Empty);
                    }

                    if (row[isoluctionParameterDto.ColumnOrField].ToString() == " ")
                    {
                        exists = ParameterStatus.NullOrEmpty;
                        return(string.Empty);
                    }

                    if (string.IsNullOrEmpty(row[isoluctionParameterDto.ColumnOrField].ToString()))
                    {
                        exists = ParameterStatus.NullOrEmpty;
                        return(string.Empty);
                    }

                    exists = ParameterStatus.Exist;
                    return(row[isoluctionParameterDto.ColumnOrField].ToString());
                }

                exists = ParameterStatus.DoesNotExist;
                return(string.Empty);
            }
            catch (Exception e)
            {
                exists = ParameterStatus.DoesNotExist;
                return(e.ToString());
            }
            finally
            {
                if (dbConnection != null && dbConnection.State == ConnectionState.Open)
                {
                    dbConnection.Close();
                }
            }
        }
Exemple #18
0
        //public virtual List<IParameter> getParameters(ParameterStatus status, IParameterSet parameters, bool[] includeFlags) {
        public virtual IEnumerable <IParameter> getParameters(ParameterStatus status, ISpectrum spectrum, bool[] includeFlags, CheckOptions co)
        {
            //List<IParameter> result = new List<IParameter>();
            bool includeInts          = includeFlags[0];
            bool includeSourceContrib = includeFlags[1];
            bool promptOnly           = includeFlags[2];
            //result.Add(null);
            IGroup group;
            //foreach (IGroup group in parameters) {
            int cid, pid;

            for (int gr = 1; gr < spectrum.Parameters.GroupCount; gr++)
            {
                group = spectrum.Parameters[gr];
                if (promptOnly && group.Definition.kind != 3)
                {
                    continue;
                }
                //foreach (IComponent component in group.Components) {
                for (cid = 0; cid < group.Components.Size; cid++)
                {
                    //foreach (IParameter parameter in component) {
                    for (pid = 0; pid < group.Components[cid].Size; pid++)
                    {
                        if (pid == 0 && cid == 0)
                        {
                            continue;
                        }
                        if ((group.Components[cid][pid].Definition.Properties & ParameterProperties.Unsearchable) == ParameterProperties.Unsearchable)
                        {
                            continue;
                        }
                        if (((group.Components[cid][pid].Status & status) == status) &&
                            !((group.Components[cid][pid].Definition.Name == "int") && (group.Components[cid][pid] == group.Components[0])))
                        {
                            if (!includeInts && (group.Components[cid][pid].Definition.Name == "int") &&
                                !(group.Definition.kind == 3) &&                                                                                       //prompt intensities are always put into Search parameters
                                !(group.Components[cid][pid].Definition.Name == "int" && (status & ParameterStatus.Common) == ParameterStatus.Common)) //common intensities are also always put into search
                            {
                                continue;
                            }
                            switch (group.Definition.kind)
                            {
                            case 4:     //ranges
                                if (includeInts && (group.Components[cid][pid].Definition.Name == "background") && !group.Components[cid][pid].HasReferenceValue)
                                {
                                    yield return(addParameter(group.Components[cid][pid], spectrum, co));
                                }
                                break;

                            default:
                                yield return(addParameter(group.Components[cid][pid], spectrum, co));

                                //if (group.Definition.kind == 3 && cid > 0 && pid == 2)
                                //    group.Components[cid][pid].Delta /= 10;
                                break;
                            }
                        }
                    }
                }
                if (((group.Definition.Type & GroupType.Contributet) == GroupType.Contributet) &&
                    ((group.Definition.Type & GroupType.CalcContribution) != GroupType.CalcContribution) &&
                    (group.Components.Size > 0))
                {
                    IParameter contribution = ((ContributedGroup)group).contribution;
                    if ((contribution.Status & status) == status)
                    {
                        switch (group.Definition.kind)
                        {
                        /*sample*/
                        case 1:
                            yield return(addParameter(contribution, spectrum, co));

                            break;

                        /*source*/
                        case 2:
                            if (!((contribution.Status & ParameterStatus.Fixed) == ParameterStatus.Fixed))
                            {
                                if (includeInts || (includeSourceContrib && ((contribution.Status & ParameterStatus.Common)) == ParameterStatus.Common))
                                {
                                    yield return(addParameter(contribution, spectrum, co));
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }