[1301] | 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 |
|
---|
[1371] | 10 | /*!
|
---|
| 11 | \class SOPHYA::FITS_AutoReader
|
---|
| 12 | \ingroup FitsIOServer
|
---|
| 13 | FITS reader with automatic mapping on SOPHYA objects.
|
---|
| 14 | */
|
---|
| 15 |
|
---|
[1301] | 16 | FITS_AutoReader::FITS_AutoReader() {InitNull();};
|
---|
| 17 | FITS_AutoReader::FITS_AutoReader(const char inputfile[])
|
---|
| 18 | {
|
---|
| 19 | InitNull();
|
---|
| 20 | inFits_ = new FitsInFile (inputfile);
|
---|
[2130] | 21 | filename_ = string(inputfile);
|
---|
[1301] | 22 | }
|
---|
| 23 | FITS_AutoReader::FITS_AutoReader(string const & inputfile)
|
---|
| 24 | {
|
---|
| 25 | InitNull();
|
---|
| 26 | inFits_ = new FitsInFile (inputfile);
|
---|
[2130] | 27 | filename_ = inputfile;
|
---|
[1301] | 28 | }
|
---|
| 29 | FITS_AutoReader::~FITS_AutoReader()
|
---|
| 30 | {
|
---|
| 31 | if (inFits_ != NULL) delete inFits_;
|
---|
| 32 | if (dobj_ != NULL) delete dobj_;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[1334] | 35 | int FITS_AutoReader::NbBlocks()
|
---|
| 36 | {
|
---|
| 37 | return inFits_->NbBlocks();
|
---|
| 38 | }
|
---|
[1301] | 39 |
|
---|
[2130] | 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)
|
---|
| 48 | AnyDataObj* FITS_AutoReader::ReadObject(int hdunum, bool toutCharger) const
|
---|
[1301] | 49 | {
|
---|
[1334] | 50 | if (hdunum<=0)
|
---|
| 51 | {
|
---|
| 52 | throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive");
|
---|
| 53 | }
|
---|
[1301] | 54 | inFits_->ReadHeader(hdunum);
|
---|
[1334] | 55 | if (inFits_->IsFitsEOF()) return NULL;
|
---|
| 56 | if (inFits_->IsFitsERROR())
|
---|
| 57 | {
|
---|
| 58 | throw IOExc("FITS_AutoReader::ReadObject: FITSIO error in reading");
|
---|
| 59 | }
|
---|
[1301] | 60 | DVList dvl=inFits_->DVListFromFits();
|
---|
| 61 | string nameObj = dvl.GetS("CONTENT");
|
---|
[1334] | 62 | // cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
|
---|
[1301] | 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
|
---|
[2130] | 92 | // une spherehealpix
|
---|
[1301] | 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();
|
---|
[2130] | 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 | }
|
---|
[1301] | 124 | }
|
---|
| 125 | }
|
---|
| 126 | else
|
---|
| 127 | {
|
---|
[1334] | 128 | cout << " WARNING ( FITS_AutoReader::ReadObject) : object not recognized as a SOPHYA object" << endl;
|
---|
| 129 | return new DVList(dvl);
|
---|
[1301] | 130 | }
|
---|
| 131 |
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | AnyDataObj* 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 :
|
---|
[1351] | 161 | cout << "type = " << (int) dtype << endl;
|
---|
[1301] | 162 | throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for TArray");
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | AnyDataObj* 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 | }
|
---|
[2163] | 191 | //CMV: Bon c'est quand meme sympa de pouvoir re-lire ce
|
---|
| 192 | // qu'on a ecrit !! Je fais cette modif mais a priori
|
---|
| 193 | // ce n'est que du sparadra car ca devrait planter
|
---|
| 194 | // sur certaines machines (int!=long).
|
---|
[1301] | 195 | case FitsFile::FitsDataType_int :
|
---|
[2163] | 196 | case FitsFile::FitsDataType_long :
|
---|
[1301] | 197 | {
|
---|
| 198 | SphereHEALPix<int_4>* sphptr = new SphereHEALPix<int_4>;
|
---|
| 199 | FITS_SphereHEALPix<int_4> fta(sphptr);
|
---|
| 200 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 201 | return sphptr;
|
---|
| 202 | }
|
---|
| 203 | default :
|
---|
[1351] | 204 | cout << "type = " << (int) dtype << endl;
|
---|
[1301] | 205 | throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for SphereHEALpix");
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | AnyDataObj* FITS_AutoReader::newLocalMap() const
|
---|
| 210 | {
|
---|
| 211 | FitsFile::FitsDataType dtype;
|
---|
| 212 | if (inFits_->IsFitsTable()) dtype = inFits_->ColTypeFromFits(0);
|
---|
| 213 | else
|
---|
| 214 | {
|
---|
| 215 | cout << " WARNING : Localmap not binary table : unusual " << endl;
|
---|
| 216 | dtype = inFits_->ImageType();
|
---|
| 217 | }
|
---|
| 218 | switch (dtype)
|
---|
| 219 | {
|
---|
| 220 | case FitsFile::FitsDataType_double :
|
---|
| 221 | {
|
---|
| 222 | LocalMap<r_8>* locmptr = new LocalMap<r_8>;
|
---|
| 223 | FITS_LocalMap<r_8> fta(locmptr);
|
---|
| 224 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 225 | return locmptr;
|
---|
| 226 | }
|
---|
| 227 | case FitsFile::FitsDataType_float :
|
---|
| 228 | {
|
---|
| 229 | LocalMap<r_4>* locmptr = new LocalMap<r_4>;
|
---|
| 230 | FITS_LocalMap<r_4> fta(locmptr);
|
---|
| 231 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 232 | return locmptr;
|
---|
| 233 | }
|
---|
| 234 | case FitsFile::FitsDataType_int :
|
---|
| 235 | {
|
---|
| 236 | LocalMap<int_4>* locmptr = new LocalMap<int_4>;
|
---|
| 237 | FITS_LocalMap<int_4> fta(locmptr);
|
---|
| 238 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 239 | return locmptr;
|
---|
| 240 | }
|
---|
| 241 | default :
|
---|
[1351] | 242 | cout << "type = " << (int) dtype << endl;
|
---|
[1301] | 243 | throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for LocalMap");
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | NTuple* FITS_AutoReader::newNTuple() const
|
---|
| 247 | {
|
---|
| 248 | NTuple* ntptr = new NTuple;
|
---|
| 249 | FITS_NTuple fta(ntptr);
|
---|
| 250 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 251 | return ntptr;
|
---|
| 252 | }
|
---|
| 253 | XNTuple* FITS_AutoReader::newXNTuple() const
|
---|
| 254 | {
|
---|
| 255 | XNTuple* xntptr = new XNTuple;
|
---|
| 256 | FITS_XNTuple fta(xntptr);
|
---|
| 257 | fta.Read(*inFits_, inFits_->currentHeaderIndex());
|
---|
| 258 | return xntptr;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[2130] | 261 | FitsBTNtuIntf* FITS_AutoReader::newFitsBTNtuIntf(int hdunum) const
|
---|
| 262 | {
|
---|
| 263 | FitsBTNtuIntf* btnptr = new FitsBTNtuIntf(filename_,hdunum);
|
---|
| 264 | return btnptr;
|
---|
| 265 | }
|
---|
| 266 |
|
---|