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