LCOV - code coverage report
Current view: top level - alma/ASDM - PulsarTable.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 7 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 1 0.0 %

          Line data    Source code
       1             : 
       2             : /*
       3             :  * ALMA - Atacama Large Millimeter Array
       4             :  * (c) European Southern Observatory, 2002
       5             :  * (c) Associated Universities Inc., 2002
       6             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       7             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       8             :  * All rights reserved.
       9             :  * 
      10             :  * This library is free software; you can redistribute it and/or
      11             :  * modify it under the terms of the GNU Lesser General Public
      12             :  * License as published by the Free software Foundation; either
      13             :  * version 2.1 of the License, or (at your option) any later version.
      14             :  * 
      15             :  * This library is distributed in the hope that it will be useful,
      16             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      17             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18             :  * Lesser General Public License for more details.
      19             :  * 
      20             :  * You should have received a copy of the GNU Lesser General Public
      21             :  * License along with this library; if not, write to the Free Software
      22             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      23             :  * MA 02111-1307  USA
      24             :  *
      25             :  * Warning!
      26             :  *  -------------------------------------------------------------------- 
      27             :  * | This is generated code!  Do not modify this file.                  |
      28             :  * | If you do, all changes will be lost when the file is re-generated. |
      29             :  *  --------------------------------------------------------------------
      30             :  *
      31             :  * File PulsarTable.h
      32             :  */
      33             :  
      34             : #ifndef PulsarTable_CLASS
      35             : #define PulsarTable_CLASS
      36             : 
      37             : #include <string>
      38             : #include <vector>
      39             : #include <map>
      40             : 
      41             : 
      42             : 
      43             :         
      44             : #include <alma/ASDM/ArrayTime.h>
      45             :         
      46             : 
      47             :         
      48             : #include <alma/ASDM/Frequency.h>
      49             :         
      50             : 
      51             :         
      52             : #include <alma/ASDM/Tag.h>
      53             :         
      54             : 
      55             :         
      56             : #include <alma/ASDM/Interval.h>
      57             :         
      58             : 
      59             : 
      60             : 
      61             : 
      62             :         
      63             : 
      64             :         
      65             : 
      66             :         
      67             : 
      68             :         
      69             : 
      70             :         
      71             : 
      72             :         
      73             : 
      74             :         
      75             : 
      76             :         
      77             : 
      78             :         
      79             : 
      80             :         
      81             : 
      82             :         
      83             : 
      84             :         
      85             : 
      86             : 
      87             : 
      88             : #include <alma/ASDM/ConversionException.h>
      89             : #include <alma/ASDM/DuplicateKey.h>
      90             : #include <alma/ASDM/UniquenessViolationException.h>
      91             : #include <alma/ASDM/NoSuchRow.h>
      92             : #include <alma/ASDM/DuplicateKey.h>
      93             : 
      94             : 
      95             : #ifndef WITHOUT_ACS
      96             : #include <asdmIDLC.h>
      97             : #endif
      98             : 
      99             : #include <alma/ASDM/Representable.h>
     100             : 
     101             : #include <pthread.h>
     102             : 
     103             : namespace asdm {
     104             : 
     105             : //class asdm::ASDM;
     106             : //class asdm::PulsarRow;
     107             : 
     108             : class ASDM;
     109             : class PulsarRow;
     110             : /**
     111             :  * The PulsarTable class is an Alma table.
     112             :  * <BR>
     113             :  * 
     114             :  * \par Role
     115             :  * Polarization information.
     116             :  * <BR>
     117             :  
     118             :  * Generated from model's revision "-1", branch ""
     119             :  *
     120             :  * <TABLE BORDER="1">
     121             :  * <CAPTION> Attributes of Pulsar </CAPTION>
     122             :  * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape  </TH> <TH> Comment </TH></TR>
     123             :  
     124             :  * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
     125             :         
     126             :  * <TR>
     127             :                 
     128             :  * <TD><I> pulsarId </I></TD>
     129             :                  
     130             :  * <TD> Tag</TD>
     131             :  * <TD> &nbsp; </TD>
     132             :  * <TD> &nbsp;Pulsar Table identifier </TD>
     133             :  * </TR>
     134             :         
     135             : 
     136             : 
     137             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
     138             :         
     139             :  * <TR>
     140             :  * <TD> refTime </TD> 
     141             :  * <TD> ArrayTime </TD>
     142             :  * <TD>  &nbsp;  </TD> 
     143             :  * <TD> &nbsp;Reference time for a polynomial </TD>
     144             :  * </TR>
     145             :         
     146             :  * <TR>
     147             :  * <TD> refPulseFreq </TD> 
     148             :  * <TD> Frequency </TD>
     149             :  * <TD>  &nbsp;  </TD> 
     150             :  * <TD> &nbsp;Reference pulse frequency </TD>
     151             :  * </TR>
     152             :         
     153             :  * <TR>
     154             :  * <TD> refPhase </TD> 
     155             :  * <TD> double </TD>
     156             :  * <TD>  &nbsp;  </TD> 
     157             :  * <TD> &nbsp;Reference pulse phase (turns) </TD>
     158             :  * </TR>
     159             :         
     160             :  * <TR>
     161             :  * <TD> numBin (numBin)</TD> 
     162             :  * <TD> int </TD>
     163             :  * <TD>  &nbsp;  </TD> 
     164             :  * <TD> &nbsp;Number of phase bins </TD>
     165             :  * </TR>
     166             :         
     167             : 
     168             : 
     169             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Optional) </TH></TR>
     170             :         
     171             :  * <TR>
     172             :  * <TD> numPoly(numPoly)</TD> 
     173             :  * <TD> int </TD>
     174             :  * <TD>  &nbsp; </TD>
     175             :  * <TD>&nbsp; Number of polynomial coefficients </TD>
     176             :  * </TR>
     177             :         
     178             :  * <TR>
     179             :  * <TD> phasePoly</TD> 
     180             :  * <TD> std::vector<double > </TD>
     181             :  * <TD>  numPoly  </TD>
     182             :  * <TD>&nbsp; The phase polynomial coefficients (Tempo units) </TD>
     183             :  * </TR>
     184             :         
     185             :  * <TR>
     186             :  * <TD> timeSpan</TD> 
     187             :  * <TD> Interval </TD>
     188             :  * <TD>  &nbsp; </TD>
     189             :  * <TD>&nbsp; Time range over which the polynomial is valid </TD>
     190             :  * </TR>
     191             :         
     192             :  * <TR>
     193             :  * <TD> startPhaseBin</TD> 
     194             :  * <TD> std::vector<float > </TD>
     195             :  * <TD>  numBin  </TD>
     196             :  * <TD>&nbsp; Start phase for each bin (turns) </TD>
     197             :  * </TR>
     198             :         
     199             :  * <TR>
     200             :  * <TD> endPhaseBin</TD> 
     201             :  * <TD> std::vector<float > </TD>
     202             :  * <TD>  numBin  </TD>
     203             :  * <TD>&nbsp; End phase for each bin (turns) </TD>
     204             :  * </TR>
     205             :         
     206             :  * <TR>
     207             :  * <TD> dispersionMeasure</TD> 
     208             :  * <TD> double </TD>
     209             :  * <TD>  &nbsp; </TD>
     210             :  * <TD>&nbsp; Dispersion measure applied, if data have been dedispersed (pc cm?3 ) </TD>
     211             :  * </TR>
     212             :         
     213             :  * <TR>
     214             :  * <TD> refFrequency</TD> 
     215             :  * <TD> Frequency </TD>
     216             :  * <TD>  &nbsp; </TD>
     217             :  * <TD>&nbsp; Reference radio frequency for dedispersion
     218             :  </TD>
     219             :  * </TR>
     220             :         
     221             : 
     222             :  * </TABLE>
     223             :  */
     224             : class PulsarTable : public Representable {
     225             :         friend class ASDM;
     226             : 
     227             : public:
     228             : 
     229             : 
     230             :         /**
     231             :          * Return the list of field names that make up key key
     232             :          * as an array of strings.
     233             :          * @return a vector of string.
     234             :          */     
     235             :         static const std::vector<std::string>& getKeyName();
     236             : 
     237             : 
     238             :         virtual ~PulsarTable();
     239             :         
     240             :         /**
     241             :          * Return the container to which this table belongs.
     242             :          *
     243             :          * @return the ASDM containing this table.
     244             :          */
     245             :         ASDM &getContainer() const;
     246             :         
     247             :         /**
     248             :          * Return the number of rows in the table.
     249             :          *
     250             :          * @return the number of rows in an unsigned int.
     251             :          */
     252             :         unsigned int size() const;
     253             :         
     254             :         /**
     255             :          * Return the name of this table.
     256             :          *
     257             :          * This is a instance method of the class.
     258             :          *
     259             :          * @return the name of this table in a string.
     260             :          */
     261             :         std::string getName() const;
     262             :         
     263             :         /**
     264             :          * Return the name of this table.
     265             :          *
     266             :          * This is a static method of the class.
     267             :          *
     268             :          * @return the name of this table in a string.
     269             :          */
     270             :         static std::string name() ;     
     271             :         
     272             :         /**
     273             :          * Return the version information about this table.
     274             :          *
     275             :          */
     276             :          std::string getVersion() const ;
     277             :         
     278             :         /**
     279             :          * Return the names of the attributes of this table.
     280             :          *
     281             :          * @return a vector of string
     282             :          */
     283             :          static const std::vector<std::string>& getAttributesNames();
     284             : 
     285             :         /**
     286             :          * Return the default sorted list of attributes names in the binary representation of the table.
     287             :          *
     288             :          * @return a const reference to a vector of string
     289             :          */
     290             :          static const std::vector<std::string>& defaultAttributesNamesInBin();
     291             :          
     292             :         /**
     293             :          * Return this table's Entity.
     294             :          */
     295             :         Entity getEntity() const;
     296             : 
     297             :         /**
     298             :          * Set this table's Entity.
     299             :          * @param e An entity. 
     300             :          */
     301             :         void setEntity(Entity e);
     302             :                 
     303             :         /**
     304             :          * Produces an XML representation conform
     305             :          * to the schema defined for Pulsar (PulsarTable.xsd).
     306             :          *
     307             :          * @returns a string containing the XML representation.
     308             :          * @throws ConversionException
     309             :          */
     310             :         std::string toXML()  ;
     311             : 
     312             : #ifndef WITHOUT_ACS
     313             :         // Conversion Methods
     314             :         /**
     315             :          * Convert this table into a PulsarTableIDL CORBA structure.
     316             :          *
     317             :          * @return a pointer to a PulsarTableIDL
     318             :          */
     319             :         asdmIDL::PulsarTableIDL *toIDL() ;
     320             :         
     321             :         /**
     322             :          * Fills the CORBA data structure passed in parameter
     323             :          * with the content of this table.
     324             :          *
     325             :          * @param x a reference to the asdmIDL::PulsarTableIDL to be populated
     326             :          * with the content of this.
     327             :          */
     328             :          void toIDL(asdmIDL::PulsarTableIDL& x) const;
     329             :          
     330             : #endif
     331             : 
     332             : #ifndef WITHOUT_ACS
     333             :         /**
     334             :          * Populate this table from the content of a PulsarTableIDL Corba structure.
     335             :          *
     336             :          * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
     337             :          * @throws ConversionException
     338             :          */     
     339             :         void fromIDL(asdmIDL::PulsarTableIDL x) ;
     340             : #endif
     341             :         
     342             :         //
     343             :         // ====> Row creation.
     344             :         //
     345             :         
     346             :         /**
     347             :          * Create a new row with default values.
     348             :          * @return a pointer on a PulsarRow
     349             :          */
     350             :         PulsarRow *newRow();
     351             :         
     352             :         
     353             :         /**
     354             :          * Create a new row initialized to the specified values.
     355             :          * @return a pointer on the created and initialized row.
     356             :         
     357             :          * @param refTime
     358             :         
     359             :          * @param refPulseFreq
     360             :         
     361             :          * @param refPhase
     362             :         
     363             :          * @param numBin
     364             :         
     365             :      */
     366             :         PulsarRow *newRow(ArrayTime refTime, Frequency refPulseFreq, double refPhase, int numBin);
     367             :         
     368             : 
     369             : 
     370             :         /**
     371             :          * Create a new row using a copy constructor mechanism.
     372             :          * 
     373             :          * The method creates a new PulsarRow owned by this. Each attribute of the created row 
     374             :          * is a (deep) copy of the corresponding attribute of row. The method does not add 
     375             :          * the created row to this, its simply parents it to this, a call to the add method
     376             :          * has to be done in order to get the row added (very likely after having modified
     377             :          * some of its attributes).
     378             :          * If row is null then the method returns a new PulsarRow with default values for its attributes. 
     379             :          *
     380             :          * @param row the row which is to be copied.
     381             :          */
     382             :          PulsarRow *newRow(PulsarRow *row); 
     383             : 
     384             :         //
     385             :         // ====> Append a row to its table.
     386             :         //
     387             : 
     388             :         
     389             :         
     390             :         
     391             :         /** 
     392             :          * Add a row.
     393             :          * If there table contains a row whose key's fields are equal
     394             :          * to x's ones then return a pointer on this row (i.e. no actual insertion is performed) 
     395             :          * otherwise add x to the table and return x.
     396             :          * @param x . A pointer on the row to be added.
     397             :          * @returns a pointer to a PulsarRow.    
     398             :          */      
     399             :          
     400             :          PulsarRow* add(PulsarRow* x) ;
     401             : 
     402             : 
     403             : 
     404             :         //
     405             :         // ====> Methods returning rows.
     406             :         //
     407             :                 
     408             :         /**
     409             :          * Get a collection of pointers on the rows of the table.
     410             :          * @return Alls rows in a vector of pointers of PulsarRow. The elements of this vector are stored in the order 
     411             :          * in which they have been added to the PulsarTable.
     412             :          */
     413             :         std::vector<PulsarRow *> get() ;
     414             :         
     415             :         /**
     416             :          * Get a const reference on the collection of rows pointers internally hold by the table.
     417             :          * @return A const reference of a vector of pointers of PulsarRow. The elements of this vector are stored in the order 
     418             :          * in which they have been added to the PulsarTable.
     419             :          *
     420             :          */
     421             :          const std::vector<PulsarRow *>& get() const ;
     422             :         
     423             : 
     424             : 
     425             :  
     426             :         
     427             :         /**
     428             :          * Returns a PulsarRow* given a key.
     429             :          * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     430             :          * no row exists for that key.
     431             :         
     432             :          * @param pulsarId
     433             :         
     434             :          *
     435             :          */
     436             :         PulsarRow* getRowByKey(Tag pulsarId);
     437             : 
     438             :                 
     439             : 
     440             : 
     441             : 
     442             :         /**
     443             :          * Look up the table for a row whose all attributes  except the autoincrementable one 
     444             :          * are equal to the corresponding parameters of the method.
     445             :          * @return a pointer on this row if any, null otherwise.
     446             :          *
     447             :                         
     448             :          * @param refTime
     449             :                         
     450             :          * @param refPulseFreq
     451             :                         
     452             :          * @param refPhase
     453             :                         
     454             :          * @param numBin
     455             :                          
     456             :          */
     457             :         PulsarRow* lookup(ArrayTime refTime, Frequency refPulseFreq, double refPhase, int numBin); 
     458             : 
     459             : 
     460             :         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
     461             :         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
     462             : 
     463             : private:
     464             : 
     465             :         /**
     466             :          * Create a PulsarTable.
     467             :          * <p>
     468             :          * This constructor is private because only the
     469             :          * container can create tables.  All tables must know the container
     470             :          * to which they belong.
     471             :          * @param container The container to which this table belongs.
     472             :          */ 
     473             :         PulsarTable (ASDM & container);
     474             : 
     475             :         ASDM & container;
     476             :         
     477             :         bool archiveAsBin; // If true archive binary else archive XML
     478             :         bool fileAsBin ; // If true file binary else file XML   
     479             :         
     480             :         std::string version ; 
     481             :         
     482             :         Entity entity;
     483             :         
     484             : 
     485             :         
     486             :         
     487             : 
     488             :         // A map for the autoincrementation algorithm
     489             :         std::map<std::string,int>  noAutoIncIds;
     490             :         void autoIncrement(std::string key, PulsarRow* x);
     491             : 
     492             : 
     493             :         /**
     494             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     495             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     496             :          * Append x to its table.
     497             :          * @throws DuplicateKey
     498             :          
     499             :          * @throws UniquenessViolationException
     500             :          
     501             :          */
     502             :         PulsarRow* checkAndAdd(PulsarRow* x, bool skipCheckUniqueness=false) ;
     503             :         
     504             :         /**
     505             :          * Brutally append an PulsarRow x to the collection of rows already stored in this table. No uniqueness check is done !
     506             :          *
     507             :          * @param PulsarRow* x a pointer onto the PulsarRow to be appended.
     508             :          */
     509             :          void append(PulsarRow* x) ;
     510             :          
     511             :         /**
     512             :          * Brutally append an PulsarRow x to the collection of rows already stored in this table. No uniqueness check is done !
     513             :          *
     514             :          * @param PulsarRow* x a pointer onto the PulsarRow to be appended.
     515             :          */
     516             :          void addWithoutCheckingUnique(PulsarRow* x) ;
     517             :          
     518             :          
     519             : 
     520             : 
     521             : 
     522             : // A data structure to store the pointers on the table's rows.
     523             : 
     524             : // In all cases we maintain a private vector of PulsarRow s.
     525             :    std::vector<PulsarRow * > privateRows;
     526             :    
     527             : 
     528             :                         
     529             :         std::vector<PulsarRow *> row;
     530             : 
     531             :         
     532             :         void error() ; //throw(ConversionException);
     533             : 
     534             :         
     535             :         /**
     536             :          * Populate this table from the content of a XML document that is required to
     537             :          * be conform to the XML schema defined for a Pulsar (PulsarTable.xsd).
     538             :          * @throws ConversionException
     539             :          * 
     540             :          */
     541             :         void fromXML(std::string& xmlDoc) ;
     542             :                 
     543             :         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
     544             : 
     545             :         /**
     546             :           * Private methods involved during the build of this table out of the content
     547             :           * of file(s) containing an external representation of a Pulsar table.
     548             :           */
     549             :         void setFromMIMEFile(const std::string& directory);
     550             :         /*
     551             :         void openMIMEFile(const std::string& directory);
     552             :         */
     553             :         void setFromXMLFile(const std::string& directory);
     554             :         
     555             :                  /**
     556             :          * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
     557             :          * @returns a string containing the MIME message.
     558             :          *
     559             :          * @param byteOrder a const pointer to a static instance of the class ByteOrder.
     560             :          * 
     561             :          */
     562             :         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     563             :   
     564             :         
     565             :    /** 
     566             :      * Extracts the binary part of a MIME message and deserialize its content
     567             :          * to fill this with the result of the deserialization. 
     568             :          * @param mimeMsg the string containing the MIME message.
     569             :          * @throws ConversionException
     570             :          */
     571             :          void setFromMIME(const std::string & mimeMsg);
     572             :         
     573             :         /**
     574             :           * Private methods involved during the export of this table into disk file(s).
     575             :           */
     576             :         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     577             :         
     578             :         /**
     579             :           * Stores a representation (binary or XML) of this table into a file.
     580             :           *
     581             :           * Depending on the boolean value of its private field fileAsBin a binary serialization  of this (fileAsBin==true)  
     582             :           * will be saved in a file "Pulsar.bin" or an XML representation (fileAsBin==false) will be saved in a file "Pulsar.xml".
     583             :           * The file is always written in a directory whose name is passed as a parameter.
     584             :          * @param directory The name of directory  where the file containing the table's representation will be saved.
     585             :           * 
     586             :           */
     587             :           void toFile(std::string directory);
     588             :           
     589             :           /**
     590             :            * Load the table in memory if necessary.
     591             :            */
     592             :           bool loadInProgress;
     593           0 :           void checkPresenceInMemory() {
     594           0 :                 if (!presentInMemory && !loadInProgress) {
     595           0 :                         loadInProgress = true;
     596           0 :                         setFromFile(getContainer().getDirectory());
     597           0 :                         presentInMemory = true;
     598           0 :                         loadInProgress = false;
     599             :                 }
     600           0 :           }
     601             :         /**
     602             :          * Reads and parses a file containing a representation of a PulsarTable as those produced  by the toFile method.
     603             :          * This table is populated with the result of the parsing.
     604             :          * @param directory The name of the directory containing the file te be read and parsed.
     605             :          * @throws ConversionException If any error occurs while reading the 
     606             :          * files in the directory or parsing them.
     607             :          *
     608             :          */
     609             :          void setFromFile(const std::string& directory);    
     610             :  
     611             : };
     612             : 
     613             : } // End namespace asdm
     614             : 
     615             : #endif /* PulsarTable_CLASS */

Generated by: LCOV version 1.16