Blame view

src/TimeTableCatalog/InternalXMLReader.cc 10.3 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * InternalXMLReader.cc
 *
 *  Created on: 6 août 2013
 *      Author: CS
 */

#include "InternalXMLData.hh"
#include "InternalXMLReader.hh"
#include <stdio.h>
#include "TimeTableCatalogUtil.hh"
#include <string>
#include "AsciiReader.hh"
#include "Catalog.hh"

68c29629   Benjamin Renard   Fix in TT/Catalog...
16
17
#include <boost/algorithm/string.hpp>

fbe3c2bb   Benjamin Renard   First commit
18
19
20
21
22
23
24
#ifdef LIBXML_READER_ENABLED

/*
 <?xml version="1.0" encoding="UTF-8"?>
 <timetable>
 <name>FTE_c3</name>
 <created>2013-07-14T09:09:32</created>
91128aae   Hacene SI HADJ MOHAND   kernel arguments ok
25
26
27
28
29
 <modified>2013-07-14T09:09:32</modified>
 <modified>2013-07-14T09:09:32</modified>
 <surveyStart>2013-07-14T09:09:32</surveyStart>
 <surveyStop>2013-07-14T09:09:32</surveyStop>
 <contact>tototiti<contact>
fbe3c2bb   Benjamin Renard   First commit
30
31
32
33
34
35
36
37
38
 <description>Uploaded Time Table
 Time Table generated by AMDA @ CDPP;Description: FTE list from Cluster 3 data. From \"A new multivariate time series data analysis technique: Automated detection of flux transfer events using Cluster data\" by Karimabadi et al., JOURNAL OF GEOPHYSICAL RESEARCH, VOL. 114, A06216, doi:10.1029/2009JA014202, 2009 http://www.agu.org/journals/ja/ja0906/2009JA014202/The list is available as Auxiliary material \"Data Set S3\"Transformation into AMDA Time Table by V. Genot, CESR, Toulouse, France 29/06/2009 : - millisec have been omitted - the original event corresponds to the StartTime of the Time Table - if StopTime-StartTime = 1 sec then the event is a magnetosheath FTE - if StopTime-StartTime = 2 sec then the event is a magnetospheric FTE;Source: Upload Time Table;Creation Date :  2009-07-01 17:16:46 shared by Vincent Genot on 2009-11-24 18:52:50;</description>
 <history>created from another TT</history>
 <nbIntervals>738</nbIntervals>
 <intervals>
 <start>2001-02-02T16:27:12</start>
 <stop>2001-02-02T16:27:13</stop>
 </intervals>
 */
