Blame view

src/Info/InstrumentMgr.cc 1.21 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * 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 */