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