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

Generated by: LCOV version 1.16