Commit 0b54bedc authored by Andrea Bignamini's avatar Andrea Bignamini
Browse files

Read all HDU and add version file

The primary keyword instrument and observation date can be read
from secondary HDUs.
Two new columns must be added to datamodel.instrument table:
fits_key_hdu, fits_date_hdu.

The Version.h file manages the version number. Just run

fitsImporter-srv --version
parent 9a0c13fe
Loading
Loading
Loading
Loading
+21 −12
Original line number Original line Diff line number Diff line
@@ -144,7 +144,7 @@ Instrument::SP DMDBImporter::getInstrument(std::string instrumentName)
    DEBUG_STREAM << "DMDBImporter::getInstrument()" << endl;
    DEBUG_STREAM << "DMDBImporter::getInstrument()" << endl;


    soci::rowset< InstrumentTuple > rows = (m_session_sp->prepare <<
    soci::rowset< InstrumentTuple > rows = (m_session_sp->prepare <<
        "SELECT id, name, fits_key, fits_value, fits_date, dest_id "
        "SELECT id, name, fits_key_hdu, fits_key, fits_value, fits_date_hdu, fits_date, dest_id "
        "FROM " << m_instrumentTable << " WHERE name=:name",
        "FROM " << m_instrumentTable << " WHERE name=:name",
        soci::use(instrumentName, "name"));
        soci::use(instrumentName, "name"));


@@ -168,31 +168,40 @@ Instrument::SP DMDBImporter::getInstrument(std::string instrumentName)
    std::string name = instrumentTuple.get<1>().get();
    std::string name = instrumentTuple.get<1>().get();


    if(!instrumentTuple.get<2>())
    if(!instrumentTuple.get<2>())
        throw soci::soci_error("FitsKey not found for id " + instId);
        throw soci::soci_error("FitsKeyHdu not found for id " + instId);
    std::string fitsKey = instrumentTuple.get<2>().get();
    int fitsKeyHdu = instrumentTuple.get<2>().get();


    if(!instrumentTuple.get<3>())
    if(!instrumentTuple.get<3>())
        throw soci::soci_error("FitsValue not found for id " + instId);
        throw soci::soci_error("FitsKey not found for id " + instId);
    std::string fitsValue = instrumentTuple.get<3>().get();
    std::string fitsKey = instrumentTuple.get<3>().get();


    if(!instrumentTuple.get<4>())
    if(!instrumentTuple.get<4>())
        throw soci::soci_error("FitsDate not found for id " + instId);
        throw soci::soci_error("FitsValue not found for id " + instId);
    std::string fitsDate = instrumentTuple.get<4>().get();
    std::string fitsValue = instrumentTuple.get<4>().get();


    if(!instrumentTuple.get<5>())
    if(!instrumentTuple.get<5>())
        throw soci::soci_error("FitsDateHdu not found for id " + instId);
    int fitsDateHdu = instrumentTuple.get<5>().get();

    if(!instrumentTuple.get<6>())
        throw soci::soci_error("FitsDate not found for id " + instId);
    std::string fitsDate = instrumentTuple.get<6>().get();

    if(!instrumentTuple.get<7>())
        throw soci::soci_error("DestId not found for id " + instId);
        throw soci::soci_error("DestId not found for id " + instId);
    int destinationId = instrumentTuple.get<5>().get();
    int destinationId = instrumentTuple.get<7>().get();


#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
    INFO_STREAM << "INSTRUMENT: " << instId << " " << name << " " << fitsKey
    INFO_STREAM << "INSTRUMENT: " << instId << " " << name << " " << fitsKeyHdu
        << " " << fitsValue << " " << fitsDate << " " << destinationId << endl;
        << " " << fitsKey << " " << fitsValue << " "
	<< fitsDateHdu << " " << fitsDate << " " << destinationId << endl;
    INFO_STREAM << "-------------------------------------------------" << endl;
    INFO_STREAM << "-------------------------------------------------" << endl;
