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