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

Generated by: LCOV version 1.16