casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDMDataObjectParser.h
Go to the documentation of this file.
1 #ifndef SDMDataObjectParser_CLASS
2 #define SDMDataObjectParser_CLASS
3 
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <libxml/parser.h>
8 #include <libxml/tree.h>
9 
10 
11 
12 #ifdef REG_BASIC
13 #undef REG_BASIC
14 #endif
15 
16 #ifdef REG_EXTENDED
17 #undef REG_EXTENDED
18 #endif
19 
20 #ifdef REG_ICASE
21 #undef REG_ICASE
22 #endif
23 
24 #ifdef REG_NOSUB
25 #undef REG_NOSUB
26 #endif
27 
28 #ifdef REG_NEWLINE
29 #undef REG_NEWLINE
30 #endif
31 
32 #ifdef REG_NOTBOL
33 #undef REG_NOTBOL
34 #endif
35 
36 #ifdef REG_NOTEOL
37 #undef REG_NOTEOL
38 #endif
39 
40 #ifdef REG_STARTEND
41 #undef REG_STARTEND
42 #endif
43 
44 #ifndef WITHOUT_BOOST
45 #include <boost/regex.hpp>
46 #else
47 #include <regex>
48 #endif
49 
51 
52 
53 #ifndef WITHOUT_ACS
54 #include "almaEnumerations_IFC.h"
55 #endif
57 
59 
61 
62 namespace asdmbinaries {
63 
69 
70  public:
75 
80  SDMDataObjectParserException(std::string m);
81 
86 
91  std::string getMessage() const;
92 
93  protected:
94  std::string message;
95 
96  };
97 
98  inline SDMDataObjectParserException::SDMDataObjectParserException() : message ("SDMDataObjectParserException") {}
99  inline SDMDataObjectParserException::SDMDataObjectParserException(std::string m) : message(m) {}
101  inline std::string SDMDataObjectParserException::getMessage() const {
102  return "SDMDataObjectParserException : " + message;
103  }
104 
105 
106  // class HeaderParser
107  class HeaderParser {
108  friend class SDMDataObjectParser;
109  friend class SDMDataObject;
110 
111  public:
112  HeaderParser();
113  virtual ~HeaderParser();
114 
115  void parseFile(const std::string& filename, SDMDataObject& sdmDataObject);
116  void parseMemory(const std::string& buffer, SDMDataObject& sdmDataObject);
117 
118  void reset();
119 
120 
121 
122  private:
123  void parseSDMDataHeader(xmlNode* a_node, SDMDataObject& sdmDataObject);
124 
125  void parseProjectPath(xmlNode* a_node, SDMDataObject& sdmDataObject);
126  long long parseStartTime(xmlNode* a_node);
127  std::string parseDataOID(xmlNode* a_node);
128  int parseDimensionality(xmlNode* a_node);
129  int parseNumTime(xmlNode* a_node);
130  void parseExecBlock(xmlNode* a_node, SDMDataObject& sdmDataObject);
131  int parseExecBlockNum(xmlNode* a_node);
132  int parseScanNum(xmlNode* a_node);
133  int parseSubscanNum(xmlNode* a_node);
134 
135  int parseNumAntenna(xmlNode* a_node);
136 
137  void parseCorrelationMode(xmlNode* a_node, SDMDataObject& sdmDataObject);
138  void parseSpectralResolution(xmlNode* a_node, SDMDataObject& sdmDataObject);
139  void parseProcessorType(xmlNode* a_node, SDMDataObject& sdmDataObject);
140  void parseDataStruct (xmlNode* a_node, SDMDataObject& sdmDataObject);
141 
143 
144  void parseSpectralWindow(xmlNode* a_node, SDMDataObject& sdmDataObject, std::vector<SDMDataObject::SpectralWindow>& spectralWindow);
145 
146  SDMDataObject::BinaryPart parseBinaryPart(xmlNode* a_node, const std::string& attachmentName);
147  SDMDataObject::AutoDataBinaryPart parseAutoDataBinaryPart(xmlNode* a_node, const std::string& attachmentName);
148  SDMDataObject::ZeroLagsBinaryPart parseZeroLagsBinaryPart(xmlNode* a_node, const std::string& attachmentName);
149 
150  // SDMDataObject::TypedBinaryPart parseTypedBinaryPart(xmlNode* a_node, const std::string& attachmentName);
151 
153 
154 #ifndef WITHOUT_BOOST
156 #else
157  static const std::regex PROJECTPATH3;
158 #endif
159  const static std::string SDMDATAHEADER;
160  const static std::string SCHEMAVERSION;
161  const static std::string BYTEORDER;
162  const static std::string PROJECTPATH;
163  const static std::string STARTTIME;
164  const static std::string DATAOID;
165  const static std::string XLINKHREF;
166  const static std::string XLINKTITLE;
167 
168  const static std::string DIMENSIONALITY;
169  const static std::string NUMTIME;
170 
171  const static std::string EXECBLOCK;
172  const static std::string EXECBLOCKNUM;
173  const static std::string SCANNUM;
174  const static std::string SUBSCANNUM;
175 
176  const static std::string NUMANTENNA;
177 
178  const static std::string CORRELATIONMODE;
179  const static std::string SPECTRALRESOLUTION;
180  const static std::string PROCESSORTYPE;
181  const static std::string DATASTRUCT;
182  const static std::string APC;
183  const static std::string REF;
184 
185  const static std::string BASEBAND;
186  const static std::string NAME;
187 
188  const static std::string SPECTRALWINDOW;
189  const static std::string SW;
190  const static std::string SWBB;
191  const static std::string CROSSPOLPRODUCTS;
192  const static std::string SDPOLPRODUCTS;
193  const static std::string SCALEFACTOR;
194  const static std::string NUMSPECTRALPOINT;
195  const static std::string NUMBIN;
196  const static std::string SIDEBAND;
197  const static std::string IMAGE;
198 
199  const static std::string FLAGS;
200  const static std::string ACTUALTIMES;
201  const static std::string ACTUALDURATIONS;
202  const static std::string ZEROLAGS;
203  const static std::string CORRELATORTYPE;
204  const static std::string CROSSDATA;
205  const static std::string AUTODATA;
206  const static std::string NORMALIZED;
207 
208  const static std::string SIZE;
209  const static std::string AXES;
210  const static std::string TYPE;
211  }; // class HeaderParser
212 
213  // class CorrSubsetHeaderParser
215  friend class SDMDataSubset;
216 
217  public:
219  virtual ~CorrSubsetHeaderParser();
220  void parseFile(const std::string& filename, SDMDataSubset& sdmCorrDataSubset);
221  void parseMemory(const std::string& buffer, SDMDataSubset& sdmCorrDataSubset);
222  void parseCrossDataType(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
223  void reset();
224 
225  private:
226  // Regular expressions used to decipher the content of projectPath attribute.
227 #ifndef WITHOUT_BOOST
230 #else
231  static const std::regex PROJECTPATH4;
232  static const std::regex PROJECTPATH5;
233 #endif
234 
235  void parseSDMDataSubsetHeader(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
236  // void parseProjectPath(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
237  void parseSchedulePeriodTime(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
238  long long parseTime(xmlNode* a_node);
239  long long parseInterval(xmlNode* a_node);
240  void parseAbortObservation(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
241 
243 
244  const static std::string SDMDATASUBSETHEADER;
245  const static std::string PROJECTPATH;
246  const static std::string SCHEDULEPERIODTIME;
247  const static std::string TIME;
248  const static std::string INTERVAL;
249  const static std::string DATASTRUCT;
250  const static std::string REF;
251  const static std::string ABORTOBSERVATION;
252  const static std::string ABORTTIME;
253  const static std::string ABORTREASON;
254  const static std::string XLINKHREF;
255  const static std::string DATAREF;
256  const static std::string FLAGSREF;
257  const static std::string ACTUALTIMESREF;
258  const static std::string ACTUALDURATIONSREF;
259  const static std::string ZEROLAGSREF;
260  const static std::string CROSSDATAREF;
261  const static std::string TYPE;
262  const static std::string AUTODATAREF;
263  }; // class CorrSubsetHeaderParser
264 
265 
266  // class TPSubsetHeaderParser
268  friend class SDMDataSubset;
269  public:
271  virtual ~TPSubsetHeaderParser();
272  void parseFile(const std::string& filename,SDMDataSubset& sdmTPDataSubset );
273  void parseMemory(const std::string& buffer,SDMDataSubset& sdmTPDataSubset );
274  void reset();
275 
276  private:
277  // Regular expressions used to decipher the content of projectPath attribute.
278 #ifndef WITHOUT_BOOST
280 #else
281  static const std::regex PROJECTPATH3;
282 #endif
283 
284  void parseSDMDataSubsetHeader(xmlNode* a_node,SDMDataSubset& sdmTPDataSubset);
285  void parseProjectPath(xmlNode* a_node, SDMDataSubset& sdmTPDataSubset);
286  void parseSchedulePeriodTime(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset);
287  long long parseTime(xmlNode* a_node);
288  long long parseInterval(xmlNode* a_node);
289  std::string parseDataStructureDesc(xmlNode* a_node);
290  void parseBinaryData(xmlNode* a_node, SDMDataSubset& sdmTPDataSubset);
291 
293 
294  const static std::string SDMDATASUBSETHEADER;
295  const static std::string PROJECTPATH;
296  const static std::string SCHEDULEPERIODTIME;
297  const static std::string TIME;
298  const static std::string INTERVAL;
299  const static std::string DATASTRUCT;
300  const static std::string REF;
301  const static std::string DATAREF;
302  const static std::string XLINKHREF;
303  const static std::string FLAGSREF;
304  const static std::string ACTUALTIMESREF;
305  const static std::string ACTUALDURATIONSREF;
306  const static std::string AUTODATAREF;
307  }; // class TPSubsetHeaderParser
308 
309 
311  friend class SDMDataObject;
312  friend class SDMDataSubset;
313  friend class HeaderParser;
314 
315  public:
317  virtual ~SDMDataObjectParser();
318  void parseFileHeader(const std::string& filename, SDMDataObject& sdmDataObject);
319  void parseMemoryHeader(const std::string& buffer, SDMDataObject& sdmDataObject);
320 
321  void parseFileCorrSubsetHeader(const std::string& filename, SDMDataSubset& sdmCorrSubset);
322  void parseMemoryCorrSubsetHeader(const std::string& buffer, SDMDataSubset& sdmCorrSubset);
323 
324  void parseFileTPSubsetHeader(const std::string& filename, SDMDataSubset& sdmCorrDataSubset);
325  void parseMemoryTPSubsetHeader(const std::string& filename, SDMDataSubset& sdmCorrDataSubset);
326 
327  static void isElement(xmlNode* a_node, const std::string& elementName);
328  static bool testElement(xmlNode* a_node, const std::string& elementName);
329  static void inElements(xmlNode* a_node, const std::vector<std::string>& elementNames);
330 
331  static xmlAttr* hasAttr(xmlNode* a_node, const std::string& attrName);
332 
333  static void tokenize(const std::string& str,
334  std::vector<std::string>& tokens,
335  const std::string& delimiters = " ");
336 
337  static void tokenize(const std::string& str,
338  std::set<std::string>& tokens,
339  const std::string& delimiters = " ");
340  static std::string substring(const std::string &s, int a, int b);
341  static std::string trim(const std::string &s);
342 
343  static std::string parseString(xmlNode* a_node);
344  static long long parseLongLong(xmlNode* a_node);
345  static int parseInt(xmlNode* a_node);
346  static bool parseBool(xmlNode* a_node);
347  static float parseFloat(xmlNode* a_node);
348  static int parseIntAttr(xmlNode* a_node, const std::string& attrName);
349  static bool parseBoolAttr(xmlNode* a_node, const std::string& attrName);
350  static float parseFloatAttr(xmlNode* a_node, const std::string& attrName);
351  static std::string parseStringAttr(xmlNode* a_node, const std::string& attrName);
352  static const ByteOrder* parseByteOrderAttr(xmlNode* a_node, const std::string& attrName);
353 
354  template<class Enum, class EnumHelper> static Enum parseStringAttr(xmlNode* a_node, const std::string& attrName) {
355  xmlAttr* attr = 0;
356 
357  if ((attr = hasAttr(a_node, attrName))) {
358  std::string s = std::string((const char*)attr->children->content);
359  try {
360  Enum result = EnumHelper::literal(SDMDataObjectParser::trim(s));
361  return result;
362  }
363  catch(std::string m) {
365  }
366  }
367  else
368  throw SDMDataObjectParserException("could not find attribute '" + attrName + "' in " + std::string((const char*)a_node->name));
369  }
370 
371  template<class Enum, class EnumHelper> static Enum parseLiteral(xmlNode* a_node) {
372  if ((a_node != NULL) && (a_node->next == NULL)) {
373  try {
374  Enum result = EnumHelper::literal(SDMDataObjectParser::trim(std::string((const char*) a_node->content)));
375  return result;
376  }
377  catch (std::string m) {
379  }
380  }
381  else
382  throw SDMDataObjectParserException("The content of an element could not parsed into a literal");
383  }
384 
385 
386  static std::vector<std::string> parseStringsAttr(xmlNode* a_node, const std::string& attrName);
387  static std::set<std::string> parseStringSetAttr(xmlNode* a_node, const std::string& attrName);
388 
389  template<class Enum, class EnumHelper> static std::vector<Enum> parseStringsAttr(xmlNode* a_node, const std::string& attrName) {
390  xmlAttr* attr = 0;
391 
392  if ((attr = hasAttr(a_node, attrName))) {
393  std::vector<std::string> v_s;
394  tokenize((const char*)attr->children->content, v_s);
395 
396  std::vector<Enum> result;
397  unsigned int i = 0;
398  try {
399  for (i = 0; i < v_s.size(); i++)
400  result.push_back(EnumHelper::literal(v_s.at(i)));
401  return result;
402  }
403  catch (std::string m) {
405  }
406  }
407  else
408  throw SDMDataObjectParserException("could not find attribute '" + attrName + "' in " + std::string((const char*)a_node->name));
409  }
410 
411  static std::vector<unsigned int> parseProjectPath(xmlNode* a_node, unsigned int len);
412 
413  static std::vector<unsigned int> parseProjectPath(xmlNode* a_node);
414 
415  private:
416 
417 #ifndef WITHOUT_BOOST
422 #else
423  static const std::regex PROJECTPATH3;
424  static const std::regex PROJECTPATH4;
425  static const std::regex PROJECTPATH5;
426  static const std::regex PROJECTPATH4OR5;
427 #endif
428 
432 
433  }; // class SDMDataObjectParser
434 
435 
436 } // namespace asdmbinaries
437 #endif // HeaderParser_CLASS
static const std::string SCANNUM
static std::string trim(const std::string &s)
static const std::string AUTODATA
static const std::string EXECBLOCK
SDMDataObject:: declarations.
static const std::string CROSSDATA
static const std::string DIMENSIONALITY
static const std::string ACTUALTIMES
static std::vector< std::string > parseStringsAttr(xmlNode *a_node, const std::string &attrName)
void parseMemoryHeader(const std::string &buffer, SDMDataObject &sdmDataObject)
static Enum parseStringAttr(xmlNode *a_node, const std::string &attrName)
static std::string parseString(xmlNode *a_node)
void parseSchedulePeriodTime(xmlNode *a_node, SDMDataSubset &sdmCorrDataSubset)
void parseSDMDataHeader(xmlNode *a_node, SDMDataObject &sdmDataObject)
void parseCrossDataType(xmlNode *a_node, SDMDataSubset &sdmCorrDataSubset)
int parseScanNum(xmlNode *a_node)
static const boost::regex PROJECTPATH4
Regular expressions used to decipher the content of projectPath attribute.
static const std::string STARTTIME
void parseProjectPath(xmlNode *a_node, SDMDataSubset &sdmTPDataSubset)
SDMDataObject::Baseband parseBaseband(xmlNode *a_node, SDMDataObject &sdmDataObject)
std::string parseDataStructureDesc(xmlNode *a_node)
struct _xmlDoc xmlDoc
Definition: Misc.h:59
static const std::string EXECBLOCKNUM
SDMDataObject::Baseband:: declarations.
static bool parseBoolAttr(xmlNode *a_node, const std::string &attrName)
SDMDataObject::ZeroLagsBinaryPart parseZeroLagsBinaryPart(xmlNode *a_node, const std::string &attachmentName)
static const std::string BASEBAND
void parseSpectralResolution(xmlNode *a_node, SDMDataObject &sdmDataObject)
static std::string substring(const std::string &s, int a, int b)
static const std::string NAME
static const boost::regex PROJECTPATH4OR5
static const boost::regex PROJECTPATH5
static const std::string ZEROLAGS
static const std::string NUMBIN
void parseFile(const std::string &filename, SDMDataObject &sdmDataObject)
static long long parseLongLong(xmlNode *a_node)
void parseAbortObservation(xmlNode *a_node, SDMDataSubset &sdmCorrDataSubset)
static const std::string TYPE
static std::vector< unsigned int > parseProjectPath(xmlNode *a_node, unsigned int len)
void parseProjectPath(xmlNode *a_node, SDMDataObject &sdmDataObject)
static const std::string XLINKHREF
static const std::string AXES
void parseDataStruct(xmlNode *a_node, SDMDataObject &sdmDataObject)
static const std::string SPECTRALWINDOW
static const boost::regex PROJECTPATH5
static const std::string SCHEMAVERSION
void parseExecBlock(xmlNode *a_node, SDMDataObject &sdmDataObject)
SDMDataObject::BinaryPart parseBinaryPart(xmlNode *a_node, const std::string &attachmentName)
static void isElement(xmlNode *a_node, const std::string &elementName)
static const std::string ACTUALTIMESREF
A subclass of binaryPart to describe the autodata.
static const std::string AUTODATAREF
static const std::string SW
void parseMemoryCorrSubsetHeader(const std::string &buffer, SDMDataSubset &sdmCorrSubset)
static const std::string DATAOID
A subclass of binaryPart to describe the zeroLags.
static const std::string CROSSPOLPRODUCTS
static const boost::regex PROJECTPATH3
static const ByteOrder * parseByteOrderAttr(xmlNode *a_node, const std::string &attrName)
static bool parseBool(xmlNode *a_node)
void parseFileTPSubsetHeader(const std::string &filename, SDMDataSubset &sdmCorrDataSubset)
static std::string parseStringAttr(xmlNode *a_node, const std::string &attrName)
int parseExecBlockNum(xmlNode *a_node)
static const std::string ABORTOBSERVATION
static const std::string SCHEDULEPERIODTIME
static const std::string SIDEBAND
static const std::string REF
void parseSchedulePeriodTime(xmlNode *a_node, SDMDataSubset &sdmCorrDataSubset)
void parseProjectPath(xmlNode* a_node, SDMDataSubset&amp; sdmCorrDataSubset);
static int parseIntAttr(xmlNode *a_node, const std::string &attrName)
static const boost::regex PROJECTPATH3
static const std::string SWBB
long long parseInterval(xmlNode *a_node)
static const std::string SIZE
static bool testElement(xmlNode *a_node, const std::string &elementName)
long long parseInterval(xmlNode *a_node)
static const std::string FLAGS
std::string getMessage() const
Returns the message associated to this exception.
static const std::string SCHEDULEPERIODTIME
void parseMemory(const std::string &buffer, SDMDataSubset &sdmCorrDataSubset)
static const std::string SDMDATAHEADER
static const boost::regex PROJECTPATH4
xmlDoc * doc
SDMDataObject::TypedBinaryPart parseTypedBinaryPart(xmlNode* a_node, const std::string&amp; attachmentNam...
void parseFileCorrSubsetHeader(const std::string &filename, SDMDataSubset &sdmCorrSubset)
void parseFile(const std::string &filename, SDMDataSubset &sdmTPDataSubset)
static Enum parseLiteral(xmlNode *a_node)
void parseSDMDataSubsetHeader(xmlNode *a_node, SDMDataSubset &sdmCorrDataSubset)
static int parseInt(xmlNode *a_node)
void parseCorrelationMode(xmlNode *a_node, SDMDataObject &sdmDataObject)
void parseFileHeader(const std::string &filename, SDMDataObject &sdmDataObject)
static const std::string SDMDATASUBSETHEADER
long long parseTime(xmlNode *a_node)
CorrSubsetHeaderParser corrSubsetHeaderParser
virtual ~SDMDataObjectParserException()
The destructor.
long long parseTime(xmlNode *a_node)
static const std::string PROJECTPATH
A class to represent byte order information.
static const std::string PROCESSORTYPE
static const std::string SCALEFACTOR
static const std::string SDMDATASUBSETHEADER
class CorrSubsetHeaderParser
std::string parseDataOID(xmlNode *a_node)
int parseDimensionality(xmlNode *a_node)
void parseMemoryTPSubsetHeader(const std::string &filename, SDMDataSubset &sdmCorrDataSubset)
void parseSpectralWindow(xmlNode *a_node, SDMDataObject &sdmDataObject, std::vector< SDMDataObject::SpectralWindow > &spectralWindow)
static const std::string SUBSCANNUM
void parseFile(const std::string &filename, SDMDataSubset &sdmCorrDataSubset)
static const std::string ACTUALDURATIONSREF
static void inElements(xmlNode *a_node, const std::vector< std::string > &elementNames)
int parseNumAntenna(xmlNode *a_node)
void parseMemory(const std::string &buffer, SDMDataObject &sdmDataObject)
static xmlAttr * hasAttr(xmlNode *a_node, const std::string &attrName)
static const std::string BYTEORDER
struct _xmlNode xmlNode
Definition: Misc.h:55
static const std::string NUMANTENNA
TableExprNode regex(const TableExprNode &node)
Functions for regular expression matching and pattern matching.
Definition: ExprNode.h:1440
static const std::string NUMSPECTRALPOINT
static const boost::regex PROJECTPATH3
Regular expressions used to decipher the content of projectPath attribute.
void parseMemory(const std::string &buffer, SDMDataSubset &sdmTPDataSubset)
static const std::string ACTUALDURATIONSREF
static const std::string APC
static const std::string XLINKTITLE
static const std::string SPECTRALRESOLUTION
static std::vector< Enum > parseStringsAttr(xmlNode *a_node, const std::string &attrName)
int parseNumTime(xmlNode *a_node)
long long parseStartTime(xmlNode *a_node)
static const std::string DATASTRUCT
static std::set< std::string > parseStringSetAttr(xmlNode *a_node, const std::string &attrName)
static float parseFloatAttr(xmlNode *a_node, const std::string &attrName)
static const std::string CORRELATORTYPE
static const std::string NORMALIZED
static const std::string PROJECTPATH
static const std::string SDPOLPRODUCTS
SDMDataObject::BinaryPart:: declarations.
void parseBinaryData(xmlNode *a_node, SDMDataSubset &sdmTPDataSubset)
A class to represent an exception thrown during the parsing of an XML header in a MIME message contai...
static const std::string CORRELATIONMODE
static const std::string IMAGE
void parseSDMDataSubsetHeader(xmlNode *a_node, SDMDataSubset &sdmTPDataSubset)
static const std::string NUMTIME
void parseProcessorType(xmlNode *a_node, SDMDataObject &sdmDataObject)
static const std::string ACTUALDURATIONS
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
int parseSubscanNum(xmlNode *a_node)
static float parseFloat(xmlNode *a_node)
SDMDataObject::AutoDataBinaryPart parseAutoDataBinaryPart(xmlNode *a_node, const std::string &attachmentName)