Changeset 1073 in Sophya
- Timestamp:
- Jul 16, 2000, 1:31:22 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r1071 r1073 75 75 76 76 kw = "h/cadd"; 77 usage = "Add a constant to an histogram ";77 usage = "Add a constant to an histogram, a vector or a matrix"; 78 78 usage += "\n h/cadd namehisto val"; 79 79 usage += "\n Related commands: h/cmult h/oper"; … … 81 81 82 82 kw = "h/cmult"; 83 usage = "Multiply an histogram by a constant";83 usage = "Multiply an histogram, a vector or a matrix by a constant"; 84 84 usage += "\n h/cmult namehisto val"; 85 85 usage += "\n Related commands: h/cadd h/oper"; … … 87 87 88 88 kw = "h/oper"; 89 usage = "Operation on histograms ";89 usage = "Operation on histograms vectors or matrices"; 90 90 usage += "\n h/oper @ h1 h2 hres"; 91 91 usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)"; 92 usage += "\n For vectors and matrices, operations are elements by elements"; 92 93 usage += "\n Related commands: h/cadd h/cmult"; 93 94 piac->RegisterCommand(kw,usage,this,hgrp); … … 134 135 135 136 kw = "h/copy"; 136 usage = "Copy content of object1 into objec ft2";137 usage = "Copy content of object1 into object2"; 137 138 usage += "\n objects are Vector,Matrix,Histo,Histo2D"; 138 139 usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"; … … 378 379 //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1) 379 380 if(!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; 381 382 return;} 382 383 h1->HRebin(nbin); … … 398 399 HProf* hp = dynamic_cast<HProf*>(mobj); 399 400 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); 401 Vector* v = dynamic_cast<Vector*>(mobj); 402 Matrix* m = dynamic_cast<Matrix*>(mobj); 400 403 if(h1 && !hp) *h1 += val; 401 404 else if(h2) *h2 += val; 402 else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/Histo2D"<<endl; 405 else if(v) *v += val; 406 else if(m) *m += val; 407 else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl; 403 408 } 404 409 … … 418 423 HProf* hp = dynamic_cast<HProf*>(mobj); 419 424 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); 425 Vector* v = dynamic_cast<Vector*>(mobj); 426 Matrix* m = dynamic_cast<Matrix*>(mobj); 420 427 if(h1 && !hp) *h1 *= val; 421 428 else if(h2) *h2 *= val; 422 else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0] 423 <<" not an Histo/Histo2D"<<endl; 429 else if(v) *v += val; 430 else if(m) *m += val; 431 else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl; 424 432 } 425 433 … … 427 435 void PAWExecutor::h_oper(vector<string>& tokens) 428 436 // 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 430 438 // h/oper @ h1 h2 hres 431 439 // hres = h1 @ h2 with @ = (+,-,*,/) 440 // Pour les vecteurs et les matrices, il sagit d'operations elements a elements 432 441 { 433 442 if(tokens.size()<4) 434 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/ )"<<endl;443 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl; 435 444 return;} 436 445 … … 468 477 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;} 469 478 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(); 484 490 485 491 // Operations on Histo … … 495 501 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;} 496 502 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; 513 516 514 517 // Operations on Histo2D … … 525 528 <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;} 526 529 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; 527 557 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); 543 564 } 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 544 622 545 623 // Doesn't work for other objects … … 571 649 572 650 Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1"; 573 //AnyDataObj* mobjh1 = omg.GetObj(nametoplot);574 651 575 652 string dopt = ""; if(tokens.size()>=3) dopt = tokens[2]; … … 754 831 Vector* v = NULL; 755 832 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);} 758 834 if(typeid(*mobjv) != typeid(Vector)) 759 835 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n" … … 769 845 Matrix* v = NULL; 770 846 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);} 773 848 if(typeid(*mobjv) != typeid(Matrix)) 774 849 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n" … … 795 870 Vector* v = NULL; 796 871 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);} 799 873 if(typeid(*mobjv) != typeid(Vector)) 800 874 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj … … 852 926 Vector* v2 = NULL; 853 927 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]);} 856 929 if(typeid(*mobjv2) != typeid(Vector)) 857 930 {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector " … … 879 952 Histo* v2 = NULL; 880 953 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]);} 883 956 if(typeid(*mobjv2) != typeid(Histo)) 884 957 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo " … … 910 983 Matrix* v2 = NULL; 911 984 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]);} 914 987 if(typeid(*mobjv2) != typeid(Matrix)) 915 988 {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix " … … 942 1015 if(mobjv2==NULL) 943 1016 {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]);} 946 1018 if(typeid(*mobjv2) != typeid(Histo2D)) 947 1019 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
Note:
See TracChangeset
for help on using the changeset viewer.