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