Logo Search packages:      
Sourcecode: libgdf version File versions  Download package

void gdf::GDFHeaderAccess::sanitize (  )

perform sanity check on header and normalize header information.

If there are issues with the configuration an exception with detailed information is thrown.

Definition at line 64 of file GDFHeaderAccess.cpp.

References gdf::TagHeader::getLength(), gdf::EventHeader::getMode(), gdf::EventHeader::getSamplingRate(), and gdf::EventHeader::setSamplingRate().

Referenced by gdf::Writer::open().

    {
        using boost::lexical_cast;

        std::list< std::string > warnings, errors;

        // ------------ Check number of signals ------------------
        if( m_sighdr.size() == 0 )
            warnings.push_back( "GDF will contain no signals." );

        m_mainhdr.set_num_signals( m_sighdr.size() );

        // ------------ Check signal indices ------------------
        std::map<uint16,SignalHeader>::iterator it = m_sighdr.begin( );
        std::string tmp;
        for( size_t i=0; it != m_sighdr.end(); it++, i++ )
            while( it->first != i )
                tmp = tmp + lexical_cast<std::string>(i++)+',';
        if( tmp.length() > 0 )
        {
            tmp = tmp.substr(0,tmp.length()-1);
            errors.push_back( "Signal indices not contiguous (Missing signals number "+tmp+")." );
        }

        // ------------ Gather Sampling rates ------------------
        std::vector<uint32> fs;
        for( it=m_sighdr.begin( ); it!=m_sighdr.end(); it++ )
        {
            uint32 rate = it->second.get_samplerate( );
            fs.push_back( rate );
        }

        uint32 ddur[2];
        if( fs.size() == 0 )
        {
            // ------------ No Signals: set record duration to 0 ------------------
            ddur[0] = 0;
            ddur[1] = 1;
        }
        else if( drd_den == 0 )
        {
            // ------------ Automatically Set datarecord duration ------------------
            ddur[0] = 1;
            ddur[1] =gcd( fs );

            if( ddur[1] == 0 )  // invalid sampling rates, set record duration to 0
            {
                ddur[0] = 0;
                ddur[1] = 1;
            }
        }
        else
        {
            // ------------ Manually Set datarecord duration ------------------
            if( (gcd(fs) * drd_num) % drd_den != 0 )
                errors.push_back( "(Manually set) record duration does not fit sample rates." );
            ddur[0] = drd_num;
            ddur[1] = drd_den;
        }
        m_mainhdr.set_datarecord_duration( ddur, 2 );

        // ------------ Signal specific information ------------------
        for( it=m_sighdr.begin( ); it!=m_sighdr.end(); it++ )
        {
            // ------------ Check data type ------------------
            if( it->second.get_datatype() == INVALID_TYPE )
                errors.push_back( "Signal "+lexical_cast<std::string>(it->first)+" has no valid data type." );

            // ------------ Check sampling rate ------------------
            it->second.set_samples_per_record( it->second.get_samplerate() * ddur[0] / ddur[1] );
            if( it->second.get_samples_per_record() == 0 )
                errors.push_back( "Signal "+lexical_cast<std::string>(it->first)+" has sample rate set to 0 or not set at all." );

            // ------------ Check ranges ------------------
            if( it->second.get_digmin() > it->second.get_digmax() )
                errors.push_back( "Signal "+lexical_cast<std::string>(it->first)+" has digmin > digmax." );

            if( it->second.get_digmin() == it->second.get_digmax() )
                errors.push_back( "Signal "+lexical_cast<std::string>(it->first)+" has digmin = digmax." );

            if( it->second.get_physmin() == it->second.get_physmax() )
                errors.push_back( "Signal "+lexical_cast<std::string>(it->first)+" has physmin = physmax." );
        }

        m_mainhdr.set_header_length( 1 + m_sighdr.size() + m_taghdr.getLength() );


        if( m_events.getMode() != 1 && m_events.getMode() != 3 )
            errors.push_back( "Event Mode "+lexical_cast<std::string>(m_events.getMode())+" is not valid.");

        if( m_events.getSamplingRate() < 0 )
        {
            if( fs.size() > 0)
                m_events.setSamplingRate( boost::numeric_cast<float32>( max(fs) ) );
            else
                errors.push_back( "Could not determine event sampling rate." );
        }

        if( warnings.size() > 0 || errors.size() > 0 )
            throw exception::header_issues( warnings, errors );
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index