Changeset 3054 in Sophya for trunk/SophyaExt/FitsIOServer/fitshistos.cc
- Timestamp:
- Aug 12, 2006, 7:30:20 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitshistos.cc
r3049 r3054 11 11 #include "histerr.h" 12 12 #include "histos2.h" 13 13 14 #include "fitsblkrw.h" 14 15 #include "fitshandler.h" … … 65 66 } 66 67 // Le nombre d'entrees dans le bin 67 if(he!=NULL ) {68 if(he!=NULL || hp!=NULL) { 68 69 if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); 69 70 colnames.push_back("nb"); … … 78 79 int n = h->NBins(); 79 80 if(n>0) { 81 if(hp) hp->UpdateHisto(); 80 82 FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h->mData,n); 81 83 if(h->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h->mErr2,n); 84 if(hp!=NULL) FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,hp->mSumW,n); 82 85 if(he!=NULL) FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,he->mNData,n); 83 86 } … … 128 131 mtv = ok; 129 132 os.WriteKey("UPDOK",mtv," update status flag"); 133 134 mtv = (int_4)hp->Opt; 135 os.WriteKey("SIGOPT",mtv," sigma statistic flag"); 130 136 131 137 mtv = hp->YMin; … … 165 171 //--- Lecture entete FITS 166 172 string key = "SOPCLSNM"; string clsnm = is.KeyValue(key); 167 if( (clsnm != "SOPHYA::Histo") 168 && (clsnm != "SOPHYA::HProf") 169 && (clsnm != "SOPHYA::HistoErr") ) 170 throw FitsIOException("FitsHandler<Histo>::Read() bad value for key SOPCLSNM"); 171 172 DVList dvl; 173 is.GetHeaderRecords(dvl,true,false); 173 DVList dvl; is.GetHeaderRecords(dvl,true,false); 174 174 175 175 int_4 nbin = dvl.GetI("NBIN",-1); … … 180 180 r_8 xmax = dvl.GetD("XMAX",+1.); 181 181 182 //--- Creation de l'objet 183 if (dobj != NULL) delete dobj; // destruction si existe 184 if( clsnm == "SOPHYA::Histo" ) { 185 dobj = new Histo(xmin,xmax,nbin); 186 int_4 haserr2 = dvl.GetI("HASERR2",0); 187 if(ncol>1 && haserr2>0) dobj->Errors(); 188 } else if( clsnm == "SOPHYA::HProf" ) { 189 if(ncol<2) 190 throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HProf"); 191 r_8 ymin = dvl.GetD("YMIN",1.); 192 r_8 ymax = dvl.GetD("YMAX",-1.); 193 dobj = new HProf(xmin,xmax,nbin,ymin,ymax); 194 } else if( clsnm == "SOPHYA::HistoErr" ) { 195 if(ncol<3) 196 throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HistoErr"); 197 dobj = new HistoErr(xmin,xmax,nbin); 198 } else { 199 throw FitsIOException("FitsHandler<Histo>::Read() Not a Histo or HProf or HistoErr"); 182 //--- Creation de l'objet si necessaire 183 if(dobj == NULL) { 184 if(clsnm == "SOPHYA::Histo") dobj = new Histo; 185 else if(clsnm == "SOPHYA::HProf") dobj = new HProf; 186 else if(clsnm == "SOPHYA::HistoErr") dobj = new HistoErr; 200 187 } 201 188 … … 204 191 HProf* hp = dynamic_cast< HProf *> (dobj); 205 192 HistoErr* he = dynamic_cast< HistoErr *> (dobj); 193 194 //--- Allocation pour histo 195 if(he && (clsnm=="SOPHYA::HistoErr")) { 196 if(ncol<3) 197 throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HistoErr"); 198 he->CreateOrResize(xmin,xmax,nbin); 199 } else if(hp&& (clsnm=="SOPHYA::HProf")) { 200 if(ncol<3) 201 throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HProf"); 202 r_8 ymin = dvl.GetD("YMIN",1.); 203 r_8 ymax = dvl.GetD("YMAX",-1.); 204 hp->CreateOrResize(xmin,xmax,nbin,ymin,ymax); 205 } else if(h && clsnm == "SOPHYA::Histo" ) { 206 h->CreateOrResize(xmin,xmax,nbin); 207 int_4 haserr2 = dvl.GetI("HASERR2",0); 208 if(ncol>1 && haserr2>0) h->Errors(); 209 } else { 210 throw FitsIOException("FitsHandler<Histo>::Read() No assocaition classe/fits_header"); 211 } 206 212 207 213 //--- remplissage des variables d'entete … … 213 219 if(hp) { 214 220 int_4 ok = dvl.GetI("UPDOK",0); hp->Ok = (ok)? true : false; 221 hp->Opt = (uint_2)dvl.GetI("SIGOPT",0); 215 222 hp->YMin = dvl.GetD("YMIN",1.); 216 223 hp->YMax = dvl.GetD("YMAX",-1.); … … 222 229 FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,h->mData,nbin); 223 230 if(h->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,h->mErr2,nbin); 231 if(hp) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,hp->mSumW,nbin); 224 232 if(he) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,he->mNData,nbin); 225 233 … … 234 242 int FitsHandler<Histo2D>::CheckReadability(FitsInOutFile& is) 235 243 { 236 if (is.CurrentHDUType() != IMAGE_HDU ) return 0;244 if (is.CurrentHDUType() == IMAGE_HDU ) return 0; 237 245 string key = "SOPCLSNM"; 238 246 string clsnm = is.KeyValue(key); 239 if( clsnm == "SOPHYA::Histo2D" 247 if( clsnm == "SOPHYA::Histo2D") return 2; 240 248 return 0; 241 249 } … … 340 348 341 349 //--- Nb de lignes et de colonnes 342 vector<string> colnames; 343 vector<int> coltypes; 344 vector<long> repcnt, width; 350 vector<string> colnames; vector<int> coltypes; vector<long> repcnt, width; 345 351 is.GetColInfo(colnames,coltypes,repcnt,width); 346 352 long ncol = colnames.size(); … … 352 358 353 359 //--- Lecture entete FITS 354 string key = "SOPCLSNM"; string clsnm = is.KeyValue(key); 355 if( clsnm != "SOPHYA::Histo2D" ) 356 throw FitsIOException("FitsHandler<Histo2D>::Read() bad value for key SOPCLSNM"); 357 358 DVList dvl; 359 is.GetHeaderRecords(dvl,true,false); 360 DVList dvl; is.GetHeaderRecords(dvl,true,false); 360 361 361 362 int_4 nbinx = dvl.GetI("NBINX",-1); … … 371 372 372 373 //--- Creation de l'objet 373 if (dobj != NULL) delete dobj; // destruction si existe 374 if( clsnm == "SOPHYA::Histo2D" ) { 375 dobj = new Histo2D(xmin,xmax,nbinx,ymin,ymax,nbiny); 376 int_4 haserr2 = dvl.GetI("HASERR2",0); 377 if(ncol>1 && haserr2>0) dobj->Errors(); 378 } else { 379 throw FitsIOException("FitsHandler<Histo2D>::Read() Not a Histo2D"); 380 } 381 382 //--- Type de l'histo 383 Histo2D* h = dynamic_cast< Histo2D *> (dobj); 374 if(dobj == NULL) dobj = new Histo2D; 375 dobj->CreateOrResize(xmin,xmax,nbinx,ymin,ymax,nbiny); 376 int_4 haserr2 = dvl.GetI("HASERR2",0); 377 if(ncol>1 && haserr2>0) dobj->Errors(); 384 378 385 379 //--- remplissage des variables d'entete 386 h->nHist = dvl.GetD("NHIST",0.);387 h->nEntries = dvl.GetI("NENTRIES",0);380 dobj->nHist = dvl.GetD("NHIST",0.); 381 dobj->nEntries = dvl.GetI("NENTRIES",0); 388 382 389 383 for(int i=0;i<3;i++) for(int j=0;j<3;j++) { 390 384 char str[16]; sprintf(str,"OUT%1d%1d",i,j); 391 h->mOver[i][j] = dvl.GetD(str,0.);385 dobj->mOver[i][j] = dvl.GetD(str,0.); 392 386 } 393 387 394 388 //--- remplissage de l'histo 395 FitsBlockRW<r_8>::ReadColumnData(is,1,1,1, h->mData,nbinxy);396 if( h->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,h->mErr2,nbinxy);397 398 } 389 FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,dobj->mData,nbinxy); 390 if(dobj->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,dobj->mErr2,nbinxy); 391 392 }
Note:
See TracChangeset
for help on using the changeset viewer.