Changeset 2608 in Sophya for trunk/SophyaLib/HiStats/histerr.cc


Ignore:
Timestamp:
Sep 7, 2004, 12:50:35 PM (21 years ago)
Author:
cmv
Message:

correct. erreur persistance HistoErr, methode ReCenterBin cmv (sur les conseils de rz) 7/9/04

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/HiStats/histerr.cc

    r2604 r2608  
    2323/*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
    2424HistoErr::HistoErr(r_8 xMin, r_8 xMax, int_4 nBin)
    25 : Histo(xMin,xMax,nBin), mNData((nBin>0) ? new uint_4[nBin] : NULL)
     25: Histo(xMin,xMax,nBin), mNData(NULL)
    2626{
    2727 this->Errors();
    28  if(mNData) memset(mNData,0,mBins*sizeof(uint_4));
     28 allocate_mNData(nBin);
     29 Zero();
    2930}
    3031
     
    3233/*! Constructeur par copie */
    3334HistoErr::HistoErr(const HistoErr& H)
    34 : Histo(H), mNData((H.mBins>0)? new uint_4[H.mBins] : NULL)
    35 {
     35: Histo(H), mNData(NULL)
     36{
     37 allocate_mNData(H.mBins);
    3638 if(mBins>0) memcpy(mNData,H.mNData,mBins*sizeof(uint_4));
    3739}
     
    4244{
    4345 if(mNData) {delete [] mNData; mNData=NULL;}
     46}
     47/********* Methode *********/
     48/*! Allocation du tableau mNData */
     49void HistoErr::allocate_mNData(int nbin)
     50{
     51 if(nbin<=0) return;
     52 if(mNData) {delete [] mNData; mNData=NULL;}
     53 mNData = new uint_4[nbin];
    4454}
    4555
     
    126136}
    127137
     138/********* Methode *********/
     139/*!
     140 Recompute XMin and XMax so that
     141 the center of the first bin is exactly xcmin and
     142 the center of the last bin is exactly xcmax
     143*/
     144void HistoErr::ReCenterBin(r_8 xcmin,r_8 xcmax)
     145{
     146 if(xcmax<=xcmin) return;
     147 if(mBins<=1) return;
     148 double dx = (mMax-mMin)/(mBins-1);
     149  mMin -= dx/2.;
     150  mMax += dx/2.;
     151  binWidth = (mMax-mMin)/mBins;
     152}
    128153
    129154/********* Methode *********/
     
    155180void ObjFileIO<HistoErr>::ReadSelf(PInPersist& is)
    156181{
    157 char strg[256];
     182string strg;
    158183
    159184if(dobj==NULL) dobj=new HistoErr;
     
    161186
    162187// Lecture entete
    163 is.GetLine(strg, 255);
     188is.GetStr(strg);
    164189
    165190// Lecture des donnees HistoErr
    166191is.Get(dobj->mBins);
    167 is.GetLine(strg, 255);
     192  dobj->allocate_mNData(dobj->mBins);
    168193is.Get(dobj->mNData, dobj->mBins);
    169194
     
    178203{
    179204if(dobj == NULL)   return;
    180 char strg[256];
    181 
    182 sprintf(strg,"HistErr");
    183 os.PutLine(strg);
     205string strg;
     206
     207strg = "HistErr";
     208os.PutStr(strg);
    184209
    185210// Ecriture des valeurs
     
    187212
    188213// Ecriture des donnees HistoErr nombre d entree par bin
    189 sprintf(strg,"Tableau du nombre d entree par bin");
    190 os.PutLine(strg);
    191214os.Put(dobj->mNData, dobj->mBins);
    192215
Note: See TracChangeset for help on using the changeset viewer.