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