InstrumentMgr.cc 1.21 KB
/*
 * InstrumentMgr.cc
 *
 *  Created on: Oct 6, 2014
 *      Author: m.mazel
 */

#include "Helper.hh"
#include "Properties.hh"
#include "InstrumentMgr.hh"
#include "InstrumentParser.hh"
#include "InfoLogger.hh"

namespace AMDA {
namespace Info {

const InstrumentInfoSPtr InstrumentMgr::getInstrumentInfoFromId (const std::string &id) {
	if (id.empty())
		return InstrumentInfoSPtr();

	// If Instrument id already loaded, return it
	if (_instrumentInfoMap.find (id) != _instrumentInfoMap.end()) {
		return _instrumentInfoMap [id];
	}

	// Otherwise, build Instrument path & filename using the id
	AMDA::helpers::Properties lProperties("app.properties");

	std::string xmlFileName = lProperties["app.instrumentInfo.path"] + "/" + id + ".xml";
	_instrumentInfoMap [id] = getInstrumentInfoFromFile (xmlFileName);
	return _instrumentInfoMap [id];
}

InstrumentInfoSPtr InstrumentMgr::getInstrumentInfoFromFile (const std::string &xmlFilename) {
	AMDA::helpers::Properties lProperties("app.properties");

	// Retrieve XSD file for Instrument and build a parser
	InstrumentParser parser(lProperties["app.instrumentInfo.xsd"].c_str());

	// Parse XML file
	return parser.parse (xmlFilename);
}

} /* namespace Info */
} /* namespace AMDA */