casa
$Rev:20696$
|
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 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 00052 void close(); 00053 00059 unsigned long long currentIntegrationStartsAt() const; 00060 00067 unsigned int currentIntegrationIndex() const; 00068 00073 string title() const; 00074 00079 unsigned long long startTime() const; 00080 00086 unsigned int numTime() const; 00087 00092 string dataOID() const; 00093 00098 string execBlockUID() const; 00099 00104 unsigned int execBlockNum() const; 00105 00110 unsigned int scanNum() const; 00111 00116 unsigned int subscanNum() const; 00117 00122 string projectPath() const; 00123 00128 unsigned int numAntenna() const; 00129 00134 CorrelationMode correlationMode() const; 00135 00136 00145 OptionalSpectralResolutionType spectralResolutionType() const; 00146 00151 ProcessorType processorType() const; 00152 00153 00160 CorrelatorType correlatorType() const; 00161 00168 bool isTP() const ; 00169 00170 00177 bool isCorrelation() const; 00178 00183 const SDMDataObject::DataStruct& dataStruct() const; 00184 00193 bool aborted() const; 00194 00205 unsigned long long abortTime() const; 00206 00217 string abortReason() const; 00218 00223 string toString() const; 00224 00229 bool hasSubset(); 00230 00231 /* 00232 * Returns a reference to an SDMDataSubset. 00233 * This SDMDataSubset represents the (sub)integration read and parsed at the current position (see currentIntegrationIndex() 00234 * and currentIntegrationStartsAt()) in the sequence stored in the stream. 00235 * O 00236 * 00237 * @return a reference to an SDMDataSubset 00238 */ 00239 const SDMDataSubset& getSubset(); 00240 00241 /* 00242 * Returns binary data found in the BDF file from the current location and contained in the next 00243 * nDataSubsets at maximum. 00244 * 00245 * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector 00246 * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open 00247 * from the current position in that file. 00248 * 00249 * The size of the resulting vector determines how many SDMDataSubsets have been actually read. 00250 * 00251 * @return const vector<SDMDataSubset>& 00252 */ 00253 const vector<SDMDataSubset>& nextSubsets(unsigned int nSubsets); 00254 00255 /* 00256 * Returns all binary data found in the BDF file from the current location. 00257 * 00258 * The result is returned as a reference to a vector of SDMDataSubset. Each element of this vector 00259 * is an instance of an SDMDataSubset obtained by a sequential read of the file opened with the method open 00260 * from the current position in that file. 00261 * 00262 * @return const vector<SDMDataSubset>& 00263 */ 00264 const vector<SDMDataSubset>& allRemainingSubsets(); 00265 00266 private: 00267 // Enumerations to manage the state of an instance of SDMDataObjectStreamReader. 00268 // 00269 enum States {S_NO_BDF, S_AT_BEGINNING, S_READING, S_AT_END}; 00270 enum Transitions {T_OPEN, T_QUERY, T_TEST_END, T_READ, T_READ_NEXT, T_READ_ALL, T_CLOSE}; 00271 00272 // Private variables 00273 unsigned long long integrationStartsAt; 00274 unsigned int integrationIndex; 00275 string path; 00276 ifstream f; 00277 States currentState; 00278 string currentLine; 00279 string boundary_1; 00280 string boundary_2; 00281 bool opened; 00282 00283 map<string, int64_t> binaryPartSize; 00284 set<string> s_partNames; 00285 char* actualTimesBuffer; 00286 char* actualDurationsBuffer; 00287 char* autoDataBuffer; 00288 char* crossDataBuffer; 00289 char* flagsBuffer; 00290 char* zeroLagsBuffer; 00291 00292 SDMDataObjectParser parser; 00293 SDMDataObject sdmDataObject; 00294 SDMDataSubset sdmDataSubset; 00295 vector<SDMDataSubset> remainingSubsets; 00296 vector<SDMDataSubset> someSubsets; 00297 00298 // Private methods 00299 void checkState(Transitions t, const string& methodName) const; 00300 string nextLine(); 00301 pair<string, string> headerField2Pair(const string& hf); 00302 pair<string, string> requireHeaderField(const string& hf); 00303 string requireMIMEHeader(); 00304 string requireBoundaryInCT(const string& ctValue); 00305 void skipUntilEmptyLine(int maxSkips); 00306 string accumulateUntilBoundary(const string& boundary, int maxLines); 00307 void requireBoundary(const string&, int maxLines); 00308 void lookForBinaryPartSize(xmlNode* aNode); 00309 string requireCrossDataType(xmlNode* parent); 00310 00311 void printElementNames(xmlNode * a_node); 00312 void requireSDMDataHeaderMIMEPart(); 00313 void requireSDMDataSubsetMIMEPart(SDMDataSubset& sdmDataSubset); 00314 00315 void releaseMemory(SDMDataSubset & sdmDataSubset); 00316 }; 00317 } // end namespace asdmbinaries 00318 00319 #endif