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