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 SBSummaryTable.h
32 : */
33 :
34 : #ifndef SBSummaryTable_CLASS
35 : #define SBSummaryTable_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 : #include <alma/ASDM/EntityRef.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 : #include <alma/Enumerations/CReceiverBand.h>
78 :
79 :
80 :
81 : #include <alma/Enumerations/CSBType.h>
82 :
83 :
84 :
85 :
86 :
87 :
88 :
89 :
90 :
91 :
92 :
93 :
94 :
95 :
96 :
97 :
98 :
99 :
100 :
101 :
102 :
103 : #include <alma/Enumerations/CDirectionReferenceCode.h>
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::SBSummaryRow;
129 :
130 : class ASDM;
131 : class SBSummaryRow;
132 : /**
133 : * The SBSummaryTable class is an Alma table.
134 : * <BR>
135 : *
136 : * \par Role
137 : * Characteristics of the Scheduling Block that has been executed. Much of the data here is reproduced from the Scheduling block itself.
138 : * <BR>
139 :
140 : * Generated from model's revision "-1", branch ""
141 : *
142 : * <TABLE BORDER="1">
143 : * <CAPTION> Attributes of SBSummary </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><I> sBSummaryId </I></TD>
151 :
152 : * <TD> Tag</TD>
153 : * <TD> </TD>
154 : * <TD> refers to a unique row in the table. </TD>
155 : * </TR>
156 :
157 :
158 :
159 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
160 :
161 : * <TR>
162 : * <TD> sbSummaryUID </TD>
163 : * <TD> EntityRef </TD>
164 : * <TD> </TD>
165 : * <TD> the scheduling block archive's UID. </TD>
166 : * </TR>
167 :
168 : * <TR>
169 : * <TD> projectUID </TD>
170 : * <TD> EntityRef </TD>
171 : * <TD> </TD>
172 : * <TD> the projet archive's UID. </TD>
173 : * </TR>
174 :
175 : * <TR>
176 : * <TD> obsUnitSetUID </TD>
177 : * <TD> EntityRef </TD>
178 : * <TD> </TD>
179 : * <TD> the observing unit set archive's UID. </TD>
180 : * </TR>
181 :
182 : * <TR>
183 : * <TD> frequency </TD>
184 : * <TD> double </TD>
185 : * <TD> </TD>
186 : * <TD> a representative frequency. </TD>
187 : * </TR>
188 :
189 : * <TR>
190 : * <TD> frequencyBand </TD>
191 : * <TD> ReceiverBandMod::ReceiverBand </TD>
192 : * <TD> </TD>
193 : * <TD> the frequency band. </TD>
194 : * </TR>
195 :
196 : * <TR>
197 : * <TD> sbType </TD>
198 : * <TD> SBTypeMod::SBType </TD>
199 : * <TD> </TD>
200 : * <TD> the type of scheduling block. </TD>
201 : * </TR>
202 :
203 : * <TR>
204 : * <TD> sbDuration </TD>
205 : * <TD> Interval </TD>
206 : * <TD> </TD>
207 : * <TD> the duration of the scheduling block. </TD>
208 : * </TR>
209 :
210 : * <TR>
211 : * <TD> numObservingMode (numObservingMode)</TD>
212 : * <TD> int </TD>
213 : * <TD> </TD>
214 : * <TD> the number of observing modes. </TD>
215 : * </TR>
216 :
217 : * <TR>
218 : * <TD> observingMode </TD>
219 : * <TD> std::vector<std::string > </TD>
220 : * <TD> numObservingMode </TD>
221 : * <TD> the observing modes. </TD>
222 : * </TR>
223 :
224 : * <TR>
225 : * <TD> numberRepeats (numberRepeats)</TD>
226 : * <TD> int </TD>
227 : * <TD> </TD>
228 : * <TD> the number of repeats. </TD>
229 : * </TR>
230 :
231 : * <TR>
232 : * <TD> numScienceGoal (numScienceGoal)</TD>
233 : * <TD> int </TD>
234 : * <TD> </TD>
235 : * <TD> the number of scientific goals. </TD>
236 : * </TR>
237 :
238 : * <TR>
239 : * <TD> scienceGoal </TD>
240 : * <TD> std::vector<std::string > </TD>
241 : * <TD> numScienceGoal </TD>
242 : * <TD> the scientific goals. </TD>
243 : * </TR>
244 :
245 : * <TR>
246 : * <TD> numWeatherConstraint (numWeatherConstraint)</TD>
247 : * <TD> int </TD>
248 : * <TD> </TD>
249 : * <TD> the number of weather constraints. </TD>
250 : * </TR>
251 :
252 : * <TR>
253 : * <TD> weatherConstraint </TD>
254 : * <TD> std::vector<std::string > </TD>
255 : * <TD> numWeatherConstraint </TD>
256 : * <TD> the weather constraints. </TD>
257 : * </TR>
258 :
259 :
260 :
261 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" valign="center"> Value <br> (Optional) </TH></TR>
262 :
263 : * <TR>
264 : * <TD> centerDirection</TD>
265 : * <TD> std::vector<Angle > </TD>
266 : * <TD> 2 </TD>
267 : * <TD> the representative target direction. </TD>
268 : * </TR>
269 :
270 : * <TR>
271 : * <TD> centerDirectionCode</TD>
272 : * <TD> DirectionReferenceCodeMod::DirectionReferenceCode </TD>
273 : * <TD> </TD>
274 : * <TD> identifies the direction reference frame associated with centerDirection. </TD>
275 : * </TR>
276 :
277 : * <TR>
278 : * <TD> centerDirectionEquinox</TD>
279 : * <TD> ArrayTime </TD>
280 : * <TD> </TD>
281 : * <TD> the equinox associated to centerDirectionReferenceCode (if needed). </TD>
282 : * </TR>
283 :
284 :
285 : * </TABLE>
286 : */
287 : class SBSummaryTable : public Representable {
288 : friend class ASDM;
289 :
290 : public:
291 :
292 :
293 : /**
294 : * Return the list of field names that make up key key
295 : * as an array of strings.
296 : * @return a vector of string.
297 : */
298 : static const std::vector<std::string>& getKeyName();
299 :
300 :
301 : virtual ~SBSummaryTable();
302 :
303 : /**
304 : * Return the container to which this table belongs.
305 : *
306 : * @return the ASDM containing this table.
307 : */
308 : ASDM &getContainer() const;
309 :
310 : /**
311 : * Return the number of rows in the table.
312 : *
313 : * @return the number of rows in an unsigned int.
314 : */
315 : unsigned int size() const;
316 :
317 : /**
318 : * Return the name of this table.
319 : *
320 : * This is a instance method of the class.
321 : *
322 : * @return the name of this table in a string.
323 : */
324 : std::string getName() const;
325 :
326 : /**
327 : * Return the name of this table.
328 : *
329 : * This is a static method of the class.
330 : *
331 : * @return the name of this table in a string.
332 : */
333 : static std::string name() ;
334 :
335 : /**
336 : * Return the version information about this table.
337 : *
338 : */
339 : std::string getVersion() const ;
340 :
341 : /**
342 : * Return the names of the attributes of this table.
343 : *
344 : * @return a vector of string
345 : */
346 : static const std::vector<std::string>& getAttributesNames();
347 :
348 : /**
349 : * Return the default sorted list of attributes names in the binary representation of the table.
350 : *
351 : * @return a const reference to a vector of string
352 : */
353 : static const std::vector<std::string>& defaultAttributesNamesInBin();
354 :
355 : /**
356 : * Return this table's Entity.
357 : */
358 : Entity getEntity() const;
359 :
360 : /**
361 : * Set this table's Entity.
362 : * @param e An entity.
363 : */
364 : void setEntity(Entity e);
365 :
366 : /**
367 : * Produces an XML representation conform
368 : * to the schema defined for SBSummary (SBSummaryTable.xsd).
369 : *
370 : * @returns a string containing the XML representation.
371 : * @throws ConversionException
372 : */
373 : std::string toXML() ;
374 :
375 : #ifndef WITHOUT_ACS
376 : // Conversion Methods
377 : /**
378 : * Convert this table into a SBSummaryTableIDL CORBA structure.
379 : *
380 : * @return a pointer to a SBSummaryTableIDL
381 : */
382 : asdmIDL::SBSummaryTableIDL *toIDL() ;
383 :
384 : /**
385 : * Fills the CORBA data structure passed in parameter
386 : * with the content of this table.
387 : *
388 : * @param x a reference to the asdmIDL::SBSummaryTableIDL to be populated
389 : * with the content of this.
390 : */
391 : void toIDL(asdmIDL::SBSummaryTableIDL& x) const;
392 :
393 : #endif
394 :
395 : #ifndef WITHOUT_ACS
396 : /**
397 : * Populate this table from the content of a SBSummaryTableIDL Corba structure.
398 : *
399 : * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
400 : * @throws ConversionException
401 : */
402 : void fromIDL(asdmIDL::SBSummaryTableIDL x) ;
403 : #endif
404 :
405 : //
406 : // ====> Row creation.
407 : //
408 :
409 : /**
410 : * Create a new row with default values.
411 : * @return a pointer on a SBSummaryRow
412 : */
413 : SBSummaryRow *newRow();
414 :
415 :
416 : /**
417 : * Create a new row initialized to the specified values.
418 : * @return a pointer on the created and initialized row.
419 :
420 : * @param sbSummaryUID
421 :
422 : * @param projectUID
423 :
424 : * @param obsUnitSetUID
425 :
426 : * @param frequency
427 :
428 : * @param frequencyBand
429 :
430 : * @param sbType
431 :
432 : * @param sbDuration
433 :
434 : * @param numObservingMode
435 :
436 : * @param observingMode
437 :
438 : * @param numberRepeats
439 :
440 : * @param numScienceGoal
441 :
442 : * @param scienceGoal
443 :
444 : * @param numWeatherConstraint
445 :
446 : * @param weatherConstraint
447 :
448 : */
449 : SBSummaryRow *newRow(EntityRef sbSummaryUID, EntityRef projectUID, EntityRef obsUnitSetUID, double frequency, ReceiverBandMod::ReceiverBand frequencyBand, SBTypeMod::SBType sbType, Interval sbDuration, int numObservingMode, std::vector<std::string > observingMode, int numberRepeats, int numScienceGoal, std::vector<std::string > scienceGoal, int numWeatherConstraint, std::vector<std::string > weatherConstraint);
450 :
451 :
452 :
453 : /**
454 : * Create a new row using a copy constructor mechanism.
455 : *
456 : * The method creates a new SBSummaryRow owned by this. Each attribute of the created row
457 : * is a (deep) copy of the corresponding attribute of row. The method does not add
458 : * the created row to this, its simply parents it to this, a call to the add method
459 : * has to be done in order to get the row added (very likely after having modified
460 : * some of its attributes).
461 : * If row is null then the method returns a new SBSummaryRow with default values for its attributes.
462 : *
463 : * @param row the row which is to be copied.
464 : */
465 : SBSummaryRow *newRow(SBSummaryRow *row);
466 :
467 : //
468 : // ====> Append a row to its table.
469 : //
470 :
471 :
472 :
473 :
474 : /**
475 : * Add a row.
476 : * If there table contains a row whose key's fields are equal
477 : * to x's ones then return a pointer on this row (i.e. no actual insertion is performed)
478 : * otherwise add x to the table and return x.
479 : * @param x . A pointer on the row to be added.
480 : * @returns a pointer to a SBSummaryRow.
481 : */
482 :
483 : SBSummaryRow* add(SBSummaryRow* x) ;
484 :
485 :
486 :
487 : //
488 : // ====> Methods returning rows.
489 : //
490 :
491 : /**
492 : * Get a collection of pointers on the rows of the table.
493 : * @return Alls rows in a vector of pointers of SBSummaryRow. The elements of this vector are stored in the order
494 : * in which they have been added to the SBSummaryTable.
495 : */
496 : std::vector<SBSummaryRow *> get() ;
497 :
498 : /**
499 : * Get a const reference on the collection of rows pointers internally hold by the table.
500 : * @return A const reference of a vector of pointers of SBSummaryRow. The elements of this vector are stored in the order
501 : * in which they have been added to the SBSummaryTable.
502 : *
503 : */
504 : const std::vector<SBSummaryRow *>& get() const ;
505 :
506 :
507 :
508 :
509 :
510 : /**
511 : * Returns a SBSummaryRow* given a key.
512 : * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
513 : * no row exists for that key.
514 :
515 : * @param sBSummaryId
516 :
517 : *
518 : */
519 : SBSummaryRow* getRowByKey(Tag sBSummaryId);
520 :
521 :
522 :
523 :
524 :
525 : /**
526 : * Look up the table for a row whose all attributes except the autoincrementable one
527 : * are equal to the corresponding parameters of the method.
528 : * @return a pointer on this row if any, null otherwise.
529 : *
530 :
531 : * @param sbSummaryUID
532 :
533 : * @param projectUID
534 :
535 : * @param obsUnitSetUID
536 :
537 : * @param frequency
538 :
539 : * @param frequencyBand
540 :
541 : * @param sbType
542 :
543 : * @param sbDuration
544 :
545 : * @param numObservingMode
546 :
547 : * @param observingMode
548 :
549 : * @param numberRepeats
550 :
551 : * @param numScienceGoal
552 :
553 : * @param scienceGoal
554 :
555 : * @param numWeatherConstraint
556 :
557 : * @param weatherConstraint
558 :
559 : */
560 : SBSummaryRow* lookup(EntityRef sbSummaryUID, EntityRef projectUID, EntityRef obsUnitSetUID, double frequency, ReceiverBandMod::ReceiverBand frequencyBand, SBTypeMod::SBType sbType, Interval sbDuration, int numObservingMode, std::vector<std::string > observingMode, int numberRepeats, int numScienceGoal, std::vector<std::string > scienceGoal, int numWeatherConstraint, std::vector<std::string > weatherConstraint);
561 :
562 :
563 : void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
564 : BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
565 :
566 : private:
567 :
568 : /**
569 : * Create a SBSummaryTable.
570 : * <p>
571 : * This constructor is private because only the
572 : * container can create tables. All tables must know the container
573 : * to which they belong.
574 : * @param container The container to which this table belongs.
575 : */
576 : SBSummaryTable (ASDM & container);
577 :
578 : ASDM & container;
579 :
580 : bool archiveAsBin; // If true archive binary else archive XML
581 : bool fileAsBin ; // If true file binary else file XML
582 :
583 : std::string version ;
584 :
585 : Entity entity;
586 :
587 :
588 :
589 :
590 :
591 : // A map for the autoincrementation algorithm
592 : std::map<std::string,int> noAutoIncIds;
593 : void autoIncrement(std::string key, SBSummaryRow* x);
594 :
595 :
596 : /**
597 : * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
598 : * Check if *x verifies the key uniqueness rule and throw an exception if not.
599 : * Append x to its table.
600 : * @throws DuplicateKey
601 :
602 : * @throws UniquenessViolationException
603 :
604 : */
605 : SBSummaryRow* checkAndAdd(SBSummaryRow* x, bool skipCheckUniqueness=false) ;
606 :
607 : /**
608 : * Brutally append an SBSummaryRow x to the collection of rows already stored in this table. No uniqueness check is done !
609 : *
610 : * @param SBSummaryRow* x a pointer onto the SBSummaryRow to be appended.
611 : */
612 : void append(SBSummaryRow* x) ;
613 :
614 : /**
615 : * Brutally append an SBSummaryRow x to the collection of rows already stored in this table. No uniqueness check is done !
616 : *
617 : * @param SBSummaryRow* x a pointer onto the SBSummaryRow to be appended.
618 : */
619 : void addWithoutCheckingUnique(SBSummaryRow* x) ;
620 :
621 :
622 :
623 :
624 :
625 : // A data structure to store the pointers on the table's rows.
626 :
627 : // In all cases we maintain a private vector of SBSummaryRow s.
628 : std::vector<SBSummaryRow * > privateRows;
629 :
630 :
631 :
632 : std::vector<SBSummaryRow *> row;
633 :
634 :
635 : void error() ; //throw(ConversionException);
636 :
637 :
638 : /**
639 : * Populate this table from the content of a XML document that is required to
640 : * be conform to the XML schema defined for a SBSummary (SBSummaryTable.xsd).
641 : * @throws ConversionException
642 : *
643 : */
644 : void fromXML(std::string& xmlDoc) ;
645 :
646 : std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
647 :
648 : /**
649 : * Private methods involved during the build of this table out of the content
650 : * of file(s) containing an external representation of a SBSummary table.
651 : */
652 : void setFromMIMEFile(const std::string& directory);
653 : /*
654 : void openMIMEFile(const std::string& directory);
655 : */
656 : void setFromXMLFile(const std::string& directory);
657 :
658 : /**
659 : * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
660 : * @returns a string containing the MIME message.
661 : *
662 : * @param byteOrder a const pointer to a static instance of the class ByteOrder.
663 : *
664 : */
665 : std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
666 :
667 :
668 : /**
669 : * Extracts the binary part of a MIME message and deserialize its content
670 : * to fill this with the result of the deserialization.
671 : * @param mimeMsg the string containing the MIME message.
672 : * @throws ConversionException
673 : */
674 : void setFromMIME(const std::string & mimeMsg);
675 :
676 : /**
677 : * Private methods involved during the export of this table into disk file(s).
678 : */
679 : std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
680 :
681 : /**
682 : * Stores a representation (binary or XML) of this table into a file.
683 : *
684 : * Depending on the boolean value of its private field fileAsBin a binary serialization of this (fileAsBin==true)
685 : * will be saved in a file "SBSummary.bin" or an XML representation (fileAsBin==false) will be saved in a file "SBSummary.xml".
686 : * The file is always written in a directory whose name is passed as a parameter.
687 : * @param directory The name of directory where the file containing the table's representation will be saved.
688 : *
689 : */
690 : void toFile(std::string directory);
691 :
692 : /**
693 : * Load the table in memory if necessary.
694 : */
695 : bool loadInProgress;
696 526 : void checkPresenceInMemory() {
697 526 : if (!presentInMemory && !loadInProgress) {
698 72 : loadInProgress = true;
699 72 : setFromFile(getContainer().getDirectory());
700 72 : presentInMemory = true;
701 72 : loadInProgress = false;
702 : }
703 526 : }
704 : /**
705 : * Reads and parses a file containing a representation of a SBSummaryTable as those produced by the toFile method.
706 : * This table is populated with the result of the parsing.
707 : * @param directory The name of the directory containing the file te be read and parsed.
708 : * @throws ConversionException If any error occurs while reading the
709 : * files in the directory or parsing them.
710 : *
711 : */
712 : void setFromFile(const std::string& directory);
713 :
714 : };
715 :
716 : } // End namespace asdm
717 :
718 : #endif /* SBSummaryTable_CLASS */
|