fbe3c2bb   Benjamin Renard   First commit
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
namespace TimeTableCatalog {

const std::string InternalXMLReader::FORMAT = "Internal";

InternalXMLReader::InternalXMLReader(const std::string& pPath) :
		XMLReader(pPath) {

}

InternalXMLReader::~InternalXMLReader() {

}

// ---------------- PUBLIC -----------------

std::unique_ptr<AbstractReader> InternalXMLReader::createInstance(
		const std::string& pPath) {
	return std::unique_ptr < AbstractReader
			> (new InternalXMLReader(pPath));
}

std::string InternalXMLReader::getFirstNode() {
	return "timetable";
}

// ----------------- PRIVATE --------------------------

/**
 *
 * @pTT : the timetable to load
 * @reader: the xmlReader
 *
 * Fills the given TimeTable with the xml file content
 */
void InternalXMLReader::processNode(TimeTable& pTT,	xmlTextReaderPtr reader, int &crtIndex) {
	const xmlChar *name, *value;

	// -- read tag
	name = xmlTextReaderConstName(reader);
	if (name == NULL)
		name = BAD_CAST "--";
	// -- read tag text (may be NULL)
	value = xmlTextReaderConstValue(reader);

	// -- is tag interested ?
	std::string tagName = reinterpret_cast<const char*>(name);
	if (_step == READ_STEP::NO_TAG
			&& (tagName == InternalXMLData::ELEM_NAME
					|| tagName == InternalXMLData::ELEM_CREATED
					|| tagName == InternalXMLData::ELEM_DESCRIPTION
					|| tagName == InternalXMLData::ELEM_HISTORY
					|| tagName == InternalXMLData::ELEM_START
					|| tagName == InternalXMLData::ELEM_STOP
					|| tagName == InternalXMLData::ELEM_PARAMETER
					|| tagName == InternalXMLData::ELEM_PARAM
d1774421   Hacene SI HADJ MOHAND   Kernek ok
94
95
96
97
98
					|| tagName == InternalXMLData::ELEM_NB_INTERVALS
                                                                                                    ||tagName == InternalXMLData::ELEM_MODIFIED
                                                                                                    || tagName == InternalXMLData::SURVEY_START_DATE
                                                                                                    || tagName == InternalXMLData::SURVEY_STOP_DATE
                                                                                                    || tagName == InternalXMLData::ELEM_CONTACT)) {
fbe3c2bb   Benjamin Renard   First commit
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
		// yes, it is !
		// save current tag to get its text value next process
		_tmpCurrentTag = reinterpret_cast<const char*>(name);
		_step = READ_STEP::START_TAG;
	}
	// are we waiting for a tag value of an interested tag ?
	if (_step == READ_STEP::TEXT) {
		// now the tag is read, do not care anymore of it
		_step = READ_STEP::END_TAG;
		// process tag value according to current tag
		if (value != NULL) {
			std::string tagValue = reinterpret_cast<const char*>(value);

			if (_tmpCurrentTag == InternalXMLData::ELEM_NAME) {
				pTT._name = tagValue;
			} else if (_tmpCurrentTag == InternalXMLData::ELEM_DESCRIPTION) {
				split(tagValue, '\n', pTT._description);
			} else if (_tmpCurrentTag == InternalXMLData::ELEM_HISTORY) {
				pTT._history = tagValue;
			} else if (_tmpCurrentTag == InternalXMLData::ELEM_CREATED) {
				pTT._creationDate = readISOTime(tagValue);
			} else if (_tmpCurrentTag == InternalXMLData::ELEM_NB_INTERVALS) {
				// NOP, dont care about interval number
91128aae   Hacene SI HADJ MOHAND   kernel arguments ok
122
123
124
125
126
127
128
			} else if( _tmpCurrentTag == InternalXMLData::ELEM_MODIFIED) {
                                                                        pTT._modificationDate = readISOTime(tagValue);
                                                            }else if( _tmpCurrentTag == InternalXMLData::SURVEY_START_DATE) {
                                                                        pTT._listStartDate = readISOTime(tagValue);
                                                            }else if( _tmpCurrentTag == InternalXMLData::SURVEY_STOP_DATE) {
                                                                        pTT._listStopDate = readISOTime(tagValue);
                                                            }else if( _tmpCurrentTag == InternalXMLData::ELEM_CONTACT) {
61bdda87   Hacene SI HADJ MOHAND   correcting contact
129
                                                                        pTT._contact = tagValue;
91128aae   Hacene SI HADJ MOHAND   kernel arguments ok
130
                                                            }else{
fbe3c2bb   Benjamin Renard   First commit
131
132
133
134
				// read intervals
				if (_tmpCurrentTag == InternalXMLData::ELEM_START) {
					_tmpIntervalstartdate = readISOTime(tagValue);
					if (pTT._timeFormat == TimeTable::TIME_FORMAT::UNKNOWN) {
818d2ea6   Benjamin Renard   Support new time ...
135
136
						int size = 0;
						pTT._timeFormat = getTimeFormat(tagValue, size);
fbe3c2bb   Benjamin Renard   First commit
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
					}
				} else if (_tmpCurrentTag == InternalXMLData::ELEM_STOP) {
					pTT.addInterval(TimeInterval(_tmpIntervalstartdate, readISOTime(tagValue), crtIndex));
					++crtIndex;
				}
				// Read parameters data
				else if (_tmpCurrentTag == InternalXMLData::ELEM_PARAM) {
					TimeInterval * pLastInterval = pTT.getLastInterval();
					// If interval list is not empty, add parameter data to the last interval
					if (pLastInterval != NULL) {
						ParameterDescriptionList pdl = pTT.getParameterDescritptions();

						std::vector<std::string> paramList;
						split (tagValue, InternalXMLData::SEPARATOR.c_str()[0], paramList);

						int nbParamDataInterval = pLastInterval->getParameterDataCount();
						std::string paramKey = pdl [nbParamDataInterval].getId();
						pLastInterval->addParameterData(paramKey, paramList);
					}
				}
			}
		}
		else {
			_step = READ_STEP::NO_TAG;
		}
	} else if (_step == READ_STEP::START_TAG) {

		// Read XML_PARAMETER_TAG attributes (if found)
		if (tagName == InternalXMLData::ELEM_PARAMETER) {
0b2d2cab   Erdogan Furkan   Kernel part for c...
166
			const xmlChar *attrId, *attrName, *attrSize, *attrType, *attrUnit, *attrDescription, *attrStatus, *attrUcd, *attrUtype;
fbe3c2bb   Benjamin Renard   First commit
167
			attrId	 		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_ID);
ff88ef71   Benjamin Renard   Allow ID tag to d...
168
169
170
			if (attrId == NULL)
				//Compatibility mode with older catalogs
				attrId          = xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_ID_UPPER_CASE);
fbe3c2bb   Benjamin Renard   First commit
171
172
173
174
175
			attrName 		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_NAME);
			attrSize 		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_SIZE);
			attrType 		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_TYPE);
			attrUnit		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_UNIT);
			attrDescription = xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_DESCRITION);
