⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rec_observ.cpp

📁 电能质量交换格式转换库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    return status;
    }

CPQDIF_E_Vector * CPQDIF_R_Observation::GetSeriesValueVector
            (
            long        idxChannel,
            long        idxSeries
            )
    {
    CPQDIF_E_Vector *       pvectReturn = NULL;

    CPQDIF_E_Collection *   pcolOneSeries;

    pcolOneSeries = GetOneSeries( idxChannel, idxSeries );
    if( pcolOneSeries )
        {
        pvectReturn = FindVectorInCollection( pcolOneSeries, tagSeriesValues );
        }

    return pvectReturn;
    }

bool CPQDIF_R_Observation::SetTriggerInfo
            (
                    UINT4               idTriggerMethod,
                    long                countTriggers,
            const   UINT4 *             aidxTriggerChan,
            const   TIMESTAMPPQDIF&     timeTriggered
            )
{
    bool    status = false;

    CPQDIF_E_Scalar *   psc;
    CPQDIF_E_Vector *   pvect;

    //  Init
    ASSERT( aidxTriggerChan );

    //  First, find (or create) the trigger method
    psc = FindOrCreateScalarInCollection( m_record->m_pcollMain, 
            tagTriggerMethodID, ID_PHYS_TYPE_UNS_INTEGER4 );
    //  Set its value
    if( psc )
    {
        status = psc->SetValueUINT4( idTriggerMethod );
    }

    //  Get triggered channels?
    if( status && idTriggerMethod == ID_TRIGGER_METH_CHANNEL )
    {
        status = false;
        pvect = FindOrCreateVectorInCollection( m_record->m_pcollMain, 
                    tagChannelTriggerIdx, ID_PHYS_TYPE_UNS_INTEGER4 );
        //  Set its value(s)
        if( pvect )
        {
            //  Validate physical type
            if( pvect->GetPhysicalType() == ID_PHYS_TYPE_UNS_INTEGER4 )
            {
                pvect->SetCount( countTriggers );
                for( long idx = 0; idx < countTriggers; idx++ )
                {
                    pvect->SetValueUINT4( idx, aidxTriggerChan[ idx ] );
                }
                status = TRUE;
            }
        }
    }

    //  Set the time it was triggered
    if( status )
    {
        status = false;
        psc = FindOrCreateScalarInCollection( m_record->m_pcollMain,
            tagTimeTriggered, ID_PHYS_TYPE_TIMESTAMPPQDIF );
        //  Set value
        if( psc )
        {
            status = psc->SetValueTimeStamp( timeTriggered );
        }
    }

    return status;
}


