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

Generated by: LCOV version 1.16