source: Sophya/trunk/SophyaExt/FitsIOServer/fitsautoreader.cc@ 2130

Last change on this file since 2130 was 2130, checked in by lemeur, 23 years ago

ouverture FitsBTNtuIntf au lieu de XNTUPLE pour grose BINTABLE

File size: 7.1 KB
Line 
1#include "pexceptions.h"
2#include "fitsautoreader.h"
3#include "dvlist.h"
4
5///////////////////////////////////////////////////////////////////////
6// ---- gestion de persistance I/O format fits--
7// objets
8////////////////////////////////////////////////////////////////////
9
10/*!
11 \class SOPHYA::FITS_AutoReader
12 \ingroup FitsIOServer
13 FITS reader with automatic mapping on SOPHYA objects.
14*/
15
16FITS_AutoReader::FITS_AutoReader() {InitNull();};
17FITS_AutoReader::FITS_AutoReader(const char inputfile[])
18{
19 InitNull();
20 inFits_ = new FitsInFile (inputfile);
21 filename_ = string(inputfile);
22}
23FITS_AutoReader::FITS_AutoReader(string const & inputfile)
24{
25 InitNull();
26 inFits_ = new FitsInFile (inputfile);
27 filename_ = inputfile;
28}
29FITS_AutoReader::~FITS_AutoReader()
30{
31 if (inFits_ != NULL) delete inFits_;
32 if (dobj_ != NULL) delete dobj_;
33}
34
35int FITS_AutoReader::NbBlocks()
36{
37 return inFits_->NbBlocks();
38}
39
40 // parametre toutCharger : uniquement pour les BINTABLE et s'il ne
41 // s'agit pas explicitement d'un objet SOPHYA, on charge toute la
42 // table en memoire sous forme d'un xntuple si toutCharger= true.
43 // et si le nombre d'entrees est superieur a 1000.
44 // sinon (c-a-d : il ne s'agit pas d'un objet connu de SOPHYA
45 // c'est une BINTABLE avec plus de 1000 entrees
46 // totuCharger = false)
47 // on ouvre une FitsBTNtuIntf (lecture ulterieure, bufferisee, des valeurs)
48AnyDataObj* FITS_AutoReader::ReadObject(int hdunum, bool toutCharger) const
49{
50 if (hdunum<=0)
51 {
52 throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive");
53 }
54 inFits_->ReadHeader(hdunum);
55 if (inFits_->IsFitsEOF()) return NULL;
56 if (inFits_->IsFitsERROR())
57 {
58 throw IOExc("FITS_AutoReader::ReadObject: FITSIO error in reading");
59 }
60 DVList dvl=inFits_->DVListFromFits();
61 string nameObj = dvl.GetS("CONTENT");
62 // cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
63 if (nameObj == string("TArray") )
64 {
65 return newTArray();
66 }
67 else if (nameObj == string("SphereHEALPix") )
68 {
69 return newSphereHEALPix();
70 }
71 else if (nameObj == string("LocalMap") )
72 {
73 return newLocalMap();
74 }
75 else if (nameObj == string("NTuple") )
76 {
77 return newNTuple();
78 }
79 else if (nameObj == string("XNTuple") )
80 {
81 return newXNTuple();
82 }
83 // on n'a trouve aucun nom d'objet connu de SOPHYA, on fait une
84 // recherche qualitative.
85 //
86 // si c'est une image fits, on cree un TArray
87 else if (inFits_->IsFitsImage())
88 {
89 return newTArray();
90 }
91 // si c'est une bintable on cherche le mot cle ORDERING pour identifier
92 // une spherehealpix
93 else if (inFits_->IsFitsTable())
94 {
95 if (dvl.GetS("ORDERING") != string("")) return newSphereHEALPix();
96 // sinon on cherche ntuple ou xntuple
97 else
98 {
99 int index=0;
100 for (int k=0; k < inFits_->NbColsFromFits(); k++)
101 {
102 if (inFits_->ColTypeFromFits(k) != FitsFile::FitsDataType_float)
103 {
104 index = 1;
105 break;
106 }
107 }
108 if (index == 0) return newNTuple();
109 else
110 {
111 if (!toutCharger )
112 {
113 int maxEntries=0;
114 for (int k=0; k < inFits_->NbColsFromFits(); k++)
115 {
116 if (inFits_->NentriesFromFits(k) > maxEntries ) maxEntries = inFits_->NentriesFromFits(k);
117 }
118 if ( maxEntries > 1000) return newFitsBTNtuIntf(hdunum);
119 else return newXNTuple();
120 }
121 else return newXNTuple();
122
123 }
124 }
125 }
126 else
127 {
128 cout << " WARNING ( FITS_AutoReader::ReadObject) : object not recognized as a SOPHYA object" << endl;
129 return new DVList(dvl);
130 }
131
132}
133
134AnyDataObj* FITS_AutoReader::newTArray() const
135{
136 FitsFile::FitsDataType dtype = inFits_->ImageType();
137 switch (dtype)
138 {
139 case FitsFile::FitsDataType_double :
140 {
141 TArray<r_8>* matptr = new TArray<r_8>;
142 FITS_TArray<r_8> fta(matptr);
143 fta.Read(*inFits_, inFits_->currentHeaderIndex());
144 return matptr;
145 }
146 case FitsFile::FitsDataType_float :
147 {
148 TArray<r_4>* matptr = new TArray<r_4>;
149 FITS_TArray<r_4> fta(matptr);
150 fta.Read(*inFits_, inFits_->currentHeaderIndex());
151 return matptr;
152 }
153 case FitsFile::FitsDataType_int :
154 {
155 TArray<int_4>* matptr = new TArray<int_4>;
156 FITS_TArray<int_4> fta(matptr);
157 fta.Read(*inFits_, inFits_->currentHeaderIndex());
158 return matptr;
159 }
160 default :
161 cout << "type = " << (int) dtype << endl;
162 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for TArray");
163 }
164}
165
166AnyDataObj* FITS_AutoReader::newSphereHEALPix() const
167{
168 FitsFile::FitsDataType dtype;
169 if (inFits_->IsFitsTable()) dtype = inFits_->ColTypeFromFits(0);
170 else
171 {
172 cout << " WARNING : Sperehealpix not binary table : unusual " << endl;
173 dtype = inFits_->ImageType();
174 }
175 switch (dtype)
176 {
177 case FitsFile::FitsDataType_double :
178 {
179 SphereHEALPix<r_8>* sphptr = new SphereHEALPix<r_8>;
180 FITS_SphereHEALPix<r_8> fta(sphptr);
181 fta.Read(*inFits_, inFits_->currentHeaderIndex());
182 return sphptr;
183 }
184 case FitsFile::FitsDataType_float :
185 {
186 SphereHEALPix<r_4>* sphptr = new SphereHEALPix<r_4>;
187 FITS_SphereHEALPix<r_4> fta(sphptr);
188 fta.Read(*inFits_, inFits_->currentHeaderIndex());
189 return sphptr;
190 }
191 case FitsFile::FitsDataType_int :
192 {
193 SphereHEALPix<int_4>* sphptr = new SphereHEALPix<int_4>;
194 FITS_SphereHEALPix<int_4> fta(sphptr);
195 fta.Read(*inFits_, inFits_->currentHeaderIndex());
196 return sphptr;
197 }
198 default :
199 cout << "type = " << (int) dtype << endl;
200 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for SphereHEALpix");
201 }
202}
203
204AnyDataObj* FITS_AutoReader::newLocalMap() const
205{
206 FitsFile::FitsDataType dtype;
207 if (inFits_->IsFitsTable()) dtype = inFits_->ColTypeFromFits(0);
208 else
209 {
210 cout << " WARNING : Localmap not binary table : unusual " << endl;
211 dtype = inFits_->ImageType();
212 }
213 switch (dtype)
214 {
215 case FitsFile::FitsDataType_double :
216 {
217 LocalMap<r_8>* locmptr = new LocalMap<r_8>;
218 FITS_LocalMap<r_8> fta(locmptr);
219 fta.Read(*inFits_, inFits_->currentHeaderIndex());
220 return locmptr;
221 }
222 case FitsFile::FitsDataType_float :
223 {
224 LocalMap<r_4>* locmptr = new LocalMap<r_4>;
225 FITS_LocalMap<r_4> fta(locmptr);
226 fta.Read(*inFits_, inFits_->currentHeaderIndex());
227 return locmptr;
228 }
229 case FitsFile::FitsDataType_int :
230 {
231 LocalMap<int_4>* locmptr = new LocalMap<int_4>;
232 FITS_LocalMap<int_4> fta(locmptr);
233 fta.Read(*inFits_, inFits_->currentHeaderIndex());
234 return locmptr;
235 }
236 default :
237 cout << "type = " << (int) dtype << endl;
238 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for LocalMap");
239 }
240}
241NTuple* FITS_AutoReader::newNTuple() const
242{
243 NTuple* ntptr = new NTuple;
244 FITS_NTuple fta(ntptr);
245 fta.Read(*inFits_, inFits_->currentHeaderIndex());
246 return ntptr;
247}
248XNTuple* FITS_AutoReader::newXNTuple() const
249{
250 XNTuple* xntptr = new XNTuple;
251 FITS_XNTuple fta(xntptr);
252 fta.Read(*inFits_, inFits_->currentHeaderIndex());
253 return xntptr;
254}
255
256FitsBTNtuIntf* FITS_AutoReader::newFitsBTNtuIntf(int hdunum) const
257{
258 FitsBTNtuIntf* btnptr = new FitsBTNtuIntf(filename_,hdunum);
259 return btnptr;
260}
261
Note: See TracBrowser for help on using the repository browser.