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