Index: trunk/SophyaPI/PIext/pawexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.cc	(revision 1071)
+++ trunk/SophyaPI/PIext/pawexecut.cc	(revision 1073)
@@ -75,5 +75,5 @@
 
 kw = "h/cadd";
-usage = "Add a constant to an histogram";
+usage = "Add a constant to an histogram, a vector or a matrix";
 usage += "\n h/cadd namehisto val";
 usage += "\n  Related commands: h/cmult h/oper";  
@@ -81,5 +81,5 @@
 
 kw = "h/cmult";
-usage = "Multiply an histogram by a constant";
+usage = "Multiply an histogram, a vector or a matrix by a constant";
 usage += "\n h/cmult namehisto val";
 usage += "\n  Related commands: h/cadd h/oper";  
@@ -87,7 +87,8 @@
 
 kw = "h/oper";
-usage = "Operation on histograms";
+usage = "Operation on histograms vectors or matrices";
 usage += "\n h/oper @ h1 h2 hres";
 usage += "\n        hres = h1 @ h2   with @ = (+,-,*,/)";
+usage += "\n For vectors and matrices, operations are elements by elements";
 usage += "\n  Related commands: h/cadd h/cmult";  
 piac->RegisterCommand(kw,usage,this,hgrp);
@@ -134,5 +135,5 @@
 
 kw = "h/copy";
-usage = "Copy content of object1 into objecft2";
+usage = "Copy content of object1 into object2";
 usage += "\n objects are Vector,Matrix,Histo,Histo2D";
 usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
@@ -378,5 +379,5 @@
 //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
 if(!h1)
-  {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo"<<endl;
+  {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
   return;}
 h1->HRebin(nbin);
@@ -398,7 +399,11 @@
 HProf*   hp = dynamic_cast<HProf*>(mobj);
 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
+Vector*  v  = dynamic_cast<Vector*>(mobj);
+Matrix*  m  = dynamic_cast<Matrix*>(mobj);
 if(h1 && !hp) *h1 += val;
 else if(h2)   *h2 += val;
-else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/Histo2D"<<endl;
+else if(v)    *v  += val;
+else if(m)    *m  += val;
+else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
 }
 
@@ -418,8 +423,11 @@
 HProf*   hp = dynamic_cast<HProf*>(mobj);
 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
+Vector*  v  = dynamic_cast<Vector*>(mobj);
+Matrix*  m  = dynamic_cast<Matrix*>(mobj);
 if(h1 && !hp) *h1 *= val;
 else if(h2)   *h2 *= val;
-else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
-         <<" not an Histo/Histo2D"<<endl;
+else if(v)    *v  += val;
+else if(m)    *m  += val;
+else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
 }
 
@@ -427,10 +435,11 @@
 void PAWExecutor::h_oper(vector<string>& tokens)
 // Equivalent h/oper/add sub,mul,div de paw
-// Operation entre 2 histogrammes
+// Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
 // h/oper @ h1 h2 hres
 // hres = h1 @ h2    with @ = (+,-,*,/)
+// Pour les vecteurs et les matrices, il sagit d'operations elements a elements
 {
 if(tokens.size()<4)
-  {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
+  {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
    return;}
 
@@ -468,18 +477,15 @@
          <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
   HProf* h3 = NULL;
-  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
-    h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
-  } else {                // l'objet existe
-    h3 = dynamic_cast<HProf*>(mobjh3);
-    if(h3 == NULL)  // ce n'est pas un HProf
-      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
-           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
-      return;}
-    if(h1->NBins() != h3->NBins())
-      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
-           <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
-    *h3 = *h1 + *h2;
-    h3->UpdateHisto();
-  }
+  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
+    {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
+  h3 = dynamic_cast<HProf*>(mobjh3);
+  if(h3 == NULL)  // ce n'est pas un HProf
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
+  if(h1->NBins() != h3->NBins())
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
+         <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
+  *h3 = *h1 + *h2;
+  h3->UpdateHisto();
 
 // Operations on Histo
@@ -495,20 +501,17 @@
          <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
   Histo* h3 = NULL;
-  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
-    h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
-  } else {                // l'objet existe
-    h3 = dynamic_cast<Histo*>(mobjh3);
-    if(h3 == NULL)  // ce n'est pas un Histo
-      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
-           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
-      return;}
-    if(h1->NBins() != h3->NBins())
-      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
-           <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
-    if( oper[0]=='+')      *h3 = *h1 + *h2;
-    else if( oper[0]=='-') *h3 = *h1 - *h2;
-    else if( oper[0]=='*') *h3 = *h1 * *h2;
-    else if( oper[0]=='/') *h3 = *h1 / *h2;
-  }
+  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
+    {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
+  h3 = dynamic_cast<Histo*>(mobjh3);
+  if(h3 == NULL)  // ce n'est pas un Histo
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
+  if(h1->NBins() != h3->NBins())
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
+         <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
+  if( oper[0]=='+')      *h3 = *h1 + *h2;
+  else if( oper[0]=='-') *h3 = *h1 - *h2;
+  else if( oper[0]=='*') *h3 = *h1 * *h2;
+  else if( oper[0]=='/') *h3 = *h1 / *h2;
 
 // Operations on Histo2D
@@ -525,21 +528,96 @@
          <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
   Histo2D* h3 = NULL;
+  if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
+    {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
+  h3 = dynamic_cast<Histo2D*>(mobjh3);
+  if(h3 == NULL)  // ce n'est pas un Histo2D
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
+  if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
+         <<h1->NBinX()<<","<<h1->NBinY()<<"   "
+         <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
+  if( oper[0]=='+')      *h3 = *h1 + *h2;
+  else if( oper[0]=='-') *h3 = *h1 - *h2;
+  else if( oper[0]=='*') *h3 = *h1 * *h2;
+  else if( oper[0]=='/') *h3 = *h1 / *h2;
+
+// Operations on Vector
+} else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
+  if( dynamic_cast<Vector*>(mobjh2) == NULL )
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
+    return;}
+  Vector* h1 =(Vector*) mobjh1;
+  Vector* h2 =(Vector*) mobjh2;
+  if( h1->NElts() != h2->NElts() )
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
+         <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
+  Vector* h3 = NULL;
   if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
