casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CalDeviceTable.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 CalDeviceTable.h
00032  */
00033  
00034 #ifndef CalDeviceTable_CLASS
00035 #define CalDeviceTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <Tag.h>
00045         
00046 
00047         
00048 #include <Temperature.h>
00049         
00050 
00051         
00052 #include <ArrayTimeInterval.h>
00053         
00054 
00055 
00056 
00057 
00058         
00059 
00060         
00061 
00062         
00063 #include "CCalibrationDevice.h"
00064         
00065 
00066         
00067 
00068         
00069 
00070         
00071 
00072         
00073 
00074         
00075 
00076 
00077 
00078 #include <ConversionException.h>
00079 #include <DuplicateKey.h>
00080 #include <UniquenessViolationException.h>
00081 #include <NoSuchRow.h>
00082 #include <DuplicateKey.h>
00083 
00084 
00085 #ifndef WITHOUT_ACS
00086 #include <asdmIDLC.h>
00087 #endif
00088 
00089 #include <Representable.h>
00090 
00091 #include <pthread.h>
00092 
00093 namespace asdm {
00094 
00095 //class asdm::ASDM;
00096 //class asdm::CalDeviceRow;
00097 
00098 class ASDM;
00099 class CalDeviceRow;
00212 class CalDeviceTable : public Representable {
00213         friend class ASDM;
00214 
00215 public:
00216 
00217 
00223         static const std::vector<std::string>& getKeyName();
00224 
00225 
00226         virtual ~CalDeviceTable();
00227         
00233         ASDM &getContainer() const;
00234         
00240         unsigned int size() const;
00241         
00249         std::string getName() const;
00250         
00258         static std::string name() ;     
00259         
00264          std::string getVersion() const ;
00265         
00271          static const std::vector<std::string>& getAttributesNames();
00272 
00278          static const std::vector<std::string>& defaultAttributesNamesInBin();
00279          
00283         Entity getEntity() const;
00284 
00289         void setEntity(Entity e);
00290                 
00298         std::string toXML()  ;
00299 
00300 #ifndef WITHOUT_ACS
00301         // Conversion Methods
00307         asdmIDL::CalDeviceTableIDL *toIDL() ;
00308         
00316          void toIDL(asdmIDL::CalDeviceTableIDL& x) const;
00317          
00318 #endif
00319 
00320 #ifndef WITHOUT_ACS
00321 
00327         void fromIDL(asdmIDL::CalDeviceTableIDL x) ;
00328 #endif
00329         
00330         //
00331         // ====> Row creation.
00332         //
00333         
00338         CalDeviceRow *newRow();
00339         
00340         
00358         CalDeviceRow *newRow(Tag antennaId, Tag spectralWindowId, ArrayTimeInterval timeInterval, int feedId, int numCalload, vector<CalibrationDeviceMod::CalibrationDevice > calLoadNames);
00359         
00360 
00361 
00374          CalDeviceRow *newRow(CalDeviceRow *row); 
00375 
00376         //
00377         // ====> Append a row to its table.
00378         //
00379  
00380         
00397         CalDeviceRow* add(CalDeviceRow* x) ; 
00398 
00399  
00400 
00401 
00402 
00403         //
00404         // ====> Methods returning rows.
00405         //
00406                 
00412         std::vector<CalDeviceRow *> get() ;
00413         
00420          const std::vector<CalDeviceRow *>& get() const ;
00421         
00422 
00433          std::vector <CalDeviceRow*> *getByContext(Tag antennaId, Tag spectralWindowId, int feedId);
00434          
00435 
00436 
00437  
00438         
00454         CalDeviceRow* getRowByKey(Tag antennaId, Tag spectralWindowId, ArrayTimeInterval timeInterval, int feedId);
00455 
00456                 
00457 
00458 
00459 
00479         CalDeviceRow* lookup(Tag antennaId, Tag spectralWindowId, ArrayTimeInterval timeInterval, int feedId, int numCalload, vector<CalibrationDeviceMod::CalibrationDevice > calLoadNames); 
00480 
00481 
00482         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00483         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00484 
00485 private:
00486 
00495         CalDeviceTable (ASDM & container);
00496 
00497         ASDM & container;
00498         
00499         bool archiveAsBin; // If true archive binary else archive XML
00500         bool fileAsBin ; // If true file binary else file XML   
00501         
00502         std::string version ; 
00503         
00504         Entity entity;
00505         
00506 
00507 
00515         CalDeviceRow* checkAndAdd(CalDeviceRow* x, bool skipCheckUniqueness=false) ;
00516         
00522          void append(CalDeviceRow* x) ;
00523          
00529          void addWithoutCheckingUnique(CalDeviceRow* x) ;
00530          
00531          
00532 
00533 
00534         
00535         
00543          CalDeviceRow * insertByStartTime(CalDeviceRow* x, std::vector<CalDeviceRow* >& row);
00544           
00545 
00546 
00547 // A data structure to store the pointers on the table's rows.
00548 
00549 // In all cases we maintain a private vector of CalDeviceRow s.
00550    std::vector<CalDeviceRow * > privateRows;
00551    
00552 
00553         
00554 
00555         
00556         
00557                 
00558                                 
00559         typedef std::vector <CalDeviceRow* > TIME_ROWS;
00560         std::map<std::string, TIME_ROWS > context;
00561                 
00566          std::string Key(Tag antennaId, Tag spectralWindowId, int feedId) ;
00567                  
00568                 
00569         
00570         
00576         void getByKeyNoAutoIncNoTime(std::vector <CalDeviceRow*>& vin, std::vector <CalDeviceRow*>& vout,  Tag antennaId, Tag spectralWindowId, int feedId);
00577         
00578 
00579         
00580         void error() ; //throw(ConversionException);
00581 
00582         
00589         void fromXML(std::string& xmlDoc) ;
00590                 
00591         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00592 
00597         void setFromMIMEFile(const std::string& directory);
00598         /*
00599         void openMIMEFile(const std::string& directory);
00600         */
00601         void setFromXMLFile(const std::string& directory);
00602         
00610         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00611   
00612         
00619          void setFromMIME(const std::string & mimeMsg);
00620         
00624         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00625         
00635           void toFile(std::string directory);
00636           
00640           bool loadInProgress;
00641           void checkPresenceInMemory() {
00642                 if (!presentInMemory && !loadInProgress) {
00643                         loadInProgress = true;
00644                         setFromFile(getContainer().getDirectory());
00645                         presentInMemory = true;
00646                         loadInProgress = false;
00647                 }
00648           }
00657          void setFromFile(const std::string& directory);        
00658  
00659 };
00660 
00661 } // End namespace asdm
00662 
00663 #endif /* CalDeviceTable_CLASS */