DataSetMgr.cc
1.33 KB
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
46
47
48
49
50
51
52
/*
* DataSetMgr.cc
*
* Created on: Oct 6, 2014
* Author: m.mazel
*/
#include "Helper.hh"
#include "Properties.hh"
#include "DataSetMgr.hh"
#include "DataSetParser.hh"
#include "InfoLogger.hh"
namespace AMDA {
namespace Info {
const DataSetInfoSPtr DataSetMgr::getDataSetInfoFromId (const std::string &id, bool forceCreateIfNoExist) {
if (id.empty())
return DataSetInfoSPtr();
// If dataset id already loaded, return it
if (_dataSetInfoMap.find (id) != _dataSetInfoMap.end()) {
return _dataSetInfoMap [id];
}
// Otherwise, build DataSet path & filename using the id
AMDA::helpers::Properties lProperties("app.properties");
std::string xmlFileName = lProperties["app.dataSetInfo.path"] + "/" + id + ".xml";
_dataSetInfoMap [id] = getDataSetInfoFromFile (xmlFileName);
if (forceCreateIfNoExist && (_dataSetInfoMap [id] == nullptr))
{
_dataSetInfoMap [id] = DataSetInfoSPtr(new DataSetInfo);
_dataSetInfoMap [id]->setId(id);
}
return _dataSetInfoMap [id];
}
DataSetInfoSPtr DataSetMgr::getDataSetInfoFromFile (const std::string &xmlFilename) {
AMDA::helpers::Properties lProperties("app.properties");
// Retrieve XSD file for DataSet and build a parser
DataSetParser parser(lProperties["app.dataSetInfo.xsd"].c_str());
// Parse XML file
return parser.parse (xmlFilename);
}
} /* namespace Info */
} /* namespace AMDA */