LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - SDMDataObjectReader.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 4 0.0 %
Date: 2025-12-12 07:32:35 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #ifndef SDMDataObjectReader_CLASS
       2             : #define SDMDataObjectReader_CLASS
       3             : 
       4             : #include <string>
       5             : #include <map>
       6             : #include <set>
       7             : #include <vector>
       8             : #include <bitset>
       9             : 
      10             : #ifdef REG_BASIC
      11             : #undef REG_BASIC
      12             : #endif
      13             : 
      14             : #ifdef REG_EXTENDED 
      15             : #undef REG_EXTENDED
      16             : #endif 
      17             : 
      18             : #ifdef REG_ICASE
      19             : #undef REG_ICASE
      20             : #endif
      21             : 
      22             : #ifdef REG_NOSUB
      23             : #undef REG_NOSUB
      24             : #endif
      25             : 
      26             : #ifdef REG_NEWLINE
      27             : #undef REG_NEWLINE
      28             : #endif
      29             : 
      30             : #ifdef REG_NOTBOL
      31             : #undef REG_NOTBOL
      32             : #endif
      33             : 
      34             : #ifdef REG_NOTEOL
      35             : #undef REG_NOTEOL
      36             : #endif
      37             : 
      38             : #ifdef REG_STARTEND
      39             : #undef REG_STARTEND
      40             : #endif
      41             : 
      42             : #include <regex>
      43             : 
      44             : #include <alma/ASDMBinaries/SDMDataObjectParser.h>
      45             : #include <alma/ASDMBinaries/SDMDataObject.h>
      46             : 
      47             : /*
      48             : typedef long long          ACTUALDURATIONSTYPE;
      49             : typedef long long          ACTUALTIMESTYPE;     
      50             : typedef float              AUTODATATYPE;        
      51             : typedef int                LONGCROSSDATATYPE;   // mcaillat 
      52             : typedef short int          SHORTCROSSDATATYPE;
      53             : typedef float              FLOATCROSSDATATYPE;  
      54             : typedef unsigned int       FLAGSTYPE; // mcaillat
      55             : typedef float              ZEROLAGSTYPE;   
      56             : */
      57             : 
      58             : namespace asdmbinaries {
      59             :   /**
      60             :    * A class to represent an exception thrown while reading a MIME message containing ALMA binary data.
      61             :    */ 
      62             :   class SDMDataObjectReaderException {
      63             :     
      64             :   public:
      65             :     /**
      66             :      * An empty contructor.
      67             :      */
      68             :     SDMDataObjectReaderException();
      69             : 
      70             :     /**
      71             :      * A constructor with a message associated with the exception.
      72             :      * @param m a string containing the message.
      73             :      */
      74             :     SDMDataObjectReaderException(std::string m);
      75             :     
      76             :     /**
      77             :      * The destructor.
      78             :      */
      79             :     virtual ~SDMDataObjectReaderException();
      80             : 
      81             :     /**
      82             :      * Returns the message associated to this exception.
      83             :      * @return a string.
      84             :      */
      85             :     std::string getMessage() const;
      86             :     
      87             :   protected:
      88             :     std::string message;
      89             :     
      90             :   };
      91             : 
      92             :   inline SDMDataObjectReaderException::SDMDataObjectReaderException() : message ("SDMDataObjectReaderException") {}
      93           0 :   inline SDMDataObjectReaderException::SDMDataObjectReaderException(std::string m) : message(m) {}
      94           0 :   inline SDMDataObjectReaderException::~SDMDataObjectReaderException() {}
      95           0 :   inline std::string SDMDataObjectReaderException::getMessage() const {
      96           0 :     return "SDMDataObjectReaderException : " + message;
      97             :   }
      98             : 
      99             :   /**
     100             :    * A class to read a MIME message containing ALMA binary data and provide a view on these binary data through an instance of SDMDataObject.
     101             :    * An instance of a SDMDataObjectReader can read MIME messages stored in a file or in a memory buffer, via two different versions of
     102             :    * the read() method.
     103             :    * The binary data read can be Total Power or Correlator (integration and subintegration) data.
     104             :    * Once the data obtained by a call to a read method are not needed any more the done() method must be called to release the resources allocated to 
     105             :    * access the data.
     106             :    */
     107             :   class SDMDataObjectReader {
     108             :   public:
     109             :     /**
     110             :      * An empty constructor.
     111             :      */
     112             :     SDMDataObjectReader();
     113             : 
     114             :     /**
     115             :      * The destructor.
     116             :      */
     117             :     virtual ~SDMDataObjectReader();
     118             : 
     119             :     /**
     120             :      * This method reads a MIME message contained in a disk file and returns a reference to an SDMDataObject.
     121             :      * @param filename the name of the file to be read.
     122             :      * @return a reference to an SDMDataObject built during the read operation.
     123             :      * @throw SDMDataObjectReaderException
     124             :      */
     125             : 
     126             :     const SDMDataObject & read(std::string filename);
     127             : 
     128             :     /**
     129             :      * This method reads a MIME message contained in a memory buffer and returns a reference to an SDMDataObject.
     130             :      * @param buffer the adress of the buffer containing the MIME message.
     131             :      * @param size the size in *bytes* of that buffer.
     132             :      * @param fromFile a bool to indicate if the buffer is actually the result of a mapping of a file to virtual memory (false by default).
     133             :      * @return a reference to an SDMDataObject built during the read operation.
     134             :      * @throw SDMDataObjectReaderException
     135             :      */
     136             :     const SDMDataObject & read(const char * buffer, unsigned long int size, bool fromFile=false);
     137             : 
     138             :     
     139             :     /**
     140             :      * This method returns a reference to the SDMDataObject instance built during the execution of 
     141             :      * the read method.
     142             :      * @return a reference to an SDMDataObject.
     143             :      * @throw SDMDataObjectReaderException.
     144             :      */
     145             :     const SDMDataObject & ref() const;
     146             :     
     147             :     /**
     148             :      * This method returns a pointer to the SDMDataObject instance built during the execution of 
     149             :      * the read method.
     150             :      * @return a reference to an SDMDataObject.
     151             :      * @throw SDMDataObjectReaderException.
     152             :      */
     153             :     const SDMDataObject * ptr() const;
     154             :     
     155             :     /**
     156             :      * A method to release the resources allocated by the read operation. 
     157             :      * This method must be called once the SDMDataObject built by the read method is no more needed.
     158             :      */
     159             :     void done();
     160             : 
     161             :   private:
     162             :     enum READ {UNKNOWN_, MEMORY_, FILE_};
     163             :     READ read_;
     164             : 
     165             :     int filedes_;
     166             :     unsigned int dataSize_;
     167             :     char* data_;
     168             :     std::string::size_type position_;
     169             :     std::string::size_type lastPosition_;
     170             :     std::string::size_type endPosition_;
     171             : 
     172             :     unsigned int integrationNum_;
     173             : 
     174             :     static const bool initClass_;
     175             :     static bool initClass();
     176             :     void init() ;
     177             :     std::string::size_type find(const std::string& s);
     178             :     bool compare(const std::string& s);
     179             :     bool EOD();
     180             : 
     181             :     // Two strings used as MIME boundaries
     182             :     static const std::string MIMEBOUNDARY_1;
     183             :     static const std::string MIMEBOUNDARY_2;
     184             :     
     185             :     // Regular expressions used to identify a Content-ID field in a MIME header
     186             :     static const std::regex CONTENTIDDATASTRUCTUREREGEXP;
     187             :     static const std::regex CONTENTIDSUBSETREGEXP;
     188             :     static const std::regex CONTENTIDBINREGEXP;
     189             :     static const std::regex CONTENTIDBINREGEXP1;
     190             :     static const std::regex CONTENTIDBINREGEXP2;
     191             :     // Set of valid binary attachment names
     192             :     static std::set<std::string> BINATTACHNAMES;
     193             :     enum BINATTACHCODES {ACTUALDURATIONS=0, ACTUALTIMES=1, AUTODATA=2, FLAGS=3, CROSSDATA=4, ZEROLAGS=5};
     194             :     static std::map<std::string, BINATTACHCODES> name2code;
     195             : 
     196             :     std::string extractXMLHeader(const std::string& boundary);
     197             :     void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters);
     198             :     void getFields(const std::string& header, std::map<std::string, std::string>& fields);
     199             :     std::string getContentID();
     200             :     std::string getContentLocation();
     201             : 
     202             :     void processMIME();
     203             :     void processMIMESDMDataHeader();
     204             :     void processMIMESDMDataSubsetHeader(SDMDataSubset& sdmDataSubset);
     205             :     void processMIMEIntegrations();
     206             :     void processMIMEIntegration();
     207             :     void processMIMESubscan();
     208             :     void processBinaryAttachment(const std::string& boundary, const SDMDataSubset& sdmDataSubset);
     209             : 
     210             : 
     211             :     // SDMDataObject related stuff
     212             :     SDMDataObjectParser parser_;
     213             :     SDMDataObject sdmDataObject_;
     214             :     const SDMDataObject& sdmDataObject();
     215             : 
     216             :     std::bitset<6> attachmentFlags;
     217             : 
     218             :     const ACTUALTIMESTYPE * actualTimes_;
     219             :     unsigned long int nActualTimes_;
     220             :     const ACTUALDURATIONSTYPE * actualDurations_;
     221             :     unsigned long int nActualDurations_;
     222             :     const ZEROLAGSTYPE * zeroLags_;
     223             :     unsigned long int nZeroLags_;
     224             :     const FLAGSTYPE * flags_;
     225             :     unsigned long int nFlags_;
     226             :     const INTCROSSDATATYPE  * longCrossData_;
     227             :     const SHORTCROSSDATATYPE * shortCrossData_;
     228             :     const FLOATCROSSDATATYPE * floatCrossData_;
     229             :     unsigned long int nCrossData_;
     230             :     const AUTODATATYPE * autoData_;
     231             :     unsigned long int nAutoData_;   
     232             : 
     233             :   };
     234             : } // namespace asdmbinaries
     235             : #endif // SDMDataObjectReader_CLASS

Generated by: LCOV version 1.16