casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceTable.h
Go to the documentation of this file.
00001 
00002 /*
00003  * ALMA - Atacama Large Millimeter Array
00004  * (c) European Southern Observatory, 2002
00005  * (c) Associated Universities Inc., 2002
00006  * Copyright by ESO (in the framework of the ALMA collaboration),
00007  * Copyright by AUI (in the framework of the ALMA collaboration),
00008  * All rights reserved.
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  * 
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023  * MA 02111-1307  USA
00024  *
00025  * Warning!
00026  *  -------------------------------------------------------------------- 
00027  * | This is generated code!  Do not modify this file.                  |
00028  * | If you do, all changes will be lost when the file is re-generated. |
00029  *  --------------------------------------------------------------------
00030  *
00031  * File SourceTable.h
00032  */
00033  
00034 #ifndef SourceTable_CLASS
00035 #define SourceTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <AngularRate.h>
00049         
00050 
00051         
00052 #include <Angle.h>
00053         
00054 
00055         
00056 #include <Speed.h>
00057         
00058 
00059         
00060 #include <Flux.h>
00061         
00062 
00063         
00064 #include <Tag.h>
00065         
00066 
00067         
00068 #include <Length.h>
00069         
00070 
00071         
00072 #include <Frequency.h>
00073         
00074 
00075         
00076 #include <ArrayTimeInterval.h>
00077         
00078 
00079 
00080 
00081 
00082         
00083 
00084         
00085 
00086         
00087 
00088         
00089 
00090         
00091 
00092         
00093 
00094         
00095 #include "CDirectionReferenceCode.h"
00096         
00097 
00098         
00099 
00100         
00101 
00102         
00103 
00104         
00105 
00106         
00107 
00108         
00109 
00110         
00111 
00112         
00113 
00114         
00115 
00116         
00117 
00118         
00119 #include "CSourceModel.h"
00120         
00121 
00122         
00123 #include "CFrequencyReferenceCode.h"
00124         
00125 
00126         
00127 
00128         
00129 
00130         
00131 
00132         
00133 
00134         
00135 #include "CStokesParameter.h"
00136         
00137 
00138         
00139 
00140         
00141 
00142         
00143 
00144         
00145 
00146         
00147 
00148         
00149 
00150         
00151 #include "CRadialVelocityReferenceCode.h"
00152         
00153 
00154 
00155 
00156 #include <ConversionException.h>
00157 #include <DuplicateKey.h>
00158 #include <UniquenessViolationException.h>
00159 #include <NoSuchRow.h>
00160 #include <DuplicateKey.h>
00161 
00162 
00163 #ifndef WITHOUT_ACS
00164 #include <asdmIDLC.h>
00165 #endif
00166 
00167 #include <Representable.h>
00168 
00169 #include <pthread.h>
00170 
00171 namespace asdm {
00172 
00173 //class asdm::ASDM;
00174 //class asdm::SourceRow;
00175 
00176 class ASDM;
00177 class SourceRow;
00435 class SourceTable : public Representable {
00436         friend class ASDM;
00437 
00438 public:
00439 
00440 
00446         static const std::vector<std::string>& getKeyName();
00447 
00448 
00449         virtual ~SourceTable();
00450         
00456         ASDM &getContainer() const;
00457         
00463         unsigned int size() const;
00464         
00472         std::string getName() const;
00473         
00481         static std::string name() ;     
00482         
00487          std::string getVersion() const ;
00488         
00494          static const std::vector<std::string>& getAttributesNames();
00495 
00501          static const std::vector<std::string>& defaultAttributesNamesInBin();
00502          
00506         Entity getEntity() const;
00507 
00512         void setEntity(Entity e);
00513                 
00521         std::string toXML()  ;
00522 
00523 #ifndef WITHOUT_ACS
00524         // Conversion Methods
00530         asdmIDL::SourceTableIDL *toIDL() ;
00531         
00539          void toIDL(asdmIDL::SourceTableIDL& x) const;
00540          
00541 #endif
00542 
00543 #ifndef WITHOUT_ACS
00544 
00550         void fromIDL(asdmIDL::SourceTableIDL x) ;
00551 #endif
00552         
00553         //
00554         // ====> Row creation.
00555         //
00556         
00561         SourceRow *newRow();
00562         
00563         
00581         SourceRow *newRow(ArrayTimeInterval timeInterval, Tag spectralWindowId, string code, vector<Angle > direction, vector<AngularRate > properMotion, string sourceName);
00582         
00583 
00584 
00597          SourceRow *newRow(SourceRow *row); 
00598 
00599         //
00600         // ====> Append a row to its table.
00601         //
00602 
00603         
00604          
00605         
00606         
00616          SourceRow* add(SourceRow* x) ;
00617 
00618 
00619 
00620         //
00621         // ====> Methods returning rows.
00622         //
00623                 
00629         std::vector<SourceRow *> get() ;
00630         
00637          const std::vector<SourceRow *>& get() const ;
00638         
00639 
00640 
00641  
00642         
00656         SourceRow* getRowByKey(int sourceId, ArrayTimeInterval timeInterval, Tag spectralWindowId);
00657 
00658                 
00659         
00667         std::vector <SourceRow *>  getRowBySourceId(int);
00668 
00669 
00670 
00690         SourceRow* lookup(ArrayTimeInterval timeInterval, Tag spectralWindowId, string code, vector<Angle > direction, vector<AngularRate > properMotion, string sourceName); 
00691 
00692 
00693         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00694         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00695 
00696 private:
00697 
00706         SourceTable (ASDM & container);
00707 
00708         ASDM & container;
00709         
00710         bool archiveAsBin; // If true archive binary else archive XML
00711         bool fileAsBin ; // If true file binary else file XML   
00712         
00713         std::string version ; 
00714         
00715         Entity entity;
00716         
00717 
00718 
00728         SourceRow* checkAndAdd(SourceRow* x, bool skipCheckUniqueness=false) ;
00729         
00735          void append(SourceRow* x) ;
00736          
00742          void addWithoutCheckingUnique(SourceRow* x) ;
00743          
00744          
00745 
00746 
00747         
00748         
00756          SourceRow * insertByStartTime(SourceRow* x, std::vector<SourceRow* >& row);
00757           
00758 
00759 
00760 // A data structure to store the pointers on the table's rows.
00761 
00762 // In all cases we maintain a private vector of SourceRow s.
00763    std::vector<SourceRow * > privateRows;
00764    
00765 
00766         
00767 
00768         
00769         
00770                 
00771                 
00772         typedef std::vector <std::vector <SourceRow* > > ID_TIME_ROWS;
00773         std::map<std::string, ID_TIME_ROWS > context;
00774         
00779          std::string Key(Tag spectralWindowId) ;
00780                 
00781                 
00782         
00783         
00789         void getByKeyNoAutoIncNoTime(std::vector <SourceRow*>& vin, std::vector <SourceRow*>& vout,  Tag spectralWindowId);
00790         
00791 
00792         
00793         void error() ; //throw(ConversionException);
00794 
00795         
00802         void fromXML(std::string& xmlDoc) ;
00803                 
00804         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00805 
00810         void setFromMIMEFile(const std::string& directory);
00811         /*
00812         void openMIMEFile(const std::string& directory);
00813         */
00814         void setFromXMLFile(const std::string& directory);
00815         
00823         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00824   
00825         
00832          void setFromMIME(const std::string & mimeMsg);
00833         
00837         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00838         
00848           void toFile(std::string directory);
00849           
00853           bool loadInProgress;
00854           void checkPresenceInMemory() {
00855                 if (!presentInMemory && !loadInProgress) {
00856                         loadInProgress = true;
00857                         setFromFile(getContainer().getDirectory());
00858                         presentInMemory = true;
00859                         loadInProgress = false;
00860                 }
00861           }
00870          void setFromFile(const std::string& directory);        
00871  
00872 };
00873 
00874 } // End namespace asdm
00875 
00876 #endif /* SourceTable_CLASS */