Changeset 1054 in Sophya
- Timestamp:
- Jun 30, 2000, 3:38:30 PM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r1035 r1054 6 6 7 7 #include "strutil.h" 8 #include "histos.h"9 8 #include "histos.h" 10 9 #include "histos2.h" … … 76 75 77 76 kw = "h/cadd"; 78 usage = "Add a constant to an histogram me";77 usage = "Add a constant to an histogram"; 79 78 usage += "\n h/cadd val"; 80 usage += "\n Related commands: h/cmult ";79 usage += "\n Related commands: h/cmult h/oper"; 81 80 piac->RegisterCommand(kw,usage,this,hgrp); 82 81 83 82 kw = "h/cmult"; 84 usage = "Multiply an histogram meby a constant";83 usage = "Multiply an histogram by a constant"; 85 84 usage += "\n h/cmult val"; 86 usage += "\n Related commands: h/cadd"; 85 usage += "\n Related commands: h/cadd h/oper"; 86 piac->RegisterCommand(kw,usage,this,hgrp); 87 88 kw = "h/oper"; 89 usage = "Operation on histograms"; 90 usage += "\n h/oper @ h1 h2 hres"; 91 usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)"; 92 usage += "\n Related commands: h/cadd h/cmult"; 87 93 piac->RegisterCommand(kw,usage,this,hgrp); 88 94 … … 125 131 } else if(kw == "h/cmult") { 126 132 h_cmult(tokens); return(0); 133 } else if(kw == "h/oper") { 134 h_oper(tokens); return(0); 127 135 } else if(kw == "h/plot/2d") { 128 136 h_plot_2d(tokens); return(0); … … 359 367 else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0] 360 368 <<" not an Histo/HProf/Histo2D"<<endl; 369 } 370 371 /* methode */ 372 void 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 { 378 cout<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl; 379 cerr<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl; 380 if(tokens.size()<4) 381 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl; 382 return;} 383 384 // Decode arguments 385 const char * oper = tokens[0].c_str(); 386 if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' ) 387 {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl; 388 return;} 389 string h1name = tokens[1]; 390 string h2name = tokens[2]; 391 string h3name = tokens[3]; 392 393 // Get objects 394 NamedObjMgr omg; 395 AnyDataObj* mobjh1 = omg.GetObj(h1name); 396 AnyDataObj* mobjh2 = omg.GetObj(h2name); 397 if( mobjh1==NULL || mobjh2==NULL ) 398 {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl; 399 return;} 400 AnyDataObj* mobjh3 = omg.GetObj(h3name); 401 402 // Operations on HProf, only + is working 403 if( 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 501 return; 361 502 } 362 503 -
trunk/SophyaPI/PIext/pawexecut.h
r1035 r1054 28 28 void h_cadd(vector<string>& tokens); 29 29 void h_cmult(vector<string>& tokens); 30 void h_oper(vector<string>& tokens); 30 31 void h_plot_2d(vector<string>& tokens); 31 32 int decodepawstring(string tokens,string& nameobj
Note:
See TracChangeset
for help on using the changeset viewer.