Commit fe31fcdb authored by Marco De Marco's avatar Marco De Marco
Browse files

Mandatory fits properties fix

parent 252df89a
Loading
Loading
Loading
Loading
+48 −6
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ void WorkerThread::workerLoop()
{    
    DEBUG_STREAM << "WorkerThread::workerLoop(): starting loop" << endl;
    
	int waitTime = m_configuration_sp->getWaitTime();
	unsigned int waitTime = m_configuration_sp->getWaitTime();
	std::string watchPath = m_configuration_sp->getWatchPath();
       
    while(true)
@@ -360,6 +360,8 @@ void WorkerThread::execQuery(ConnectionManager::SessionSP session_sp,
		}
		catch(CCfits::HDU::NoSuchKeyword& ex)
		{
            WARN_STREAM << "WorkerThread::execQuery() exception: " << ex.message() << endl;
            
			try
			{
				//Search for secondary fits key (alias)
@@ -370,6 +372,8 @@ void WorkerThread::execQuery(ConnectionManager::SessionSP session_sp,
			}
			catch(CCfits::HDU::NoSuchKeyword& ex)
			{
                WARN_STREAM << "WorkerThread::execQuery() exception: " << ex.message() << endl;
                
				//If key is mandatory throw and exception
				if((*it)->isMandatory())
					throw ex;
@@ -394,12 +398,50 @@ std::string WorkerThread::readKey(CCfits::PHDU& phdu, std::string keyName,
{
    DEBUG_STREAM << "WorkerThread::readKey()" << endl;

    //Use this place to add special parsing if necessary
    //accordingly with data model database mapping
    
    std::stringstream result_stream;

    if(dMDBKeyType.compare("varchar")==0 ||
    boost::regex pattern("^(NAXIS)([0-9]+)$");
    boost::smatch matches;
    
    if(keyName.compare("NAXIS")==0)
    {
        result_stream << phdu.axes();
    }
    else if(boost::regex_match(keyName, matches, pattern))
    {
        long axisMax = phdu.axes();
        
        try
        {
            long axisReq = boost::lexical_cast<long>(matches[2]) - 1;

            if(axisReq<0 || axisReq>=axisMax)
                throw std::runtime_error("Invalid naxis number");

            result_stream << phdu.axis(axisReq);            
        }
        catch(boost::bad_lexical_cast& ex)
        {
            throw std::runtime_error("Exception parsing naxis number");
        }        
    }    
    else if(keyName.compare("BITPIX")==0)
    {
        result_stream << phdu.bitpix();
    }
    else if(keyName.compare("BSCALE")==0)
    {
        result_stream << phdu.scale();
    }    
    else if(keyName.compare("BZERO")==0)
    {
        result_stream << phdu.zero();
    }    
    else if(keyName.compare("EXTEND")==0)
    {
        result_stream << phdu.extend();
    }    
    else if(dMDBKeyType.compare("varchar")==0 ||
        dMDBKeyType.compare("char")==0)
    {
        result_stream << "\'" << extractKey(phdu, keyName, dMDBKeyType) << "\'";
+1 −1

File changed.

Contains only whitespace changes.