LCOV - code coverage report
Current view: top level - alma/ASDM - CalHolographyTable.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 448 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 36 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 CalHolographyTable.cpp
      32             :  */
      33             : #include <alma/ASDM/ConversionException.h>
      34             : #include <alma/ASDM/DuplicateKey.h>
      35             : #include <alma/ASDM/OutOfBoundsException.h>
      36             : 
      37             : using asdm::ConversionException;
      38             : using asdm::DuplicateKey;
      39             : using asdm::OutOfBoundsException;
      40             : 
      41             : #include <alma/ASDM/ASDM.h>
      42             : #include <alma/ASDM/CalHolographyTable.h>
      43             : #include <alma/ASDM/CalHolographyRow.h>
      44             : #include <alma/ASDM/Parser.h>
      45             : 
      46             : using asdm::ASDM;
      47             : using asdm::CalHolographyTable;
      48             : using asdm::CalHolographyRow;
      49             : using asdm::Parser;
      50             : 
      51             : #include <iostream>
      52             : #include <fstream>
      53             : #include <iterator>
      54             : #include <sstream>
      55             : #include <set>
      56             : #include <algorithm>
      57             : using namespace std;
      58             : 
      59             : #include <alma/ASDM/Misc.h>
      60             : using namespace asdm;
      61             : 
      62             : #include <libxml/parser.h>
      63             : #include <libxml/tree.h>
      64             : 
      65             : #ifndef WITHOUT_BOOST
      66             : #include "boost/filesystem/operations.hpp"
      67             : #include <boost/algorithm/string.hpp>
      68             : #else
      69             : #include <sys/stat.h>
      70             : #endif
      71             : 
      72             : namespace asdm {
      73             :         // The name of the entity we will store in this table.
      74             :         static string entityNameOfCalHolography = "CalHolography";
      75             :         
      76             :         // An array of string containing the names of the columns of this table.
      77             :         // The array is filled in the order : key, required value, optional value.
      78             :         //
      79             :         static string attributesNamesOfCalHolography_a[] = {
      80             :                 
      81             :                         "antennaName"
      82             :                 ,
      83             :                         "calDataId"
      84             :                 ,
      85             :                         "calReductionId"
      86             :                 
      87             :                 
      88             :                         , "antennaMake"
      89             :                 
      90             :                         , "startValidTime"
      91             :                 
      92             :                         , "endValidTime"
      93             :                 
      94             :                         , "ambientTemperature"
      95             :                 
      96             :                         , "focusPosition"
      97             :                 
      98             :                         , "frequencyRange"
      99             :                 
     100             :                         , "illuminationTaper"
     101             :                 
     102             :                         , "numReceptor"
     103             :                 
     104             :                         , "polarizationTypes"
     105             :                 
     106             :                         , "numPanelModes"
     107             :                 
     108             :                         , "receiverBand"
     109             :                 
     110             :                         , "beamMapUID"
     111             :                 
     112             :                         , "rawRMS"
     113             :                 
     114             :                         , "weightedRMS"
     115             :                 
     116             :                         , "surfaceMapUID"
     117             :                 
     118             :                         , "direction"
     119             :                                 
     120             :                 
     121             :                         , "numScrew"
     122             :                 
     123             :                         , "screwName"
     124             :                 
     125             :                         , "screwMotion"
     126             :                 
     127             :                         , "screwMotionError"
     128             :                 
     129             :                         , "gravCorrection"
     130             :                 
     131             :                         , "gravOptRange"
     132             :                 
     133             :                         , "tempCorrection"
     134             :                 
     135             :                         , "tempOptRange"
     136             :                                 
     137             :         };
     138             :         
     139             :         // A vector of string whose content is a copy of the strings in the array above.
     140             :         //
     141             :         static vector<string> attributesNamesOfCalHolography_v (attributesNamesOfCalHolography_a, attributesNamesOfCalHolography_a + sizeof(attributesNamesOfCalHolography_a) / sizeof(attributesNamesOfCalHolography_a[0]));
     142             : 
     143             :         // An array of string containing the names of the columns of this table.
     144             :         // The array is filled in the order where the names would be read by default in the XML header of a file containing
     145             :         // the table exported in binary mode.
     146             :         //      
     147             :         static string attributesNamesInBinOfCalHolography_a[] = {
     148             :     
     149             :          "antennaName" , "calDataId" , "calReductionId" , "antennaMake" , "startValidTime" , "endValidTime" , "ambientTemperature" , "focusPosition" , "frequencyRange" , "illuminationTaper" , "numReceptor" , "polarizationTypes" , "numPanelModes" , "receiverBand" , "beamMapUID" , "rawRMS" , "weightedRMS" , "surfaceMapUID" , "direction" 
     150             :         ,
     151             :          "numScrew" , "screwName" , "screwMotion" , "screwMotionError" , "gravCorrection" , "gravOptRange" , "tempCorrection" , "tempOptRange" 
     152             :     
     153             :         };
     154             :                                         
     155             :         // A vector of string whose content is a copy of the strings in the array above.
     156             :         //
     157             :         static vector<string> attributesNamesInBinOfCalHolography_v(attributesNamesInBinOfCalHolography_a, attributesNamesInBinOfCalHolography_a + sizeof(attributesNamesInBinOfCalHolography_a) / sizeof(attributesNamesInBinOfCalHolography_a[0]));             
     158             :         
     159             : 
     160             :         // The array of attributes (or column) names that make up key key.
     161             :         //
     162             :         string keyOfCalHolography_a[] = {
     163             :         
     164             :                 "antennaName"
     165             :         ,
     166             :                 "calDataId"
     167             :         ,
     168             :                 "calReductionId"
     169             :                  
     170             :         };
     171             :          
     172             :         // A vector of strings which are copies of those stored in the array above.
     173             :         vector<string> keyOfCalHolography_v(keyOfCalHolography_a, keyOfCalHolography_a + sizeof(keyOfCalHolography_a) / sizeof(keyOfCalHolography_a[0]));
     174             : 
     175             :         /**
     176             :          * Return the list of field names that make up key key
     177             :          * as a const reference to a vector of strings.
     178             :          */     
     179           0 :         const vector<string>& CalHolographyTable::getKeyName() {
     180           0 :                 return keyOfCalHolography_v;
     181             :         }
     182             : 
     183             : 
     184           0 :         CalHolographyTable::CalHolographyTable(ASDM &c) : container(c) {
     185             : 
     186             :                 // Define a default entity.
     187           0 :                 entity.setEntityId(EntityId("uid://X0/X0/X0"));
     188           0 :                 entity.setEntityIdEncrypted("na");
     189           0 :                 entity.setEntityTypeName("CalHolographyTable");
     190           0 :                 entity.setEntityVersion("1");
     191           0 :                 entity.setInstanceVersion("1");
     192             :                 
     193             :                 // Archive XML
     194           0 :                 archiveAsBin = true;
     195             :                 
     196             :                 // File XML
     197           0 :                 fileAsBin = true;
     198             :                 
     199             :                 // By default the table is considered as present in memory
     200           0 :                 presentInMemory = true;
     201             :                 
     202             :                 // By default there is no load in progress
     203           0 :                 loadInProgress = false;
     204           0 :         }
     205             :         
     206             : /**
     207             :  * A destructor for CalHolographyTable.
     208             :  */
     209           0 :         CalHolographyTable::~CalHolographyTable() {
     210           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) 
     211           0 :                         delete(privateRows.at(i));
     212           0 :         }
     213             : 
     214             :         /**
     215             :          * Container to which this table belongs.
     216             :          */
     217           0 :         ASDM &CalHolographyTable::getContainer() const {
     218           0 :                 return container;
     219             :         }
     220             : 
     221             :         /**
     222             :          * Return the number of rows in the table.
     223             :          */
     224           0 :         unsigned int CalHolographyTable::size() const {
     225           0 :                 if (presentInMemory) 
     226           0 :                         return privateRows.size();
     227             :                 else
     228           0 :                         return declaredSize;
     229             :         }
     230             :         
     231             :         /**
     232             :          * Return the name of this table.
     233             :          */
     234           0 :         string CalHolographyTable::getName() const {
     235           0 :                 return entityNameOfCalHolography;
     236             :         }
     237             :         
     238             :         /**
     239             :          * Return the name of this table.
     240             :          */
     241           0 :         string CalHolographyTable::name() {
     242           0 :                 return entityNameOfCalHolography;
     243             :         }
     244             :         
     245             :         /**
     246             :          * Return the the names of the attributes (or columns) of this table.
     247             :          */
     248           0 :         const vector<string>& CalHolographyTable::getAttributesNames() { return attributesNamesOfCalHolography_v; }
     249             :         
     250             :         /**
     251             :          * Return the the names of the attributes (or columns) of this table as they appear by default
     252             :          * in an binary export of this table.
     253             :          */
     254           0 :         const vector<string>& CalHolographyTable::defaultAttributesNamesInBin() { return attributesNamesInBinOfCalHolography_v; }
     255             : 
     256             :         /**
     257             :          * Return this table's Entity.
     258             :          */
     259           0 :         Entity CalHolographyTable::getEntity() const {
     260           0 :                 return entity;
     261             :         }
     262             : 
     263             :         /**
     264             :          * Set this table's Entity.
     265             :          */
     266           0 :         void CalHolographyTable::setEntity(Entity e) {
     267           0 :                 this->entity = e; 
     268           0 :         }
     269             :         
     270             :         //
     271             :         // ====> Row creation.
     272             :         //
     273             :         
     274             :         /**
     275             :          * Create a new row.
     276             :          */
     277           0 :         CalHolographyRow *CalHolographyTable::newRow() {
     278           0 :                 return new CalHolographyRow (*this);
     279             :         }
     280             :         
     281             : 
     282             :         /**
     283             :          * Create a new row initialized to the specified values.
     284             :          * @return a pointer on the created and initialized row.
     285             :         
     286             :          * @param antennaName 
     287             :         
     288             :          * @param calDataId 
     289             :         
     290             :          * @param calReductionId 
     291             :         
     292             :          * @param antennaMake 
     293             :         
     294             :          * @param startValidTime 
     295             :         
     296             :          * @param endValidTime 
     297             :         
     298             :          * @param ambientTemperature 
     299             :         
     300             :          * @param focusPosition 
     301             :         
     302             :          * @param frequencyRange 
     303             :         
     304             :          * @param illuminationTaper 
     305             :         
     306             :          * @param numReceptor 
     307             :         
     308             :          * @param polarizationTypes 
     309             :         
     310             :          * @param numPanelModes 
     311             :         
     312             :          * @param receiverBand 
     313             :         
     314             :          * @param beamMapUID 
     315             :         
     316             :          * @param rawRMS 
     317             :         
     318             :          * @param weightedRMS 
     319             :         
     320             :          * @param surfaceMapUID 
     321             :         
     322             :          * @param direction 
     323             :         
     324             :      */
     325           0 :         CalHolographyRow* CalHolographyTable::newRow(std::string antennaName, Tag calDataId, Tag calReductionId, AntennaMakeMod::AntennaMake antennaMake, ArrayTime startValidTime, ArrayTime endValidTime, Temperature ambientTemperature, std::vector<Length > focusPosition, std::vector<Frequency > frequencyRange, double illuminationTaper, int numReceptor, std::vector<PolarizationTypeMod::PolarizationType > polarizationTypes, int numPanelModes, ReceiverBandMod::ReceiverBand receiverBand, EntityRef beamMapUID, Length rawRMS, Length weightedRMS, EntityRef surfaceMapUID, std::vector<Angle > direction){
     326           0 :                 CalHolographyRow *row = new CalHolographyRow(*this);
     327             :                         
     328           0 :                 row->setAntennaName(antennaName);
     329             :                         
     330           0 :                 row->setCalDataId(calDataId);
     331             :                         
     332           0 :                 row->setCalReductionId(calReductionId);
     333             :                         
     334           0 :                 row->setAntennaMake(antennaMake);
     335             :                         
     336           0 :                 row->setStartValidTime(startValidTime);
     337             :                         
     338           0 :                 row->setEndValidTime(endValidTime);
     339             :                         
     340           0 :                 row->setAmbientTemperature(ambientTemperature);
     341             :                         
     342           0 :                 row->setFocusPosition(focusPosition);
     343             :                         
     344           0 :                 row->setFrequencyRange(frequencyRange);
     345             :                         
     346           0 :                 row->setIlluminationTaper(illuminationTaper);
     347             :                         
     348           0 :                 row->setNumReceptor(numReceptor);
     349             :                         
     350           0 :                 row->setPolarizationTypes(polarizationTypes);
     351             :                         
     352           0 :                 row->setNumPanelModes(numPanelModes);
     353             :                         
     354           0 :                 row->setReceiverBand(receiverBand);
     355             :                         
     356           0 :                 row->setBeamMapUID(beamMapUID);
     357             :                         
     358           0 :                 row->setRawRMS(rawRMS);
     359             :                         
     360           0 :                 row->setWeightedRMS(weightedRMS);
     361             :                         
     362           0 :                 row->setSurfaceMapUID(surfaceMapUID);
     363             :                         
     364           0 :                 row->setDirection(direction);
     365             :         
     366           0 :                 return row;             
     367             :         }       
     368             :         
     369             : 
     370             : 
     371           0 : CalHolographyRow* CalHolographyTable::newRow(CalHolographyRow* row) {
     372           0 :         return new CalHolographyRow(*this, row);
     373             : }
     374             : 
     375             :         //
     376             :         // Append a row to its table.
     377             :         //
     378             : 
     379             :         
     380             :          
     381             :         /**
     382             :          * Add a row.
     383             :          * @throws DuplicateKey Thrown if the new row has a key that is already in the table.
     384             :          * @param x A pointer to the row to be added.
     385             :          * @return x
     386             :          */
     387           0 :         CalHolographyRow* CalHolographyTable::add(CalHolographyRow* x) {
     388             :                 
     389           0 :                 if (getRowByKey(
     390           0 :                                                 x->getAntennaName()
     391             :                                                 ,
     392           0 :                                                 x->getCalDataId()
     393             :                                                 ,
     394           0 :                                                 x->getCalReductionId()
     395             :                                                 ))
     396             :                         //throw DuplicateKey(x.getAntennaName() + "|" + x.getCalDataId() + "|" + x.getCalReductionId(),"CalHolography");
     397           0 :                         throw DuplicateKey("Duplicate key exception in ","CalHolographyTable");
     398             :                 
     399           0 :                 row.push_back(x);
     400           0 :                 privateRows.push_back(x);
     401           0 :                 x->isAdded(true);
     402           0 :                 return x;
     403             :         }
     404             : 
     405             :         
     406             :                 
     407           0 :         void CalHolographyTable::addWithoutCheckingUnique(CalHolographyRow * x) {
     408           0 :                 if (getRowByKey(
     409           0 :                                                 x->getAntennaName()
     410             :                                                 ,
     411           0 :                                                 x->getCalDataId()
     412             :                                                 ,
     413           0 :                                                 x->getCalReductionId()
     414           0 :                                                 ) != (CalHolographyRow *) 0) 
     415           0 :                         throw DuplicateKey("Dupicate key exception in ", "CalHolographyTable");
     416           0 :                 row.push_back(x);
     417           0 :                 privateRows.push_back(x);
     418           0 :                 x->isAdded(true);
     419           0 :         }
     420             : 
     421             : 
     422             : 
     423             : 
     424             :         // 
     425             :         // A private method to append a row to its table, used by input conversion
     426             :         // methods, with row uniqueness.
     427             :         //
     428             : 
     429             :         
     430             :         /**
     431             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     432             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     433             :          * Append x to its table.
     434             :          * @param x a pointer on the row to be appended.
     435             :          * @returns a pointer on x.
     436             :          * @throws DuplicateKey
     437             :          
     438             :          */
     439           0 :         CalHolographyRow*  CalHolographyTable::checkAndAdd(CalHolographyRow* x, bool skipCheckUniqueness)  {
     440           0 :                 if (!skipCheckUniqueness) { 
     441             :                 
     442             :                 }
     443             :                 
     444           0 :                 if (getRowByKey(
     445             :         
     446           0 :                         x->getAntennaName()
     447             :         ,
     448           0 :                         x->getCalDataId()
     449             :         ,
     450           0 :                         x->getCalReductionId()
     451             :                         
     452           0 :                 )) throw DuplicateKey("Duplicate key exception in ", "CalHolographyTable");
     453             :                 
     454           0 :                 row.push_back(x);
     455           0 :                 privateRows.push_back(x);
     456           0 :                 x->isAdded(true);
     457           0 :                 return x;       
     458             :         }       
     459             : 
     460             : 
     461             : 
     462             :         //
     463             :         // A private method to brutally append a row to its table, without checking for row uniqueness.
     464             :         //
     465             : 
     466           0 :         void CalHolographyTable::append(CalHolographyRow *x) {
     467           0 :                 privateRows.push_back(x);
     468           0 :                 x->isAdded(true);
     469           0 :         }
     470             : 
     471             : 
     472             : 
     473             : 
     474             : 
     475           0 :          vector<CalHolographyRow *> CalHolographyTable::get() {
     476           0 :                 checkPresenceInMemory();
     477           0 :             return privateRows;
     478             :          }
     479             :          
     480           0 :          const vector<CalHolographyRow *>& CalHolographyTable::get() const {
     481           0 :                 const_cast<CalHolographyTable&>(*this).checkPresenceInMemory();       
     482           0 :             return privateRows;
     483             :          }       
     484             :                 
     485             : 
     486             : 
     487             : 
     488             : 
     489             :         
     490             : 
     491             :         
     492             : /*
     493             :  ** Returns a CalHolographyRow* given a key.
     494             :  ** @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     495             :  ** no row exists for that key.
     496             :  **
     497             :  */
     498           0 :         CalHolographyRow* CalHolographyTable::getRowByKey(std::string antennaName, Tag calDataId, Tag calReductionId)  {
     499           0 :         checkPresenceInMemory();
     500           0 :         CalHolographyRow* aRow = 0;
     501           0 :         for (unsigned int i = 0; i < privateRows.size(); i++) {
     502           0 :                 aRow = row.at(i);
     503             :                 
     504             :                         
     505           0 :                                 if (aRow->antennaName != antennaName) continue;
     506             :                         
     507             :                 
     508             :                         
     509           0 :                                 if (aRow->calDataId != calDataId) continue;
     510             :                         
     511             :                 
     512             :                         
     513           0 :                                 if (aRow->calReductionId != calReductionId) continue;
     514             :                         
     515             :                 
     516           0 :                 return aRow;
     517             :         }
     518           0 :         return 0;               
     519             : }
     520             :         
     521             : 
     522             :         
     523             : /**
     524             :  * Look up the table for a row whose all attributes 
     525             :  * are equal to the corresponding parameters of the method.
     526             :  * @return a pointer on this row if any, 0 otherwise.
     527             :  *
     528             :                         
     529             :  * @param antennaName.
     530             :                         
     531             :  * @param calDataId.
     532             :                         
     533             :  * @param calReductionId.
     534             :                         
     535             :  * @param antennaMake.
     536             :                         
     537             :  * @param startValidTime.
     538             :                         
     539             :  * @param endValidTime.
     540             :                         
     541             :  * @param ambientTemperature.
     542             :                         
     543             :  * @param focusPosition.
     544             :                         
     545             :  * @param frequencyRange.
     546             :                         
     547             :  * @param illuminationTaper.
     548             :                         
     549             :  * @param numReceptor.
     550             :                         
     551             :  * @param polarizationTypes.
     552             :                         
     553             :  * @param numPanelModes.
     554             :                         
     555             :  * @param receiverBand.
     556             :                         
     557             :  * @param beamMapUID.
     558             :                         
     559             :  * @param rawRMS.
     560             :                         
     561             :  * @param weightedRMS.
     562             :                         
     563             :  * @param surfaceMapUID.
     564             :                         
     565             :  * @param direction.
     566             :                          
     567             :  */
     568           0 : CalHolographyRow* CalHolographyTable::lookup(std::string antennaName, Tag calDataId, Tag calReductionId, AntennaMakeMod::AntennaMake antennaMake, ArrayTime startValidTime, ArrayTime endValidTime, Temperature ambientTemperature, std::vector<Length > focusPosition, std::vector<Frequency > frequencyRange, double illuminationTaper, int numReceptor, std::vector<PolarizationTypeMod::PolarizationType > polarizationTypes, int numPanelModes, ReceiverBandMod::ReceiverBand receiverBand, EntityRef beamMapUID, Length rawRMS, Length weightedRMS, EntityRef surfaceMapUID, std::vector<Angle > direction) {
     569             :                 CalHolographyRow* aRow;
     570           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) {
     571           0 :                         aRow = privateRows.at(i); 
     572           0 :                         if (aRow->compareNoAutoInc(antennaName, calDataId, calReductionId, antennaMake, startValidTime, endValidTime, ambientTemperature, focusPosition, frequencyRange, illuminationTaper, numReceptor, polarizationTypes, numPanelModes, receiverBand, beamMapUID, rawRMS, weightedRMS, surfaceMapUID, direction)) return aRow;
     573             :                 }                       
     574           0 :                 return 0;       
     575             : } 
     576             :         
     577             :                 
     578             : 
     579             :         
     580             : 
     581             : 
     582             : 
     583             : #ifndef WITHOUT_ACS
     584             :         using asdmIDL::CalHolographyTableIDL;
     585             : #endif
     586             : 
     587             : #ifndef WITHOUT_ACS
     588             :         // Conversion Methods
     589             : 
     590             :         CalHolographyTableIDL *CalHolographyTable::toIDL() {
     591             :                 CalHolographyTableIDL *x = new CalHolographyTableIDL ();
     592             :                 unsigned int nrow = size();
     593             :                 x->row.length(nrow);
     594             :                 vector<CalHolographyRow*> v = get();
     595             :                 for (unsigned int i = 0; i < nrow; ++i) {
     596             :                         //x->row[i] = *(v[i]->toIDL());
     597             :                         v[i]->toIDL(x->row[i]);
     598             :                 }
     599             :                 return x;
     600             :         }
     601             :         
     602             :         void CalHolographyTable::toIDL(asdmIDL::CalHolographyTableIDL& x) const {
     603             :                 unsigned int nrow = size();
     604             :                 x.row.length(nrow);
     605             :                 vector<CalHolographyRow*> v = get();
     606             :                 for (unsigned int i = 0; i < nrow; ++i) {
     607             :                         v[i]->toIDL(x.row[i]);
     608             :                 }
     609             :         }       
     610             : #endif
     611             :         
     612             : #ifndef WITHOUT_ACS
     613             :         void CalHolographyTable::fromIDL(CalHolographyTableIDL x) {
     614             :                 unsigned int nrow = x.row.length();
     615             :                 for (unsigned int i = 0; i < nrow; ++i) {
     616             :                         CalHolographyRow *tmp = newRow();
     617             :                         tmp->setFromIDL(x.row[i]);
     618             :                         // checkAndAdd(tmp);
     619             :                         add(tmp);
     620             :                 }
     621             :         }       
     622             : #endif
     623             : 
     624             :         
     625           0 :         string CalHolographyTable::toXML()  {
     626           0 :                 string buf;
     627             : 
     628           0 :                 buf.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> ");
     629           0 :                 buf.append("<CalHolographyTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:clholo=\"http://Alma/XASDM/CalHolographyTable\" xsi:schemaLocation=\"http://Alma/XASDM/CalHolographyTable http://almaobservatory.org/XML/XASDM/4/CalHolographyTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n");
     630             :         
     631           0 :                 buf.append(entity.toXML());
     632           0 :                 string s = container.getEntity().toXML();
     633             :                 // Change the "Entity" tag to "ContainerEntity".
     634           0 :                 buf.append("<Container" + s.substr(1,s.length() - 1)+" ");
     635           0 :                 vector<CalHolographyRow*> v = get();
     636           0 :                 for (unsigned int i = 0; i < v.size(); ++i) {
     637             :                         try {
     638           0 :                                 buf.append(v[i]->toXML());
     639           0 :                         } catch (const NoSuchRow &e) {
     640           0 :                         }
     641           0 :                         buf.append("  ");
     642             :                 }               
     643           0 :                 buf.append("</CalHolographyTable> ");
     644           0 :                 return buf;
     645           0 :         }
     646             : 
     647             :         
     648           0 :         string CalHolographyTable::getVersion() const {
     649           0 :                 return version;
     650             :         }
     651             :         
     652             : 
     653           0 :         void CalHolographyTable::fromXML(string& tableInXML)  {
     654             :                 //
     655             :                 // Look for a version information in the schemaVersion of the XML
     656             :                 //
     657             :                 xmlDoc *doc;
     658             : #if LIBXML_VERSION >= 20703
     659           0 :         doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS|XML_PARSE_HUGE);
     660             : #else
     661             :                 doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
     662             : #endif
     663           0 :                 if ( doc == NULL )
     664           0 :                         throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "CalHolography");
     665             :                 
     666           0 :                 xmlNode* root_element = xmlDocGetRootElement(doc);
     667           0 :                 if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
     668           0 :                 throw ConversionException("Failed to retrieve the root element in the DOM structure.", "CalHolography");
     669             :                 
     670           0 :         xmlChar * propValue = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
     671           0 :         if ( propValue != 0 ) {
     672           0 :                 version = string( (const char*) propValue);
     673           0 :                 xmlFree(propValue);             
     674             :         }
     675             :                                                                         
     676           0 :                 Parser xml(tableInXML);
     677           0 :                 if (!xml.isStr("<CalHolographyTable")) 
     678           0 :                         error();
     679             :                 // cout << "Parsing a CalHolographyTable" << endl;
     680           0 :                 string s = xml.getElement("<Entity","/>");
     681           0 :                 if (s.length() == 0) 
     682           0 :                         error();
     683           0 :                 Entity e;
     684           0 :                 e.setFromXML(s);
     685           0 :                 if (e.getEntityTypeName() != "CalHolographyTable")
     686           0 :                         error();
     687           0 :                 setEntity(e);
     688             :                 // Skip the container's entity; but, it has to be there.
     689           0 :                 s = xml.getElement("<ContainerEntity","/>");
     690           0 :                 if (s.length() == 0) 
     691           0 :                         error();
     692             : 
     693             :                 // Get each row in the table.
     694           0 :                 s = xml.getElementContent("<row>","</row>");
     695             :                 CalHolographyRow *row;
     696           0 :                 if (getContainer().checkRowUniqueness()) {
     697             :                         try {
     698           0 :                                 while (s.length() != 0) {
     699           0 :                                         row = newRow();
     700           0 :                                         row->setFromXML(s);
     701           0 :                                         checkAndAdd(row);
     702           0 :                                         s = xml.getElementContent("<row>","</row>");
     703             :                                 }
     704             :                                 
     705             :                         }
     706           0 :                         catch (const DuplicateKey &e1) {
     707           0 :                                 throw ConversionException(e1.getMessage(),"CalHolographyTable");
     708           0 :                         } 
     709           0 :                         catch (const UniquenessViolationException &e1) {
     710           0 :                                 throw ConversionException(e1.getMessage(),"CalHolographyTable");      
     711           0 :                         }
     712           0 :                         catch (...) {
     713             :                                 // cout << "Unexpected error in CalHolographyTable::checkAndAdd called from CalHolographyTable::fromXML " << endl;
     714           0 :                         }
     715             :                 }
     716             :                 else {
     717             :                         try {
     718           0 :                                 while (s.length() != 0) {
     719           0 :                                         row = newRow();
     720           0 :                                         row->setFromXML(s);
     721           0 :                                         addWithoutCheckingUnique(row);
     722           0 :                                         s = xml.getElementContent("<row>","</row>");
     723             :                                 }
     724             :                         }
     725           0 :                         catch (const DuplicateKey &e1) {
     726           0 :                                 throw ConversionException(e1.getMessage(),"CalHolographyTable");
     727           0 :                         } 
     728           0 :                         catch (...) {
     729             :                                 // cout << "Unexpected error in CalHolographyTable::addWithoutCheckingUnique called from CalHolographyTable::fromXML " << endl;
     730           0 :                         }
     731             :                 }                               
     732             :                                 
     733             :                                 
     734           0 :                 if (!xml.isStr("</CalHolographyTable>")) 
     735           0 :                 error();
     736             :                 
     737             :                 //Does not change the convention defined in the model.  
     738             :                 //archiveAsBin = false;
     739             :                 //fileAsBin = false;
     740             : 
     741             :                 // clean up the xmlDoc pointer
     742           0 :                 if ( doc != NULL ) xmlFreeDoc(doc);
     743             :                 
     744           0 :         }
     745             : 
     746             :         
     747           0 :         void CalHolographyTable::error()  {
     748           0 :                 throw ConversionException("Invalid xml document","CalHolography");
     749             :         }
     750             :         
     751             :         
     752           0 :         string CalHolographyTable::MIMEXMLPart(const asdm::ByteOrder* byteOrder) {
     753           0 :                 string UID = getEntity().getEntityId().toString();
     754           0 :                 string withoutUID = UID.substr(6);
     755           0 :                 string containerUID = getContainer().getEntity().getEntityId().toString();
     756           0 :                 ostringstream oss;
     757           0 :                 oss << "<?xml version='1.0'  encoding='ISO-8859-1'?>";
     758           0 :                 oss << "\n";
     759           0 :                 oss << "<CalHolographyTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:clholo=\"http://Alma/XASDM/CalHolographyTable\" xsi:schemaLocation=\"http://Alma/XASDM/CalHolographyTable http://almaobservatory.org/XML/XASDM/4/CalHolographyTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n";
     760           0 :                 oss<< "<Entity entityId='"<<UID<<"' entityIdEncrypted='na' entityTypeName='CalHolographyTable' schemaVersion='1' documentVersion='1'/>\n";
     761           0 :                 oss<< "<ContainerEntity entityId='"<<containerUID<<"' entityIdEncrypted='na' entityTypeName='ASDM' schemaVersion='1' documentVersion='1'/>\n";
     762           0 :                 oss << "<BulkStoreRef file_id='"<<withoutUID<<"' byteOrder='"<<byteOrder->toString()<<"' />\n";
     763           0 :                 oss << "<Attributes>\n";
     764             : 
     765           0 :                 oss << "<antennaName/>\n"; 
     766           0 :                 oss << "<calDataId/>\n"; 
     767           0 :                 oss << "<calReductionId/>\n"; 
     768           0 :                 oss << "<antennaMake/>\n"; 
     769           0 :                 oss << "<startValidTime/>\n"; 
     770           0 :                 oss << "<endValidTime/>\n"; 
     771           0 :                 oss << "<ambientTemperature/>\n"; 
     772           0 :                 oss << "<focusPosition/>\n"; 
     773           0 :                 oss << "<frequencyRange/>\n"; 
     774           0 :                 oss << "<illuminationTaper/>\n"; 
     775           0 :                 oss << "<numReceptor/>\n"; 
     776           0 :                 oss << "<polarizationTypes/>\n"; 
     777           0 :                 oss << "<numPanelModes/>\n"; 
     778           0 :                 oss << "<receiverBand/>\n"; 
     779           0 :                 oss << "<beamMapUID/>\n"; 
     780           0 :                 oss << "<rawRMS/>\n"; 
     781           0 :                 oss << "<weightedRMS/>\n"; 
     782           0 :                 oss << "<surfaceMapUID/>\n"; 
     783           0 :                 oss << "<direction/>\n"; 
     784             : 
     785           0 :                 oss << "<numScrew/>\n"; 
     786           0 :                 oss << "<screwName/>\n"; 
     787           0 :                 oss << "<screwMotion/>\n"; 
     788           0 :                 oss << "<screwMotionError/>\n"; 
     789           0 :                 oss << "<gravCorrection/>\n"; 
     790           0 :                 oss << "<gravOptRange/>\n"; 
     791           0 :                 oss << "<tempCorrection/>\n"; 
     792           0 :                 oss << "<tempOptRange/>\n"; 
     793           0 :                 oss << "</Attributes>\n";         
     794           0 :                 oss << "</CalHolographyTable>\n";
     795             : 
     796           0 :                 return oss.str();                               
     797           0 :         }
     798             :         
     799           0 :         string CalHolographyTable::toMIME(const asdm::ByteOrder* byteOrder) {
     800           0 :                 EndianOSStream eoss(byteOrder);
     801             :                 
     802           0 :                 string UID = getEntity().getEntityId().toString();
     803             :                 
     804             :                 // The MIME Header
     805           0 :                 eoss <<"MIME-Version: 1.0";
     806           0 :                 eoss << "\n";
     807           0 :                 eoss << "Content-Type: Multipart/Related; boundary='MIME_boundary'; type='text/xml'; start= '<header.xml>'";
     808           0 :                 eoss <<"\n";
     809           0 :                 eoss <<"Content-Description: Correlator";
     810           0 :                 eoss <<"\n";
     811           0 :                 eoss <<"alma-uid:" << UID;
     812           0 :                 eoss <<"\n";
     813           0 :                 eoss <<"\n";            
     814             :                 
     815             :                 // The MIME XML part header.
     816           0 :                 eoss <<"--MIME_boundary";
     817           0 :                 eoss <<"\n";
     818           0 :                 eoss <<"Content-Type: text/xml; charset='ISO-8859-1'";
     819           0 :                 eoss <<"\n";
     820           0 :                 eoss <<"Content-Transfer-Encoding: 8bit";
     821           0 :                 eoss <<"\n";
     822           0 :                 eoss <<"Content-ID: <header.xml>";
     823           0 :                 eoss <<"\n";
     824           0 :                 eoss <<"\n";
     825             :                 
     826             :                 // The MIME XML part content.
     827           0 :                 eoss << MIMEXMLPart(byteOrder);
     828             : 
     829             :                 // The MIME binary part header
     830           0 :                 eoss <<"--MIME_boundary";
     831           0 :                 eoss <<"\n";
     832           0 :                 eoss <<"Content-Type: binary/octet-stream";
     833           0 :                 eoss <<"\n";
     834           0 :                 eoss <<"Content-ID: <content.bin>";
     835           0 :                 eoss <<"\n";
     836           0 :                 eoss <<"\n";    
     837             :                 
     838             :                 // The MIME binary content
     839           0 :                 entity.toBin(eoss);
     840           0 :                 container.getEntity().toBin(eoss);
     841           0 :                 eoss.writeInt((int) privateRows.size());
     842           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) {
     843           0 :                         privateRows.at(i)->toBin(eoss);      
     844             :                 }
     845             :                 
     846             :                 // The closing MIME boundary
     847           0 :                 eoss << "\n--MIME_boundary--";
     848           0 :                 eoss << "\n";
     849             :                 
     850           0 :                 return eoss.str();      
     851           0 :         }
     852             : 
     853             :         
     854           0 :         void CalHolographyTable::setFromMIME(const string & mimeMsg) {
     855           0 :     string xmlPartMIMEHeader = "Content-ID: <header.xml>\n\n";
     856             :     
     857           0 :     string binPartMIMEHeader = "--MIME_boundary\nContent-Type: binary/octet-stream\nContent-ID: <content.bin>\n\n";
     858             :     
     859             :     // Detect the XML header.
     860           0 :     string::size_type loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
     861           0 :     if ( loc0 == string::npos) {
     862             :       // let's try with CRLFs
     863           0 :       xmlPartMIMEHeader = "Content-ID: <header.xml>\r\n\r\n";
     864           0 :       loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
     865           0 :       if  ( loc0 == string::npos ) 
     866           0 :               throw ConversionException("Failed to detect the beginning of the XML header", "CalHolography");
     867             :     }
     868             : 
     869           0 :     loc0 += xmlPartMIMEHeader.size();
     870             :     
     871             :     // Look for the string announcing the binary part.
     872           0 :     string::size_type loc1 = mimeMsg.find( binPartMIMEHeader, loc0 );
     873             :     
     874           0 :     if ( loc1 == string::npos ) {
     875           0 :       throw ConversionException("Failed to detect the beginning of the binary part", "CalHolography");
     876             :     }
     877             :     
     878             :     //
     879             :     // Extract the xmlHeader and analyze it to find out what is the byte order and the sequence
     880             :     // of attribute names.
     881             :     //
     882           0 :     string xmlHeader = mimeMsg.substr(loc0, loc1-loc0);
     883             :     xmlDoc *doc;
     884           0 :     doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
     885           0 :     if ( doc == NULL ) 
     886           0 :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "CalHolography");
     887             :     
     888             :    // This vector will be filled by the names of  all the attributes of the table
     889             :    // in the order in which they are expected to be found in the binary representation.
     890             :    //
     891           0 :     vector<string> attributesSeq;
     892             :       
     893           0 :     xmlNode* root_element = xmlDocGetRootElement(doc);
     894           0 :     if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
     895           0 :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "CalHolography");
     896             :     
     897           0 :     const ByteOrder* byteOrder=0;
     898           0 :     if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
     899             :       // Then it's an "old fashioned" MIME file for tables.
     900             :       // Just try to deserialize it with Big_Endian for the bytes ordering.
     901           0 :       byteOrder = asdm::ByteOrder::Big_Endian;
     902             :       
     903             :          //
     904             :     // Let's consider a  default order for the sequence of attributes.
     905             :     //
     906             :     
     907             :          
     908           0 :     attributesSeq.push_back("antennaName") ; 
     909             :          
     910           0 :     attributesSeq.push_back("calDataId") ; 
     911             :          
     912           0 :     attributesSeq.push_back("calReductionId") ; 
     913             :          
     914           0 :     attributesSeq.push_back("antennaMake") ; 
     915             :          
     916           0 :     attributesSeq.push_back("startValidTime") ; 
     917             :          
     918           0 :     attributesSeq.push_back("endValidTime") ; 
     919             :          
     920           0 :     attributesSeq.push_back("ambientTemperature") ; 
     921             :          
     922           0 :     attributesSeq.push_back("focusPosition") ; 
     923             :          
     924           0 :     attributesSeq.push_back("frequencyRange") ; 
     925             :          
     926           0 :     attributesSeq.push_back("illuminationTaper") ; 
     927             :          
     928           0 :     attributesSeq.push_back("numReceptor") ; 
     929             :          
     930           0 :     attributesSeq.push_back("polarizationTypes") ; 
     931             :          
     932           0 :     attributesSeq.push_back("numPanelModes") ; 
     933             :          
     934           0 :     attributesSeq.push_back("receiverBand") ; 
     935             :          
     936           0 :     attributesSeq.push_back("beamMapUID") ; 
     937             :          
     938           0 :     attributesSeq.push_back("rawRMS") ; 
     939             :          
     940           0 :     attributesSeq.push_back("weightedRMS") ; 
     941             :          
     942           0 :     attributesSeq.push_back("surfaceMapUID") ; 
     943             :          
     944           0 :     attributesSeq.push_back("direction") ; 
     945             :         
     946             :          
     947           0 :     attributesSeq.push_back("numScrew") ; 
     948             :          
     949           0 :     attributesSeq.push_back("screwName") ; 
     950             :          
     951           0 :     attributesSeq.push_back("screwMotion") ; 
     952             :          
     953           0 :     attributesSeq.push_back("screwMotionError") ; 
     954             :          
     955           0 :     attributesSeq.push_back("gravCorrection") ; 
     956             :          
     957           0 :     attributesSeq.push_back("gravOptRange") ; 
     958             :          
     959           0 :     attributesSeq.push_back("tempCorrection") ; 
     960             :          
     961           0 :     attributesSeq.push_back("tempOptRange") ; 
     962             :         
     963             :      
     964             :     
     965             :     
     966             :     // And decide that it has version == "2"
     967           0 :     version = "2";         
     968             :      }
     969           0 :     else if (string("CalHolographyTable").compare((const char*) root_element->name) == 0) {
     970             :       // It's a new (and correct) MIME file for tables.
     971             :       //
     972             :       // 1st )  Look for a BulkStoreRef element with an attribute byteOrder.
     973             :       //
     974           0 :       xmlNode* bulkStoreRef = 0;
     975           0 :       xmlNode* child = root_element->children;
     976             :       
     977           0 :       if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
     978           0 :         xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
     979           0 :         version = string ((const char *) value);
     980           0 :         xmlFree(value); 
     981             :       }
     982             :       
     983             :       // Skip the two first children (Entity and ContainerEntity).
     984           0 :       bulkStoreRef = (child ==  0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
     985             :       
     986           0 :       if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE)  || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
     987           0 :         throw ConversionException ("Could not find the element '/CalHolographyTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "CalHolography");
     988             :         
     989             :       // We found BulkStoreRef, now look for its attribute byteOrder.
     990           0 :       _xmlAttr* byteOrderAttr = 0;
     991           0 :       for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next) 
     992           0 :           if (string("byteOrder").compare((const char*) attr->name) == 0) {
     993           0 :            byteOrderAttr = attr;
     994           0 :            break;
     995             :          }
     996             :       
     997           0 :       if (byteOrderAttr == 0) 
     998           0 :              throw ConversionException("Could not find the element '/CalHolographyTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "CalHolography");
     999             :       
    1000           0 :       string byteOrderValue = string((const char*) byteOrderAttr->children->content);
    1001           0 :       if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
    1002           0 :                 throw ConversionException("No valid value retrieved for the element '/CalHolographyTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "CalHolography");
    1003             :                 
    1004             :          //
    1005             :          // 2nd) Look for the Attributes element and grab the names of the elements it contains.
    1006             :          //
    1007           0 :          xmlNode* attributes = bulkStoreRef->next;
    1008           0 :      if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE)  || (string("Attributes").compare((const char*) attributes->name) != 0))     
    1009           0 :         throw ConversionException ("Could not find the element '/CalHolographyTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "CalHolography");
    1010             :  
    1011           0 :         xmlNode* childOfAttributes = attributes->children;
    1012             :         
    1013           0 :         while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
    1014           0 :                 attributesSeq.push_back(string((const char*) childOfAttributes->name));
    1015           0 :                 childOfAttributes = childOfAttributes->next;
    1016             :     }
    1017           0 :     }
    1018             :     // Create an EndianISStream from the substring containing the binary part.
    1019           0 :     EndianISStream eiss(mimeMsg.substr(loc1+binPartMIMEHeader.size()), byteOrder);
    1020             :     
    1021           0 :     entity = Entity::fromBin((EndianIStream&) eiss);
    1022             :     
    1023             :     // We do nothing with that but we have to read it.
    1024           0 :     Entity containerEntity = Entity::fromBin((EndianIStream&) eiss);
    1025             : 
    1026             :         // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.    
    1027           0 :     int numRows = ((EndianIStream&) eiss).readInt();
    1028           0 :     if ((numRows != -1)                        // Then these are *not* data produced at the EVLA.
    1029           0 :         && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one 
    1030             :                                                // written into the binary representation of the table.
    1031           0 :                 cout << "The a number of rows ('" 
    1032             :                          << numRows
    1033           0 :                          << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
    1034           0 :                          << this->declaredSize
    1035           0 :                          << "'). I'll proceed with the value declared in ASDM.xml"
    1036           0 :                          << endl;
    1037             :     }                                           
    1038             : 
    1039           0 :         if (getContainer().checkRowUniqueness()) {
    1040             :         try {
    1041           0 :                 for (uint32_t i = 0; i < this->declaredSize; i++) {
    1042           0 :                                 CalHolographyRow* aRow = CalHolographyRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
    1043           0 :                                 checkAndAdd(aRow);
    1044             :                 }
    1045             :         }
    1046           0 :         catch (const DuplicateKey &e) {
    1047           0 :                 throw ConversionException("Error while writing binary data , the message was "
    1048           0 :                                 + e.getMessage(), "CalHolography");
    1049           0 :         }
    1050           0 :         catch (const TagFormatException &e) {
    1051           0 :                  throw ConversionException("Error while reading binary data , the message was "
    1052           0 :                                 + e.getMessage(), "CalHolography");
    1053           0 :         }
    1054             :     }
    1055             :     else {
    1056           0 :                 for (uint32_t i = 0; i < this->declaredSize; i++) {
    1057           0 :                         CalHolographyRow* aRow = CalHolographyRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
    1058           0 :                         append(aRow);
    1059             :         }       
    1060             :     }
    1061             :     //Does not change the convention defined in the model.      
    1062             :     //archiveAsBin = true;
    1063             :     //fileAsBin = true;
    1064           0 :     if ( doc != NULL ) xmlFreeDoc(doc);
    1065             : 
    1066           0 :         }
    1067             :         
    1068           0 :         void CalHolographyTable::setUnknownAttributeBinaryReader(const string& attributeName, BinaryAttributeReaderFunctor* barFctr) {
    1069             :                 //
    1070             :                 // Is this attribute really unknown ?
    1071             :                 //
    1072           0 :                 for (vector<string>::const_iterator iter = attributesNamesOfCalHolography_v.begin(); iter != attributesNamesOfCalHolography_v.end(); iter++) {
    1073           0 :                         if ((*iter).compare(attributeName) == 0) 
    1074           0 :                                 throw ConversionException("the attribute '"+attributeName+"' is known you can't override the way it's read in the MIME binary file containing the table.", "CalHolography"); 
    1075             :                 }
    1076             :                 
    1077             :                 // Ok then register the functor to activate when an unknown attribute is met during the reading of a binary table?
    1078           0 :                 unknownAttributes2Functors[attributeName] = barFctr;
    1079           0 :         }
    1080             :         
    1081           0 :         BinaryAttributeReaderFunctor* CalHolographyTable::getUnknownAttributeBinaryReader(const string& attributeName) const {
    1082           0 :                 map<string, BinaryAttributeReaderFunctor*>::const_iterator iter = unknownAttributes2Functors.find(attributeName);
    1083           0 :                 return (iter == unknownAttributes2Functors.end()) ? 0 : iter->second;
    1084             :         }
    1085             : 
    1086             :         
    1087           0 :         void CalHolographyTable::toFile(string directory) {
    1088           0 :                 if (!directoryExists(directory.c_str()) &&
    1089           0 :                         !createPath(directory.c_str())) {
    1090           0 :                         throw ConversionException("Could not create directory " , directory);
    1091             :                 }
    1092             : 
    1093           0 :                 string fileName = directory + "/CalHolography.xml";
    1094           0 :                 ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
    1095           0 :                 if (tableout.rdstate() == ostream::failbit)
    1096           0 :                         throw ConversionException("Could not open file " + fileName + " to write ", "CalHolography");
    1097           0 :                 if (fileAsBin) 
    1098           0 :                         tableout << MIMEXMLPart();
    1099             :                 else
    1100           0 :                         tableout << toXML() << endl;
    1101           0 :                 tableout.close();
    1102           0 :                 if (tableout.rdstate() == ostream::failbit)
    1103           0 :                         throw ConversionException("Could not close file " + fileName, "CalHolography");
    1104             : 
    1105           0 :                 if (fileAsBin) {
    1106             :                         // write the bin serialized
    1107           0 :                         string fileName = directory + "/CalHolography.bin";
    1108           0 :                         ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
    1109           0 :                         if (tableout.rdstate() == ostream::failbit)
    1110           0 :                                 throw ConversionException("Could not open file " + fileName + " to write ", "CalHolography");
    1111           0 :                         tableout << toMIME() << endl;
    1112           0 :                         tableout.close();
    1113           0 :                         if (tableout.rdstate() == ostream::failbit)
    1114           0 :                                 throw ConversionException("Could not close file " + fileName, "CalHolography");
    1115           0 :                 }
    1116           0 :         }
    1117             : 
    1118             :         
    1119           0 :         void CalHolographyTable::setFromFile(const string& directory) {
    1120             : #ifndef WITHOUT_BOOST
    1121             :     if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/CalHolography.xml"))))
    1122             :       setFromXMLFile(directory);
    1123             :     else if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/CalHolography.bin"))))
    1124             :       setFromMIMEFile(directory);
    1125             : #else 
    1126             :     // alternative in Misc.h
    1127           0 :     if (file_exists(uniqSlashes(directory + "/CalHolography.xml")))
    1128           0 :       setFromXMLFile(directory);
    1129           0 :     else if (file_exists(uniqSlashes(directory + "/CalHolography.bin")))
    1130           0 :       setFromMIMEFile(directory);
    1131             : #endif
    1132             :     else
    1133           0 :       throw ConversionException("No file found for the CalHolography table", "CalHolography");
    1134           0 :         }                       
    1135             : 
    1136             :         
    1137           0 :   void CalHolographyTable::setFromMIMEFile(const string& directory) {
    1138           0 :     string tablePath ;
    1139             :     
    1140           0 :     tablePath = directory + "/CalHolography.bin";
    1141           0 :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
    1142           0 :     if (!tablefile.is_open()) { 
    1143           0 :       throw ConversionException("Could not open file " + tablePath, "CalHolography");
    1144             :     }
    1145             :     // Read in a stringstream.
    1146           0 :     stringstream ss; ss << tablefile.rdbuf();
    1147             :     
    1148           0 :     if (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
    1149           0 :       throw ConversionException("Error reading file " + tablePath,"CalHolography");
    1150             :     }
    1151             :     
    1152             :     // And close.
    1153           0 :     tablefile.close();
    1154           0 :     if (tablefile.rdstate() == istream::failbit)
    1155           0 :       throw ConversionException("Could not close file " + tablePath,"CalHolography");
    1156             :     
    1157           0 :     setFromMIME(ss.str());
    1158           0 :   }     
    1159             : /* 
    1160             :   void CalHolographyTable::openMIMEFile (const string& directory) {
    1161             :                 
    1162             :         // Open the file.
    1163             :         string tablePath ;
    1164             :     tablePath = directory + "/CalHolography.bin";
    1165             :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
    1166             :     if (!tablefile.is_open())
    1167             :       throw ConversionException("Could not open file " + tablePath, "CalHolography");
    1168             :       
    1169             :         // Locate the xmlPartMIMEHeader.
    1170             :     string xmlPartMIMEHeader = "CONTENT-ID: <HEADER.XML>\n\n";
    1171             :     CharComparator comparator;
    1172             :     istreambuf_iterator<char> BEGIN(tablefile.rdbuf());
    1173             :     istreambuf_iterator<char> END;
    1174             :     istreambuf_iterator<char> it = search(BEGIN, END, xmlPartMIMEHeader.begin(), xmlPartMIMEHeader.end(), comparator);
    1175             :     if (it == END) 
    1176             :         throw ConversionException("failed to detect the beginning of the XML header", "CalHolography");
    1177             :     
    1178             :     // Locate the binaryPartMIMEHeader while accumulating the characters of the xml header.     
    1179             :     string binPartMIMEHeader = "--MIME_BOUNDARY\nCONTENT-TYPE: BINARY/OCTET-STREAM\nCONTENT-ID: <CONTENT.BIN>\n\n";
    1180             :     string xmlHeader;
    1181             :         CharCompAccumulator compaccumulator(&xmlHeader, 100000);
    1182             :         ++it;
    1183             :         it = search(it, END, binPartMIMEHeader.begin(), binPartMIMEHeader.end(), compaccumulator);
    1184             :         if (it == END) 
    1185             :                 throw ConversionException("failed to detect the beginning of the binary part", "CalHolography");
    1186             :         
    1187             :         cout << xmlHeader << endl;
    1188             :         //
    1189             :         // We have the xmlHeader , let's parse it.
    1190             :         //
    1191             :         xmlDoc *doc;
    1192             :     doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
    1193             :     if ( doc == NULL ) 
    1194             :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "CalHolography");
    1195             :     
    1196             :    // This vector will be filled by the names of  all the attributes of the table
    1197             :    // in the order in which they are expected to be found in the binary representation.
    1198             :    //
    1199             :     vector<string> attributesSeq(attributesNamesInBinOfCalHolography_v);
    1200             :       
    1201             :     xmlNode* root_element = xmlDocGetRootElement(doc);
    1202             :     if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
    1203             :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "CalHolography");
    1204             :     
    1205             :     const ByteOrder* byteOrder=0;
    1206             :     if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
    1207             :       // Then it's an "old fashioned" MIME file for tables.
    1208             :       // Just try to deserialize it with Big_Endian for the bytes ordering.
    1209             :       byteOrder = asdm::ByteOrder::Big_Endian;
    1210             :         
    1211             :       // And decide that it has version == "2"
    1212             :     version = "2";         
    1213             :      }
    1214             :     else if (string("CalHolographyTable").compare((const char*) root_element->name) == 0) {
    1215             :       // It's a new (and correct) MIME file for tables.
    1216             :       //
    1217             :       // 1st )  Look for a BulkStoreRef element with an attribute byteOrder.
    1218             :       //
    1219             :       xmlNode* bulkStoreRef = 0;
    1220             :       xmlNode* child = root_element->children;
    1221             :       
    1222             :       if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
    1223             :         xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
    1224             :         version = string ((const char *) value);
    1225             :         xmlFree(value); 
    1226             :       }
    1227             :       
    1228             :       // Skip the two first children (Entity and ContainerEntity).
    1229             :       bulkStoreRef = (child ==  0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
    1230             :       
    1231             :       if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE)  || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
    1232             :         throw ConversionException ("Could not find the element '/CalHolographyTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "CalHolography");
    1233             :         
    1234             :       // We found BulkStoreRef, now look for its attribute byteOrder.
    1235             :       _xmlAttr* byteOrderAttr = 0;
    1236             :       for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next) 
    1237             :           if (string("byteOrder").compare((const char*) attr->name) == 0) {
    1238             :            byteOrderAttr = attr;
    1239             :            break;
    1240             :          }
    1241             :       
    1242             :       if (byteOrderAttr == 0) 
    1243             :              throw ConversionException("Could not find the element '/CalHolographyTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "CalHolography");
    1244             :       
    1245             :       string byteOrderValue = string((const char*) byteOrderAttr->children->content);
    1246             :       if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
    1247             :                 throw ConversionException("No valid value retrieved for the element '/CalHolographyTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "CalHolography");
    1248             :                 
    1249             :          //
    1250             :          // 2nd) Look for the Attributes element and grab the names of the elements it contains.
    1251             :          //
    1252             :          xmlNode* attributes = bulkStoreRef->next;
    1253             :      if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE)  || (string("Attributes").compare((const char*) attributes->name) != 0))     
    1254             :         throw ConversionException ("Could not find the element '/CalHolographyTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "CalHolography");
    1255             :  
    1256             :         xmlNode* childOfAttributes = attributes->children;
    1257             :         
    1258             :         while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
    1259             :                 attributesSeq.push_back(string((const char*) childOfAttributes->name));
    1260             :                 childOfAttributes = childOfAttributes->next;
    1261             :     }
    1262             :     }
    1263             :     // Create an EndianISStream from the substring containing the binary part.
    1264             :     EndianIFStream eifs(&tablefile, byteOrder);
    1265             :     
    1266             :     entity = Entity::fromBin((EndianIStream &) eifs);
    1267             :     
    1268             :     // We do nothing with that but we have to read it.
    1269             :     Entity containerEntity = Entity::fromBin((EndianIStream &) eifs);
    1270             : 
    1271             :         // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.    
    1272             :     int numRows = eifs.readInt();
    1273             :     if ((numRows != -1)                        // Then these are *not* data produced at the EVLA.
    1274             :         && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one 
    1275             :                                                // written into the binary representation of the table.
    1276             :                 cout << "The a number of rows ('" 
    1277             :                          << numRows
    1278             :                          << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
    1279             :                          << this->declaredSize
    1280             :                          << "'). I'll proceed with the value declared in ASDM.xml"
    1281             :                          << endl;
    1282             :     }
    1283             :     // clean up xmlDoc pointer
    1284             :     if ( doc != NULL ) xmlFreeDoc(doc);    
    1285             :   } 
    1286             :  */
    1287             : 
    1288             :         
    1289           0 : void CalHolographyTable::setFromXMLFile(const string& directory) {
    1290           0 :     string tablePath ;
    1291             :     
    1292           0 :     tablePath = directory + "/CalHolography.xml";
    1293             :     
    1294             :     /*
    1295             :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
    1296             :     if (!tablefile.is_open()) { 
    1297             :       throw ConversionException("Could not open file " + tablePath, "CalHolography");
    1298             :     }
    1299             :       // Read in a stringstream.
    1300             :     stringstream ss;
    1301             :     ss << tablefile.rdbuf();
    1302             :     
    1303             :     if  (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
    1304             :       throw ConversionException("Error reading file '" + tablePath + "'", "CalHolography");
    1305             :     }
    1306             :     
    1307             :     // And close
    1308             :     tablefile.close();
    1309             :     if (tablefile.rdstate() == istream::failbit)
    1310             :       throw ConversionException("Could not close file '" + tablePath + "'", "CalHolography");
    1311             : 
    1312             :     // Let's make a string out of the stringstream content and empty the stringstream.
    1313             :     string xmlDocument = ss.str(); ss.str("");
    1314             :         
    1315             :     // Let's make a very primitive check to decide
    1316             :     // whether the XML content represents the table
    1317             :     // or refers to it via a <BulkStoreRef element.
    1318             :     */
    1319             :     
    1320           0 :     string xmlDocument;
    1321             :     try {
    1322           0 :         xmlDocument = getContainer().getXSLTransformer()(tablePath);
    1323           0 :         if (getenv("ASDM_DEBUG")) cout << "About to read " << tablePath << endl;
    1324             :     }
    1325           0 :     catch (const XSLTransformerException &e) {
    1326           0 :         throw ConversionException("Caugth an exception whose message is '" + e.getMessage() + "'.", "CalHolography");
    1327           0 :     }
    1328             :     
    1329           0 :     if (xmlDocument.find("<BulkStoreRef") != string::npos)
    1330           0 :       setFromMIMEFile(directory);
    1331             :     else
    1332           0 :       fromXML(xmlDocument);
    1333           0 :   }
    1334             : 
    1335             :         
    1336             : 
    1337             :         
    1338             : 
    1339             :                         
    1340             :         
    1341             :         
    1342             : 
    1343             :         
    1344             : } // End namespace asdm
    1345             :  

Generated by: LCOV version 1.16