casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDMDataObjectWriter.h
Go to the documentation of this file.
1 #ifndef SDMDataObjectWriter_CLASS
2 #define SDMDataObjectWriter_CLASS
3 
4 #include <string>
5 #include <map>
6 #include <set>
7 #include <vector>
8 #include <bitset>
9 
10 #include <iostream>
11 #include <fstream>
12 #include <sstream>
13 
15 
21 
22 namespace asdmbinaries {
27 
28  public:
33 
38  SDMDataObjectWriterException(const std::string& m);
39 
44 
49  std::string getMessage() const;
50 
51  protected:
52  std::string message;
53 
54  };
55 
56  inline SDMDataObjectWriterException::SDMDataObjectWriterException() : message ("SDMDataObjectWritererException") {}
57  inline SDMDataObjectWriterException::SDMDataObjectWriterException(const std::string& m) : message(m) {}
59  inline std::string SDMDataObjectWriterException::getMessage() const {
60  return "SDMDataObjectWriterException : " + message;
61  }
62 
267  public:
268 
275  SDMDataObjectWriter(const std::string& uid="uid://X0/X0/X0", const std::string& title="ALMA Binary Data");
276 
277 
285  SDMDataObjectWriter(std::ofstream* ofs, const std::string& uid="uid://X0/X0/X0", const std::string& title="ALMA Binary Data");
286 
295  SDMDataObjectWriter(std::ostringstream* oss, const std::string& uid="uid://X0/X0/X0", const std::string& title="ALMA Binary Data");
296 
297 
302  virtual ~SDMDataObjectWriter();
303 
304 
311  void done();
312 
313 
314  /* /\** */
315  /* * Writes a data subset of Total Power binary data. */
316  /* * @param time time of the subscan. */
317  /* * @param interval duration of the subscan. */
318  /* * @param flags the values of flags (see note). */
319  /* * @param actualTimes the values of actualTimes (see note). */
320  /* * @param actualDurations the values of actualDurations (see note). */
321  /* * @param autoData the values of autoData. */
322  /* * */
323  /* * @throws SDMDataObjectWriterException */
324  /* * */
325  /* * @note */
326  /* * This method must called only once after a call to tpDataHeader. */
327  /* **\/ */
328  /* void addTPSubscan(uint64_t time, */
329  /* uint64_t interval, */
330  /* const vector<FLAGSTYPE>& flags, */
331  /* const vector<ACTUALTIMESTYPE>& actualTimes, */
332  /* const vector<ACTUALDURATIONSTYPE>& actualDurations, */
333  /* const vector<AUTODATATYPE>& autoData); */
334 
363  void tpData(uint64_t startTime,
364  const std::string& execBlockUID,
365  uint32_t execBlockNum,
366  uint32_t scanNum,
367  uint32_t subscanNum,
368  uint32_t numOfIntegrations,
369  uint32_t numAntenna,
370  const std::vector<SDMDataObject::Baseband>& basebands,
371  uint64_t time,
372  uint64_t interval,
373  const std::vector<AxisNameMod::AxisName>& flagsAxes,
374  const std::vector<FLAGSTYPE>& flags,
375  const std::vector<AxisNameMod::AxisName>& actualTimesAxes,
376  const std::vector<ACTUALTIMESTYPE>& actualTimes,
377  const std::vector<AxisNameMod::AxisName>& actualDurationsAxes,
378  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
379  const std::vector<AxisNameMod::AxisName>& autoDataAxes,
380  const std::vector<AUTODATATYPE>& autoData);
381 
404  void tpData(uint64_t startTime,
405  const std::string& execBlockUID,
406  uint32_t execBlockNum,
407  uint32_t scanNum,
408  uint32_t subscanNum,
409  uint32_t numOfIntegrations,
410  uint32_t numAntenna,
411  const std::vector<SDMDataObject::Baseband>& basebands,
412  uint64_t time,
413  uint64_t interval,
414  const std::vector<AxisNameMod::AxisName>& autoDataAxes,
415  const std::vector<AUTODATATYPE>& autoData);
416 
431  void tpDataHeader(uint64_t startTime,
432  const std::string& execBlockUID,
433  uint32_t execBlockNum,
434  uint32_t scanNum,
435  uint32_t subscanNum,
436  uint32_t numAntenna,
437  SDMDataObject::DataStruct& dataStruct);
438 
455  void tpAddIntegration(uint32_t integrationNum,
456  uint64_t time,
457  uint64_t interval,
458  const std::vector<FLAGSTYPE>& flags,
459  const std::vector<ACTUALTIMESTYPE>& actualTimes,
460  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
461  const std::vector<AUTODATATYPE>& autoData);
462 
506  void wvrData (const std::string & execBlockUID,
507  uint32_t execBlockNum,
508  uint32_t scanNum,
509  uint32_t subscanNum,
510  uint32_t numTimes,
511  uint32_t numAntennas,
512  uint32_t numChannels,
513  NetSidebandMod::NetSideband netSideband,
514  uint64_t time,
515  uint64_t interval,
516  const std::vector<AUTODATATYPE>& wvrData,
517  const std::vector<FLAGSTYPE>& flags);
518 
519 
535  void corrDataHeader(uint64_t startime,
536  const std::string& execBlockUID,
537  uint32_t execBlockNum,
538  uint32_t scanNum,
539  uint32_t subscanNum,
540  uint32_t numAntenna,
541  CorrelationModeMod::CorrelationMode correlationMode,
542  const OptionalSpectralResolutionType& spectralResolutionType,
543  SDMDataObject::DataStruct& dataStruct);
544 
545 
568  void addIntegration(uint32_t integrationNum,
569  uint64_t time,
570  uint64_t interval,
571  const std::vector<FLAGSTYPE>& flags,
572  const std::vector<ACTUALTIMESTYPE>& actualTimes,
573  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
574  const std::vector<ZEROLAGSTYPE>& zeroLags,
575  const std::vector<INTCROSSDATATYPE>& crossData,
576  const std::vector<AUTODATATYPE>& autoData);
577 
578 
601  void addIntegration(uint32_t integrationNum,
602  uint64_t time,
603  uint64_t interval,
604  const std::vector<FLAGSTYPE>& flags,
605  const std::vector<ACTUALTIMESTYPE>& actualTimes,
606  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
607  const std::vector<ZEROLAGSTYPE>& zeroLags,
608  const std::vector<SHORTCROSSDATATYPE>& crossData,
609  const std::vector<AUTODATATYPE>& autoData);
610 
633  void addIntegration(uint32_t integrationNum,
634  uint64_t time,
635  uint64_t interval,
636  const std::vector<FLAGSTYPE>& flags,
637  const std::vector<ACTUALTIMESTYPE>& actualTimes,
638  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
639  const std::vector<ZEROLAGSTYPE>& zeroLags,
640  const std::vector<FLOATCROSSDATATYPE>& crossData,
641  const std::vector<AUTODATATYPE>& autoData);
642 
643 
667  void addSubintegration(uint32_t integrationNum,
668  uint32_t subintegrationNum,
669  uint64_t time,
670  uint64_t interval,
671  const std::vector<FLAGSTYPE>& flags,
672  const std::vector<ACTUALTIMESTYPE>& actualTimes,
673  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
674  const std::vector<ZEROLAGSTYPE>& zeroLags,
675  const std::vector<INTCROSSDATATYPE>& crossData,
676  const std::vector<AUTODATATYPE>& autoData);
677 
678 
702  void addSubintegration(uint32_t integrationNum,
703  uint32_t subintegrationNum,
704  uint64_t time,
705  uint64_t interval,
706  const std::vector<FLAGSTYPE>& flags,
707  const std::vector<ACTUALTIMESTYPE>& actualTimes,
708  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
709  const std::vector<ZEROLAGSTYPE>& zeroLags,
710  const std::vector<SHORTCROSSDATATYPE>& crossData,
711  const std::vector<AUTODATATYPE>& autoData);
712 
736  void addSubintegration(uint32_t integrationNum,
737  uint32_t subintegrationNum,
738  uint64_t time,
739  uint64_t interval,
740  const std::vector<FLAGSTYPE>& flags,
741  const std::vector<ACTUALTIMESTYPE>& actualTimes,
742  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
743  const std::vector<ZEROLAGSTYPE>& zeroLags,
744  const std::vector<FLOATCROSSDATATYPE>& crossData,
745  const std::vector<AUTODATATYPE>& autoData);
746 
760  uint64_t numBytes();
761 
762 
763  void output (const std::string& s);
764  void outputln (const std::string& s);
765  void output (const float* data, uint32_t numData);
766  void outputln (const float* data, uint32_t numData);
767  void outputln (const long long* data, uint32_t numData);
768 
769  template <class T> void output(const std::vector<T>& data) {
770  numBytes_ += data.size()*sizeof(T);
771  switch (otype_) {
772 
773  case STDOUT:
774  std::cout.write((const char*)&data.at(0), data.size()*sizeof(T));
775  break;
776 
777  case MEMORY:
778  oss_->write((const char*)&data.at(0), data.size()*sizeof(T));
779  break;
780 
781  case FILE:
782  ofs_->write((const char*)&data.at(0), data.size()*sizeof(T));
783  break;
784  }
785  }
786 
787  template <class T> void outputln (const std::vector<T>& data) {
788  output<T>(data);
789  outputln();
790  }
791 
792  void outputln ();
793 
794  void outputlnLocation(const std::string& name, const SDMDataSubset& sdmDataSubset);
795 
796  private:
799  std::ofstream* ofs_;
800  std::ostringstream* oss_;
801 
802  // The ALMA uid of the MIME message.
803  std::string uid_;
804 
805  // The title of the binary data.
806  std::string title_;
807 
808  // The subscan path.
809  std::string subscanPath_;
810 
811  // An SDMDataObject
813 
814  // The number of the SDMDataSubset being written
816 
817  // Two strings used as MIME boundaries
818  static const std::string MIMEBOUNDARY_1;
819  static const std::string MIMEBOUNDARY_2;
820 
821 
822  // Class initialization stuff
823  static const bool initClass_;
824  static bool initClass();
825 
826  // The axes names definitions for WVR data and their related flags.
827  static std::vector<AxisNameMod::AxisName> WVRDATAAXES, WVRDATAFLAGSAXES;
828 
829  // A utility to fill a vector of <Enum> from a an array of c-strings.
830  template <class Enum, class EnumHelper> static std::vector<Enum> enumvec(const std::string& strliterals) {
831  std::vector<Enum> result;
832 
833  std::string strliteral;
834  std::stringstream ss(strliterals);
835 
836  std::vector<std::string> tokens;
837  while (ss >> strliteral)
838  result.push_back(EnumHelper::literal(strliteral));
839 
840  return result;
841  }
842 
843  // Writes the very first part of the MIME message.
844  void preamble();
845 
846  // Write the very end of the MIME message.
847  void postamble();
848 
849 
850  void addData(uint32_t integrationNum,
851  uint32_t subintegrationNum,
852  uint64_t time,
853  uint64_t interval,
854  const std::vector<FLAGSTYPE>& flags,
855  const std::vector<ACTUALTIMESTYPE>& actualTimes,
856  const std::vector<ACTUALDURATIONSTYPE>& actualDurations,
857  const std::vector<ZEROLAGSTYPE>& zeroLags,
858  const std::vector<INTCROSSDATATYPE>& intCrossData,
859  const std::vector<SHORTCROSSDATATYPE>& shortCrossData,
860  const std::vector<FLOATCROSSDATATYPE>& floatCrossData,
861  const std::vector<AUTODATATYPE>& autoData);
862 
863  // Are we done with this ?
864  bool done_;
865 
866  // The number of bytes written so far.
867  uint64_t numBytes_;
868 
869 
870  // A small finite state automaton to control the usage of SDMDataObjectWriter.
874 
875  void checkState(Transitions t, const std::string& methodName);
876 
877  };
878 } // namespace asdmbinaries
879 #endif // SDMDataObjectWriter_CLASS
SDMDataObject:: declarations.
void wvrData(const std::string &execBlockUID, uint32_t execBlockNum, uint32_t scanNum, uint32_t subscanNum, uint32_t numTimes, uint32_t numAntennas, uint32_t numChannels, NetSidebandMod::NetSideband netSideband, uint64_t time, uint64_t interval, const std::vector< AUTODATATYPE > &wvrData, const std::vector< FLAGSTYPE > &flags)
Writes water vapour radiometer (WVR) data in a MIME message conform with the BDF V2 format...
void output(const std::string &s)
static std::vector< Enum > enumvec(const std::string &strliterals)
A utility to fill a vector of &lt;Enum&gt; from a an array of c-strings.
bool done_
Are we done with this ?
void corrDataHeader(uint64_t startime, const std::string &execBlockUID, uint32_t execBlockNum, uint32_t scanNum, uint32_t subscanNum, uint32_t numAntenna, CorrelationModeMod::CorrelationMode correlationMode, const OptionalSpectralResolutionType &spectralResolutionType, SDMDataObject::DataStruct &dataStruct)
Writes the XML global header on the MIME message stream, when binary data are (sub)integrations produ...
States
A small finite state automaton to control the usage of SDMDataObjectWriter.
virtual ~SDMDataObjectWriter()
The destructor.
virtual ~SDMDataObjectWriterException()
The destructor.
std::string uid_
The ALMA uid of the MIME message.
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
uint64_t numBytes()
Returns the number of bytes written so far.
void postamble()
Write the very end of the MIME message.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
void done()
This method must be called to conclude the activity of this SDMDataObjectWriter.
A general class to write MIME messages containing ALMA binary data.
void outputln(const std::vector< T > &data)
static const std::string MIMEBOUNDARY_1
Two strings used as MIME boundaries.
void addIntegration(uint32_t integrationNum, uint64_t time, uint64_t interval, const std::vector< FLAGSTYPE > &flags, const std::vector< ACTUALTIMESTYPE > &actualTimes, const std::vector< ACTUALDURATIONSTYPE > &actualDurations, const std::vector< ZEROLAGSTYPE > &zeroLags, const std::vector< INTCROSSDATATYPE > &crossData, const std::vector< AUTODATATYPE > &autoData)
Writes one integration (local header + binary attachment) of correlator data on the MIME message stre...
void tpDataHeader(uint64_t startTime, const std::string &execBlockUID, uint32_t execBlockNum, uint32_t scanNum, uint32_t subscanNum, uint32_t numAntenna, SDMDataObject::DataStruct &dataStruct)
Writes the XML global header on the MIME message stream, when binary data are Total Power data and wi...
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
SDMDataObject sdmDataObject_
An SDMDataObject.
static std::vector< AxisNameMod::AxisName > WVRDATAAXES
The axes names definitions for WVR data and their related flags.
A class to represent an exception thrown while writing a MIME message containing ALMA binary data...
void preamble()
Writes the very first part of the MIME message.
std::string title_
The title of the binary data.
std::string subscanPath_
The subscan path.
void outputlnLocation(const std::string &name, const SDMDataSubset &sdmDataSubset)
void tpAddIntegration(uint32_t integrationNum, uint64_t time, uint64_t interval, const std::vector< FLAGSTYPE > &flags, const std::vector< ACTUALTIMESTYPE > &actualTimes, const std::vector< ACTUALDURATIONSTYPE > &actualDurations, const std::vector< AUTODATATYPE > &autoData)
Writes one integration (local header + binary attachment) of total power data on the MIME message str...
void addSubintegration(uint32_t integrationNum, uint32_t subintegrationNum, uint64_t time, uint64_t interval, const std::vector< FLAGSTYPE > &flags, const std::vector< ACTUALTIMESTYPE > &actualTimes, const std::vector< ACTUALDURATIONSTYPE > &actualDurations, const std::vector< ZEROLAGSTYPE > &zeroLags, const std::vector< INTCROSSDATATYPE > &crossData, const std::vector< AUTODATATYPE > &autoData)
Writes an subintegration (local header + binary attachment) on the MIME message stream.
void checkState(Transitions t, const std::string &methodName)
void tpData(uint64_t startTime, const std::string &execBlockUID, uint32_t execBlockNum, uint32_t scanNum, uint32_t subscanNum, uint32_t numOfIntegrations, uint32_t numAntenna, const std::vector< SDMDataObject::Baseband > &basebands, uint64_t time, uint64_t interval, const std::vector< AxisNameMod::AxisName > &flagsAxes, const std::vector< FLAGSTYPE > &flags, const std::vector< AxisNameMod::AxisName > &actualTimesAxes, const std::vector< ACTUALTIMESTYPE > &actualTimes, const std::vector< AxisNameMod::AxisName > &actualDurationsAxes, const std::vector< ACTUALDURATIONSTYPE > &actualDurations, const std::vector< AxisNameMod::AxisName > &autoDataAxes, const std::vector< AUTODATATYPE > &autoData)
Writes the full content of Total Power data in their respective attachments (global XML header...
static const std::string MIMEBOUNDARY_2
uint32_t sdmDataSubsetNum_
The number of the SDMDataSubset being written.
static const bool initClass_
Class initialization stuff.
std::string getMessage() const
Returns the message associated to this exception.
uint64_t numBytes_
The number of bytes written so far.
static std::vector< AxisNameMod::AxisName > WVRDATAFLAGSAXES
SDMDataObjectWriter(const std::string &uid="uid://X0/X0/X0", const std::string &title="ALMA Binary Data")
A constructor to write on standard output.
void addData(uint32_t integrationNum, uint32_t subintegrationNum, uint64_t time, uint64_t interval, const std::vector< FLAGSTYPE > &flags, const std::vector< ACTUALTIMESTYPE > &actualTimes, const std::vector< ACTUALDURATIONSTYPE > &actualDurations, const std::vector< ZEROLAGSTYPE > &zeroLags, const std::vector< INTCROSSDATATYPE > &intCrossData, const std::vector< SHORTCROSSDATATYPE > &shortCrossData, const std::vector< FLOATCROSSDATATYPE > &floatCrossData, const std::vector< AUTODATATYPE > &autoData)
SDMDataObject::DataStruct:: declarations.
void output(const std::vector< T > &data)