#endif
#endif


    Destination::SP destination_sp = getDestination(destinationId);
    Destination::SP destination_sp = getDestination(destinationId);


    Instrument::SP instrument_sp = Instrument::create(name, fitsKey, fitsValue,
    Instrument::SP instrument_sp = Instrument::create(name, fitsKeyHdu, fitsKey, fitsValue,
        fitsDate, destination_sp);
        fitsDateHdu, fitsDate, destination_sp);


    return instrument_sp;
    return instrument_sp;
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -79,8 +79,8 @@ protected:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//  [Protected] Instrument tuple typedef
//  [Protected] Instrument tuple typedef
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
    typedef boost::tuple< boost::optional<int>, boost::optional<std::string>,
    typedef boost::tuple< boost::optional<int>, boost::optional<std::string>, boost::optional<int>, 
            boost::optional<std::string>, boost::optional<std::string>,
            boost::optional<std::string>, boost::optional<std::string>, boost::optional<int>,
            boost::optional<std::string>, boost::optional<int> > InstrumentTuple;
            boost::optional<std::string>, boost::optional<int> > InstrumentTuple;


    typedef std::vector< InstrumentTuple > InstrumentTupleVector;
    typedef std::vector< InstrumentTuple > InstrumentTupleVector;
+15 −7
Original line number Original line Diff line number Diff line
@@ -22,10 +22,10 @@ private:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	[Private] Constructor destructor deleter
//	[Private] Constructor destructor deleter
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
	Instrument(std::string name, std::string fitsKey, std::string fitsValue,
	Instrument(std::string name, int fitsKeyHdu, std::string fitsKey, std::string fitsValue,
		std::string fitsDate, boost::shared_ptr<Destination> destination_sp) :		
		int fitsDateHdu, std::string fitsDate, boost::shared_ptr<Destination> destination_sp) :		
		m_name(name), m_fitsKey(fitsKey), m_fitsValue(fitsValue), 
		m_name(name), m_fitsKeyHdu(fitsKeyHdu), m_fitsKey(fitsKey), m_fitsValue(fitsValue), 
		m_fitsDate(fitsDate), m_destination_sp(destination_sp) {}		
		m_fitsDateHdu(fitsDateHdu), m_fitsDate(fitsDate), m_destination_sp(destination_sp) {}		
	~Instrument() {}
	~Instrument() {}


	class Deleter;
	class Deleter;
@@ -40,17 +40,19 @@ public:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	[Public] Users methods
//	[Public] Users methods
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
	static Instrument::SP create(std::string name, std::string fitsKey,
	static Instrument::SP create(std::string name, int fitsKeyHdu, std::string fitsKey,
		std::string fitsValue, std::string fitsDate, Destination::SP destination_sp)		
		std::string fitsValue, int fitsDateHdu, std::string fitsDate, Destination::SP destination_sp)		
	{
	{
		Instrument::SP d_sp( new Instrument(name, fitsKey, fitsValue, fitsDate,
		Instrument::SP d_sp( new Instrument(name, fitsKeyHdu, fitsKey, fitsValue, fitsDateHdu, fitsDate,
			 destination_sp), Instrument::Deleter() );
			 destination_sp), Instrument::Deleter() );
		return d_sp;
		return d_sp;
	}
	}


	std::string getName() const { return m_name; }
	std::string getName() const { return m_name; }
	int getFitsKeyHdu() const { return m_fitsKeyHdu; }
	std::string getFitsKey() const { return m_fitsKey; }
	std::string getFitsKey() const { return m_fitsKey; }
	std::string getFitsValue() const { return m_fitsValue; }
	std::string getFitsValue() const { return m_fitsValue; }
	int getFitsDateHdu() const { return m_fitsDateHdu; }
	std::string getFitsDate() const { return m_fitsDate; }
	std::string getFitsDate() const { return m_fitsDate; }
	boost::shared_ptr<Destination> getDestination() { return m_destination_sp; }
	boost::shared_ptr<Destination> getDestination() { return m_destination_sp; }


@@ -61,12 +63,18 @@ private:
	//Instrument name
	//Instrument name
	const std::string m_name;
	const std::string m_name;
	
	
	//Instrument fits key hdu 
	const int m_fitsKeyHdu;

	//Instrument fits key 
	//Instrument fits key 
	const std::string m_fitsKey;
	const std::string m_fitsKey;


	//Instrument fits value
	//Instrument fits value
	const std::string m_fitsValue;
	const std::string m_fitsValue;


	//Date fits key hdu
	const int m_fitsDateHdu;
	
	//Date fits key
	//Date fits key
	const std::string m_fitsDate;
	const std::string m_fitsDate;
	
	

src/Version.h

0 → 100644
+7 −0
Original line number Original line Diff line number Diff line
// Version.h
#if !defined(VERSION_H)
#define VERSION_H 1

std::string version = "2.0.0-alpha";

