casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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     
00061     void close();
00062 
00068     unsigned long long currentIntegrationStartsAt() const;
00069 
00076     unsigned int currentIntegrationIndex() const;
00077 
00082     string title() const;
00083 
00088     const ByteOrder* byteOrder() const ;
00089 
00094     unsigned long long startTime() const;
00095 
00101     unsigned int numTime() const;
00102 
00107     string dataOID() const;
00108 
00113     string execBlockUID() const;
00114 
00119     unsigned int execBlockNum() const;
00120 
00125     unsigned int scanNum() const;
00126 
00131     unsigned int subscanNum() const;
00132 
00137     string projectPath() const;
00138 
00143     unsigned int numAntenna() const;
00144 
00149     CorrelationMode correlationMode() const;
00150 
00151 
00160     OptionalSpectralResolutionType spectralResolutionType() const;
00161 
00166     ProcessorType processorType() const;
00167 
00168 
00175     CorrelatorType correlatorType() const;
00176 
00183     bool isTP() const ;
00184 
00185 
00192     bool isCorrelation() const;
00193 
00198     const SDMDataObject::DataStruct& dataStruct() const;
00199 
00208     bool aborted() const;
00209 
00220     unsigned long long abortTime() const;
00221 
00232     string abortReason() const;
00233 
00238     string toString() const;
00239 
00244     bool                        hasSubset();
00245 
00246     /*
00247      * Returns a reference to an SDMDataSubset.
00248      * This SDMDataSubset represents the (sub)integration read and parsed at the current position (see currentIntegrationIndex()
00249      * and currentIntegrationStartsAt()) in the sequence stored in the stream.
00250      * O
00251      * 
00252      * @return a reference to an SDMDataSubset
00253      */
00254     const SDMDataSubset&        getSubset();
00255 
00256     /*
00257      * Returns binary data found in the BDF file from the current location and contained in the next 
00258      * nDataSubsets at maximum.
00259      *
00260      * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
00261      * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
00262      * from the current position in that file.
00263      *
00264      * The size of the resulting vector determines how many SDMDataSubsets have been actually read. 
00265      *
00266      * @return const vector<SDMDataSubset>& 
00267      */
00268     const vector<SDMDataSubset>& nextSubsets(unsigned int nSubsets);
00269 
00270     /*
00271      * Returns all binary data found in the BDF file from the current location.
00272      *
00273      * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector
00274      * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open
00275      * from the current position in that file. 
00276      *
00277      * @return const vector<SDMDataSubset>& 
00278      */
00279     const vector<SDMDataSubset>& allRemainingSubsets();
00280 
00281     enum BINATTACHCODES {ACTUALDURATIONS=0, ACTUALTIMES=1, AUTODATA=2, FLAGS=3, CROSSDATA=4, ZEROLAGS=5};
00282     bitset<6> attachmentFlags;
00283 
00284   private:
00285     // Enumerations to manage the state of an instance of SDMDataObjectStreamReader.
00286     //
00287     enum States {S_NO_BDF, S_AT_BEGINNING, S_READING, S_AT_END};
00288     enum Transitions {T_OPEN, T_QUERY, T_TEST_END, T_READ, T_READ_NEXT, T_READ_ALL, T_CLOSE};
00289 
00290     // Private variables
00291     unsigned long long integrationStartsAt;
00292     unsigned int       integrationIndex;
00293     string      path;
00294     ifstream    f;
00295     States      currentState;
00296     string      currentLine;
00297     string      boundary_1;
00298     string      boundary_2;
00299     bool        opened;
00300 
00301     map<string, int64_t>        binaryPartSize;
00302     set<string>                 s_partNames;
00303     char*                       actualTimesBuffer;
00304     char*                       actualDurationsBuffer;
00305     char*                       autoDataBuffer;
00306     char*                       crossDataBuffer;
00307     char*                       flagsBuffer;
00308     char*                       zeroLagsBuffer;
00309 
00310     SDMDataObjectParser   parser;
00311     SDMDataObject         sdmDataObject;
00312     SDMDataSubset         sdmDataSubset;
00313     vector<SDMDataSubset> remainingSubsets;
00314     vector<SDMDataSubset> someSubsets;
00315 
00316     // Private methods
00317     void                        checkState(Transitions t, const string& methodName) const; 
00318     string                      nextLine();
00319     pair<string, string>        headerField2Pair(const string& hf);
00320     pair<string, string>        requireHeaderField(const string& hf);
00321     string                      requireMIMEHeader();
00322     string                      requireBoundaryInCT(const string& ctValue);
00323     void                        skipUntilEmptyLine(int maxSkips);  
00324     string                      accumulateUntilBoundary(const string& boundary, int maxLines);
00325     void                        requireBoundary(const string&, int maxLines);
00326     void                        lookForBinaryPartSize(xmlNode*  aNode);
00327     string                      requireCrossDataType(xmlNode* parent);
00328 
00329     void        printElementNames(xmlNode * a_node);
00330     void        requireSDMDataHeaderMIMEPart();
00331     void        requireSDMDataSubsetMIMEPart(SDMDataSubset& sdmDataSubset);
00332 
00333     void        releaseMemory(SDMDataSubset & sdmDataSubset);
00334   };
00335 } // end namespace asdmbinaries
00336 
00337 #endif