Changes between Version 1 and Version 2 of HowToImplementNewFiller


Ignore:
Timestamp:
08/05/10 12:23:47 (14 years ago)
Author:
Takeshi Nakazato
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowToImplementNewFiller

    v1 v2  
    2121   
    2222== Design ==
    23 
     23The !FillerBase class is defined as the above description. All Filler classes must inherit this class.
     24Constructor of the class takes Scantable object as its argument. The Scantable given will be filled by the Filler.
     25The !FillerBase is an abstract class that have three pure abstract methods:
     26
     27   * open()  --- open data file (via Reader object)
     28   * fill()  --- get information from the Reader object, and fill Scantable
     29   * close() --- close data file (via Reader object)
     30
     31These methods must be implemented in the derived classes.
     32
     33The !FillerBase is designed to fill Scantable in row-by-row manner. To do this, it has an attribute that represents a single row of the main table in Scantable. The fill() method should 1) fill that row and 2) add that row to target Scantable over all rows. The !FillerBase implements common methods that help to implement fill() method. 
     34
     35   * setHeader() --- fill header
     36   * 'setter' methods for cells --- fill certain cells in the current row
     37      * setIndex() --- fill SCANNO, CYCLENO, IFNO, POLNO, and BEAMNO
     38      * setSpectrum() --- fill SPECTRA, FLAGTRA, and TSYS
     39      * setFlagrow() --- fill FLAGROW
     40      * setDirection() --- fill DIRECTION, AZIMUTH, and ELEVATION
     41      * setTime() --- fill TIME and INTERVAL
     42      * setReferenceBeam() --- fill REFBEAMNO
     43      * setSource() --- fill SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY
     44      * setScanRate() --- fill SCANRATE
     45      * setOpacity() --- fill OPACITY
     46      * setFrequency() --- add row to FREQUENCIES subtable if necessary, and fill FREQ_ID
     47      * setMolecule() --- add row to MOLECULES subtable if necessary, and fill MOLECULE_ID
     48      * setFocus() --- add row to FOCUS subtable if necessary, and fill FOCUS_ID
     49      * setWeather() --- add row to WEATHER subtable if necessary, and fill WEATHER_ID
     50      * setTcal() --- add row to TCAL subtable if necessary, and fill TCAL_ID
     51   * commitRow() --- add row to Scantable
     52
     53The 'setter' methods including setHeader() method take some arguments that is used to fill corresponding cells. Some arguments have their default values. It means that the corresponding cell is an optional one that may not be given explicitly. On the other hand, cells without default values are mandatory. Their values must be given explicitly.
    2454
    2555
    2656== Implementation ==
    27 If you want to define new filler, it must inherit !FillerBase class.
     57To define new filler, you should go through the following steps:
     58
     59 1. define your filler as a derived class of !FillerBase
     60
     61{{{
     62#!cpp
     63class MyFiller : public FillerBase
     64{
     65   ...
     66};
     67}}}
     68
     69 2. define constructor
     70
     71 Default constructor and copy constructor should be disabled from outside.
     72 So, they should be explicitly declared in the private section.
     73 The only public constructor is the one that takes Scantable object as its argument.
     74
     75{{{
     76#!cpp
     77class MyFiller : public FillerBase
     78{
     79   public:
     80      MyFiller( CountedPtr<Scantable> stable );
     81      ...
     82   private:
     83      MyFiller();
     84      MyFiller( const MyFiller& );
     85      MyFiller &operator=( const MyFiller& );
     86      ...
     87};
     88}}}
     89
     90 You probably need to have Reader object as an attribute.
     91
     92{{{
     93#!cpp
     94class MyFiller : public FillerBase
     95{
     96   public:
     97      MyFiller( CountedPtr<Scantable> stable );
     98      ...
     99   private:
     100      CountedPtr<MyReader> reader_;
     101
     102      MyFiller();
     103      MyFiller( const MyFiller& );
     104      MyFiller &operator=( const MyFiller& );
     105      ...
     106};
     107}}}
     108
     109 At least, the constructor must call the constructor of !FillerBase class.
     110
     111{{{
     112#!cpp
     113MyFiller::MyFiller( CountedPtr<Scantable> stable )
     114   : FillerBase( stable )
     115{
     116   ...
     117}
     118}}}
     119
     120 The constructor of !FillerBase class sets Scantable object given as a target.
     121
     122 3. implement open() method
     123
     124 You must implement open() method that gets an access to the data file.
     125 In almost case, it will be realized by the open() method of Reader object.
     126 You can call setHeader() to fill header of target Scantable.
     127
     128{{{
     129#!cpp
     130bool MyFiller::open( const string &filename )
     131{
     132   ...
     133   // open file
     134   if ( reader_->open( filename ) ) {
     135      return False ;
     136   }
     137   ...
     138   // get header information
     139   ...
     140   // set header
     141   setHeader( header ) ;
     142}
     143}}}
     144
     145 The header variable must be set in the method.
     146
     147 4. implement fill() method
     148
     149 You must implement fill() method that performs 1) to fill row and 2) to add row to target Scantable.
     150 As mentioned above, a lot of useful methods are available.
     151
     152{{{
     153#!cpp
     154void MyFiller::fill()
     155{
     156   // get row information
     157   // e.g. reader_->read(...) ;
     158   ...
     159   // loop on all rows
     160   for ( int i = 0 ; i < nrow ; i++ ) {
     161      // fill row
     162      setIndex( ... ) ;
     163      setSpectrum( ... ) ;
     164      setFlagrow( ... ) ;
     165      setDirection( ... ) ;
     166      setTime( ... ) ;
     167      setReferenceBeam( ... ) ;
     168      setSource( ... ) ;
     169      setScanRate( ... ) ;
     170      setOpacity( ... ) ;
     171      setFrequency( ... ) ;
     172      setMolecule( ... ) ;
     173      setFocus( ... ) ;
     174      setWeather( ... ) ;
     175      setTcal( ... ) ;
     176
     177      // add row
     178      commitRow() ;
     179   }
     180}
     181}}}
     182
     183 5. implement close() method
     184
     185 You must implement close() method. Normally, it just closes the file.
     186
     187{{{
     188#!cpp
     189void MyFiller::close()
     190{
     191   if ( reader_.null() != False ) {
     192      reader_ = 0 ;
     193   }
     194   table_ = 0 ;
     195}
     196}}}
     197
     198 In this example, the method doesn't close the file explicitly.
     199 Instead, the file is closed when the Reader object is destructed.
     200
     201== Miscellaneous ==
     202
     203See existing Filler implementation (PKSFiller, NROFiller) for more detail.
     204