casa
$Rev:20696$
|
00001 #ifndef SDMDataObjectWriter_CLASS 00002 #define SDMDataObjectWriter_CLASS 00003 00004 #include <string> 00005 #include <map> 00006 #include <set> 00007 #include <vector> 00008 #include <bitset> 00009 //#include <boost/regex.hpp> 00010 00011 #include <iostream> 00012 #include <fstream> 00013 #include <sstream> 00014 00015 #include "SDMDataObject.h" 00016 00017 #include "CAtmPhaseCorrection.h" 00018 #include "CCorrelationMode.h" 00019 #include "CCorrelatorType.h" 00020 #include "CNetSideband.h" 00021 #include "CProcessorType.h" 00022 00023 00024 using namespace std; 00025 00026 using namespace AtmPhaseCorrectionMod; 00027 using namespace CorrelationModeMod; 00028 using namespace CorrelatorTypeMod; 00029 using namespace NetSidebandMod; 00030 using namespace ProcessorTypeMod; 00031 00032 namespace asdmbinaries { 00036 class SDMDataObjectWriterException { 00037 00038 public: 00042 SDMDataObjectWriterException(); 00043 00048 SDMDataObjectWriterException(const string& m); 00049 00053 virtual ~SDMDataObjectWriterException(); 00054 00059 string getMessage() const; 00060 00061 protected: 00062 string message; 00063 00064 }; 00065 00066 inline SDMDataObjectWriterException::SDMDataObjectWriterException() : message ("SDMDataObjectWritererException") {} 00067 inline SDMDataObjectWriterException::SDMDataObjectWriterException(const string& m) : message(m) {} 00068 inline SDMDataObjectWriterException::~SDMDataObjectWriterException() {} 00069 inline string SDMDataObjectWriterException::getMessage() const { 00070 return "SDMDataObjectWriterException : " + message; 00071 } 00072 00276 class SDMDataObjectWriter { 00277 public: 00278 00285 SDMDataObjectWriter(const string& uid="uid://X0/X0/X0", const string& title="ALMA Binary Data"); 00286 00287 00295 SDMDataObjectWriter(ofstream* ofs, const string& uid="uid://X0/X0/X0", const string& title="ALMA Binary Data"); 00296 00305 SDMDataObjectWriter(ostringstream* oss, const string& uid="uid://X0/X0/X0", const string& title="ALMA Binary Data"); 00306 00307 00312 virtual ~SDMDataObjectWriter(); 00313 00314 00321 void done(); 00322 00336 void tpDataHeader(uint64_t startTime, 00337 const string& execBlockUID, 00338 uint32_t execBlockNum, 00339 uint32_t scanNum, 00340 uint32_t subscanNum, 00341 uint32_t numOfIntegrations, 00342 uint32_t numAntenna, 00343 SDMDataObject::DataStruct& dataStruct); 00344 00359 void addTPSubscan(uint64_t time, 00360 uint64_t interval, 00361 const vector<FLAGSTYPE>& flags, 00362 const vector<ACTUALTIMESTYPE>& actualTimes, 00363 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00364 const vector<AUTODATATYPE>& autoData); 00365 00394 void tpData(uint64_t startTime, 00395 const string& execBlockUID, 00396 uint32_t execBlockNum, 00397 uint32_t scanNum, 00398 uint32_t subscanNum, 00399 uint32_t numOfIntegrations, 00400 uint32_t numAntenna, 00401 const vector<SDMDataObject::Baseband>& basebands, 00402 uint64_t time, 00403 uint64_t interval, 00404 const vector<AxisName>& flagsAxes, 00405 const vector<FLAGSTYPE>& flags, 00406 const vector<AxisName>& actualTimesAxes, 00407 const vector<ACTUALTIMESTYPE>& actualTimes, 00408 const vector<AxisName>& actualDurationsAxes, 00409 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00410 const vector<AxisName>& autoDataAxes, 00411 const vector<AUTODATATYPE>& autoData); 00412 00435 void tpData(uint64_t startTime, 00436 const string& execBlockUID, 00437 uint32_t execBlockNum, 00438 uint32_t scanNum, 00439 uint32_t subscanNum, 00440 uint32_t numOfIntegrations, 00441 uint32_t numAntenna, 00442 const vector<SDMDataObject::Baseband>& basebands, 00443 uint64_t time, 00444 uint64_t interval, 00445 const vector<AxisName>& autoDataAxes, 00446 const vector<AUTODATATYPE>& autoData); 00447 00491 void wvrData (const string & execBlockUID, 00492 uint32_t execBlockNum, 00493 uint32_t scanNum, 00494 uint32_t subscanNum, 00495 uint32_t numTimes, 00496 uint32_t numAntennas, 00497 uint32_t numChannels, 00498 NetSideband netSideband, 00499 uint64_t time, 00500 uint64_t interval, 00501 const vector<AUTODATATYPE>& wvrData, 00502 const vector<FLAGSTYPE>& flags); 00503 00504 00520 void corrDataHeader(uint64_t startime, 00521 const string& execBlockUID, 00522 uint32_t execBlockNum, 00523 uint32_t scanNum, 00524 uint32_t subscanNum, 00525 uint32_t numAntenna, 00526 CorrelationMode correlationMode, 00527 const OptionalSpectralResolutionType& spectralResolutionType, 00528 SDMDataObject::DataStruct& dataStruct); 00529 00530 00553 void addIntegration(uint32_t integrationNum, 00554 uint64_t time, 00555 uint64_t interval, 00556 const vector<FLAGSTYPE>& flags, 00557 const vector<ACTUALTIMESTYPE>& actualTimes, 00558 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00559 const vector<ZEROLAGSTYPE>& zeroLags, 00560 const vector<INTCROSSDATATYPE>& crossData, 00561 const vector<AUTODATATYPE>& autoData); 00562 00563 00586 void addIntegration(uint32_t integrationNum, 00587 uint64_t time, 00588 uint64_t interval, 00589 const vector<FLAGSTYPE>& flags, 00590 const vector<ACTUALTIMESTYPE>& actualTimes, 00591 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00592 const vector<ZEROLAGSTYPE>& zeroLags, 00593 const vector<SHORTCROSSDATATYPE>& crossData, 00594 const vector<AUTODATATYPE>& autoData); 00595 00618 void addIntegration(uint32_t integrationNum, 00619 uint64_t time, 00620 uint64_t interval, 00621 const vector<FLAGSTYPE>& flags, 00622 const vector<ACTUALTIMESTYPE>& actualTimes, 00623 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00624 const vector<ZEROLAGSTYPE>& zeroLags, 00625 const vector<FLOATCROSSDATATYPE>& crossData, 00626 const vector<AUTODATATYPE>& autoData); 00627 00628 00652 void addSubintegration(uint32_t integrationNum, 00653 uint32_t subintegrationNum, 00654 uint64_t time, 00655 uint64_t interval, 00656 const vector<FLAGSTYPE>& flags, 00657 const vector<ACTUALTIMESTYPE>& actualTimes, 00658 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00659 const vector<ZEROLAGSTYPE>& zeroLags, 00660 const vector<INTCROSSDATATYPE>& crossData, 00661 const vector<AUTODATATYPE>& autoData); 00662 00663 00687 void addSubintegration(uint32_t integrationNum, 00688 uint32_t subintegrationNum, 00689 uint64_t time, 00690 uint64_t interval, 00691 const vector<FLAGSTYPE>& flags, 00692 const vector<ACTUALTIMESTYPE>& actualTimes, 00693 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00694 const vector<ZEROLAGSTYPE>& zeroLags, 00695 const vector<SHORTCROSSDATATYPE>& crossData, 00696 const vector<AUTODATATYPE>& autoData); 00697 00721 void addSubintegration(uint32_t integrationNum, 00722 uint32_t subintegrationNum, 00723 uint64_t time, 00724 uint64_t interval, 00725 const vector<FLAGSTYPE>& flags, 00726 const vector<ACTUALTIMESTYPE>& actualTimes, 00727 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00728 const vector<ZEROLAGSTYPE>& zeroLags, 00729 const vector<FLOATCROSSDATATYPE>& crossData, 00730 const vector<AUTODATATYPE>& autoData); 00731 00745 uint64_t numBytes(); 00746 00747 00748 void output (const string& s); 00749 void outputln (const string& s); 00750 void output (const float* data, uint32_t numData); 00751 void outputln (const float* data, uint32_t numData); 00752 void outputln (const long long* data, uint32_t numData); 00753 00754 template <class T> void output(const vector<T>& data) { 00755 numBytes_ += data.size()*sizeof(T); 00756 switch (otype_) { 00757 00758 case STDOUT: 00759 cout.write((const char*)&data.at(0), data.size()*sizeof(T)); 00760 break; 00761 00762 case MEMORY: 00763 oss_->write((const char*)&data.at(0), data.size()*sizeof(T)); 00764 break; 00765 00766 case FILE: 00767 ofs_->write((const char*)&data.at(0), data.size()*sizeof(T)); 00768 break; 00769 } 00770 } 00771 00772 template <class T> void outputln (const vector<T>& data) { 00773 output<T>(data); 00774 outputln(); 00775 } 00776 00777 void outputln (); 00778 00779 void outputlnLocation(const string& name, const SDMDataSubset& sdmDataSubset); 00780 00781 private: 00782 enum OUTDEST {STDOUT, MEMORY, FILE}; 00783 OUTDEST otype_; 00784 ofstream* ofs_; 00785 ostringstream* oss_; 00786 00787 // The ALMA uid of the MIME message. 00788 string uid_; 00789 00790 // The title of the binary data. 00791 string title_; 00792 00793 // The subscan path. 00794 string subscanPath_; 00795 00796 // An SDMDataObject 00797 SDMDataObject sdmDataObject_; 00798 00799 // The number of the SDMDataSubset being written 00800 uint32_t sdmDataSubsetNum_; 00801 00802 // Two strings used as MIME boundaries 00803 static const string MIMEBOUNDARY_1; 00804 static const string MIMEBOUNDARY_2; 00805 00806 00807 // Class initialization stuff 00808 static const bool initClass_; 00809 static bool initClass(); 00810 00811 // The axes names definitions for WVR data and their related flags. 00812 static vector<AxisName> WVRDATAAXES, WVRDATAFLAGSAXES; 00813 00814 // A utility to fill a vector of <Enum> from a an array of c-strings. 00815 template <class Enum, class EnumHelper> static vector<Enum> enumvec(const string& strliterals) { 00816 vector<Enum> result; 00817 00818 string strliteral; 00819 stringstream ss(strliterals); 00820 00821 vector<string> tokens; 00822 while (ss >> strliteral) 00823 result.push_back(EnumHelper::literal(strliteral)); 00824 00825 return result; 00826 } 00827 00828 // Writes the very first part of the MIME message. 00829 void preamble(); 00830 00831 // Write the very end of the MIME message. 00832 void postamble(); 00833 00834 00835 void addData(uint32_t integrationNum, 00836 uint32_t subintegrationNum, 00837 uint64_t time, 00838 uint64_t interval, 00839 const vector<FLAGSTYPE>& flags, 00840 const vector<ACTUALTIMESTYPE>& actualTimes, 00841 const vector<ACTUALDURATIONSTYPE>& actualDurations, 00842 const vector<ZEROLAGSTYPE>& zeroLags, 00843 const vector<INTCROSSDATATYPE>& intCrossData, 00844 const vector<SHORTCROSSDATATYPE>& shortCrossData, 00845 const vector<FLOATCROSSDATATYPE>& floatCrossData, 00846 const vector<AUTODATATYPE>& autoData); 00847 00848 // Are we done with this ? 00849 bool done_; 00850 00851 // The number of bytes written so far. 00852 uint64_t numBytes_; 00853 00854 00855 // A small finite state automaton to control the usage of SDMDataObjectWriter. 00856 enum States {START, S_TPDATA, S_TPDATAHEADER, S_ADDTPSUBSCAN, S_WVRDATA, S_CORRDATAHEADER, S_ADDINTEGRATION, S_ADDSUBINTEGRATION, END}; 00857 enum Transitions {T_TPDATA, T_TPDATAHEADER, T_ADDTPSUBSCAN, T_WVRDATA, T_CORRDATAHEADER, T_ADDINTEGRATION, T_ADDSUBINTEGRATION, T_DONE}; 00858 States currentState_; 00859 00860 void checkState(Transitions t, const string& methodName); 00861 00862 }; 00863 } // namespace asdmbinaries 00864 #endif // SDMDataObjectWriter_CLASS