-    h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
-  } else {                // l'objet existe
-    h3 = dynamic_cast<Histo2D*>(mobjh3);
-    if(h3 == NULL)  // ce n'est pas un Histo2D
-      {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
-           <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
-      return;}
-    if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
-      {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
-           <<h1->NBinX()<<","<<h1->NBinY()<<"   "
-           <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
-    if( oper[0]=='+')      *h3 = *h1 + *h2;
-    else if( oper[0]=='-') *h3 = *h1 - *h2;
-    else if( oper[0]=='*') *h3 = *h1 * *h2;
-    else if( oper[0]=='/') *h3 = *h1 / *h2;
+#ifdef SANS_EVOLPLANCK
+    h3 = new Vector(*h1);
+#else
+    h3 = new Vector(*h1,false);
+#endif
+    *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
   }
+  h3 = dynamic_cast<Vector*>(mobjh3);
+  if(h3 == NULL)  // ce n'est pas un Vector
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
+  if(h1->NElts() != h3->NElts())
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
+         <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
+  if( oper[0]=='+')      *h3 = *h1 + *h2;
+  else if( oper[0]=='-') *h3 = *h1 - *h2;
+#ifdef SANS_EVOLPLANCK
+  else if(oper[0]=='*' || oper[0]=='/')
+    cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
+        <<" not implemented for Vector in Peida"<<endl;
+#else
+  else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
+  else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
+#endif
+
+// Operations on Matrix
+} else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
+  if( dynamic_cast<Matrix*>(mobjh2) == NULL )
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
+    return;}
+  Matrix* h1 =(Matrix*) mobjh1;
+  Matrix* h2 =(Matrix*) mobjh2;
+  if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
+         <<h1->NRows()<<","<<h1->NCol()<<"   "
+         <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
+  Matrix* h3 = NULL;
+  if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree
+#ifdef SANS_EVOLPLANCK
+    h3 = new Matrix(*h1);
+#else
+    h3 = new Matrix(*h1,false);
+#endif
+    *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
+  }
+  h3 = dynamic_cast<Matrix*>(mobjh3);
+  if(h3 == NULL)  // ce n'est pas un Matrix
+    {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
+         <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
+  if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
+    {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
+         <<h1->NRows()<<","<<h1->NCol()<<"   "
+         <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
+  if( oper[0]=='+')      *h3 = *h1 + *h2;
+  else if( oper[0]=='-') *h3 = *h1 - *h2;
+#ifdef SANS_EVOLPLANCK
+  else if(oper[0]=='*' || oper[0]=='/')
+    cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
+        <<" not implemented for Vector in Peida"<<endl;
+#else
+  else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
+  else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
+#endif
 
 // Doesn't work for other objects
@@ -571,5 +649,4 @@
 
 Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
-//AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
 
 string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
@@ -754,6 +831,5 @@
   Vector* v = NULL;
   if(mobjv==NULL)   // le vecteur n'existe pas
-    {v = new Vector(1); omg.AddObj(v,vname);}
-  AnyDataObj* mobjv = omg.GetObj(vname);
+    {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
   if(typeid(*mobjv) != typeid(Vector))
     {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
@@ -769,6 +845,5 @@
     Matrix*  v = NULL;
     if(mobjv==NULL)   // la matrice n'existe pas
-      {v = new Matrix(1,1); omg.AddObj(v,vname);}
-    AnyDataObj* mobjv = omg.GetObj(vname);
+      {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
     if(typeid(*mobjv) != typeid(Matrix))
       {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
@@ -795,6 +870,5 @@
     Vector* v = NULL;
     if(mobjv==NULL)   // le vecteur n'existe pas
-      {v = new Vector(1); omg.AddObj(v,vname);}
-    AnyDataObj* mobjv = omg.GetObj(vname);
+      {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
     if(typeid(*mobjv) != typeid(Vector))
       {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
@@ -852,6 +926,5 @@
   Vector* v2 = NULL;
   if(mobjv2==NULL)
-    {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);}
-  mobjv2 = omg.GetObj(tokens[1]);
+    {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
   if(typeid(*mobjv2) != typeid(Vector))
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
@@ -879,6 +952,6 @@
   Histo* v2 = NULL;
   if(mobjv2==NULL)
-    {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);}
-  mobjv2 = omg.GetObj(tokens[1]);
+    {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1);
+     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
   if(typeid(*mobjv2) != typeid(Histo))
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
@@ -910,6 +983,6 @@
   Matrix* v2 = NULL;
   if(mobjv2==NULL)
-    {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);}
-  mobjv2 = omg.GetObj(tokens[1]);
+    {v2 = new Matrix(i2-i1+1,j2-j1+1);
+     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
   if(typeid(*mobjv2) != typeid(Matrix))
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
@@ -942,6 +1015,5 @@
   if(mobjv2==NULL)
     {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
-     omg.AddObj(v2,tokens[1]);}
-  mobjv2 = omg.GetObj(tokens[1]);
+     omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
   if(typeid(*mobjv2) != typeid(Histo2D))
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