long     CPQDIF_R_Observation::GetCountResolvedSeries
            (
            long    idxChannel,
            long    idxSeries,
			bool    noShare
            ) 
{
	int		idx;
    bool    status = false;
    long    countPoints = 0;
    long    idxChannelDefn;
    UINT4   idQuantityUnits;
    GUID    idQuantityCharacteristic;
    GUID    idValueType;
    UINT4   idStorageMethod;

	bool	gotShareChannel = false;
	bool	gotShareSeries = false;
	UINT4	idxShareChannelIdx = 0;
	UINT4	idxShareSeriesIdx = 0;

    CPQDIF_Element *        pel = NULL;
    CPQDIF_E_Collection *   pcol = NULL;
    CPQDIF_E_Vector *       pvectSeriesArray = NULL;

    //  Verify that we're in an observation record
    //  Requires a data source record
    if( m_record && m_pds && idxChannel >= 0 && idxSeries >= 0)
    {
        //  Find the channel defn index
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );

        //  Fail if we got a bogus index
        if( status && idxChannelDefn < 0 )
            status = false;
    }

    //  Get the storage method
    if( status )
    {
        status = m_pds->GetSeriesDefnInfo( idxChannelDefn, idxSeries,
                    idQuantityUnits, idValueType, idQuantityCharacteristic, idStorageMethod );
    }

    //  Look for shared channel and series indices, or a vector of values
    if( status )
    {
        //  Find the series
        pcol = GetOneSeries( idxChannel, idxSeries );
        if( pcol )
        {
            status = true;

            for( idx = 0; idx < pcol->GetCount(); idx++ )
            {
                pel = pcol->GetElement( idx );
                if( pel )
                {
                    if( pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
                    {
                        CPQDIF_E_Scalar *psc = (CPQDIF_E_Scalar *) pel;
                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareChannelIdx ) )
                        {
                            gotShareChannel = TRUE;
                            psc->GetValueUINT4( idxShareChannelIdx );
							if( gotShareSeries )
								break;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareSeriesIdx ) )
                        {
                            gotShareSeries = TRUE;
                            psc->GetValueUINT4( idxShareSeriesIdx );
							if( gotShareChannel )
								break;
                        }
                    }
					else if( pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR
                        && PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesValues ) )
                    {
                        pvectSeriesArray = (CPQDIF_E_Vector *) pel;
						break;
                    }

                }
            }
        }
    }

    //  Now count the values
    if( status )
    {
        if( gotShareChannel && gotShareSeries )
        {
            //  We're sharing the series from somwhere else --
            //  generate it from the shared indices
            if( !noShare )
            {
                countPoints = GetCountResolvedSeries( 
                    (long) idxShareChannelIdx, 
                    (long) idxShareSeriesIdx, 
                    true );  // recurse only once
            }
        }
        else if( pvectSeriesArray )
        {
            //  Generate the new series array
            countPoints = _GenerateSeriesCount( idStorageMethod, pvectSeriesArray);
        }
    }

    return countPoints;
}

double * CPQDIF_R_Observation::NewResolvedSeries
            (
            long    idxChannel,
            long    idxSeries,
            long&   countPoints,
            bool    noShare
            )
{
    bool        status = false;
    int         idx;
    double *    arValues = NULL;

    CPQDIF_Element *        pel = NULL;
    CPQDIF_E_Collection *   pcol = NULL;
    CPQDIF_E_Scalar *       psc = NULL;
    CPQDIF_E_Vector *       pvectSeriesArray = NULL;

    long        typePhysical;
    PQDIFValue  value;
    double      valueReal;

    double      rBaseValue = 1.0;
    double      rScale = 1.0;
    double      rOffset = 0.0;

    long        idxChannelDefn = 0;

    string      name;
    UINT4       idPhase;
    GUID        idQuantityType;
    UINT4       idQuantityMeasured;
    UINT4       idQuantityUnits;
    GUID        idQuantityCharacteristic;
    GUID        idValueType;
    UINT4       idStorageMethod;

    bool        gotShareChannel = false;
    bool        gotShareSeries  = false;
    bool        isShared = false;
    UINT4       idxShareChannelIdx = 0;
    UINT4       idxShareSeriesIdx = 0;

    //  Verify that we're in an observation record
    //  Requires a data source record
    if( m_record && m_pds && idxChannel >= 0 && idxSeries >= 0)
    {
        //  Find the channel defn index
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );

        //  Fail if we got a bogus index
        if( status && idxChannelDefn < 0 )
            status = false;
    }

    //  Gather information from the channel & series definitions
    if( status )
    {
        status = m_pds->GetChannelDefnInfo( idxChannelDefn, name, idPhase, idQuantityType, idQuantityMeasured );
    }
    if( status )
    {
        status = m_pds->GetSeriesDefnInfo( idxChannelDefn, idxSeries,
                    idQuantityUnits, idValueType, idQuantityCharacteristic, idStorageMethod );
    }

    if( status )
    {
        status = false;

        //  Find the series
        pcol = GetOneSeries( idxChannel, idxSeries );
        if( pcol )
        {
            status = TRUE;

            //  Loop through all elements in the series collection
            for( idx = 0; idx < pcol->GetCount(); idx++ )
            {
                pel = pcol->GetElement( idx );
                if( pel )
                {
                    if( pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
                    {
                        psc = (CPQDIF_E_Scalar *) pel;

                        //  If it's REAL4 or REAL8, go ahead and pull it out
                        valueReal = 0.0;
                        psc->GetValue( typePhysical, value );
                        if( typePhysical == ID_PHYS_TYPE_REAL4 )
                        {
                            valueReal = value.real4;
                        }
                        if( typePhysical == ID_PHYS_TYPE_REAL8 )
                        {
                            valueReal = value.real8;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesBaseQuantity ) )
                        {
                            rBaseValue = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesScale ) )
                        {
                            rScale = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesOffset ) )
                        {
                            rOffset = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareChannelIdx ) )
                        {
                            gotShareChannel = TRUE;
                            psc->GetValueUINT4( idxShareChannelIdx );
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareSeriesIdx ) )
                        {
                            gotShareSeries = TRUE;
                            psc->GetValueUINT4( idxShareSeriesIdx );
                        }
                    }

                    if( pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR
                        && PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesValues ) )
                    {
                        pvectSeriesArray = (CPQDIF_E_Vector *) pel;
                    }

                }   //  if( pel )
            }
        }
    }

    //  Generate the series data
    if( status )
    {
        if( gotShareChannel && gotShareSeries )
        {
            //  We're sharing the series from somwhere else --
            //  generate it from the shared indices
            if( !noShare )
            {
                arValues = NewResolvedSeries( 
                    (long) idxShareChannelIdx, 
                    (long) idxShareSeriesIdx, 
                           countPoints, true );
            }
            else
            {
                //  Can't generate! The file is trying to share a series
                //  from another shared series. This is not legal.
                arValues = NULL;
            }
        }
        else if( pvectSeriesArray )
        {
            //  Generate the new series array
            arValues = _GenerateSeriesData( idxChannelDefn, idStorageMethod, 
                rBaseValue, rScale, rOffset, pvectSeriesArray, countPoints );
        }
        else
        {
            //  Can't generate!
            arValues = NULL;
        }
    }

    return arValues;
}


