SDMDataObjectStreamReader.h

Go to the documentation of this file.
00001 #ifndef SDMDataObjectStreamReader_CLASS
00002 #define SDMDataObjectStreamReader_CLASS
00003 #include <utility>
00004 #include <iostream>
00005 #include <sstream>
00006 #include <fstream>
00007 #include <vector>
00008 #include <map>
00009 #include <set>
00010 #include <bitset>
00011 #include <boost/algorithm/string.hpp>
00012 #include <libxml/parser.h>
00013 #include <libxml/tree.h>
00014 
00015 #include "boost/filesystem/operations.hpp"
00016 #include <boost/regex.hpp>
00017 
00018 #include "SDMDataObjectParser.h"
00019 #include "SDMDataObject.h"
00020 #include "CPrimitiveDataType.h"
00021 
00022 using namespace std;
00023 using namespace boost;
00024 
00025 namespace asdmbinaries {
00026   class SDMDataObjectStreamReaderException {
00027   public:
00028     SDMDataObjectStreamReaderException();
00029     SDMDataObjectStreamReaderException(const string& message);
00030   
00031     const string& getMessage();
00032   
00033   private:
00034     string message;
00035   };
00036  
00037   class SDMDataObjectStreamReader {
00038   public:
00039     SDMDataObjectStreamReader() ;
00040     virtual ~SDMDataObjectStreamReader() ;
00047     void        open(const string& path);
00048 
00056     int64_t position();
00057 
00058 
00063     void position(int64_t p);
00064     
00068     void close();
00069 
00075     unsigned long long currentIntegrationStartsAt() const;
00076 
00083     unsigned int currentIntegrationIndex() const;
00084 
00089     string title() const;
00090 
00095     const ByteOrder* byteOrder() const ;
00096 
00101     unsigned long long startTime() const;
00102 
00108     unsigned int numTime() const;
00109 
00114     string dataOID() const;
00115 
00120     string execBlockUID() const;
00121 
00126     unsigned int execBlockNum() const;
00127 
00132     unsigned int scanNum() const;
00133 
00138     unsigned int subscanNum() const;
00139 
00144     string projectPath() const;
00145 
00150     unsigned int numAntenna() const;
00151 
00156     CorrelationMode correlationMode() const;
00157 
00158 
00167     OptionalSpectralResolutionType spectralResolutionType() const;
00168 
00173     ProcessorType processorType() const;
00174 
00175 
00182     CorrelatorType correlatorType() const;
00183 
00190     bool hasPackedData() const;
00191 
00198     bool isTP() const ;
00199 
00206     bool isWVR() const ;
00207 
00208 
00215     bool isCorrelation() const;
00216 
00221     const SDMDataObject::DataStruct& dataStruct() const;
00222 
00231     bool aborted() const;
00232 
00243     unsigned long long abortTime() const;
00244 
00255     string abortReason() const;
00256 
00261     string toString() const;
00262 
00267     bool                        hasSubset();
00268 
00269     /*
00270      * Returns a reference to an SDMDataSubset.
00271      * This SDMDataSubset represents the (sub)integration read and parsed at the current position (see currentIntegrationIndex()
00272      * and currentIntegrationStartsAt()) in the sequence stored in the stream.
00273      * O
00274      * 
00275      * @return a reference to an SDMDataSubset
00276      */
00277     const SDMDataSubset&        getSubset();
00278 
00279     /*
00280      * Returns binary data found in the BDF file from the current location and contained in the next 
00281      * nDataSubsets at maximum.
00282      *
00283      * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
00284      * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
00285      * from the current position in that file.
00286      *
00287      * The size of the resulting vector determines how many SDMDataSubsets have been actually read. 
00288      *
00289      * @return const vector<SDMDataSubset>& 
00290      */
00291     const vector<SDMDataSubset>& nextSubsets(unsigned int nSubsets);
00292 
00293     /*
00294      * Returns all binary data found in the BDF file from the current location.
00295      *
00296      * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
00297      * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
00298      * from the current position in that file. 
00299      *
00300      * @return const vector<SDMDataSubset>& 
00301      */
00302     const vector<SDMDataSubset>& allRemainingSubsets();
00303 
00304     enum BINATTACHCODES {ACTUALDURATIONS=0, ACTUALTIMES=1, AUTODATA=2, FLAGS=3, CROSSDATA=4, ZEROLAGS=5};
00305     bitset<6> attachmentFlags;
00306 
00307   private:
00308     // Enumerations to manage the state of an instance of SDMDataObjectStreamReader.
00309     //
00310     enum States {S_NO_BDF, S_AT_BEGINNING, S_READING, S_AT_END};
00311     enum Transitions {T_OPEN, T_QUERY, T_TEST_END, T_READ, T_READ_NEXT, T_READ_ALL, T_CLOSE};
00312 
00313     // Private variables
00314     unsigned long long integrationStartsAt;
00315     unsigned int       integrationIndex;
00316     string      path;
00317     ifstream    f;
00318     States      currentState;
00319     string      currentLine;
00320     string      boundary_1;
00321     string      boundary_2;
00322     bool        opened;
00323 
00324     map<string, int64_t>        binaryPartSize;
00325     set<string>                 s_partNames;
00326     char*                       actualTimesBuffer;
00327     char*                       actualDurationsBuffer;
00328     char*                       autoDataBuffer;
00329     char*                       crossDataBuffer;
00330     char*                       flagsBuffer;
00331     char*                       zeroLagsBuffer;
00332 
00333     SDMDataObjectParser   parser;
00334     SDMDataObject         sdmDataObject;
00335     SDMDataSubset         sdmDataSubset;
00336     vector<SDMDataSubset> remainingSubsets;
00337     vector<SDMDataSubset> someSubsets;
00338 
00339     // Private methods
00340     void                        checkState(Transitions t, const string& methodName) const; 
00341     string                      nextLine();
00342     pair<string, string>        headerField2Pair(const string& hf);
00343     pair<string, string>        requireHeaderField(const string& hf);
00344     string                      requireMIMEHeader();
00345     string                      requireBoundaryInCT(const string& ctValue);
00346     void                        skipAsLongAsLineStartsWith(const string& start);
00347     void                        skipUntilEmptyLine(int maxSkips);  
00348     string                      accumulateUntilBoundary(const string& boundary, int maxLines);
00349     void                        requireBoundary(const string&, int maxLines);
00350     void                        lookForBinaryPartSize(xmlNode*  aNode);
00351     string                      requireCrossDataType(xmlNode* parent);
00352 
00353     void        printElementNames(xmlNode * a_node);
00354     void        requireSDMDataHeaderMIMEPart();
00355     void        requireSDMDataSubsetMIMEPart(SDMDataSubset& sdmDataSubset);
00356 
00357     void        releaseMemory(SDMDataSubset & sdmDataSubset);
00358   };
00359 } // end namespace asdmbinaries
00360 
00361 #endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1