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