Changeset 1073 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Jul 16, 2000, 1:31:22 AM (25 years ago)
Author:
ercodmgr
Message:

h/oper,h/cadd,h/cmult sur matrice et vecteur

correction bug dans cas ou objet recevant non-existant dans h/oper h/get_vec h/copy

cmv 16/7/0

File:
1 edited

Legend:

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

    r1071 r1073  
    7575
    7676kw = "h/cadd";
    77 usage = "Add a constant to an histogram";
     77usage = "Add a constant to an histogram, a vector or a matrix";
    7878usage += "\n h/cadd namehisto val";
    7979usage += "\n  Related commands: h/cmult h/oper"; 
     
    8181
    8282kw = "h/cmult";
    83 usage = "Multiply an histogram by a constant";
     83usage = "Multiply an histogram, a vector or a matrix by a constant";
    8484usage += "\n h/cmult namehisto val";
    8585usage += "\n  Related commands: h/cadd h/oper"; 
     
    8787
    8888kw = "h/oper";
    89 usage = "Operation on histograms";
     89usage = "Operation on histograms vectors or matrices";
    9090usage += "\n h/oper @ h1 h2 hres";
    9191usage += "\n        hres = h1 @ h2   with @ = (+,-,*,/)";
     92usage += "\n For vectors and matrices, operations are elements by elements";
    9293usage += "\n  Related commands: h/cadd h/cmult"; 
    9394piac->RegisterCommand(kw,usage,this,hgrp);
     
    134135
    135136kw = "h/copy";
    136 usage = "Copy content of object1 into objecft2";
     137usage = "Copy content of object1 into object2";
    137138usage += "\n objects are Vector,Matrix,Histo,Histo2D";
    138139usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
     
    378379//HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
    379380if(!h1)
    380   {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo"<<endl;
     381  {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
    381382  return;}
    382383h1->HRebin(nbin);
     
    398399HProf*   hp = dynamic_cast<HProf*>(mobj);
    399400Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
     401Vector*  v  = dynamic_cast<Vector*>(mobj);
     402Matrix*  m  = dynamic_cast<Matrix*>(mobj);
    400403if(h1 && !hp) *h1 += val;
    401404else if(h2)   *h2 += val;
    402 else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/Histo2D"<<endl;
     405else if(v)    *v  += val;
     406else if(m)    *m  += val;
     407else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
    403408}
    404409
     
    418423HProf*   hp = dynamic_cast<HProf*>(mobj);
    419424Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
     425Vector*  v  = dynamic_cast<Vector*>(mobj);
     426Matrix*  m  = dynamic_cast<Matrix*>(mobj);
    420427if(h1 && !hp) *h1 *= val;
    421428else if(h2)   *h2 *= val;
    422 else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
    423          <<" not an Histo/Histo2D"<<endl;
     429else if(v)    *v  += val;
     430else if(m)    *m  += val;
     431else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
    424432}
    425433
     
    427435void PAWExecutor::h_oper(vector<string>& tokens)
    428436// Equivalent h/oper/add sub,mul,div de paw
    429 // Operation entre 2 histogrammes
     437// Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
    430438// h/oper @ h1 h2 hres
    431439// hres = h1 @ h2    with @ = (+,-,*,/)
     440// Pour les vecteurs et les matrices, il sagit d'operations elements a elements
    432441{
    433442if(tokens.size()<4)
    434   {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
     443  {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
    435444   return;}
    436445
     
    468477         <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
    469478  HProf* h3 = NULL;
    470   if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
    471     h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
    472   } else {                // l'objet existe
    473     h3 = dynamic_cast<HProf*>(mobjh3);
    474     if(h3 == NULL)  // ce n'est pas un HProf
    475       {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
    476            <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
    477       return;}
    478     if(h1->NBins() != h3->NBins())
    479       {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
    480            <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
    481     *h3 = *h1 + *h2;
    482     h3->UpdateHisto();
    483   }
     479  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
     480    {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
     481  h3 = dynamic_cast<HProf*>(mobjh3);
     482  if(h3 == NULL)  // ce n'est pas un HProf
     483    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
     484         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
     485  if(h1->NBins() != h3->NBins())
     486    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     487         <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
     488  *h3 = *h1 + *h2;
     489  h3->UpdateHisto();
    484490
    485491// Operations on Histo
     
    495501         <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
    496502  Histo* h3 = NULL;
    497   if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
    498     h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
    499   } else {                // l'objet existe
    500     h3 = dynamic_cast<Histo*>(mobjh3);
    501     if(h3 == NULL)  // ce n'est pas un Histo
    502       {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
    503            <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
    504       return;}
    505     if(h1->NBins() != h3->NBins())
    506       {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
    507            <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
    508     if( oper[0]=='+')      *h3 = *h1 + *h2;
    509     else if( oper[0]=='-') *h3 = *h1 - *h2;
    510     else if( oper[0]=='*') *h3 = *h1 * *h2;
    511     else if( oper[0]=='/') *h3 = *h1 / *h2;
    512   }
     503  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
     504    {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
     505  h3 = dynamic_cast<Histo*>(mobjh3);
     506  if(h3 == NULL)  // ce n'est pas un Histo
     507    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
     508         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
     509  if(h1->NBins() != h3->NBins())
     510    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     511         <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
     512  if( oper[0]=='+')      *h3 = *h1 + *h2;
     513  else if( oper[0]=='-') *h3 = *h1 - *h2;
     514  else if( oper[0]=='*') *h3 = *h1 * *h2;
     515  else if( oper[0]=='/') *h3 = *h1 / *h2;
    513516
    514517// Operations on Histo2D
     
    525528         <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
    526529  Histo2D* h3 = NULL;
     530  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
     531    {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
     532  h3 = dynamic_cast<Histo2D*>(mobjh3);
     533  if(h3 == NULL)  // ce n'est pas un Histo2D
     534    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
     535         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
     536  if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
     537    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     538         <<h1->NBinX()<<","<<h1->NBinY()<<"   "
     539         <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
     540  if( oper[0]=='+')      *h3 = *h1 + *h2;
     541  else if( oper[0]=='-') *h3 = *h1 - *h2;
     542  else if( oper[0]=='*') *h3 = *h1 * *h2;
     543  else if( oper[0]=='/') *h3 = *h1 / *h2;
     544
     545// Operations on Vector
     546} else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
     547  if( dynamic_cast<Vector*>(mobjh2) == NULL )
     548    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
     549         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
     550    return;}
     551  Vector* h1 =(Vector*) mobjh1;
     552  Vector* h2 =(Vector*) mobjh2;
     553  if( h1->NElts() != h2->NElts() )
     554    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
     555         <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
     556  Vector* h3 = NULL;
    527557  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
    528     h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
    529   } else {                // l'objet existe
    530     h3 = dynamic_cast<Histo2D*>(mobjh3);
    531     if(h3 == NULL)  // ce n'est pas un Histo2D
    532       {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
    533            <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
    534       return;}
    535     if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
    536       {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
    537            <<h1->NBinX()<<","<<h1->NBinY()<<"   "
    538            <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
    539     if( oper[0]=='+')      *h3 = *h1 + *h2;
    540     else if( oper[0]=='-') *h3 = *h1 - *h2;
    541     else if( oper[0]=='*') *h3 = *h1 * *h2;
    542     else if( oper[0]=='/') *h3 = *h1 / *h2;
     558#ifdef SANS_EVOLPLANCK
     559    h3 = new Vector(*h1);
     560#else
     561    h3 = new Vector(*h1,false);
     562#endif
     563    *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
    543564  }
     565  h3 = dynamic_cast<Vector*>(mobjh3);
     566  if(h3 == NULL)  // ce n'est pas un Vector
     567    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
     568         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
     569  if(h1->NElts() != h3->NElts())
     570    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     571         <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
     572  if( oper[0]=='+')      *h3 = *h1 + *h2;
     573  else if( oper[0]=='-') *h3 = *h1 - *h2;
     574#ifdef SANS_EVOLPLANCK
     575  else if(oper[0]=='*' || oper[0]=='/')
     576    cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
     577        <<" not implemented for Vector in Peida"<<endl;
     578#else
     579  else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
     580  else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
     581#endif
     582
     583// Operations on Matrix
     584} else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
     585  if( dynamic_cast<Matrix*>(mobjh2) == NULL )
     586    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
     587         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
     588    return;}
     589  Matrix* h1 =(Matrix*) mobjh1;
     590  Matrix* h2 =(Matrix*) mobjh2;
     591  if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
     592    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
     593         <<h1->NRows()<<","<<h1->NCol()<<"   "
     594         <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
     595  Matrix* h3 = NULL;
     596  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
     597#ifdef SANS_EVOLPLANCK
     598    h3 = new Matrix(*h1);
     599#else
     600    h3 = new Matrix(*h1,false);
     601#endif
     602    *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
     603  }
     604  h3 = dynamic_cast<Matrix*>(mobjh3);
     605  if(h3 == NULL)  // ce n'est pas un Matrix
     606    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
     607         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
     608  if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
     609    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     610         <<h1->NRows()<<","<<h1->NCol()<<"   "
     611         <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
     612  if( oper[0]=='+')      *h3 = *h1 + *h2;
     613  else if( oper[0]=='-') *h3 = *h1 - *h2;
     614#ifdef SANS_EVOLPLANCK
     615  else if(oper[0]=='*' || oper[0]=='/')
     616    cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
     617        <<" not implemented for Vector in Peida"<<endl;
     618#else
     619  else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
     620  else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
     621#endif
    544622
    545623// Doesn't work for other objects
     
    571649
    572650Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
    573 //AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
    574651
    575652string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
     
    754831  Vector* v = NULL;
    755832  if(mobjv==NULL)   // le vecteur n'existe pas
    756     {v = new Vector(1); omg.AddObj(v,vname);}
    757   AnyDataObj* mobjv = omg.GetObj(vname);
     833    {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
    758834  if(typeid(*mobjv) != typeid(Vector))
    759835    {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
     
    769845    Matrix*  v = NULL;
    770846    if(mobjv==NULL)   // la matrice n'existe pas
    771       {v = new Matrix(1,1); omg.AddObj(v,vname);}
    772     AnyDataObj* mobjv = omg.GetObj(vname);
     847      {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
    773848    if(typeid(*mobjv) != typeid(Matrix))
    774849      {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
     
    795870    Vector* v = NULL;
    796871    if(mobjv==NULL)   // le vecteur n'existe pas
    797       {v = new Vector(1); omg.AddObj(v,vname);}
    798     AnyDataObj* mobjv = omg.GetObj(vname);
     872      {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
    799873    if(typeid(*mobjv) != typeid(Vector))
    800874      {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
     
    852926  Vector* v2 = NULL;
    853927  if(mobjv2==NULL)
    854     {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);}
    855   mobjv2 = omg.GetObj(tokens[1]);
     928    {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
    856929  if(typeid(*mobjv2) != typeid(Vector))
    857930    {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
     
    879952  Histo* v2 = NULL;
    880953  if(mobjv2==NULL)
    881     {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);}
    882   mobjv2 = omg.GetObj(tokens[1]);
     954    {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1);
     955     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
    883956  if(typeid(*mobjv2) != typeid(Histo))
    884957    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
     
    910983  Matrix* v2 = NULL;
    911984  if(mobjv2==NULL)
    912     {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);}
    913   mobjv2 = omg.GetObj(tokens[1]);
     985    {v2 = new Matrix(i2-i1+1,j2-j1+1);
     986     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
    914987  if(typeid(*mobjv2) != typeid(Matrix))
    915988    {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
     
    9421015  if(mobjv2==NULL)
    9431016    {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
    944      omg.AddObj(v2,tokens[1]);}
    945   mobjv2 = omg.GetObj(tokens[1]);
     1017     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
    9461018  if(typeid(*mobjv2) != typeid(Histo2D))
    9471019    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
Note: See TracChangeset for help on using the changeset viewer.