casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDMDataObjectStreamReader.h
Go to the documentation of this file.
1 #ifndef SDMDataObjectStreamReader_CLASS
2 #define SDMDataObjectStreamReader_CLASS
3 #include <utility>
4 #include <iostream>
5 #include <sstream>
6 #include <fstream>
7 #include <vector>
8 #include <map>
9 #include <set>
10 #include <bitset>
11 #ifndef WITHOUT_BOOST
12 #include <boost/algorithm/string.hpp>
13 #endif
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
16 
17 #ifndef WITHOUT_BOOST
18 #include "boost/filesystem/operations.hpp"
19 #include <boost/regex.hpp>
20 #endif
21 
25 
26 namespace asdmbinaries {
28  public:
30  SDMDataObjectStreamReaderException(const std::string& message);
31 
32  const std::string& getMessage();
33 
34  private:
35  std::string message;
36  };
37 
39  public:
41  virtual ~SDMDataObjectStreamReader() ;
48  void open(const std::string& path);
49 
57  int64_t position();
58 
59 
64  void position(int64_t p);
65 
69  void close();
70 
76  unsigned long long currentIntegrationStartsAt() const;
77 
84  unsigned int currentIntegrationIndex() const;
85 
90  std::string title() const;
91 
96  const ByteOrder* byteOrder() const ;
97 
102  unsigned long long startTime() const;
103 
109  unsigned int numTime() const;
110 
115  std::string dataOID() const;
116 
121  std::string execBlockUID() const;
122 
127  unsigned int execBlockNum() const;
128 
133  unsigned int scanNum() const;
134 
139  unsigned int subscanNum() const;
140 
145  std::string projectPath() const;
146 
151  unsigned int numAntenna() const;
152 
157  CorrelationModeMod::CorrelationMode correlationMode() const;
158 
159 
169 
174  ProcessorTypeMod::ProcessorType processorType() const;
175 
176 
183  CorrelatorTypeMod::CorrelatorType correlatorType() const;
184 
191  bool hasPackedData() const;
192 
199  bool isTP() const ;
200 
207  bool isWVR() const ;
208 
209 
216  bool isCorrelation() const;
217 
222  const SDMDataObject::DataStruct& dataStruct() const;
223 
232  bool aborted() const;
233 
244  unsigned long long abortTime() const;
245 
256  std::string abortReason() const;
257 
262  std::string toString() const;
263 
268  bool hasSubset();
269 
270  /*
271  * Returns a reference to an SDMDataSubset.
272  * This SDMDataSubset represents the (sub)integration read and parsed at the current position (see currentIntegrationIndex()
273  * and currentIntegrationStartsAt()) in the sequence stored in the stream.
274  * O
275  *
276  * @return a reference to an SDMDataSubset
277  */
278  const SDMDataSubset& getSubset();
279 
280  /*
281  * Returns binary data found in the BDF file from the current location and contained in the next
282  * nDataSubsets at maximum.
283  *
284  * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
285  * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
286  * from the current position in that file.
287  *
288  * The size of the resulting vector determines how many SDMDataSubsets have been actually read.
289  *
290  * @return const vector<SDMDataSubset>&
291  */
292  const std::vector<SDMDataSubset>& nextSubsets(unsigned int nSubsets);
293 
294  /*
295  * Returns all binary data found in the BDF file from the current location.
296  *
297  * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
298  * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
299  * from the current position in that file.
300  *
301  * @return const vector<SDMDataSubset>&
302  */
303  const std::vector<SDMDataSubset>& allRemainingSubsets();
304 
306  std::bitset<6> attachmentFlags;
307 
308  private:
309  // Enumerations to manage the state of an instance of SDMDataObjectStreamReader.
310  //
313 
314  // Private variables
315  unsigned long long integrationStartsAt;
316  unsigned int integrationIndex;
317  std::string path;
318  std::ifstream f;
320  std::string currentLine;
321  std::string boundary_1;
322  std::string boundary_2;
323  bool opened;
324 
325  std::map<std::string, int64_t> binaryPartSize;
326  std::set<std::string> s_partNames;
331  char* flagsBuffer;
333 
337  std::vector<SDMDataSubset> remainingSubsets;
338  std::vector<SDMDataSubset> someSubsets;
339 
340  // Private methods
341  void checkState(Transitions t, const std::string& methodName) const;
342  std::string nextLine();
343  std::pair<std::string, std::string> headerField2Pair(const std::string& hf);
344  std::pair<std::string, std::string> requireHeaderField(const std::string& hf);
345  std::string requireMIMEHeader();
346  std::string requireBoundaryInCT(const std::string& ctValue);
347  void skipAsLongAsLineStartsWith(const std::string& start);
348  void skipUntilEmptyLine(int maxSkips);
349  std::string accumulateUntilBoundary(const std::string& boundary, int maxLines);
350  void requireBoundary(const std::string&, int maxLines);
351  void lookForBinaryPartSize(xmlNode* aNode);
352  std::string requireCrossDataType(xmlNode* parent);
353 
354  void printElementNames(xmlNode * a_node);
357 
359  };
360 } // end namespace asdmbinaries
361 
362 #endif
const ByteOrder * byteOrder() const
Returns the byte order of the SDMDataObject.
SDMDataObject:: declarations.
std::string requireBoundaryInCT(const std::string &ctValue)
void releaseMemory(SDMDataSubset &sdmDataSubset)
int64_t position()
Returns the current position in the BDF file.
bool isWVR() const
Returns true if the data are WVR data and false otherwise.
std::string abortReason() const
Returns the reason, as a string, why the observation has been aborted.
const std::vector< SDMDataSubset > & nextSubsets(unsigned int nSubsets)
void open(const std::string &path)
Open a file expected to contain BDF data, read and parse the global header.
std::string dataOID() const
Returns the dataOID.
ProcessorTypeMod::ProcessorType processorType() const
Returns the processor type.
bool hasPackedData() const
Returns true if the binary data are all packed in one subset or distributed in a sequence of subsets ...
std::pair< std::string, std::string > requireHeaderField(const std::string &hf)
std::pair< std::string, std::string > headerField2Pair(const std::string &hf)
void checkState(Transitions t, const std::string &methodName) const
Private methods.
bool aborted() const
Returns true if the observation has been aborted.
unsigned int execBlockNum() const
Returns the number of the ExecBlock.
unsigned int numTime() const
Returns the number of (sub) integrations.
unsigned long long startTime() const
Returns the start time.
unsigned long long currentIntegrationStartsAt() const
Returns the current position in bytes in the file of the current block of data (subscan, integration or subintegration) .
std::map< std::string, int64_t > binaryPartSize
std::string projectPath() const
Returns the project path.
OptionalSpectralResolutionType spectralResolutionType() const
Returns the spectral resolution.
States
Enumerations to manage the state of an instance of SDMDataObjectStreamReader.
unsigned long long integrationStartsAt
Private variables.
bool isCorrelation() const
Returns true if the data are correlator data and false otherwise.
CorrelationModeMod::CorrelationMode correlationMode() const
Returns the correlation mode.
unsigned long long abortTime() const
Returns the time, as an unsigned long long, at which the observation has been aborted.
CorrelatorTypeMod::CorrelatorType correlatorType() const
Returns the correlator type.
void requireBoundary(const std::string &, int maxLines)
void close()
Close the file containing the BDF data and releases all the memory dynamically allocated.
std::string requireCrossDataType(xmlNode *parent)
unsigned int numAntenna() const
Returns the number of antenna.
A class to represent byte order information.
const std::vector< SDMDataSubset > & allRemainingSubsets()
void lookForBinaryPartSize(xmlNode *aNode)
struct _xmlNode xmlNode
Definition: Misc.h:55
std::string toString() const
Returns a string representation of the global header of this SDMDataObject.
std::string execBlockUID() const
Returns the UID of the ExecBlock.
bool hasSubset()
Returns true as long as the mark announcing the end of the sequence of (sub)integrations is not read ...
std::string accumulateUntilBoundary(const std::string &boundary, int maxLines)
void printElementNames(xmlNode *a_node)
void skipAsLongAsLineStartsWith(const std::string &start)
std::string title() const
Returns the title of the SDMDataObject.
bool isTP() const
Returns true if the data are total power data and false otherwise.
unsigned int currentIntegrationIndex() const
Returns the index of the current block of data (subscan, integration or subintegration).
unsigned int subscanNum() const
Returns the number of the subscan.
unsigned int scanNum() const
Returns the number of the scan.
void requireSDMDataSubsetMIMEPart(SDMDataSubset &sdmDataSubset)
SDMDataObject::DataStruct:: declarations.
const SDMDataObject::DataStruct & dataStruct() const
Returns the structure of the data.