TIMESTAMPPQDIF * CPQDIF_R_Observation::NewResolvedSeriesTimeStamp
            (
            long    idxChannel,
            long    idxSeries,
            long&   countPoints,
            bool    noShare
            )
{
    TIMESTAMPPQDIF *        result = NULL;

    CPQDIF_E_Collection *   pcol;
    CPQDIF_Element *        pel;
    CPQDIF_E_Scalar *       psc;
    CPQDIF_E_Vector *       pvectSeriesArray;

    //  Shared?
    BOOL    gotShareChannel = FALSE;
    BOOL    gotShareSeries = FALSE;
    UINT4   idxShareChannelIdx = 0;
    UINT4   idxShareSeriesIdx = 0;

    pcol = GetOneSeries( idxChannel, idxSeries );
    if( pcol )
    {
        //  Is this sucker shared?
        pel = pcol->GetElement( tagSeriesShareChannelIdx );
        if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
        {
            gotShareChannel = TRUE;
            psc = static_cast<CPQDIF_E_Scalar *>( pel );
            psc->GetValueUINT4( idxShareChannelIdx );
        }

        pel = pcol->GetElement( tagSeriesShareSeriesIdx );
        if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
        {
            gotShareSeries = TRUE;
            psc = static_cast<CPQDIF_E_Scalar *>( pel );
            psc->GetValueUINT4( idxShareSeriesIdx );
        }


        if( gotShareSeries && gotShareSeries && !noShare )
        {
            //  SHARED.
            //  Allow ONE level of recursion -- no more.
            result = NewResolvedSeriesTimeStamp( idxShareChannelIdx, 
                        idxShareSeriesIdx, countPoints, true );
        }
        else
        {
            //  NOT SHARED.
            //  Try to decode it the normal way.
            pel = pcol->GetElement( tagSeriesValues );
            if( pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR )
            {
                pvectSeriesArray = static_cast<CPQDIF_E_Vector *>( pel );


                //  Determine size/allocate space for the timestamp array
                if( pvectSeriesArray->GetCount( countPoints ) )
                {
                    result = new TIMESTAMPPQDIF[ countPoints ];
                    if( result )
                    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -