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