Changeset 3125 in Sophya for trunk/SophyaPI/PIext/pihisto.cc


Ignore:
Timestamp:
Jan 11, 2007, 7:02:52 PM (19 years ago)
Author:
ansari
Message:

1/ Introduction d'une classe P1DHistoWrapper (fichier phistwrapper.h) pour rendre PIHisto independant de SOPHYA et des objets Histo, HistErr, HProf ...
2/ Ecriture du wrapper/adaptateur pour SOPHYA::Histo,HProf,HistErr
3/ mise en conformite des ObjAdapter piapp pour Histo,HistErr, chgt numero de version

Reza 11/01/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pihisto.cc

    r3055 r3125  
    11// Classe traceur d histogramme                 96-99
    2 // CEA-DAPNIA      LAL-IN2P3/CNRS
     2//  C. Magneville , R. Ansari               2000-2007
     3// (C)  CEA-DAPNIA          LAL-IN2P3/CNRS
    34
    45#include <stdio.h>
     
    89#include <typeinfo>
    910
    10 #include "sopnamsp.h"
     11//RZDEL #include "sopnamsp.h"
    1112#include "pihisto.h"
    12 #include "hisprof.h"
    1313
    1414//++
     
    1717// include      pihisto.h
    1818//
    19 //      Classe traceur d'objet histogramme (classe *Histo*)
     19//      Classe traceur d'objet histogramme (classe *P1DHistoWrapper*)
    2020//--
    2121//++
     
    2727//--
    2828//++
    29 // PIHisto(Histo* histo, bool ad=false)
     29// PIHisto(P1DHistoWrapper* histo, bool ad=false)
    3030//      Constructeur. Si "ad == true", l'objet "histo" est détruit par
    3131//      le destructeur de l'objet "PIHisto"
     
    3737
    3838
    39 PIHisto::PIHisto(Histo* histo, bool ad)
     39PIHisto::PIHisto(P1DHistoWrapper* histo, bool ad)
    4040: PIDrawer(), mHisto(histo)
    4141{
     
    5757{
    5858  if (!mHisto)  return;
    59   float hmin = mHisto->VMin();
    60   float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin());
    61   // si HBProf min,max calcules en tenant compte des erreurs
    62   if( typeid(*mHisto) == typeid(HProf) ) {
    63     float v1,v2;
    64     for (int i=1; i<mHisto->NBins(); i++) {
    65       v1 = (*mHisto)(i) - mHisto->Error(i);
    66       v2 = (*mHisto)(i) + mHisto->Error(i);
    67       if(v1<hmin) hmin = v1;
    68       if(v2>hmax) hmax = v2;
    69     }
    70     v1 = 0.1*(hmax-hmin);
    71     hmin -= v1;   hmax += v1;
    72   }
     59  double v1,v2,hmin,hmax;
     60  hmin = 9.e39;
     61  hmax = -9.e39;
     62  for (int i=1; i<mHisto->NBins(); i++) {
     63    v1 = (*mHisto)(i); //DEL  - mHisto->Error(i);
     64    v2 = (*mHisto)(i); //DEL  + mHisto->Error(i);
     65    if(v1<hmin) hmin = v1;
     66    if(v2>hmax) hmax = v2;
     67  }
     68  // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log
     69  v1 = 0.1*(hmax-hmin);
     70  hmin -= v1;   hmax += v1;
     71
    7372  if(hmax<=hmin) hmax = hmin+1.;
    7473  SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
     
    8382  if (mHisto->NBins()<=0) return;
    8483 
    85   if( typeid(*mHisto)==typeid(HProf) ) mHisto->UpdateHisto();
     84  mHisto->Update();
    8685
    8786  bool oktrace=false;
     
    9190  // Tracer des marqueurs si demande ou si HProf
    9291  bool drawmarker=false;
    93   if( (GetGraphicAtt().GetMarker() != PI_NotDefMarker) || 
    94       (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;
     92  if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true;
     93//RZDEL   ||  (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;
    9594  // Tracer des erreurs ?
    9695  bool drawerr=false;
    9796  if(error==0) {  // Gestion automatique des erreurs
    98     // Tracer les erreurs si HProf
    99     if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;
     97    //RZDEL Tracer les erreurs si HProf
     98//RZDEL    if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;
    10099    // Trace les erreurs si marqueurs demandes
    101100    if(drawmarker) drawerr=true;
     
    263262  PIGrCoord a, d;
    264263  double cH = (double)g->GetFontHeight(a,d);
    265   double cellHeight = 3.6 * cH;
    266 
    267   // Les labels et leurs longueurs -> largeur de la cellule
    268   char *label, label1[64], label2[64], label3[64];
    269   sprintf(label1, "N= %-g",mHisto->NData());
    270   sprintf(label2, "m= %-g",mHisto->Mean());
    271   sprintf(label3, "s= %-g",mHisto->Sigma());
    272   label = label1;
    273   if(strlen(label)<strlen(label2)) label = label2;
    274   if(strlen(label)<strlen(label3)) label = label3;
    275   double cellWidth =  1.1 * (double)g->CalcStringWidth(label);
     264  vector<string> lines;
     265  int nlig = mHisto->GetStatInfoAsText(lines);
     266  if (nlig < 1) return;
     267
     268  double cellHeight = (nlig+0.6) * cH;
     269
     270  int idxll = 0;
     271 
     272  int kl;
     273  // on recherche la ligne la plus longue
     274  for(kl=1; kl<nlig; kl++)
     275    if ( lines[kl].length() > lines[idxll].length() )  idxll = kl;
     276
     277  double cellWidth =  1.1 * (double)g->CalcStringWidth(lines[idxll].c_str());
    276278
    277279  double ofpx = spoX*(XMax()-XMin());
     
    294296  yu = g->DeltaUCY(YMax(),cw);
    295297  xu += ofpx;  yu += ofpy;
    296   g->DrawString(xu, yu,label1);
    297   cw +=  -1.15*cH;
    298   yu = g->DeltaUCY(YMax(),cw);  yu += ofpy;
    299   g->DrawString(xu, yu,label2);
    300   cw +=  -1.15*cH;
    301   yu = g->DeltaUCY(YMax(),cw);  yu += ofpy;
    302   g->DrawString(xu, yu,label3);
     298
     299  for(kl=0; kl<nlig; kl++) {
     300    g->DrawString(xu, yu, lines[kl].c_str() );
     301    cw +=  -1.15*cH;
     302    yu = g->DeltaUCY(YMax(),cw);  yu += ofpy;
     303  }
    303304                       
    304305}
Note: See TracChangeset for help on using the changeset viewer.