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