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