0b2d2cab   Erdogan Furkan   Kernel part for c...
176
			attrStatus		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_STATUS);
fbe3c2bb   Benjamin Renard   First commit
177
178
179
			attrUcd			= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_UCD);
			attrUtype		= xmlTextReaderGetAttribute (reader, (const xmlChar*)InternalXMLData::ATTRIB_UTYPE);

5b91d159   Benjamin Renard   Fix catalog reade...
180
181
182
			std::string attrIdStr = (attrId != NULL) ? std::string((const char *)attrId) : "";
			std::string attrNameStr = (attrName != NULL) ? std::string((const char *)attrName) : "";
			std::string attrSizeStr = (attrSize != NULL) ? std::string((const char *)attrSize) : "";
68c29629   Benjamin Renard   Fix in TT/Catalog...
183
			ParameterDescription::ParameterType type = (attrType != NULL) ? getTypeFromString(std::string((const char *)attrType)) : ParameterDescription::ParameterType::String;
5b91d159   Benjamin Renard   Fix catalog reade...
184
185
			std::string attrUnitStr = (attrUnit != NULL) ? std::string((const char *)attrUnit) : "";
			std::string attrDescriptionStr = (attrDescription != NULL) ? std::string((const char *)attrDescription) : "";
0b2d2cab   Erdogan Furkan   Kernel part for c...
186
			std::string attrStatusStr = (attrStatus != NULL) ? std::string((const char *)attrStatus) : "";
5b91d159   Benjamin Renard   Fix catalog reade...
187
188
189
			std::string attrUcdStr = (attrUcd != NULL) ? std::string((const char *)attrUcd) : "";
			std::string attrUtypeStr = (attrUtype != NULL) ? std::string((const char *)attrUtype) : "";

fbe3c2bb   Benjamin Renard   First commit
190
			((Catalog *) &pTT)->addParameterDescription(ParameterDescription(
5b91d159   Benjamin Renard   Fix catalog reade...
191
192
193
					attrIdStr,
					attrNameStr,
					attrSizeStr,
68c29629   Benjamin Renard   Fix in TT/Catalog...
194
					type,
5b91d159   Benjamin Renard   Fix catalog reade...
195
196
					attrUnitStr,
					attrDescriptionStr,
0b2d2cab   Erdogan Furkan   Kernel part for c...
197
					attrStatusStr,
5b91d159   Benjamin Renard   Fix catalog reade...
198
199
					attrUcdStr,
					attrUtypeStr));
fbe3c2bb   Benjamin Renard   First commit
200
201
202
203
204
205
206
207
208
209
210
211

			// Jump to next XML_PARAMETER_TAG
			_step = READ_STEP::NO_TAG;
		}
		else {
			_step = READ_STEP::TEXT;
		}
	} else if (_step == READ_STEP::END_TAG) {
		_step = READ_STEP::NO_TAG;
	}
}

68c29629   Benjamin Renard   Fix in TT/Catalog...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
ParameterDescription::ParameterType InternalXMLReader::getTypeFromString(std::string type) {
	boost::algorithm::trim(type);
	boost::algorithm::to_lower(type);

	if ((type.compare("2") == 0) || (type.compare("string") == 0) || (type.compare("char") == 0)) {
		return ParameterDescription::ParameterType::String;
	}
	else if ((type.compare("3") == 0) || (type.compare("integer") == 0) || (type.compare("int") == 0)) {
		return ParameterDescription::ParameterType::Integer;
	}
	else if ((type.compare("0") == 0) || (type.compare("float") == 0) || (type.compare("double") == 0)) {
		return ParameterDescription::ParameterType::Double;
	}
	else if ((type.compare("1") == 0) || (type.compare("date") == 0)) {
		return ParameterDescription::ParameterType::Date;
	}
	return ParameterDescription::ParameterType::String;
}

fbe3c2bb   Benjamin Renard   First commit
231
232
233
} /* namespace TimeTableCatalog */

#endif