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