Changeset 1054 in Sophya for trunk/SophyaPI/PIext/pawexecut.cc


Ignore:
Timestamp:
Jun 30, 2000, 3:38:30 PM (25 years ago)
Author:
ercodmgr
Message:

h/oper non-teste cmv 30/06/00

File:
1 edited

Legend:

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

    r1035 r1054  
    66
    77#include "strutil.h"
    8 #include "histos.h"
    98#include "histos.h"
    109#include "histos2.h"
     
    7675
    7776kw = "h/cadd";
    78 usage = "Add a constant to an histogramme";
     77usage = "Add a constant to an histogram";
    7978usage += "\n h/cadd val";
    80 usage += "\n  Related commands: h/cmult"; 
     79usage += "\n  Related commands: h/cmult h/oper"; 
    8180piac->RegisterCommand(kw,usage,this,hgrp);
    8281
    8382kw = "h/cmult";
    84 usage = "Multiply an histogramme by a constant";
     83usage = "Multiply an histogram by a constant";
    8584usage += "\n h/cmult val";
    86 usage += "\n  Related commands: h/cadd"; 
     85usage += "\n  Related commands: h/cadd h/oper"; 
     86piac->RegisterCommand(kw,usage,this,hgrp);
     87
     88kw = "h/oper";
     89usage = "Operation on histograms";
     90usage += "\n h/oper @ h1 h2 hres";
     91usage += "\n        hres = h1 @ h2   with @ = (+,-,*,/)";
     92usage += "\n  Related commands: h/cadd h/cmult"; 
    8793piac->RegisterCommand(kw,usage,this,hgrp);
    8894
     
    125131} else if(kw == "h/cmult") {
    126132  h_cmult(tokens); return(0);
     133} else if(kw == "h/oper") {
     134  h_oper(tokens); return(0);
    127135} else if(kw == "h/plot/2d") {
    128136  h_plot_2d(tokens); return(0);
     
    359367else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
    360368         <<" not an Histo/HProf/Histo2D"<<endl;
     369}
     370
     371/* methode */
     372void PAWExecutor::h_oper(vector<string>& tokens)
     373// Equivalent h/oper/add sub,mul,div de paw
     374// Operation entre 2 histogrammes
     375// h/oper @ h1 h2 hres
     376// hres = h1 @ h2    with @ = (+,-,*,/)
     377{
     378cout<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl;
     379cerr<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl;
     380if(tokens.size()<4)
     381  {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
     382   return;}
     383
     384// Decode arguments
     385const char * oper = tokens[0].c_str();
     386if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
     387  {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
     388  return;}
     389string h1name = tokens[1];
     390string h2name = tokens[2];
     391string h3name = tokens[3];
     392
     393// Get objects
     394NamedObjMgr omg;
     395AnyDataObj* mobjh1 = omg.GetObj(h1name);
     396AnyDataObj* mobjh2 = omg.GetObj(h2name);
     397if( mobjh1==NULL || mobjh2==NULL )
     398  {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
     399  return;}
     400AnyDataObj* mobjh3 = omg.GetObj(h3name);
     401
     402// Operations on HProf, only + is working
     403if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
     404  if( oper[0]!='+' )
     405    { cout<<"PAWExecutor::h_oper Error: operation "<<oper
     406          <<" not implemented for HProf"<<endl; return;}
     407  if( dynamic_cast<HProf*>(mobjh2) == NULL )
     408    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
     409         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
     410    return;}
     411  HProf* h1 =(HProf*) mobjh1;
     412  HProf* h2 =(HProf*) mobjh2;
     413  if( h1->NBins() != h2->NBins() )
     414    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
     415         <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
     416  HProf* h3 = NULL;
     417  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
     418    h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
     419  } else {                // l'objet existe
     420    h3 = dynamic_cast<HProf*>(mobjh3);
     421    if(h3 == NULL)  // ce n'est pas un HProf
     422      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
     423           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
     424      return;}
     425    if(h1->NBins() != h3->NBins())
     426      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     427           <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
     428    h3->Zero();
     429    *h3 = *h1 + *h2;
     430    h3->UpdateHisto();
     431  }
     432
     433// Operations on Histo
     434} else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
     435  if( dynamic_cast<Histo*>(mobjh2) == NULL )
     436    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
     437         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
     438    return;}
     439  Histo* h1 =(Histo*) mobjh1;
     440  Histo* h2 =(Histo*) mobjh2;
     441  if( h1->NBins() != h2->NBins() )
     442    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
     443         <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
     444  Histo* h3 = NULL;
     445  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
     446    h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
     447  } else {                // l'objet existe
     448    h3 = dynamic_cast<Histo*>(mobjh3);
     449    if(h3 == NULL)  // ce n'est pas un Histo
     450      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
     451           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
     452      return;}
     453    if(h1->NBins() != h3->NBins())
     454      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     455           <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
     456    h3->Zero();
     457    if( oper[0]=='+')      *h3 = *h1 + *h2;
     458    else if( oper[0]=='-') *h3 = *h1 - *h2;
     459    else if( oper[0]=='*') *h3 = *h1 * *h2;
     460    else if( oper[0]=='/') *h3 = *h1 / *h2;
     461  }
     462
     463// Operations on Histo2D
     464} else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
     465  if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
     466    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
     467         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
     468    return;}
     469  Histo2D* h1 =(Histo2D*) mobjh1;
     470  Histo2D* h2 =(Histo2D*) mobjh2;
     471  if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
     472    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
     473         <<h1->NBinX()<<","<<h1->NBinY()<<"   "
     474         <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
     475  Histo2D* h3 = NULL;
     476  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
     477    h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
     478  } else {                // l'objet existe
     479    h3 = dynamic_cast<Histo2D*>(mobjh3);
     480    if(h3 == NULL)  // ce n'est pas un Histo2D
     481      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
     482           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
     483      return;}
     484    if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
     485      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
     486           <<h1->NBinX()<<","<<h1->NBinY()<<"   "
     487           <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
     488    h3->Zero();
     489    if( oper[0]=='+')      *h3 = *h1 + *h2;
     490    else if( oper[0]=='-') *h3 = *h1 - *h2;
     491    else if( oper[0]=='*') *h3 = *h1 * *h2;
     492    else if( oper[0]=='/') *h3 = *h1 / *h2;
     493  }
     494
     495// Doesn't work for other objects
     496} else {
     497  cout<<"PAWExecutor::h_oper Error: not implemented for "<<typeid(*mobjh1).name()<<endl;
     498  return;
     499}
     500
     501return;
    361502}
    362503
Note: See TracChangeset for help on using the changeset viewer.