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