source: branches/hpc33/src/FillerWrapper.h@ 2546

Last change on this file since 2546 was 2519, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: Defined STIdxIter and its python interface

Test Programs: List test programs

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Defined STIdxIter module that contains STIdxIterAcc class.
Python interface for STIdxIterAcc class also defined.
STMath::almacal is rewritten using STIdxIterAcc.


File size: 2.7 KB
RevLine 
[1778]1//
2// C++ Interface: Filler
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2010
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAPFILLER_H
13#define ASAPFILLER_H
14
15#include <casa/aips.h>
[1786]16#include <casa/Exceptions.h>
[1778]17#include <casa/Utilities/CountedPtr.h>
[1904]18#include <casa/Containers/Record.h>
[1813]19#include <casa/OS/File.h>
20
[1778]21#include <string>
22
[1786]23#include "ScantableWrapper.h"
24#include "FillerBase.h"
25#include "PKSFiller.h"
26#include "NROFiller.h"
27
[1794]28
[1778]29namespace asap
30{
[1786]31class FillerWrapper
[1778]32{
33public:
34
[1787]35 explicit FillerWrapper(ScantableWrapper tbl) : filler_(0), attached_(false)
[1786]36 { stable_ = tbl.getCP(); }
37
38 virtual ~FillerWrapper() { close(); }
39
40
[1904]41 void open(const std::string& filename, const casa::Record& rec) {
42 // void open(const std::string& filename) {
[1813]43 casa::File file(filename);
44 if ( !file.exists() ) {
45 throw(AipsError("File does not exist"));
46 }
[2289]47 int fileType = dataType( filename ) ;
48 if ( fileType == 0 ) {
49 filler_ = new PKSFiller(stable_);
50 if (filler_->open(filename, rec)) {
51 attached_ = true;
52 return;
53 }
[1778]54 }
[2289]55 else if ( fileType == 1 ) {
56 filler_ = new NROFiller(stable_);
57 if (filler_->open(filename, rec)) {
58 attached_ = true;
59 return;
60 }
[1778]61 }
[1786]62 filler_ = 0;
63 attached_ = false;
64 throw casa::AipsError("Unknown Data Format");
[1778]65 }
66 void close() {
[1786]67 if (attached_) {
68 filler_->close();
[1778]69 }
70 }
71
72 void fill() {
[1786]73 if (attached_) {
74 filler_->fill();
[1778]75 }
76 }
[1786]77
78 void setReferenceRegex(const std::string& rx) {
79 if (attached_) {
80 filler_->setReferenceRegex(rx);
[1778]81 }
82 }
83
84private:
[1786]85
[2289]86 int dataType( const std::string &filename ) {
87 int ret = -1 ;
88 int pks = 0 ;
89 int nro = 1 ;
90 casa::File file( filename ) ;
91 if ( file.isDirectory() )
92 ret = pks ;
93 else if ( file.isReadable() ) {
[2334]94 // if we want to compare to 6 characters we should only read in 6
[2289]95 FILE *f = fopen( filename.c_str(), "r") ;
[2334]96 char buf[7] ;
97 size_t tmp = fread( buf, 6, 1, f ) ;
98 (void *)tmp;
[2289]99 fclose( f ) ;
[2334]100 buf[6]='\0' ;
[2289]101 // NRO data has two types:
102 // 1) specific binary data for OTF observation
103 // 2) (pseudo-)FITS data that doesn't have primary HDU
104 // So, one can distinguish NRO and non-NRO data by examining
105 // first keyword name.
106 if ( casa::String( buf ) == "SIMPLE" ) {
107 ret = pks ;
108 }
109 else {
110 ret = nro ;
111 }
112 }
113 return ret ;
114 }
115
[1811]116 FillerWrapper();
117 FillerWrapper(const FillerWrapper&);
118 FillerWrapper& operator=(const FillerWrapper&);
[1787]119
[1786]120 casa::CountedPtr<FillerBase> filler_;
121 bool attached_;
122 casa::CountedPtr<Scantable> stable_;
[1778]123};
124
125};
[1786]126#endif
Note: See TracBrowser for help on using the repository browser.