Ignore:
Timestamp:
Aug 12, 2006, 7:30:20 PM (19 years ago)
Author:
cmv
Message:

Histo,HProf,HistoErr,Histo2D ecriture fits cmv 12/8/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitshistos.cc

    r3049 r3054  
    1111#include "histerr.h"
    1212#include "histos2.h"
     13
    1314#include "fitsblkrw.h"
    1415#include "fitshandler.h"
     
    6566  }
    6667  // Le nombre d'entrees dans le bin
    67   if(he!=NULL) {
     68  if(he!=NULL || hp!=NULL) {
    6869    if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
    6970    colnames.push_back("nb");
     
    7879  int n = h->NBins();
    7980  if(n>0) {
     81    if(hp) hp->UpdateHisto();
    8082    FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h->mData,n);
    8183    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);
    8285    if(he!=NULL) FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,he->mNData,n);
    8386  }
     
    128131    mtv = ok;
    129132    os.WriteKey("UPDOK",mtv," update status flag");
     133
     134    mtv = (int_4)hp->Opt;
     135    os.WriteKey("SIGOPT",mtv," sigma statistic flag");
    130136
    131137    mtv = hp->YMin;
     
    165171  //--- Lecture entete FITS
    166172  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);
    174174
    175175  int_4 nbin = dvl.GetI("NBIN",-1);
     
    180180  r_8 xmax = dvl.GetD("XMAX",+1.);
    181181
    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;
    200187  }
    201188
     
    204191  HProf*    hp = dynamic_cast< HProf *> (dobj);
    205192  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  }
    206212
    207213  //--- remplissage des variables d'entete
     
    213219  if(hp) {
    214220    int_4 ok = dvl.GetI("UPDOK",0); hp->Ok = (ok)? true : false;
     221    hp->Opt = (uint_2)dvl.GetI("SIGOPT",0);
    215222    hp->YMin = dvl.GetD("YMIN",1.);
    216223    hp->YMax = dvl.GetD("YMAX",-1.);
     
    222229  FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,h->mData,nbin);
    223230  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);
    224232  if(he) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,he->mNData,nbin);
    225233
     
    234242int FitsHandler<Histo2D>::CheckReadability(FitsInOutFile& is)
    235243{
    236   if (is.CurrentHDUType() != IMAGE_HDU ) return 0;
     244  if (is.CurrentHDUType() == IMAGE_HDU ) return 0;
    237245  string key = "SOPCLSNM";
    238246  string clsnm = is.KeyValue(key);
    239   if( clsnm == "SOPHYA::Histo2D" ) return 2;
     247  if( clsnm == "SOPHYA::Histo2D") return 2;
    240248  return 0;
    241249}
     
    340348
    341349  //--- 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;
    345351  is.GetColInfo(colnames,coltypes,repcnt,width);
    346352  long ncol = colnames.size();
     
    352358
    353359  //--- 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);
    360361
    361362  int_4 nbinx = dvl.GetI("NBINX",-1);
     
    371372
    372373  //--- 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();
    384378
    385379  //--- 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);
    388382
    389383  for(int i=0;i<3;i++) for(int j=0;j<3;j++) {
    390384    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.);
    392386  }
    393387
    394388  //--- 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.