Commit debd7b7c authored by Andrea Bignamini's avatar Andrea Bignamini
Browse files

Merge branch 'release/v2.0.0-alpha'

parents f5eb9230 0b54bedc
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ Instrument::SP DMDBImporter::getInstrument(std::string instrumentName)
    DEBUG_STREAM << "DMDBImporter::getInstrument()" << endl;

    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",
        soci::use(instrumentName, "name"));

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

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

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

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

    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);
    int destinationId = instrumentTuple.get<5>().get();
    int destinationId = instrumentTuple.get<7>().get();

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

    Destination::SP destination_sp = getDestination(destinationId);

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

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

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

	class Deleter;
@@ -40,17 +40,19 @@ public:
//------------------------------------------------------------------------------
//	[Public] Users methods
//------------------------------------------------------------------------------
	static Instrument::SP create(std::string name, std::string fitsKey,
		std::string fitsValue, std::string fitsDate, Destination::SP destination_sp)		
	static Instrument::SP create(std::string name, int fitsKeyHdu, std::string fitsKey,
		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() );
		return d_sp;
	}

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

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

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

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

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

src/Version.h

0 → 100644
+7 −0
Original line number 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 Diff line number Diff line
@@ -161,11 +161,11 @@ void WorkerThread::ingestUsingInstrumentList(boost::filesystem::path& origPath,
{
    DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList()" << endl;

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

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

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

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

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

            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)
            {
@@ -213,6 +252,13 @@ void WorkerThread::ingestUsingInstrumentList(boost::filesystem::path& origPath,
            DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() "
                << ex.what() << endl;
        }
        catch(CCfits::FITS::NoSuchHDU& ex)
		{
            DEBUG_STREAM << "WorkerThread::ingestUsingInstrumentList() "
                << ex.message() << endl;
        }

        
	} //for

    if(found)
Loading