#endif
+61 −15
Original line number Original line Diff line number Diff line
@@ -161,11 +161,11 @@ void WorkerThread::ingestUsingInstrumentList(boost::filesystem::path& origPath,
{
{
    DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList()" << endl;
    DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList()" << endl;


    CCfits::PHDU& phdu = fitsFile_sp->pHDU();

    // Read all primary HDU keys and keep track
    // Read all primary HDU keys and keep track
    phdu.readAllKeys();
    // This is useful when all keywords are in the first HDU
    readHDUSet.insert(0);
    //CCfits::PHDU& phdu = fitsFile_sp->pHDU();
    //phdu.readAllKeys();
    //readHDUSet.insert(0);


    Instrument::SP instrument_sp;
    Instrument::SP instrument_sp;
    boost::gregorian::date date;
    boost::gregorian::date date;
@@ -175,21 +175,60 @@ void WorkerThread::ingestUsingInstrumentList(boost::filesystem::path& origPath,
    Instrument::SPVector::iterator it;
    Instrument::SPVector::iterator it;
    for(it=m_instrumentList_spvector.begin(); it!=m_instrumentList_spvector.end(); ++it)
    for(it=m_instrumentList_spvector.begin(); it!=m_instrumentList_spvector.end(); ++it)
    {
    {
        int fitsKeyHdu = (*it)->getFitsKeyHdu();
        std::string fitsKey = (*it)->getFitsKey();
        std::string fitsKey = (*it)->getFitsKey();
        std::string fitsValue = (*it)->getFitsValue();
        std::string fitsValue = (*it)->getFitsValue();
        int fitsDateHdu = (*it)->getFitsDateHdu();
        std::string fitsDate = (*it)->getFitsDate();
        std::string fitsDate = (*it)->getFitsDate();


        DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() instrument: "
        DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() instrument: "
            << (*it)->getName() << " key: " << fitsKey << " value: " << fitsValue
            << (*it)->getName() << " keyHdu: " << fitsKeyHdu << " key: " << fitsKey << " value: " << fitsValue
            << " date: " << fitsDate << endl;
            << " dateHdu: " << fitsDateHdu << " date: " << fitsDate << endl;


        try
        try
        {
        {
            std::string retrievedFitsKeyValue;
            std::string retrievedFitsKeyValue;
            phdu.readKey(fitsKey, retrievedFitsKeyValue);

            std::string retrievedFitsDateValue;
            std::string retrievedFitsDateValue;
            phdu.readKey(fitsDate, retrievedFitsDateValue);

            //If current fitsKeyHdu has not been already read
            if(readHDUSet.find(fitsKeyHdu) == readHDUSet.end())
            {
                //Read all currnet HDU keys
                if(fitsKeyHdu == 0)
                    fitsFile_sp->pHDU().readAllKeys();
                else
                    fitsFile_sp->extension(fitsKeyHdu).readAllKeys();
                //Keep track of read HDU
                readHDUSet.insert(fitsKeyHdu);
            }

            //If current fitsDateHdu has not been already read
            if(readHDUSet.find(fitsDateHdu) == readHDUSet.end())
            {
                //Read all currnet HDU keys
                if(fitsDateHdu == 0)
                    fitsFile_sp->pHDU().readAllKeys();
                else
                    fitsFile_sp->extension(fitsDateHdu).readAllKeys();
                //Keep track of read HDU
                readHDUSet.insert(fitsDateHdu);
            }

            // Read retrievedFitsKeyValue according to fitsKeyHdu
            if(fitsKeyHdu == 0)
                fitsFile_sp->pHDU().readKey(fitsKey, retrievedFitsKeyValue);
            else
                fitsFile_sp->extension(fitsKeyHdu).readKey(fitsKey, retrievedFitsKeyValue);

            // Read retrievedFitsDateValue according to fitsDateHdu
            if(fitsDateHdu == 0)
                fitsFile_sp->pHDU().readKey(fitsDate, retrievedFitsDateValue);
            else
                fitsFile_sp->extension(fitsDateHdu).readKey(fitsDate, retrievedFitsDateValue);

            // Other ways to get keywords value
            //phdu.readKey(fitsKey, retrievedFitsKeyValue);
            //phdu.readKey(fitsDate, retrievedFitsDateValue);


            if(fitsValue.compare(retrievedFitsKeyValue)==0)
            if(fitsValue.compare(retrievedFitsKeyValue)==0)
            {
            {
@@ -213,6 +252,13 @@ void WorkerThread::ingestUsingInstrumentList(boost::filesystem::path& origPath,
            DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() "
            DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() "
                << ex.what() << endl;
                << ex.what() << endl;
        }
        }
        catch(CCfits::FITS::NoSuchHDU& ex)
		{
            DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() "
                << ex.message() << endl;
        }

        
	} //for
	} //for


    if(found)
    if(found)
Loading