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 FlagTable.h
32 : */
33 :
34 : #ifndef FlagTable_CLASS
35 : #define FlagTable_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 :
66 :
67 :
68 :
69 :
70 :
71 :
72 :
73 : #include <alma/Enumerations/CPolarizationType.h>
74 :
75 :
76 :
77 :
78 :
79 :
80 : #include <alma/ASDM/ConversionException.h>
81 : #include <alma/ASDM/DuplicateKey.h>
82 : #include <alma/ASDM/UniquenessViolationException.h>
83 : #include <alma/ASDM/NoSuchRow.h>
84 : #include <alma/ASDM/DuplicateKey.h>
85 :
86 :
87 : #ifndef WITHOUT_ACS
88 : #include <asdmIDLC.h>
89 : #endif
90 :
91 : #include <alma/ASDM/Representable.h>
92 :
93 : #include <pthread.h>
94 :
95 : namespace asdm {
96 :
97 : //class asdm::ASDM;
98 : //class asdm::FlagRow;
99 :
100 : class ASDM;
101 : class FlagRow;
102 : /**
103 : * The FlagTable class is an Alma table.
104 : * <BR>
105 : *
106 : * \par Role
107 : * This table is used for flagging visibility data and is used in addition to the Binary Data Format flags produced by the correlator software.
108 : * <BR>
109 :
110 : * Generated from model's revision "-1", branch ""
111 : *
112 : * <TABLE BORDER="1">
113 : * <CAPTION> Attributes of Flag </CAPTION>
114 : * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape </TH> <TH> Comment </TH></TR>
115 :
116 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
117 :
118 : * <TR>
119 :
120 : * <TD><I> flagId </I></TD>
121 :
122 : * <TD> Tag</TD>
123 : * <TD> </TD>
124 : * <TD> identifies a unique row in the table. </TD>
125 : * </TR>
126 :
127 :
128 :
129 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
130 :
131 : * <TR>
132 : * <TD> startTime </TD>
133 : * <TD> ArrayTime </TD>
134 : * <TD> </TD>
135 : * <TD> the start time of the flagging period. </TD>
136 : * </TR>
137 :
138 : * <TR>
139 : * <TD> endTime </TD>
140 : * <TD> ArrayTime </TD>
141 : * <TD> </TD>
142 : * <TD> the end time of the flagging period. </TD>
143 : * </TR>
144 :
145 : * <TR>
146 : * <TD> reason </TD>
147 : * <TD> std::string </TD>
148 : * <TD> </TD>
149 : * <TD> Extensible list of flagging conditions. </TD>
150 : * </TR>
151 :
152 : * <TR>
153 : * <TD> numAntenna (numAntenna)</TD>
154 : * <TD> int </TD>
155 : * <TD> </TD>
156 : * <TD> The number of antennas to which the flagging refers.By convention numAntenna== 0 means that the flag applies to all the existing antennas, in such a case the array antennaId can be left empty. </TD>
157 : * </TR>
158 :
159 : * <TR>
160 : * <TD> antennaId </TD>
161 : * <TD> std::vector<Tag> </TD>
162 : * <TD> numAntenna </TD>
163 : * <TD> An array of Tag which refers to a collection of rows in the Antenna table. The flag applies to the antennas described in these rows. It is an error to have different elements with a same value in this array. </TD>
164 : * </TR>
165 :
166 :
167 :
168 : * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" valign="center"> Value <br> (Optional) </TH></TR>
169 :
170 : * <TR>
171 : * <TD> numPolarizationType(numPolarizationType)</TD>
172 : * <TD> int </TD>
173 : * <TD> </TD>
174 : * <TD> The number of polarization types , i.e. the size of the attribute polarizationType. By convention numPolarizationType == 0 means that the flag applies to all the defined polarization types. \b Remark : numPolarizationType and polarizationType, both optional, must be both present or both absent in one same row of the table, except if numPolarizationType==0 in which case all the defined polarization types are involved in the flagging. </TD>
175 : * </TR>
176 :
177 : * <TR>
178 : * <TD> numSpectralWindow(numSpectralWindow)</TD>
179 : * <TD> int </TD>
180 : * <TD> </TD>
181 : * <TD> The number of spectral windows targeted by the flagging. By convention numSpectralWindow == 0 means that the flag applies to all the existing spectral windows. \b Remark : numSpectralWindow and spectralWindow, both optional, must be both present or both absent in one same row of the table, except if numSpectralWindow==0, in which case all the declared spectral windows are involved in the flagging. </TD>
182 : * </TR>
183 :
184 : * <TR>
185 : * <TD> numPairedAntenna(numPairedAntenna)</TD>
186 : * <TD> int </TD>
187 : * <TD> </TD>
188 : * <TD> The number of antennas to be paired with to form the flagged baselines. By convention, numPairedAntenna == 0 means that the flag applies to all baselines built on the antennas declared in the attribute antennaId. \b Remark: numPairedAntenna and pairedAntenna, both optional, must be both present or both absent except if numPairedAntenna==0 in which case one has to consider all the baselines defined upon the antennas announced in antennaId. </TD>
189 : * </TR>
190 :
191 : * <TR>
192 : * <TD> numChan(numChan)</TD>
193 : * <TD> int </TD>
194 : * <TD> </TD>
195 : * <TD> Number of channels to be flaggged. </TD>
196 : * </TR>
197 :
198 : * <TR>
199 : * <TD> polarizationType</TD>
200 : * <TD> std::vector<PolarizationTypeMod::PolarizationType > </TD>
201 : * <TD> numPolarizationType </TD>
202 : * <TD> An array of values of type PolarizationType. It specifies the polarization types where the flagging applies. It is an error to have different elements with a same value in this array. </TD>
203 : * </TR>
204 :
205 : * <TR>
206 : * <TD> channel</TD>
207 : * <TD> std::vector<std::vector<int > > </TD>
208 : * <TD> numChan, 3 </TD>
209 : * <TD> An array of triplets where the first element is the number spectralWindowId. The second and third values are the startChannel and endChannel,
210 : respectively, which specify
211 : the channels where flagging applies. It is
212 : an error to have different elements with a
213 : same value in this array.
214 : </TD>
215 : * </TR>
216 :
217 : * <TR>
218 : * <TD> pairedAntennaId</TD>
219 : * <TD> std::vector<Tag> </TD>
220 : * <TD> numPairedAntenna </TD>
221 : * <TD> An array of Tag which refers to rows in the Antenna table. These rows contain the description of the antennas which are paired to form the flagged baselines. It is an error to have distinct elements with a same value in this array. </TD>
222 : * </TR>
223 :
224 : * <TR>
225 : * <TD> spectralWindowId</TD>
226 : * <TD> std::vector<Tag> </TD>
227 : * <TD> numSpectralWindow </TD>
228 : * <TD> An array of Tag which refers to a collection of rows in the SpectralWindow table. The flag applies to the spectral windows described in these rows. It is an error to have different elements with a same value in this array. </TD>
229 : * </TR>
230 :
231 :
232 : * </TABLE>
233 : */
234 : class FlagTable : public Representable {
235 : friend class ASDM;
236 :
237 : public:
238 :
239 :
240 : /**
241 : * Return the list of field names that make up key key
242 : * as an array of strings.
243 : * @return a vector of string.
244 : */
245 : static const std::vector<std::string>& getKeyName();
246 :
247 :
248 : virtual ~FlagTable();
249 :
250 : /**
251 : * Return the container to which this table belongs.
252 : *
253 : * @return the ASDM containing this table.
254 : */
255 : ASDM &getContainer() const;
256 :
257 : /**
258 : * Return the number of rows in the table.
259 : *
260 : * @return the number of rows in an unsigned int.
261 : */
262 : unsigned int size() const;
263 :
264 : /**
265 : * Return the name of this table.
266 : *
267 : * This is a instance method of the class.
268 : *
269 : * @return the name of this table in a string.
270 : */
271 : std::string getName() const;
272 :
273 : /**
274 : * Return the name of this table.
275 : *
276 : * This is a static method of the class.
277 : *
278 : * @return the name of this table in a string.
279 : */
280 : static std::string name() ;
281 :
282 : /**
283 : * Return the version information about this table.
284 : *
285 : */
286 : std::string getVersion() const ;
287 :
288 : /**
289 : * Return the names of the attributes of this table.
290 : *
291 : * @return a vector of string
292 : */
293 : static const std::vector<std::string>& getAttributesNames();
294 :
295 : /**
296 : * Return the default sorted list of attributes names in the binary representation of the table.
297 : *
298 : * @return a const reference to a vector of string
299 : */
300 : static const std::vector<std::string>& defaultAttributesNamesInBin();
301 :
302 : /**
303 : * Return this table's Entity.
304 : */
305 : Entity getEntity() const;
306 :
307 : /**
308 : * Set this table's Entity.
309 : * @param e An entity.
310 : */
311 : void setEntity(Entity e);
312 :
313 : /**
314 : * Produces an XML representation conform
315 : * to the schema defined for Flag (FlagTable.xsd).
316 : *
317 : * @returns a string containing the XML representation.
318 : * @throws ConversionException
319 : */
320 : std::string toXML() ;
321 :
322 : #ifndef WITHOUT_ACS
323 : // Conversion Methods
324 : /**
325 : * Convert this table into a FlagTableIDL CORBA structure.
326 : *
327 : * @return a pointer to a FlagTableIDL
328 : */
329 : asdmIDL::FlagTableIDL *toIDL() ;
330 :
331 : /**
332 : * Fills the CORBA data structure passed in parameter
333 : * with the content of this table.
334 : *
335 : * @param x a reference to the asdmIDL::FlagTableIDL to be populated
336 : * with the content of this.
337 : */
338 : void toIDL(asdmIDL::FlagTableIDL& x) const;
339 :
340 : #endif
341 :
342 : #ifndef WITHOUT_ACS
343 : /**
344 : * Populate this table from the content of a FlagTableIDL Corba structure.
345 : *
346 : * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
347 : * @throws ConversionException
348 : */
349 : void fromIDL(asdmIDL::FlagTableIDL x) ;
350 : #endif
351 :
352 : //
353 : // ====> Row creation.
354 : //
355 :
356 : /**
357 : * Create a new row with default values.
358 : * @return a pointer on a FlagRow
359 : */
360 : FlagRow *newRow();
361 :
362 :
363 : /**
364 : * Create a new row initialized to the specified values.
365 : * @return a pointer on the created and initialized row.
366 :
367 : * @param startTime
368 :
369 : * @param endTime
370 :
371 : * @param reason
372 :
373 : * @param numAntenna
374 :
375 : * @param antennaId
376 :
377 : */
378 : FlagRow *newRow(ArrayTime startTime, ArrayTime endTime, std::string reason, int numAntenna, std::vector<Tag> antennaId);
379 :
380 :
381 :
382 : /**
383 : * Create a new row using a copy constructor mechanism.
384 : *
385 : * The method creates a new FlagRow owned by this. Each attribute of the created row
386 : * is a (deep) copy of the corresponding attribute of row. The method does not add
387 : * the created row to this, its simply parents it to this, a call to the add method
388 : * has to be done in order to get the row added (very likely after having modified
389 : * some of its attributes).
390 : * If row is null then the method returns a new FlagRow with default values for its attributes.
391 : *
392 : * @param row the row which is to be copied.
393 : */
394 : FlagRow *newRow(FlagRow *row);
395 :
396 : //
397 : // ====> Append a row to its table.
398 : //
399 :
400 :
401 :
402 :
403 : /**
404 : * Add a row.
405 : * If there table contains a row whose key's fields are equal
406 : * to x's ones then return a pointer on this row (i.e. no actual insertion is performed)
407 : * otherwise add x to the table and return x.
408 : * @param x . A pointer on the row to be added.
409 : * @returns a pointer to a FlagRow.
410 : */
411 :
412 : FlagRow* add(FlagRow* x) ;
413 :
414 :
415 :
416 : //
417 : // ====> Methods returning rows.
418 : //
419 :
420 : /**
421 : * Get a collection of pointers on the rows of the table.
422 : * @return Alls rows in a vector of pointers of FlagRow. The elements of this vector are stored in the order
423 : * in which they have been added to the FlagTable.
424 : */
425 : std::vector<FlagRow *> get() ;
426 :
427 : /**
428 : * Get a const reference on the collection of rows pointers internally hold by the table.
429 : * @return A const reference of a vector of pointers of FlagRow. The elements of this vector are stored in the order
430 : * in which they have been added to the FlagTable.
431 : *
432 : */
433 : const std::vector<FlagRow *>& get() const ;
434 :
435 :
436 :
437 :
438 :
439 : /**
440 : * Returns a FlagRow* 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 flagId
445 :
446 : *
447 : */
448 : FlagRow* getRowByKey(Tag flagId);
449 :
450 :
451 :
452 :
453 :
454 : /**
455 : * Look up the table for a row whose all attributes except the autoincrementable one
456 : * are equal to the corresponding parameters of the method.
457 : * @return a pointer on this row if any, null otherwise.
458 : *
459 :
460 : * @param startTime
461 :
462 : * @param endTime
463 :
464 : * @param reason
465 :
466 : * @param numAntenna
467 :
468 : * @param antennaId
469 :
470 : */
471 : FlagRow* lookup(ArrayTime startTime, ArrayTime endTime, std::string reason, int numAntenna, std::vector<Tag> antennaId);
472 :
473 :
474 : void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
475 : BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
476 :
477 : private:
478 :
479 : /**
480 : * Create a FlagTable.
481 : * <p>
482 : * This constructor is private because only the
483 : * container can create tables. All tables must know the container
484 : * to which they belong.
485 : * @param container The container to which this table belongs.
486 : */
487 : FlagTable (ASDM & container);
488 :
489 : ASDM & container;
490 :
491 : bool archiveAsBin; // If true archive binary else archive XML
492 : bool fileAsBin ; // If true file binary else file XML
493 :
494 : std::string version ;
495 :
496 : Entity entity;
497 :
498 :
499 :
500 :
501 :
502 : // A map for the autoincrementation algorithm
503 : std::map<std::string,int> noAutoIncIds;
504 : void autoIncrement(std::string key, FlagRow* x);
505 :
506 :
507 : /**
508 : * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
509 : * Check if *x verifies the key uniqueness rule and throw an exception if not.
510 : * Append x to its table.
511 : * @throws DuplicateKey
512 :
513 : * @throws UniquenessViolationException
514 :
515 : */
516 : FlagRow* checkAndAdd(FlagRow* x, bool skipCheckUniqueness=false) ;
517 :
518 : /**
519 : * Brutally append an FlagRow x to the collection of rows already stored in this table. No uniqueness check is done !
520 : *
521 : * @param FlagRow* x a pointer onto the FlagRow to be appended.
522 : */
523 : void append(FlagRow* x) ;
524 :
525 : /**
526 : * Brutally append an FlagRow x to the collection of rows already stored in this table. No uniqueness check is done !
527 : *
528 : * @param FlagRow* x a pointer onto the FlagRow to be appended.
529 : */
530 : void addWithoutCheckingUnique(FlagRow* x) ;
531 :
532 :
533 :
534 :
535 :
536 : // A data structure to store the pointers on the table's rows.
537 :
538 : // In all cases we maintain a private vector of FlagRow s.
539 : std::vector<FlagRow * > privateRows;
540 :
541 :
542 :
543 : std::vector<FlagRow *> row;
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 Flag (FlagTable.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 Flag 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 "Flag.bin" or an XML representation (fileAsBin==false) will be saved in a file "Flag.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 FlagTable 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 /* FlagTable_CLASS */
|