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 WeatherTable.h 32 : */ 33 : 34 : #ifndef WeatherTable_CLASS 35 : #define WeatherTable_CLASS 36 : 37 : #include <string> 38 : #include <vector> 39 : #include <map> 40 : 41 : 42 : 43 : 44 : #include <alma/ASDM/Speed.h> 45 : 46 : 47 : 48 : #include <alma/ASDM/ArrayTimeInterval.h> 49 : 50 : 51 : 52 : #include <alma/ASDM/Temperature.h> 53 : 54 : 55 : 56 : #include <alma/ASDM/Angle.h> 57 : 58 : 59 : 60 : #include <alma/ASDM/Length.h> 61 : 62 : 63 : 64 : #include <alma/ASDM/Humidity.h> 65 : 66 : 67 : 68 : #include <alma/ASDM/Tag.h> 69 : 70 : 71 : 72 : #include <alma/ASDM/Pressure.h> 73 : 74 : 75 : 76 : 77 : 78 : 79 : 80 : 81 : 82 : 83 : 84 : 85 : 86 : 87 : 88 : 89 : 90 : 91 : 92 : 93 : 94 : 95 : 96 : 97 : 98 : 99 : 100 : 101 : 102 : 103 : 104 : 105 : 106 : 107 : 108 : 109 : 110 : #include <alma/ASDM/ConversionException.h> 111 : #include <alma/ASDM/DuplicateKey.h> 112 : #include <alma/ASDM/UniquenessViolationException.h> 113 : #include <alma/ASDM/NoSuchRow.h> 114 : #include <alma/ASDM/DuplicateKey.h> 115 : 116 : 117 : #ifndef WITHOUT_ACS 118 : #include <asdmIDLC.h> 119 : #endif 120 : 121 : #include <alma/ASDM/Representable.h> 122 : 123 : #include <pthread.h> 124 : 125 : namespace asdm { 126 : 127 : //class asdm::ASDM; 128 : //class asdm::WeatherRow; 129 : 130 : class ASDM; 131 : class WeatherRow; 132 : /** 133 : * The WeatherTable class is an Alma table. 134 : * <BR> 135 : * 136 : * \par Role 137 : * Weather station information. 138 : * <BR> 139 : 140 : * Generated from model's revision "-1", branch "" 141 : * 142 : * <TABLE BORDER="1"> 143 : * <CAPTION> Attributes of Weather </CAPTION> 144 : * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape </TH> <TH> Comment </TH></TR> 145 : 146 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR> 147 : 148 : * <TR> 149 : 150 : * <TD> stationId </TD> 151 : 152 : * <TD> Tag</TD> 153 : * <TD> </TD> 154 : * <TD> refers to a unique row in StationTable. </TD> 155 : * </TR> 156 : 157 : * <TR> 158 : 159 : * <TD> timeInterval </TD> 160 : 161 : * <TD> ArrayTimeInterval</TD> 162 : * <TD> </TD> 163 : * <TD> the time interval for which the row's content is valid. </TD> 164 : * </TR> 165 : 166 : 167 : 168 : 169 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" valign="center"> Value <br> (Optional) </TH></TR> 170 : 171 : * <TR> 172 : * <TD> pressure</TD> 173 : * <TD> Pressure </TD> 174 : * <TD> </TD> 175 : * <TD> the ambient pressure. </TD> 176 : * </TR> 177 : 178 : * <TR> 179 : * <TD> relHumidity</TD> 180 : * <TD> Humidity </TD> 181 : * <TD> </TD> 182 : * <TD> the relative humidity. </TD> 183 : * </TR> 184 : 185 : * <TR> 186 : * <TD> temperature</TD> 187 : * <TD> Temperature </TD> 188 : * <TD> </TD> 189 : * <TD> the ambient temperature. </TD> 190 : * </TR> 191 : 192 : * <TR> 193 : * <TD> windDirection</TD> 194 : * <TD> Angle </TD> 195 : * <TD> </TD> 196 : * <TD> the wind direction. </TD> 197 : * </TR> 198 : 199 : * <TR> 200 : * <TD> windSpeed</TD> 201 : * <TD> Speed </TD> 202 : * <TD> </TD> 203 : * <TD> the wind speed. </TD> 204 : * </TR> 205 : 206 : * <TR> 207 : * <TD> windMax</TD> 208 : * <TD> Speed </TD> 209 : * <TD> </TD> 210 : * <TD> the maximum wind speed </TD> 211 : * </TR> 212 : 213 : * <TR> 214 : * <TD> dewPoint</TD> 215 : * <TD> Temperature </TD> 216 : * <TD> </TD> 217 : * <TD> the dew point's value. </TD> 218 : * </TR> 219 : 220 : * <TR> 221 : * <TD> numLayer(numLayer)</TD> 222 : * <TD> int </TD> 223 : * <TD> </TD> 224 : * <TD> NLayer the number of layers in the temperature profile. </TD> 225 : * </TR> 226 : 227 : * <TR> 228 : * <TD> layerHeight</TD> 229 : * <TD> std::vector<Length > </TD> 230 : * <TD> numLayer </TD> 231 : * <TD> the height of each layer for the temperature profile. </TD> 232 : * </TR> 233 : 234 : * <TR> 235 : * <TD> temperatureProfile</TD> 236 : * <TD> std::vector<Temperature > </TD> 237 : * <TD> numLayer </TD> 238 : * <TD> the temperature on the atmosphere at each height. </TD> 239 : * </TR> 240 : 241 : * <TR> 242 : * <TD> cloudMonitor</TD> 243 : * <TD> Temperature </TD> 244 : * <TD> </TD> 245 : * <TD> the temperature of the cloud monitor. </TD> 246 : * </TR> 247 : 248 : * <TR> 249 : * <TD> numWVR(numWVR)</TD> 250 : * <TD> int </TD> 251 : * <TD> </TD> 252 : * <TD> the number of WVR channels. </TD> 253 : * </TR> 254 : 255 : * <TR> 256 : * <TD> wvrTemp</TD> 257 : * <TD> std::vector<Temperature > </TD> 258 : * <TD> numWVR </TD> 259 : * <TD> the observed temperature in each WVR channel. </TD> 260 : * </TR> 261 : 262 : * <TR> 263 : * <TD> water</TD> 264 : * <TD> double </TD> 265 : * <TD> </TD> 266 : * <TD> the water precipitable content. </TD> 267 : * </TR> 268 : 269 : 270 : * </TABLE> 271 : */ 272 : class WeatherTable : public Representable { 273 : friend class ASDM; 274 : 275 : public: 276 : 277 : 278 : /** 279 : * Return the list of field names that make up key key 280 : * as an array of strings. 281 : * @return a vector of string. 282 : */ 283 : static const std::vector<std::string>& getKeyName(); 284 : 285 : 286 : virtual ~WeatherTable(); 287 : 288 : /** 289 : * Return the container to which this table belongs. 290 : * 291 : * @return the ASDM containing this table. 292 : */ 293 : ASDM &getContainer() const; 294 : 295 : /** 296 : * Return the number of rows in the table. 297 : * 298 : * @return the number of rows in an unsigned int. 299 : */ 300 : unsigned int size() const; 301 : 302 : /** 303 : * Return the name of this table. 304 : * 305 : * This is a instance method of the class. 306 : * 307 : * @return the name of this table in a string. 308 : */ 309 : std::string getName() const; 310 : 311 : /** 312 : * Return the name of this table. 313 : * 314 : * This is a static method of the class. 315 : * 316 : * @return the name of this table in a string. 317 : */ 318 : static std::string name() ; 319 : 320 : /** 321 : * Return the version information about this table. 322 : * 323 : */ 324 : std::string getVersion() const ; 325 : 326 : /** 327 : * Return the names of the attributes of this table. 328 : * 329 : * @return a vector of string 330 : */ 331 : static const std::vector<std::string>& getAttributesNames(); 332 : 333 : /** 334 : * Return the default sorted list of attributes names in the binary representation of the table. 335 : * 336 : * @return a const reference to a vector of string 337 : */ 338 : static const std::vector<std::string>& defaultAttributesNamesInBin(); 339 : 340 : /** 341 : * Return this table's Entity. 342 : */ 343 : Entity getEntity() const; 344 : 345 : /** 346 : * Set this table's Entity. 347 : * @param e An entity. 348 : */ 349 : void setEntity(Entity e); 350 : 351 : /** 352 : * Produces an XML representation conform 353 : * to the schema defined for Weather (WeatherTable.xsd). 354 : * 355 : * @returns a string containing the XML representation. 356 : * @throws ConversionException 357 : */ 358 : std::string toXML() ; 359 : 360 : #ifndef WITHOUT_ACS 361 : // Conversion Methods 362 : /** 363 : * Convert this table into a WeatherTableIDL CORBA structure. 364 : * 365 : * @return a pointer to a WeatherTableIDL 366 : */ 367 : asdmIDL::WeatherTableIDL *toIDL() ; 368 : 369 : /** 370 : * Fills the CORBA data structure passed in parameter 371 : * with the content of this table. 372 : * 373 : * @param x a reference to the asdmIDL::WeatherTableIDL to be populated 374 : * with the content of this. 375 : */ 376 : void toIDL(asdmIDL::WeatherTableIDL& x) const; 377 : 378 : #endif 379 : 380 : #ifndef WITHOUT_ACS 381 : /** 382 : * Populate this table from the content of a WeatherTableIDL Corba structure. 383 : * 384 : * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table. 385 : * @throws ConversionException 386 : */ 387 : void fromIDL(asdmIDL::WeatherTableIDL x) ; 388 : #endif 389 : 390 : // 391 : // ====> Row creation. 392 : // 393 : 394 : /** 395 : * Create a new row with default values. 396 : * @return a pointer on a WeatherRow 397 : */ 398 : WeatherRow *newRow(); 399 : 400 : 401 : /** 402 : * Create a new row initialized to the specified values. 403 : * @return a pointer on the created and initialized row. 404 : 405 : * @param stationId 406 : 407 : * @param timeInterval 408 : 409 : */ 410 : WeatherRow *newRow(Tag stationId, ArrayTimeInterval timeInterval); 411 : 412 : 413 : 414 : /** 415 : * Create a new row using a copy constructor mechanism. 416 : * 417 : * The method creates a new WeatherRow owned by this. Each attribute of the created row 418 : * is a (deep) copy of the corresponding attribute of row. The method does not add 419 : * the created row to this, its simply parents it to this, a call to the add method 420 : * has to be done in order to get the row added (very likely after having modified 421 : * some of its attributes). 422 : * If row is null then the method returns a new WeatherRow with default values for its attributes. 423 : * 424 : * @param row the row which is to be copied. 425 : */ 426 : WeatherRow *newRow(WeatherRow *row); 427 : 428 : // 429 : // ====> Append a row to its table. 430 : // 431 : 432 : 433 : /** 434 : * Add a row. 435 : * @param x a pointer to the WeatherRow to be added. 436 : * 437 : * @return a pointer to a WeatherRow. If the table contains a WeatherRow whose attributes (key and mandatory values) are equal to x ones 438 : * then returns a pointer on that WeatherRow, otherwise returns x. 439 : * 440 : * @throw DuplicateKey { thrown when the table contains a WeatherRow with a key equal to the x one but having 441 : * and a value section different from x one } 442 : * 443 : 444 : * @note The row is inserted in the table in such a way that all the rows having the same value of 445 : * ( stationId ) are stored by ascending time. 446 : * @see method getByContext. 447 : 448 : */ 449 : WeatherRow* add(WeatherRow* x) ; 450 : 451 : 452 : 453 : 454 : 455 : // 456 : // ====> Methods returning rows. 457 : // 458 : 459 : /** 460 : * Get a collection of pointers on the rows of the table. 461 : * @return Alls rows in a vector of pointers of WeatherRow. The elements of this vector are stored in the order 462 : * in which they have been added to the WeatherTable. 463 : */ 464 : std::vector<WeatherRow *> get() ; 465 : 466 : /** 467 : * Get a const reference on the collection of rows pointers internally hold by the table. 468 : * @return A const reference of a vector of pointers of WeatherRow. The elements of this vector are stored in the order 469 : * in which they have been added to the WeatherTable. 470 : * 471 : */ 472 : const std::vector<WeatherRow *>& get() const ; 473 : 474 : 475 : /** 476 : * Returns all the rows sorted by ascending startTime for a given context. 477 : * The context is defined by a value of ( stationId ). 478 : * 479 : * @return a pointer on a vector<WeatherRow *>. A null returned value means that the table contains 480 : * no WeatherRow for the given ( stationId ). 481 : * 482 : * @throws IllegalAccessException when a call is done to this method when it's called while the dataset has been imported with the 483 : * option checkRowUniqueness set to false. 484 : */ 485 : std::vector <WeatherRow*> *getByContext(Tag stationId); 486 : 487 : 488 : 489 : 490 : 491 : /** 492 : * Returns a WeatherRow* given a key. 493 : * @return a pointer to the row having the key whose values are passed as parameters, or 0 if 494 : * no row exists for that key. 495 : 496 : * @param stationId 497 : 498 : * @param timeInterval 499 : 500 : * 501 : */ 502 : WeatherRow* getRowByKey(Tag stationId, ArrayTimeInterval timeInterval); 503 : 504 : 505 : 506 : 507 : 508 : /** 509 : * Look up the table for a row whose all attributes 510 : * are equal to the corresponding parameters of the method. 511 : * @return a pointer on this row if any, null otherwise. 512 : * 513 : 514 : * @param stationId 515 : 516 : * @param timeInterval 517 : 518 : */ 519 : WeatherRow* lookup(Tag stationId, ArrayTimeInterval timeInterval); 520 : 521 : 522 : void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr); 523 : BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const; 524 : 525 : private: 526 : 527 : /** 528 : * Create a WeatherTable. 529 : * <p> 530 : * This constructor is private because only the 531 : * container can create tables. All tables must know the container 532 : * to which they belong. 533 : * @param container The container to which this table belongs. 534 : */ 535 : WeatherTable (ASDM & container); 536 : 537 : ASDM & container; 538 : 539 : bool archiveAsBin; // If true archive binary else archive XML 540 : bool fileAsBin ; // If true file binary else file XML 541 : 542 : std::string version ; 543 : 544 : Entity entity; 545 : 546 : 547 : 548 : 549 : 550 : 551 : /** 552 : * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not. 553 : * Check if *x verifies the key uniqueness rule and throw an exception if not. 554 : * Append x to its table. 555 : * @throws DuplicateKey 556 : 557 : */ 558 : WeatherRow* checkAndAdd(WeatherRow* x, bool skipCheckUniqueness=false) ; 559 : 560 : /** 561 : * Brutally append an WeatherRow x to the collection of rows already stored in this table. No uniqueness check is done ! 562 : * 563 : * @param WeatherRow* x a pointer onto the WeatherRow to be appended. 564 : */ 565 : void append(WeatherRow* x) ; 566 : 567 : /** 568 : * Brutally append an WeatherRow x to the collection of rows already stored in this table. No uniqueness check is done ! 569 : * 570 : * @param WeatherRow* x a pointer onto the WeatherRow to be appended. 571 : */ 572 : void addWithoutCheckingUnique(WeatherRow* x) ; 573 : 574 : 575 : 576 : 577 : 578 : 579 : /** 580 : * Insert a WeatherRow* in a vector of WeatherRow* so that it's ordered by ascending time. 581 : * 582 : * @param WeatherRow* x . The pointer to be inserted. 583 : * @param vector <WeatherRow*>& row . A reference to the vector where to insert x. 584 : * 585 : */ 586 : WeatherRow * insertByStartTime(WeatherRow* x, std::vector<WeatherRow* >& row); 587 : 588 : 589 : 590 : // A data structure to store the pointers on the table's rows. 591 : 592 : // In all cases we maintain a private vector of WeatherRow s. 593 : std::vector<WeatherRow * > privateRows; 594 : 595 : 596 : 597 : 598 : 599 : 600 : 601 : 602 : typedef std::vector <WeatherRow* > TIME_ROWS; 603 : std::map<std::string, TIME_ROWS > context; 604 : 605 : /** 606 : * Returns a string built by concatenating the ascii representation of the 607 : * parameters values suffixed with a "_" character. 608 : */ 609 : std::string Key(Tag stationId) ; 610 : 611 : 612 : 613 : 614 : /** 615 : * Fills the vector vout (passed by reference) with pointers on elements of vin 616 : * whose attributes are equal to the corresponding parameters of the method. 617 : * 618 : */ 619 : void getByKeyNoAutoIncNoTime(std::vector <WeatherRow*>& vin, std::vector <WeatherRow*>& vout, Tag stationId); 620 : 621 : 622 : 623 : void error() ; //throw(ConversionException); 624 : 625 : 626 : /** 627 : * Populate this table from the content of a XML document that is required to 628 : * be conform to the XML schema defined for a Weather (WeatherTable.xsd). 629 : * @throws ConversionException 630 : * 631 : */ 632 : void fromXML(std::string& xmlDoc) ; 633 : 634 : std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors; 635 : 636 : /** 637 : * Private methods involved during the build of this table out of the content 638 : * of file(s) containing an external representation of a Weather table. 639 : */ 640 : void setFromMIMEFile(const std::string& directory); 641 : /* 642 : void openMIMEFile(const std::string& directory); 643 : */ 644 : void setFromXMLFile(const std::string& directory); 645 : 646 : /** 647 : * Serialize this into a stream of bytes and encapsulates that stream into a MIME message. 648 : * @returns a string containing the MIME message. 649 : * 650 : * @param byteOrder a const pointer to a static instance of the class ByteOrder. 651 : * 652 : */ 653 : std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity); 654 : 655 : 656 : /** 657 : * Extracts the binary part of a MIME message and deserialize its content 658 : * to fill this with the result of the deserialization. 659 : * @param mimeMsg the string containing the MIME message. 660 : * @throws ConversionException 661 : */ 662 : void setFromMIME(const std::string & mimeMsg); 663 : 664 : /** 665 : * Private methods involved during the export of this table into disk file(s). 666 : */ 667 : std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity); 668 : 669 : /** 670 : * Stores a representation (binary or XML) of this table into a file. 671 : * 672 : * Depending on the boolean value of its private field fileAsBin a binary serialization of this (fileAsBin==true) 673 : * will be saved in a file "Weather.bin" or an XML representation (fileAsBin==false) will be saved in a file "Weather.xml". 674 : * The file is always written in a directory whose name is passed as a parameter. 675 : * @param directory The name of directory where the file containing the table's representation will be saved. 676 : * 677 : */ 678 : void toFile(std::string directory); 679 : 680 : /** 681 : * Load the table in memory if necessary. 682 : */ 683 : bool loadInProgress; 684 78 : void checkPresenceInMemory() { 685 78 : if (!presentInMemory && !loadInProgress) { 686 71 : loadInProgress = true; 687 71 : setFromFile(getContainer().getDirectory()); 688 71 : presentInMemory = true; 689 71 : loadInProgress = false; 690 : } 691 78 : } 692 : /** 693 : * Reads and parses a file containing a representation of a WeatherTable as those produced by the toFile method. 694 : * This table is populated with the result of the parsing. 695 : * @param directory The name of the directory containing the file te be read and parsed. 696 : * @throws ConversionException If any error occurs while reading the 697 : * files in the directory or parsing them. 698 : * 699 : */ 700 : void setFromFile(const std::string& directory); 701 : 702 : }; 703 : 704 : } // End namespace asdm 705 : 706 : #endif /* WeatherTable_CLASS */