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