LCOV - code coverage report
Current view: top level - alma/ASDM - SubscanTable.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 7 7 100.0 %
Date: 2024-11-06 17:42:47 Functions: 1 1 100.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 SubscanTable.h
      32             :  */
      33             :  
      34             : #ifndef SubscanTable_CLASS
      35             : #define SubscanTable_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/Tag.h>
      49             :         
      50             : 
      51             : 
      52             : 
      53             : 
      54             :         
      55             : 
      56             :         
      57             : 
      58             :         
      59             : 
      60             :         
      61             : 
      62             :         
      63             : 
      64             :         
      65             : #include <alma/Enumerations/CSubscanIntent.h>
      66             :         
      67             : 
      68             :         
      69             : #include <alma/Enumerations/CSwitchingMode.h>
      70             :         
      71             : 
      72             :         
      73             : 
      74             :         
      75             : 
      76             :         
      77             : #include <alma/Enumerations/CCorrelatorCalibration.h>
      78             :         
      79             : 
      80             : 
      81             : 
      82             : #include <alma/ASDM/ConversionException.h>
      83             : #include <alma/ASDM/DuplicateKey.h>
      84             : #include <alma/ASDM/UniquenessViolationException.h>
      85             : #include <alma/ASDM/NoSuchRow.h>
      86             : #include <alma/ASDM/DuplicateKey.h>
      87             : 
      88             : 
      89             : #ifndef WITHOUT_ACS
      90             : #include <asdmIDLC.h>
      91             : #endif
      92             : 
      93             : #include <alma/ASDM/Representable.h>
      94             : 
      95             : #include <pthread.h>
      96             : 
      97             : namespace asdm {
      98             : 
      99             : //class asdm::ASDM;
     100             : //class asdm::SubscanRow;
     101             : 
     102             : class ASDM;
     103             : class SubscanRow;
     104             : /**
     105             :  * The SubscanTable class is an Alma table.
     106             :  * <BR>
     107             :  * 
     108             :  * \par Role
     109             :  * Subscan-based information.
     110             :  * <BR>
     111             :  
     112             :  * Generated from model's revision "-1", branch ""
     113             :  *
     114             :  * <TABLE BORDER="1">
     115             :  * <CAPTION> Attributes of Subscan </CAPTION>
     116             :  * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape  </TH> <TH> Comment </TH></TR>
     117             :  
     118             :  * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
     119             :         
     120             :  * <TR>
     121             :                 
     122             :  * <TD> execBlockId </TD>
     123             :                  
     124             :  * <TD> Tag</TD>
     125             :  * <TD> &nbsp; </TD>
     126             :  * <TD> &nbsp;identifies a unique row in ExecBlockTable. </TD>
     127             :  * </TR>
     128             :         
     129             :  * <TR>
     130             :                 
     131             :  * <TD> scanNumber </TD>
     132             :                  
     133             :  * <TD> int</TD>
     134             :  * <TD> &nbsp; </TD>
     135             :  * <TD> &nbsp;the number of the scan this subscan belongs to. </TD>
     136             :  * </TR>
     137             :         
     138             :  * <TR>
     139             :                 
     140             :  * <TD> subscanNumber </TD>
     141             :                  
     142             :  * <TD> int</TD>
     143             :  * <TD> &nbsp; </TD>
     144             :  * <TD> &nbsp;the subscan number. </TD>
     145             :  * </TR>
     146             :         
     147             : 
     148             : 
     149             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
     150             :         
     151             :  * <TR>
     152             :  * <TD> startTime </TD> 
     153             :  * <TD> ArrayTime </TD>
     154             :  * <TD>  &nbsp;  </TD> 
     155             :  * <TD> &nbsp;the actual start time of the subscan. </TD>
     156             :  * </TR>
     157             :         
     158             :  * <TR>
     159             :  * <TD> endTime </TD> 
     160             :  * <TD> ArrayTime </TD>
     161             :  * <TD>  &nbsp;  </TD> 
     162             :  * <TD> &nbsp;the actual end time of the subscan. </TD>
     163             :  * </TR>
     164             :         
     165             :  * <TR>
     166             :  * <TD> fieldName </TD> 
     167             :  * <TD> std::string </TD>
     168             :  * <TD>  &nbsp;  </TD> 
     169             :  * <TD> &nbsp;the name of the observed field. </TD>
     170             :  * </TR>
     171             :         
     172             :  * <TR>
     173             :  * <TD> subscanIntent </TD> 
     174             :  * <TD> SubscanIntentMod::SubscanIntent </TD>
     175             :  * <TD>  &nbsp;  </TD> 
     176             :  * <TD> &nbsp;the intent of the subscan. </TD>
     177             :  * </TR>
     178             :         
     179             :  * <TR>
     180             :  * <TD> numIntegration (numIntegration)</TD> 
     181             :  * <TD> int </TD>
     182             :  * <TD>  &nbsp;  </TD> 
     183             :  * <TD> &nbsp;the number of integrations during the scan. </TD>
     184             :  * </TR>
     185             :         
     186             :  * <TR>
     187             :  * <TD> numSubintegration (numSubintegration)</TD> 
     188             :  * <TD> std::vector<int > </TD>
     189             :  * <TD>  numIntegration </TD> 
     190             :  * <TD> &nbsp;the number of subintegrations for each integration. </TD>
     191             :  * </TR>
     192             :         
     193             : 
     194             : 
     195             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Optional) </TH></TR>
     196             :         
     197             :  * <TR>
     198             :  * <TD> subscanMode</TD> 
     199             :  * <TD> SwitchingModeMod::SwitchingMode </TD>
     200             :  * <TD>  &nbsp; </TD>
     201             :  * <TD>&nbsp; identifies the data acquisition mode during the subscan. </TD>
     202             :  * </TR>
     203             :         
     204             :  * <TR>
     205             :  * <TD> correlatorCalibration</TD> 
     206             :  * <TD> CorrelatorCalibrationMod::CorrelatorCalibration </TD>
     207             :  * <TD>  &nbsp; </TD>
     208             :  * <TD>&nbsp; identifies the correlator calibration during the subscan. </TD>
     209             :  * </TR>
     210             :         
     211             : 
     212             :  * </TABLE>
     213             :  */
     214             : class SubscanTable : public Representable {
     215             :         friend class ASDM;
     216             : 
     217             : public:
     218             : 
     219             : 
     220             :         /**
     221             :          * Return the list of field names that make up key key
     222             :          * as an array of strings.
     223             :          * @return a vector of string.
     224             :          */     
     225             :         static const std::vector<std::string>& getKeyName();
     226             : 
     227             : 
     228             :         virtual ~SubscanTable();
     229             :         
     230             :         /**
     231             :          * Return the container to which this table belongs.
     232             :          *
     233             :          * @return the ASDM containing this table.
     234             :          */
     235             :         ASDM &getContainer() const;
     236             :         
     237             :         /**
     238             :          * Return the number of rows in the table.
     239             :          *
     240             :          * @return the number of rows in an unsigned int.
     241             :          */
     242             :         unsigned int size() const;
     243             :         
     244             :         /**
     245             :          * Return the name of this table.
     246             :          *
     247             :          * This is a instance method of the class.
     248             :          *
     249             :          * @return the name of this table in a string.
     250             :          */
     251             :         std::string getName() const;
     252             :         
     253             :         /**
     254             :          * Return the name of this table.
     255             :          *
     256             :          * This is a static method of the class.
     257             :          *
     258             :          * @return the name of this table in a string.
     259             :          */
     260             :         static std::string name() ;     
     261             :         
     262             :         /**
     263             :          * Return the version information about this table.
     264             :          *
     265             :          */
     266             :          std::string getVersion() const ;
     267             :         
     268             :         /**
     269             :          * Return the names of the attributes of this table.
     270             :          *
     271             :          * @return a vector of string
     272             :          */
     273             :          static const std::vector<std::string>& getAttributesNames();
     274             : 
     275             :         /**
     276             :          * Return the default sorted list of attributes names in the binary representation of the table.
     277             :          *
     278             :          * @return a const reference to a vector of string
     279             :          */
     280             :          static const std::vector<std::string>& defaultAttributesNamesInBin();
     281             :          
     282             :         /**
     283             :          * Return this table's Entity.
     284             :          */
     285             :         Entity getEntity() const;
     286             : 
     287             :         /**
     288             :          * Set this table's Entity.
     289             :          * @param e An entity. 
     290             :          */
     291             :         void setEntity(Entity e);
     292             :                 
     293             :         /**
     294             :          * Produces an XML representation conform
     295             :          * to the schema defined for Subscan (SubscanTable.xsd).
     296             :          *
     297             :          * @returns a string containing the XML representation.
     298             :          * @throws ConversionException
     299             :          */
     300             :         std::string toXML()  ;
     301             : 
     302             : #ifndef WITHOUT_ACS
     303             :         // Conversion Methods
     304             :         /**
     305             :          * Convert this table into a SubscanTableIDL CORBA structure.
     306             :          *
     307             :          * @return a pointer to a SubscanTableIDL
     308             :          */
     309             :         asdmIDL::SubscanTableIDL *toIDL() ;
     310             :         
     311             :         /**
     312             :          * Fills the CORBA data structure passed in parameter
     313             :          * with the content of this table.
     314             :          *
     315             :          * @param x a reference to the asdmIDL::SubscanTableIDL to be populated
     316             :          * with the content of this.
     317             :          */
     318             :          void toIDL(asdmIDL::SubscanTableIDL& x) const;
     319             :          
     320             : #endif
     321             : 
     322             : #ifndef WITHOUT_ACS
     323             :         /**
     324             :          * Populate this table from the content of a SubscanTableIDL Corba structure.
     325             :          *
     326             :          * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
     327             :          * @throws ConversionException
     328             :          */     
     329             :         void fromIDL(asdmIDL::SubscanTableIDL x) ;
     330             : #endif
     331             :         
     332             :         //
     333             :         // ====> Row creation.
     334             :         //
     335             :         
     336             :         /**
     337             :          * Create a new row with default values.
     338             :          * @return a pointer on a SubscanRow
     339             :          */
     340             :         SubscanRow *newRow();
     341             :         
     342             :         
     343             :         /**
     344             :          * Create a new row initialized to the specified values.
     345             :          * @return a pointer on the created and initialized row.
     346             :         
     347             :          * @param execBlockId
     348             :         
     349             :          * @param scanNumber
     350             :         
     351             :          * @param subscanNumber
     352             :         
     353             :          * @param startTime
     354             :         
     355             :          * @param endTime
     356             :         
     357             :          * @param fieldName
     358             :         
     359             :          * @param subscanIntent
     360             :         
     361             :          * @param numIntegration
     362             :         
     363             :          * @param numSubintegration
     364             :         
     365             :      */
     366             :         SubscanRow *newRow(Tag execBlockId, int scanNumber, int subscanNumber, ArrayTime startTime, ArrayTime endTime, std::string fieldName, SubscanIntentMod::SubscanIntent subscanIntent, int numIntegration, std::vector<int > numSubintegration);
     367             :         
     368             : 
     369             : 
     370             :         /**
     371             :          * Create a new row using a copy constructor mechanism.
     372             :          * 
     373             :          * The method creates a new SubscanRow 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 SubscanRow with default values for its attributes. 
     379             :          *
     380             :          * @param row the row which is to be copied.
     381             :          */
     382             :          SubscanRow *newRow(SubscanRow *row); 
     383             : 
     384             :         //
     385             :         // ====> Append a row to its table.
     386             :         //
     387             :  
     388             :         
     389             :         /**
     390             :          * Add a row.
     391             :          * @param x a pointer to the SubscanRow to be added.
     392             :          *
     393             :          * @return a pointer to a SubscanRow. If the table contains a SubscanRow whose attributes (key and mandatory values) are equal to x ones
     394             :          * then returns a pointer on that SubscanRow, otherwise returns x.
     395             :          *
     396             :          * @throw DuplicateKey { thrown when the table contains a SubscanRow with a key equal to the x one but having
     397             :          * and a value section different from x one }
     398             :          *
     399             :         
     400             :          */
     401             :         SubscanRow* add(SubscanRow* x) ; 
     402             : 
     403             :  
     404             : 
     405             : 
     406             : 
     407             :         //
     408             :         // ====> Methods returning rows.
     409             :         //
     410             :                 
     411             :         /**
     412             :          * Get a collection of pointers on the rows of the table.
     413             :          * @return Alls rows in a vector of pointers of SubscanRow. The elements of this vector are stored in the order 
     414             :          * in which they have been added to the SubscanTable.
     415             :          */
     416             :         std::vector<SubscanRow *> get() ;
     417             :         
     418             :         /**
     419             :          * Get a const reference on the collection of rows pointers internally hold by the table.
     420             :          * @return A const reference of a vector of pointers of SubscanRow. The elements of this vector are stored in the order 
     421             :          * in which they have been added to the SubscanTable.
     422             :          *
     423             :          */
     424             :          const std::vector<SubscanRow *>& get() const ;
     425             :         
     426             : 
     427             : 
     428             :  
     429             :         
     430             :         /**
     431             :          * Returns a SubscanRow* given a key.
     432             :          * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     433             :          * no row exists for that key.
     434             :         
     435             :          * @param execBlockId
     436             :         
     437             :          * @param scanNumber
     438             :         
     439             :          * @param subscanNumber
     440             :         
     441             :          *
     442             :          */
     443             :         SubscanRow* getRowByKey(Tag execBlockId, int scanNumber, int subscanNumber);
     444             : 
     445             :                 
     446             : 
     447             : 
     448             : 
     449             :         /**
     450             :          * Look up the table for a row whose all attributes 
     451             :          * are equal to the corresponding parameters of the method.
     452             :          * @return a pointer on this row if any, null otherwise.
     453             :          *
     454             :                         
     455             :          * @param execBlockId
     456             :                         
     457             :          * @param scanNumber
     458             :                         
     459             :          * @param subscanNumber
     460             :                         
     461             :          * @param startTime
     462             :                         
     463             :          * @param endTime
     464             :                         
     465             :          * @param fieldName
     466             :                         
     467             :          * @param subscanIntent
     468             :                         
     469             :          * @param numIntegration
     470             :                         
     471             :          * @param numSubintegration
     472             :                          
     473             :          */
     474             :         SubscanRow* lookup(Tag execBlockId, int scanNumber, int subscanNumber, ArrayTime startTime, ArrayTime endTime, std::string fieldName, SubscanIntentMod::SubscanIntent subscanIntent, int numIntegration, std::vector<int > numSubintegration); 
     475             : 
     476             : 
     477             :         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
     478             :         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
     479             : 
     480             : private:
     481             : 
     482             :         /**
     483             :          * Create a SubscanTable.
     484             :          * <p>
     485             :          * This constructor is private because only the
     486             :          * container can create tables.  All tables must know the container
     487             :          * to which they belong.
     488             :          * @param container The container to which this table belongs.
     489             :          */ 
     490             :         SubscanTable (ASDM & container);
     491             : 
     492             :         ASDM & container;
     493             :         
     494             :         bool archiveAsBin; // If true archive binary else archive XML
     495             :         bool fileAsBin ; // If true file binary else file XML   
     496             :         
     497             :         std::string version ; 
     498             :         
     499             :         Entity entity;
     500             :         
     501             : 
     502             :         
     503             :         
     504             : 
     505             : 
     506             :         /**
     507             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     508             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     509             :          * Append x to its table.
     510             :          * @throws DuplicateKey
     511             :          
     512             :          */
     513             :         SubscanRow* checkAndAdd(SubscanRow* x, bool skipCheckUniqueness=false) ;
     514             :         
     515             :         /**
     516             :          * Brutally append an SubscanRow x to the collection of rows already stored in this table. No uniqueness check is done !
     517             :          *
     518             :          * @param SubscanRow* x a pointer onto the SubscanRow to be appended.
     519             :          */
     520             :          void append(SubscanRow* x) ;
     521             :          
     522             :         /**
     523             :          * Brutally append an SubscanRow x to the collection of rows already stored in this table. No uniqueness check is done !
     524             :          *
     525             :          * @param SubscanRow* x a pointer onto the SubscanRow to be appended.
     526             :          */
     527             :          void addWithoutCheckingUnique(SubscanRow* x) ;
     528             :          
     529             :          
     530             : 
     531             : 
     532             : 
     533             : // A data structure to store the pointers on the table's rows.
     534             : 
     535             : // In all cases we maintain a private vector of SubscanRow s.
     536             :    std::vector<SubscanRow * > privateRows;
     537             :    
     538             : 
     539             :                         
     540             :         std::vector<SubscanRow *> row;
     541             : 
     542             :         
     543             :         void error() ; //throw(ConversionException);
     544             : 
     545             :         
     546             :         /**
     547             :          * Populate this table from the content of a XML document that is required to
     548             :          * be conform to the XML schema defined for a Subscan (SubscanTable.xsd).
     549             :          * @throws ConversionException
     550             :          * 
     551             :          */
     552             :         void fromXML(std::string& xmlDoc) ;
     553             :                 
     554             :         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
     555             : 
     556             :         /**
     557             :           * Private methods involved during the build of this table out of the content
     558             :           * of file(s) containing an external representation of a Subscan table.
     559             :           */
     560             :         void setFromMIMEFile(const std::string& directory);
     561             :         /*
     562             :         void openMIMEFile(const std::string& directory);
     563             :         */
     564             :         void setFromXMLFile(const std::string& directory);
     565             :         
     566             :                  /**
     567             :          * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
     568             :          * @returns a string containing the MIME message.
     569             :          *
     570             :          * @param byteOrder a const pointer to a static instance of the class ByteOrder.
     571             :          * 
     572             :          */
     573             :         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     574             :   
     575             :         
     576             :    /** 
     577             :      * Extracts the binary part of a MIME message and deserialize its content
     578             :          * to fill this with the result of the deserialization. 
     579             :          * @param mimeMsg the string containing the MIME message.
     580             :          * @throws ConversionException
     581             :          */
     582             :          void setFromMIME(const std::string & mimeMsg);
     583             :         
     584             :         /**
     585             :           * Private methods involved during the export of this table into disk file(s).
     586             :           */
     587             :         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     588             :         
     589             :         /**
     590             :           * Stores a representation (binary or XML) of this table into a file.
     591             :           *
     592             :           * Depending on the boolean value of its private field fileAsBin a binary serialization  of this (fileAsBin==true)  
     593             :           * will be saved in a file "Subscan.bin" or an XML representation (fileAsBin==false) will be saved in a file "Subscan.xml".
     594             :           * The file is always written in a directory whose name is passed as a parameter.
     595             :          * @param directory The name of directory  where the file containing the table's representation will be saved.
     596             :           * 
     597             :           */
     598             :           void toFile(std::string directory);
     599             :           
     600             :           /**
     601             :            * Load the table in memory if necessary.
     602             :            */
     603             :           bool loadInProgress;
     604       11857 :           void checkPresenceInMemory() {
     605       11857 :                 if (!presentInMemory && !loadInProgress) {
     606          89 :                         loadInProgress = true;
     607          89 :                         setFromFile(getContainer().getDirectory());
     608          89 :                         presentInMemory = true;
     609          89 :                         loadInProgress = false;
     610             :                 }
     611       11857 :           }
     612             :         /**
     613             :          * Reads and parses a file containing a representation of a SubscanTable as those produced  by the toFile method.
     614             :          * This table is populated with the result of the parsing.
     615             :          * @param directory The name of the directory containing the file te be read and parsed.
     616             :          * @throws ConversionException If any error occurs while reading the 
     617             :          * files in the directory or parsing them.
     618             :          *
     619             :          */
     620             :          void setFromFile(const std::string& directory);    
     621             :  
     622             : };
     623             : 
     624             : } // End namespace asdm
     625             : 
     626             : #endif /* SubscanTable_CLASS */

Generated by: LCOV version 1.16