Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_xml_aidas 5 #define tools_xml_aidas 6 7 #include "../raxml_out" 8 9 #include "../sprintf" 10 #include "../histo/h1d" 11 #include "../histo/h2d" 12 #include "../histo/h3d" 13 #include "../histo/p1d" 14 #include "../histo/p2d" 15 #include "../histo/c1d" 16 #include "../histo/c2d" 17 #include "../histo/c3d" 18 #include "../histo/dps" 19 #include "../aida_ntuple" 20 #include "../S_STRING" 21 #include "../forit" 22 23 #include "tree" 24 25 #include <vector> 26 #include <map> 27 #include <utility> 28 29 namespace tools { 30 namespace xml { 31 32 class aidas { 33 public: 34 //tree,out,verbose,path. 35 typedef raxml_out (*reader)(tree&,std::ostream&,bool,void*); 36 typedef std::map<std::string,reader> readers; 37 public: 38 aidas() 39 { 40 add_default_readers(); 41 } 42 virtual ~aidas(){ 43 m_objects.clear(); //it may delete histos, etc... 44 } 45 protected: 46 aidas(const aidas&){} 47 aidas& operator=(const aidas&){return *this;} 48 public: 49 std::vector<raxml_out>& objects() {return m_objects;} 50 protected: 51 void clear_readers() {m_readers.clear();} 52 void add_reader(const std::string& a_class, 53 reader a_reader, 54 bool a_check = false){ 55 if(a_check) {if(find_reader(a_class)) return;} 56 m_readers[a_class] = a_reader; 57 } 58 59 reader find_reader(const std::string& a_class) const { 60 std::map<std::string,reader>::const_iterator it = m_readers.find(a_class); 61 if(it!=m_readers.end()) return (*it).second; 62 return 0; 63 } 64 65 protected: 66 TOOLS_CLASS_STRING(aida) 67 68 TOOLS_CLASS_STRING(annotation) 69 TOOLS_CLASS_STRING(histogram1d) 70 TOOLS_CLASS_STRING(histogram2d) 71 TOOLS_CLASS_STRING(histogram3d) 72 TOOLS_CLASS_STRING(profile1d) 73 TOOLS_CLASS_STRING(profile2d) 74 TOOLS_CLASS_STRING(axis) 75 TOOLS_CLASS_STRING(statistics) 76 TOOLS_CLASS_STRING(statistic) 77 TOOLS_CLASS_STRING(data1d) 78 TOOLS_CLASS_STRING(data2d) 79 TOOLS_CLASS_STRING(data3d) 80 TOOLS_CLASS_STRING(tuple) 81 TOOLS_CLASS_STRING(columns) 82 TOOLS_CLASS_STRING(rows) 83 TOOLS_CLASS_STRING(row) 84 TOOLS_CLASS_STRING(entryITuple) 85 TOOLS_CLASS_STRING(entryTuple) 86 TOOLS_CLASS_STRING(cloud1d) 87 TOOLS_CLASS_STRING(cloud2d) 88 TOOLS_CLASS_STRING(cloud3d) 89 TOOLS_CLASS_STRING(entries1d) 90 TOOLS_CLASS_STRING(entries2d) 91 TOOLS_CLASS_STRING(entries3d) 92 TOOLS_CLASS_STRING(dataPointSet) 93 TOOLS_CLASS_STRING(dataPoint) 94 //TOOLS_CLASS_STRING(function) 95 //TOOLS_CLASS_STRING(arguments) 96 //TOOLS_CLASS_STRING(argument) 97 //TOOLS_CLASS_STRING(parameters) 98 99 TOOLS_CLASS_STRING(type) 100 TOOLS_CLASS_STRING(name) 101 TOOLS_CLASS_STRING(path) 102 TOOLS_CLASS_STRING(title) 103 TOOLS_CLASS_STRING(numberOfBins) 104 TOOLS_CLASS_STRING(min) 105 TOOLS_CLASS_STRING(max) 106 TOOLS_CLASS_STRING(direction) 107 TOOLS_CLASS_STRING(value) 108 TOOLS_CLASS_STRING(entries) 109 TOOLS_CLASS_STRING(mean) 110 TOOLS_CLASS_STRING(rms) 111 TOOLS_CLASS_STRING(height) 112 TOOLS_CLASS_STRING(error) 113 TOOLS_CLASS_STRING(weightedMean) 114 TOOLS_CLASS_STRING(weightedRms) 115 TOOLS_CLASS_STRING(weightedMeanX) 116 TOOLS_CLASS_STRING(weightedMeanY) 117 TOOLS_CLASS_STRING(weightedMeanZ) 118 TOOLS_CLASS_STRING(weightedRmsX) 119 TOOLS_CLASS_STRING(weightedRmsY) 120 TOOLS_CLASS_STRING(weightedRmsZ) 121 TOOLS_CLASS_STRING(booking) 122 TOOLS_CLASS_STRING(default) 123 TOOLS_CLASS_STRING(entry) 124 TOOLS_CLASS_STRING(binBorder) 125 TOOLS_CLASS_STRING(maxEntries) 126 TOOLS_CLASS_STRING(valueX) 127 TOOLS_CLASS_STRING(valueY) 128 TOOLS_CLASS_STRING(valueZ) 129 TOOLS_CLASS_STRING(weight) 130 TOOLS_CLASS_STRING(entry1d) 131 TOOLS_CLASS_STRING(entry2d) 132 TOOLS_CLASS_STRING(entry3d) 133 TOOLS_CLASS_STRING(dimension) 134 TOOLS_CLASS_STRING(errorPlus) 135 TOOLS_CLASS_STRING(errorMinus) 136 TOOLS_CLASS_STRING(measurement) 137 138 void set_default_tags(std::vector<std::string>& a_tags) { 139 a_tags.clear(); 140 a_tags.push_back(s_aida()); 141 a_tags.push_back(s_annotation()); 142 a_tags.push_back(s_histogram1d()); 143 a_tags.push_back(s_histogram2d()); 144 a_tags.push_back(s_histogram3d()); 145 a_tags.push_back(s_profile1d()); 146 a_tags.push_back(s_profile2d()); 147 a_tags.push_back(s_axis()); 148 a_tags.push_back(s_statistics()); 149 a_tags.push_back(s_data1d()); 150 a_tags.push_back(s_data2d()); 151 a_tags.push_back(s_data3d()); 152 153 a_tags.push_back(s_tuple()); 154 a_tags.push_back(s_columns()); 155 a_tags.push_back(s_rows()); 156 a_tags.push_back(s_row()); 157 a_tags.push_back(s_entryITuple()); //aida.dtd spec. 158 a_tags.push_back(s_entryTuple()); //not in aida.dtd ! Back comp. 159 160 a_tags.push_back(s_cloud1d()); 161 a_tags.push_back(s_cloud2d()); 162 a_tags.push_back(s_cloud3d()); 163 a_tags.push_back(s_entries1d()); 164 a_tags.push_back(s_entries2d()); 165 a_tags.push_back(s_entries3d()); 166 a_tags.push_back(s_dataPointSet()); 167 a_tags.push_back(s_dataPoint()); 168 //a_tags.push_back(s_function()); 169 //a_tags.push_back(s_arguments()); 170 //a_tags.push_back(s_argument()); 171 //a_tags.push_back(s_parameters()); 172 } 173 174 void add_default_readers(){ 175 add_reader(s_histogram1d(),read_h1d); 176 add_reader(s_histogram2d(),read_h2d); 177 add_reader(s_histogram3d(),read_h3d); 178 add_reader(s_profile1d(),read_p1d); 179 add_reader(s_profile2d(),read_p2d); 180 add_reader(s_cloud1d(),read_cloud1d); 181 add_reader(s_cloud2d(),read_cloud2d); 182 add_reader(s_cloud3d(),read_cloud3d); 183 add_reader(s_tuple(),read_ntu); 184 add_reader(s_dataPointSet(),read_dps); 185 //add_reader(s_function(),read_Function); 186 } 187 static raxml_out read_h1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 188 return read_histo(a_tree,a_out,a_verbose,1,false); 189 } 190 static raxml_out read_h2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 191 return read_histo(a_tree,a_out,a_verbose,2,false); 192 } 193 static raxml_out read_h3d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 194 return read_histo(a_tree,a_out,a_verbose,3,false); 195 } 196 static raxml_out read_p1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 197 return read_histo(a_tree,a_out,a_verbose,1,true); 198 } 199 static raxml_out read_p2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 200 return read_histo(a_tree,a_out,a_verbose,2,true); 201 } 202 203 static raxml_out read_cloud1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 204 return read_cloud(a_tree,a_out,a_verbose,1); 205 } 206 static raxml_out read_cloud2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 207 return read_cloud(a_tree,a_out,a_verbose,2); 208 } 209 static raxml_out read_cloud3d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 210 return read_cloud(a_tree,a_out,a_verbose,3); 211 } 212 213 static raxml_out read_dps(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) { 214 std::string sname; 215 a_tree.attribute_value(s_name(),sname); 216 217 if(a_verbose) { 218 a_out << "tools::xml::aidas::read_dps :" 219 << " with name " << sout(sname) 220 << "..." << std::endl; 221 } 222 223 std::string spath; 224 a_tree.attribute_value(s_path(),spath); 225 226 std::string stitle; 227 a_tree.attribute_value(s_title(),stitle); 228 229 // Booking parameters : 230 unsigned int dim = 0; 231 if(!a_tree.attribute_value(s_dimension(),dim)) return raxml_out(); 232 233 // Create a BatchLab::DataPointSet : 234 histo::dps* dps = new histo::dps(stitle,dim); 235 236 // Data sub items : 237 {looper _for(a_tree); 238 while(tree* _tree = _for.next_tree()) { 239 if(!read_dps_data(*_tree,*dps)) { 240 delete dps; 241 return raxml_out(); 242 } 243 }} 244 245 base_handle* hdl = new handle<histo::dps>(dps); 246 std::string sclass = histo::dps::s_class(); 247 248 if(a_verbose) { 249 a_out << "tools::xml::aidas::read_dps :" 250 << " with name " << sout(sname) 251 << " and title " << sout(stitle) 252 << " done." << std::endl; 253 } 254 255 return raxml_out(hdl,sclass,spath,sname); 256 } 257 258 protected: 259 typedef histo::axis<double,unsigned int>::bn_t bn_t; 260 public: //used in BatchLab::XML_DataReader. 261 static raxml_out read_histo(tree& a_tree, 262 std::ostream& a_out,bool a_verbose, 263 unsigned int a_dim,bool a_is_prof){ 264 265 std::string sname; 266 a_tree.attribute_value(s_name(),sname); 267 268 if(a_verbose) { 269 a_out << "tools::xml::aidas::read_histo :" 270 << " with name " << sout(sname) 271 << "..." << std::endl; 272 } 273 274 std::string spath; 275 a_tree.attribute_value(s_path(),spath); 276 277 std::string stitle; 278 a_tree.attribute_value(s_title(),stitle); 279 280 // Booking parameters : 281 std::vector<bn_t> bins(a_dim); 282 std::vector<double> mns(a_dim); 283 std::vector<double> mxs(a_dim); 284 std::vector< std::vector<double> > edges(a_dim); 285 286 // Jump in subitems to find axes items : 287 int not_found = -1; 288 unsigned int found = 0; 289 bool isVariableBins = false; 290 291 {looper _for(a_tree); 292 while(tree* _tree = _for.next_tree()) { 293 294 int iaxis; 295 bn_t num; 296 double mn,mx; 297 std::vector<double> borders; 298 bool variableBins; 299 if(!read_axis(*_tree,a_dim,iaxis,num,mn,mx,borders,variableBins,a_out)) return raxml_out(); 300 if(iaxis!=not_found) { 301 if((iaxis<0)||(iaxis>=(int)a_dim)) return raxml_out(); 302 bins[iaxis] = num; 303 mns[iaxis] = mn; 304 mxs[iaxis] = mx; 305 edges[iaxis] = std::move(borders); 306 if(variableBins) isVariableBins = true; 307 found++; 308 } 309 }} 310 311 if(found!=a_dim) return raxml_out(); 312 if(isVariableBins) { 313 // Axes consistency : 314 for(unsigned int iaxis=0;iaxis<a_dim;iaxis++) { 315 if(edges[iaxis].size()<=2) return raxml_out(); 316 } 317 } 318 319 // Create a native histogram : 320 321 base_handle* hdl = 0; 322 std::string sclass; 323 if(a_is_prof) { 324 if(a_dim==1) { 325 histo::p1d* histo = 0; 326 if(isVariableBins) { 327 histo = new histo::p1d(stitle,edges[0]); 328 } else { 329 histo = new histo::p1d(stitle,bins[0],mns[0],mxs[0]); 330 } 331 332 // Sub items : 333 pd_data hd = histo->get_histo_data(); 334 if(hd.m_bin_number<=0) {delete histo;return raxml_out();} 335 336 {looper _for(a_tree); 337 while(tree* _tree = _for.next_tree()) { 338 339 if(!read_bins(*_tree,hd,a_out,a_is_prof)) { 340 delete histo; 341 return raxml_out(); 342 } 343 344 }} 345 346 //give histo ownership to the handle. 347 hdl = new handle<histo::p1d>(histo); 348 sclass = histo::p1d::s_class(); 349 350 hd.update_fast_getters(); 351 histo->copy_from_data(hd); 352 353 } else if(a_dim==2) { 354 histo::p2d* histo = 0; 355 if(isVariableBins) { 356 histo = new histo::p2d(stitle,edges[0],edges[1]); 357 } else { 358 histo = new histo::p2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]); 359 } 360 361 pd_data hd = histo->get_histo_data(); 362 if(hd.m_bin_number<=0) {delete histo;return raxml_out();} 363 364 {looper _for(a_tree); 365 while(tree* _tree = _for.next_tree()) { 366 367 if(!read_bins(*_tree,hd,a_out,a_is_prof)) { 368 delete histo; 369 return raxml_out(); 370 } 371 372 }} 373 374 hdl = new handle<histo::p2d>(histo); 375 sclass = histo::p2d::s_class(); 376 377 hd.update_fast_getters(); 378 histo->copy_from_data(hd); 379 } 380 } else { 381 if(a_dim==1) { 382 histo::h1d* histo = 0; 383 if(isVariableBins) { 384 histo = new histo::h1d(stitle,edges[0]); 385 } else { 386 histo = new histo::h1d(stitle,bins[0],mns[0],mxs[0]); 387 } 388 389 pd_data hd(histo->dac()); 390 if(hd.m_bin_number<=0) {delete histo;return raxml_out();} 391 392 {looper _for(a_tree); 393 while(tree* _tree = _for.next_tree()) { 394 395 if(!read_bins(*_tree,hd,a_out,a_is_prof)) { 396 delete histo; 397 return raxml_out(); 398 } 399 400 }} 401 402 hdl = new handle<histo::h1d>(histo); 403 sclass = histo::h1d::s_class(); 404 405 hd.update_fast_getters(); 406 histo->copy_from_data(hd); 407 408 } else if(a_dim==2) { 409 histo::h2d* histo = 0; 410 if(isVariableBins) { 411 histo = new histo::h2d(stitle,edges[0],edges[1]); 412 } else { 413 histo = new histo::h2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]); 414 } 415 416 pd_data hd(histo->dac()); 417 if(hd.m_bin_number<=0) {delete histo;return raxml_out();} 418 419 {looper _for(a_tree); 420 while(tree* _tree = _for.next_tree()) { 421 422 if(!read_bins(*_tree,hd,a_out,a_is_prof)) { 423 delete histo; 424 return raxml_out(); 425 } 426 427 }} 428 429 hdl = new handle<histo::h2d>(histo); 430 sclass = histo::h2d::s_class(); 431 432 hd.update_fast_getters(); 433 histo->copy_from_data(hd); 434 435 } else if(a_dim==3) { 436 histo::h3d* histo = 0; 437 if(isVariableBins) { 438 histo = new histo::h3d(stitle,edges[0],edges[1],edges[2]); 439 } else { 440 histo = new histo::h3d(stitle,bins[0],mns[0],mxs[0], 441 bins[1],mns[1],mxs[1], 442 bins[2],mns[2],mxs[2]); 443 } 444 445 pd_data hd(histo->dac()); 446 if(hd.m_bin_number<=0) {delete histo;return raxml_out();} 447 448 {looper _for(a_tree); 449 while(tree* _tree = _for.next_tree()) { 450 451 if(!read_bins(*_tree,hd,a_out,a_is_prof)) { 452 delete histo; 453 return raxml_out(); 454 } 455 456 }} 457 458 hdl = new handle<histo::h3d>(histo); 459 sclass = histo::h3d::s_class(); 460 461 hd.update_fast_getters(); 462 histo->copy_from_data(hd); 463 464 } 465 } 466 467 if(!hdl) return raxml_out(); 468 469 if(a_verbose) { 470 a_out << "tools::xml::aidas::read_histo :" 471 << " with name " << sout(sname) 472 << " and title " << sout(stitle) 473 << " done." << std::endl; 474 } 475 476 return raxml_out(hdl,sclass,spath,sname); 477 } 478 479 static raxml_out read_cloud(tree& a_tree,std::ostream& a_out,bool a_verbose,int a_dim){ 480 481 std::string sname; 482 a_tree.attribute_value(s_name(),sname); 483 484 if(a_verbose) { 485 a_out << "tools::xml::aidas::read_cloud :" 486 << " name " << sout(sname) 487 << "..." << std::endl; 488 } 489 490 std::string spath; 491 a_tree.attribute_value(s_path(),spath); 492 493 std::string stitle; 494 a_tree.attribute_value(s_title(),stitle); 495 496 std::string svalue; 497 498 // Booking parameters : 499 int max_entries = -1; //UNLIMITED 500 if(a_tree.attribute_value(s_maxEntries(),svalue)) { 501 int ival; 502 if(!to<int>(svalue,ival)) return raxml_out(); 503 max_entries = ival; 504 } 505 506 base_handle* hdl = 0; 507 std::string sclass; 508 509 if(a_dim==1) { 510 511 histo::c1d* cloud = new histo::c1d(stitle,max_entries); 512 513 // Data sub items : 514 {looper _for(a_tree); 515 while(tree* _tree = _for.next_tree()) { 516 if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) { 517 delete cloud; 518 return raxml_out(); 519 } 520 }} 521 522 hdl = new handle<histo::c1d>(cloud); 523 sclass = histo::c1d::s_class(); 524 525 } else if(a_dim==2) { 526 527 histo::c2d* cloud = new histo::c2d(stitle,max_entries); 528 529 // Data sub items : 530 {looper _for(a_tree); 531 while(tree* _tree = _for.next_tree()) { 532 if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) { 533 delete cloud; 534 return raxml_out(); 535 } 536 }} 537 538 hdl = new handle<histo::c2d>(cloud); 539 sclass = histo::c2d::s_class(); 540 541 } else if(a_dim==3) { 542 543 histo::c3d* cloud = new histo::c3d(stitle,max_entries); 544 545 // Data sub items : 546 {looper _for(a_tree); 547 while(tree* _tree = _for.next_tree()) { 548 if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) { 549 delete cloud; 550 return raxml_out(); 551 } 552 }} 553 554 hdl = new handle<histo::c3d>(cloud); 555 sclass = histo::c3d::s_class(); 556 } 557 558 if(!hdl) return raxml_out(); 559 560 if(a_verbose) { 561 a_out << "tools::xml::aidas::read_cloud :" 562 << " with name " << sout(sname) 563 << " and title " << sout(stitle) 564 << " done." << std::endl; 565 } 566 567 return raxml_out(hdl,sclass,spath,sname); 568 } 569 570 protected: 571 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data; 572 /////////////////////////////////////////////////////////////// 573 /// read histo //////////////////////////////////////////////// 574 /////////////////////////////////////////////////////////////// 575 static bool read_axis( 576 tree& a_tree 577 ,unsigned int a_dim 578 ,int& aAxis 579 ,bn_t& aNumberOfBins 580 ,double& aMin 581 ,double& aMax 582 ,std::vector<double>& aEdges 583 ,bool& aVariableBins 584 ,std::ostream& //a_out 585 ){ 586 int not_found = -1; 587 aAxis = not_found; 588 aNumberOfBins = 0; 589 aMin = 0; 590 aMax = 0; 591 aEdges.clear(); 592 aVariableBins = false; 593 594 const std::string& tagName = a_tree.tag_name(); 595 596 std::string svalue; 597 598 if(tagName==s_axis()) { 599 600 {bn_t ival; 601 if(!a_tree.attribute_value(s_numberOfBins(),svalue)) return false; 602 if(!to<bn_t>(svalue,ival)) return false; 603 aNumberOfBins = ival;} 604 605 if(!a_tree.attribute_value(s_min(),svalue)) return false; 606 if(!to<double>(svalue,aMin)) return false; 607 608 if(!a_tree.attribute_value(s_max(),svalue)) return false; 609 if(!to<double>(svalue,aMax)) return false; 610 611 if(!a_tree.attribute_value(s_direction(),svalue)) return false; 612 if(!axis_index(a_dim,svalue,aAxis)) return false; 613 614 aEdges.push_back(aMin); 615 616 {looper _for(a_tree); 617 while(element* _elem = _for.next_element()) { 618 if(_elem->name()==s_binBorder()) { 619 if(!_elem->attribute_value(s_value(),svalue)) return false; 620 double value; 621 if(!to<double>(svalue,value)) return false; 622 aEdges.push_back(value); 623 aVariableBins = true; 624 } 625 }} 626 627 aEdges.push_back(aMax); 628 if(aVariableBins) { // Variable bins histo. 629 if(aEdges.size()!=aNumberOfBins+1) return false; 630 } 631 632 } 633 634 return true; 635 } 636 static bool to_double(const std::string& a_s,double& a_v,std::ostream& a_out,const std::string& a_what) { 637 if(!to<double>(a_s,a_v)) { 638 a_out << "tools::xml::aidas::read_bins :" 639 << " problem converting a " << a_what 640 << " attribute to a double." 641 << " Value was " << sout(a_s) << "." 642 << std::endl; 643 return false; 644 } 645 return true; 646 } 647 648 static bool read_bins(tree& a_tree,pd_data& aData,std::ostream& a_out,bool a_is_prof){ 649 const std::string& tagName = a_tree.tag_name(); 650 651 std::string svalue; 652 653 if(tagName==s_annotation()) { //FIXME 654 655 return true; 656 657 } else if(tagName=="statistics") { 658 659 if(!a_tree.attribute_value(s_entries(),svalue)) return false; 660 //unsigned int ival; 661 //if(!to<unsigned int>(svalue,ival)) return false; 662 // aData.fEntries = ival; 663 664 unsigned int found = 0; 665 666 {looper _for(a_tree); 667 while(element* _elem = _for.next_element()) { 668 669 if(_elem->name()==s_statistic()) { 670 double mean,rms; 671 if(!_elem->attribute_value(s_mean(),svalue)) return false; 672 if(!to<double>(svalue,mean)) return false; 673 674 if(!_elem->attribute_value(s_rms(),svalue)) return false; 675 if(!to<double>(svalue,rms)) return false; 676 677 if(!_elem->attribute_value(s_direction(),svalue)) return false; 678 int iaxis; 679 if(!axis_index(aData.m_dimension,svalue,iaxis)) return false; 680 681 //aData.m_axes[iaxis].fSxw = mean; //Temporarily put mean on fSxw. 682 //aData.m_axes[iaxis].fSx2w = rms; //Temporarily put mean on fSx2w. 683 684 found++; 685 } 686 }} 687 688 if(found!=aData.m_dimension) return false; 689 690 return true; 691 692 } else if(tagName==s_axis()) { 693 694 return true; 695 696 } 697 698 unsigned int dimension = 0; 699 if(tagName==s_data1d()) { 700 dimension = 1; 701 } else if(tagName==s_data2d()) { 702 dimension = 2; 703 } else if(tagName==s_data3d()) { 704 dimension = 3; 705 } 706 707 if(dimension) { 708 709 if(dimension!=aData.m_dimension) return false; 710 711 std::string sbin; 712 sprintf(sbin,32,"bin%dd",dimension); 713 714 {looper _for(a_tree); 715 while(element* _elem = _for.next_element()) { 716 717 if(_elem->name()==sbin) { 718 719 std::vector<int> is(dimension); 720 721 unsigned int entries = 0; 722 double height = 0; 723 double error = 0; 724 double weightedMean = 0; 725 double weightedMeanX = 0; 726 double weightedMeanY = 0; 727 double weightedMeanZ = 0; 728 double weightedRms = 0; 729 double weightedRmsX = 0; 730 double weightedRmsY = 0; 731 double weightedRmsZ = 0; 732 double rms = 0; 733 734 // Required : 735 if(!_elem->attribute_value(s_entries(),svalue)) { 736 a_out << "tools::xml::aidas::read_bins :" 737 << " a <bin1d> has no " << "entries" 738 << " attribute." 739 << std::endl; 740 return false; 741 } 742 if(!to<unsigned int>(svalue,entries)) { 743 a_out << "tools::xml::aidas::read_bins :" 744 << " problem converting a entries attribute to an unsigned int." 745 << " Value was " << sout(svalue) << "." 746 << std::endl; 747 return false; 748 } 749 750 // Optional : 751 bool height_given; 752 if(_elem->attribute_value(s_height(),svalue)) { //FIXME : optional ? 753 if(!to_double(svalue,height,a_out,s_height())) return false; 754 height_given = true; 755 } else { // no "height". 756 // It is assumed that at fill time the weight 757 // argument "w" had always been 1. 758 // w = 1 759 // sw = entries*1 = entries 760 height = double(entries); 761 height_given = false; 762 } 763 764 if(_elem->attribute_value(s_error(),svalue)) { //FIXME : optional ? 765 if(!to_double(svalue,error,a_out,s_error())) return false; 766 } else { // no "error" 767 if(height_given) { 768 // then we are going to have : 769 // sw = height 770 // error = ? 771 // We can assume that at fill time the same weight "w" 772 // had been given to all entries. Then : 773 // sw = entries*w = height 774 // w = height/entries; 775 // sw2 = entries*(w*w) = (height**2)/entries 776 // error = sqrt(sw2) = sqrt((height**2)/entries) 777 if(entries) { 778 error = ::sqrt(::fabs( ((height*height)/entries) )); 779 } 780 } else { 781 // It is assumed that at fill time the weight 782 // argument "w" had always been 1. 783 // w = 1 784 // sw2 = entries*(w*w) = entries; 785 // error = sqrt(sw2) = sqrt(entries); 786 error = ::sqrt(::fabs(double(entries))); 787 } 788 } 789 790 if(_elem->attribute_value(s_rms(),svalue)) { 791 if(!to_double(svalue,rms,a_out,s_rms())) return false; 792 } 793 794 if(dimension==1) { 795 if(_elem->attribute_value(s_weightedMean(),svalue)) { 796 if(!to_double(svalue,weightedMean,a_out,s_weightedMean())) return false; 797 } 798 if(_elem->attribute_value(s_weightedRms(),svalue)) { 799 if(!to_double(svalue,weightedRms,a_out,s_weightedRms())) return false; 800 } 801 } else if(dimension==2) { 802 if(_elem->attribute_value(s_weightedMeanX(),svalue)) { 803 if(!to_double(svalue,weightedMeanX,a_out,s_weightedMeanX())) return false; 804 } 805 if(_elem->attribute_value(s_weightedMeanY(),svalue)) { 806 if(!to_double(svalue,weightedMeanY,a_out,s_weightedMeanY())) return false; 807 } 808 if(_elem->attribute_value(s_weightedRmsX(),svalue)) { 809 if(!to_double(svalue,weightedRmsX,a_out,s_weightedRmsX())) return false; 810 } 811 if(_elem->attribute_value(s_weightedRmsY(),svalue)) { 812 if(!to_double(svalue,weightedRmsY,a_out,s_weightedRmsY())) return false; 813 } 814 } else if(dimension==3) { 815 if(_elem->attribute_value(s_weightedMeanX(),svalue)) { 816 if(!to_double(svalue,weightedMeanX,a_out,s_weightedMeanX())) return false; 817 } 818 if(_elem->attribute_value(s_weightedMeanY(),svalue)) { 819 if(!to_double(svalue,weightedMeanY,a_out,s_weightedMeanY())) return false; 820 } 821 if(_elem->attribute_value(s_weightedMeanZ(),svalue)) { 822 if(!to_double(svalue,weightedMeanZ,a_out,s_weightedMeanZ())) return false; 823 } 824 if(_elem->attribute_value(s_weightedRmsX(),svalue)) { 825 if(!to_double(svalue,weightedRmsX,a_out,s_weightedRmsX())) return false; 826 } 827 if(_elem->attribute_value(s_weightedRmsY(),svalue)) { 828 if(!to_double(svalue,weightedRmsY,a_out,s_weightedRmsY())) return false; 829 } 830 if(_elem->attribute_value(s_weightedRmsZ(),svalue)) { 831 if(!to_double(svalue,weightedRmsZ,a_out,s_weightedRmsZ())) return false; 832 } 833 } 834 835 {for(unsigned int index=0;index<dimension;index++) { 836 std::string _s = "binNum"; 837 if(dimension!=1) { 838 if(index==0) _s += "X"; 839 else if(index==1) _s += "Y"; 840 else if(index==2) _s += "Z"; 841 } 842 if(!_elem->attribute_value(_s,svalue)) { 843 a_out << "tools::xml::aidas::read_bins :" 844 << " a <bin1d> has no " << _s << std::endl; 845 return false; 846 } 847 if(svalue=="UNDERFLOW") { 848 is[index] = histo::axis_UNDERFLOW_BIN; 849 } else if(svalue=="OVERFLOW") { 850 is[index] = histo::axis_OVERFLOW_BIN; 851 } else { 852 int ival = 0; 853 if(!to<int>(svalue,ival)) { 854 a_out << "tools::xml::aidas::read_bins :" 855 << " problem converting binNum to an int." 856 << " Value was " << sout(svalue) << "." 857 << std::endl; 858 return false; 859 } 860 int ibin = ival; 861 if( (ibin<0) || (ibin>=(int)aData.m_axes[index].bins()) ) { 862 a_out << "tools::xml::aidas::read_bins :" 863 << " a binNum is out of range." 864 << std::endl; 865 return false; 866 } 867 is[index] = ibin; 868 } 869 }} 870 871 // If we are here, then we have a valid bin : 872 bn_t offset; 873 histo::get_offset(aData.m_axes,is,offset); 874 aData.m_bin_entries[offset] = entries; 875 876 if(!a_is_prof) { 877 878 // From histo::base_histo, we have : 879 // height = sw 880 // error = sqrt(sw) 881 // weightedMean = sxw/sw 882 // weightedRms = sqrt(fabs(sx2w/sw - (sxw/sw)**2)) 883 884 double sw = height; 885 aData.m_bin_Sw[offset] = sw; 886 aData.m_bin_Sw2[offset] = error * error; 887 if(dimension==1) { 888 aData.m_bin_Sxw[offset][0] = weightedMean * sw; 889 aData.m_bin_Sx2w[offset][0] = 890 (weightedRms * weightedRms + weightedMean * weightedMean) * sw; 891 } else if(dimension==2){ 892 // X 893 aData.m_bin_Sxw[offset][0] = weightedMeanX * sw; 894 aData.m_bin_Sx2w[offset][0] = 895 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw; 896 // Y : 897 aData.m_bin_Sxw[offset][1] = weightedMeanY * sw; 898 aData.m_bin_Sx2w[offset][1] = 899 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw; 900 } else if(dimension==3){ 901 // X 902 aData.m_bin_Sxw[offset][0] = weightedMeanX * sw; 903 aData.m_bin_Sx2w[offset][0] = 904 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw; 905 // Y : 906 aData.m_bin_Sxw[offset][1] = weightedMeanY * sw; 907 aData.m_bin_Sx2w[offset][1] = 908 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw; 909 // Z : 910 aData.m_bin_Sxw[offset][2] = weightedMeanZ * sw; 911 aData.m_bin_Sx2w[offset][2] = 912 (weightedRmsZ*weightedRmsZ + weightedMeanZ*weightedMeanZ) * sw; 913 } 914 915 } else { // Profile : 916 917 // bin writing is : 918 // " height=" << sout(aObj.bin_height(aIndex)) 919 // " error=" << sout(aObj.bin_error(aIndex)) 920 // " weightedMean=" << sout(aObj.bin_mean(aIndex)) 921 // " rms=" << sout(aObj.bin_rms_value(aIndex)) 922 // " weightedRms=" << sout(bin_rms(aIndex)); 923 924 // From inlib profile, we have : 925 // height = svw / sw 926 // error = sqrt(fabs(sv2w/sw - (svw/sw)**2))/sqrt(sw) 927 // rms = sqrt(fabs(sv2w/sw - (svw/sw)**2)) 928 // weightedMean = sxw/sw 929 // weightedRms = sqrt(fabs(sx2w/sw - (sxw/sw)**2)) 930 931 // Then : 932 // sw = (rms/error)**2 933 // svw = sw * height 934 // sv2w = sw * (rms**2 + height**2) 935 // sxw = weightedMean * sw 936 // sx2w = (weightedRms*weightedRms+weightedMean*weightedMean) * sw; 937 938 double sw = 0; 939 if(error==0) { 940 // sv2w/sw = (svw/sw)**2 941 // h = svw/sw 942 //FIXME : we lack an info to get sw. 943 // We assume that at fill time weight==1 then : 944 // sw == n 945 sw = (double)entries; 946 } else { 947 double r_e = rms/error; 948 sw = r_e * r_e; 949 } 950 aData.m_bin_Sw[offset] = sw; 951 aData.m_bin_Sw2[offset] = 0; //FIXME 952 if(dimension==1) { 953 aData.m_bin_Sxw[offset][0] = weightedMean * sw; 954 aData.m_bin_Sx2w[offset][0] = 955 (weightedRms * weightedRms + weightedMean * weightedMean) * sw; 956 } else if(dimension==2){ 957 aData.m_bin_Sxw[offset][0] = weightedMeanX * sw; 958 aData.m_bin_Sxw[offset][1] = weightedMeanY * sw; 959 aData.m_bin_Sx2w[offset][0] = 960 (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw; 961 aData.m_bin_Sx2w[offset][1] = 962 (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw; 963 } 964 aData.m_bin_Svw[offset] = sw * height; 965 aData.m_bin_Sv2w[offset] = sw * (rms * rms + height * height); 966 967 } 968 } 969 }} 970 971 return true; 972 } 973 974 return false; 975 } 976 977 static bool axis_index(unsigned int a_dim,const std::string& a_axis,int& a_index) { 978 if(a_dim==1) { 979 if(a_axis=="x") {a_index = 0;return true;} 980 } else if(a_dim==2) { 981 if(a_axis=="x") {a_index = 0;return true;} 982 else if(a_axis=="y") {a_index = 1;return true;} 983 } else if(a_dim==3) { 984 if(a_axis=="x") {a_index = 0;return true;} 985 else if(a_axis=="y") {a_index = 1;return true;} 986 else if(a_axis=="z") {a_index = 2;return true;} 987 } 988 return false; 989 } 990 991 /////////////////////////////////////////////////////////////// 992 /// read ntuple /////////////////////////////////////////////// 993 /////////////////////////////////////////////////////////////// 994 class colbook { 995 public: 996 colbook(const std::string& a_type, 997 const std::string& a_name, 998 const std::string& a_s, 999 bool a_ntu) 1000 :m_type(a_type),m_name(a_name),m_def_or_bkg(a_s),m_ntu(a_ntu){} 1001 public: 1002 colbook(const colbook& a_from) 1003 :m_type(a_from.m_type) 1004 ,m_name(a_from.m_name) 1005 ,m_def_or_bkg(a_from.m_def_or_bkg) 1006 ,m_ntu(a_from.m_ntu) 1007 {} 1008 1009 colbook& operator=(const colbook& a_from){ 1010 if(&a_from==this) return *this; 1011 m_type = a_from.m_type; 1012 m_name = a_from.m_name; 1013 m_def_or_bkg = a_from.m_def_or_bkg; 1014 m_ntu = a_from.m_ntu; 1015 return *this; 1016 } 1017 public: 1018 const std::string& type() const {return m_type;} 1019 const std::string& name() const {return m_name;} 1020 const std::string& def_or_bkg() const {return m_def_or_bkg;} 1021 bool is_ntu() const {return m_ntu;} 1022 protected: 1023 std::string m_type; 1024 std::string m_name; 1025 std::string m_def_or_bkg; 1026 bool m_ntu; 1027 }; 1028 1029 static bool read_ntu_columns(tree& a_tree, 1030 bool& a_found, 1031 std::vector<colbook>& a_booking, 1032 std::ostream& a_out){ 1033 a_found = false; 1034 a_booking.clear(); 1035 1036 const std::string& tag_name = a_tree.tag_name(); 1037 1038 if(tag_name=="columns") { 1039 1040 {looper _for(a_tree); 1041 while(element* _elem = _for.next_element()) { 1042 1043 if(_elem->name()=="column") { 1044 std::string stype; 1045 if(!_elem->attribute_value(s_type(),stype)) { 1046 a_out << "tools::xml::aidas::read_ntu_columns :" 1047 << " atb type missing on <column>" 1048 << std::endl; 1049 return false; 1050 } 1051 std::string sname; 1052 if(!_elem->attribute_value(s_name(),sname)) { 1053 a_out << "tools::xml::aidas::read_ntu_columns :" 1054 << " atb name missing on <column>" 1055 << std::endl; 1056 return false; 1057 } 1058 1059 std::string _s; 1060 if(_elem->attribute_value(s_booking(),_s)) { 1061 a_booking.push_back(colbook(stype,sname,_s,true)); 1062 } else if(_elem->attribute_value(s_default(),_s)) { 1063 a_booking.push_back(colbook(stype,sname,_s,false)); 1064 } else { 1065 a_booking.push_back(colbook(stype,sname,"",false)); 1066 } 1067 } 1068 1069 }} 1070 1071 a_found = true; 1072 } 1073 return true; 1074 } 1075 1076 static bool read_ntu_rows(tree& a_tree, 1077 aida::base_ntu& a_ntu, 1078 bool& a_found, 1079 std::ostream& a_out){ 1080 a_found = false; 1081 1082 const std::string& tag_name = a_tree.tag_name(); 1083 1084 if(tag_name==s_annotation()) { //FIXME 1085 1086 return true; 1087 1088 } else if(tag_name==s_columns()) { 1089 1090 return true; 1091 1092 } else if(tag_name==s_rows()) { 1093 1094 // Sub items : 1095 {looper _for(a_tree); 1096 while(tree* _tree = _for.next_tree()) { 1097 1098 if(!read_ntu_rows(*_tree,a_ntu,a_found,a_out)) { 1099 a_out << "tools::xml::aidas::read_ntu_rows :" 1100 << " sub read_ntu_rows failed." 1101 << std::endl; 1102 return false; 1103 } 1104 1105 }} 1106 1107 a_found = true; 1108 1109 return true; 1110 1111 } else if(tag_name==s_row()) { 1112 1113 const std::vector<aida::base_col*>& cols = a_ntu.columns(); 1114 1115 std::vector<unsigned int> intus; 1116 std::vector<unsigned int> inot_ntus; 1117 {unsigned int index = 0; 1118 tools_vforcit(aida::base_col*,cols,it) { 1119 if(safe_cast<aida::base_col,aida::aida_col_ntu>(*(*it))) { 1120 intus.push_back(index); 1121 } else { 1122 inot_ntus.push_back(index); 1123 } 1124 index++; 1125 }} 1126 1127 std::string svalue; 1128 1129 {unsigned int icol = 0; 1130 1131 {looper _for(a_tree); 1132 while(element* _elem = _for.next_element()) { 1133 1134 if(_elem->name()==s_entry()) { 1135 if(!_elem->attribute_value(s_value(),svalue)) { 1136 a_out << "tools::xml::aidas::read_ntu_rows :" 1137 << " can't get \"value\" attribute." << std::endl; 1138 return false; 1139 } 1140 if(icol>=inot_ntus.size()) { 1141 a_out << "tools::xml::aidas::read_ntu_rows :" 1142 << " too much <entry>." << std::endl; 1143 return false; 1144 } 1145 if(inot_ntus[icol]>=cols.size()) { 1146 a_out << "tools::xml::aidas::read_ntu_rows :" 1147 << " too much <entry>." << std::endl; 1148 return false; 1149 } 1150 1151 aida::base_col* bcol = cols[inot_ntus[icol]]; 1152 1153 aida::aida_base_col* abcol = 1154 safe_cast<aida::base_col,aida::aida_base_col>(*bcol); 1155 1156 if(!abcol->s_fill(svalue)) { 1157 a_out << "tools::xml::aidas::read_ntu_rows :" 1158 << " can't get \"value\" attribute." << std::endl; 1159 return false; 1160 } 1161 icol++; 1162 } 1163 1164 }}} 1165 1166 // Sub items (entryITuple) : 1167 {unsigned int icol = 0; 1168 1169 {looper _for(a_tree); 1170 while(tree* _tree = _for.next_tree()) { 1171 1172 const std::string& _tag_name = _tree->tag_name(); 1173 if( (_tag_name==s_entryITuple()) || //aida.dtd spec. 1174 (_tag_name==s_entryTuple()) ){ //backward comp. 1175 if(icol>=intus.size()) { 1176 a_out << "tools::xml::aidas::read_ntu_rows :" 1177 << " too much <entry>." << std::endl; 1178 return false; 1179 } 1180 if(intus[icol]>=cols.size()) { 1181 a_out << "tools::xml::aidas::read_ntu_rows :" 1182 << " too much <entry>." << std::endl; 1183 return false; 1184 } 1185 1186 aida::base_col* bcol = cols[intus[icol]]; 1187 aida::aida_col_ntu* col_ntu = safe_cast<aida::base_col,aida::aida_col_ntu>(*bcol); 1188 if(!col_ntu) { 1189 a_out << "tools::xml::aidas::read_ntu_rows :" 1190 << " can't cast to bcol_ntu." 1191 << std::endl; 1192 return false; 1193 } 1194 aida::base_ntu* ntu = col_ntu->get_to_fill(); 1195 if(!ntu) { 1196 a_out << "tools::xml::aidas::read_ntu_rows :" 1197 << " get_to_fill() returned null." 1198 << std::endl; 1199 return false; 1200 } 1201 1202 {looper _for2(*_tree); 1203 while(tree* _tree2 = _for2.next_tree()) { 1204 bool found; 1205 if(!read_ntu_rows(*_tree2,*ntu,found,a_out)) return false; 1206 }} 1207 1208 icol++; 1209 } 1210 1211 }}} 1212 1213 if(!a_ntu.add_row()) { 1214 a_out << "tools::xml::aidas::read_ntu_rows :" 1215 << " can't add row to ntuple." 1216 << std::endl; 1217 return false; 1218 } 1219 1220 return true; 1221 1222 } 1223 1224 a_out << "tools::xml::aidas::read_ntu_rows :" 1225 << " unknown item class " << sout(tag_name) << std::endl; 1226 1227 return false; 1228 } 1229 1230 static raxml_out read_ntu(tree& a_tree,std::ostream& a_out,bool a_verbose,void*){ 1231 std::string sname; 1232 a_tree.attribute_value(s_name(),sname); 1233 1234 if(a_verbose) { 1235 a_out << "tools::xml::aidas::read_ntu :" 1236 << " with name " << sout(sname) 1237 << "..." << std::endl; 1238 } 1239 1240 std::string spath; 1241 a_tree.attribute_value(s_path(),spath); 1242 1243 std::string stitle; 1244 a_tree.attribute_value(s_title(),stitle); 1245 1246 //FIXME annotation 1247 1248 // Booking parameters : 1249 std::vector<colbook> booking; 1250 1251 // Jump in subitems to find columns items : 1252 bool found = false; 1253 1254 {looper _for(a_tree); 1255 while(tree* _tree = _for.next_tree()) { 1256 if(!read_ntu_columns(*_tree,found,booking,a_out)) return raxml_out(); 1257 if(found) break; 1258 }} 1259 1260 if(!found) { 1261 a_out << "tools::xml::aidas::read_ntu :" 1262 << " for ntuple name " << sout(sname) 1263 << " unable to read columns..." << std::endl; 1264 return raxml_out(); 1265 } 1266 1267 // Create a aida::ntuple : 1268 aida::ntuple* ntu = new aida::ntuple(a_out,stitle); 1269 {tools_vforcit(colbook,booking,it) { 1270 if(!aida::create_col(*ntu, 1271 (*it).type(), 1272 (*it).name(), 1273 (*it).def_or_bkg(), 1274 (*it).is_ntu())){ 1275 delete ntu; 1276 return raxml_out(); 1277 } 1278 }} 1279 1280 if(!ntu->columns().size()) { //??? we could have an empty ntu ! 1281 a_out << "tools::xml::aidas::read_ntu :" 1282 << " for ntuple name " << sout(sname) 1283 << " unable to create a aida::ntuple." << std::endl; 1284 delete ntu; 1285 return raxml_out(); 1286 } 1287 1288 // Get rows in sub items : 1289 found = false; 1290 1291 {looper _for(a_tree); 1292 while(tree* _tree = _for.next_tree()) { 1293 1294 if(!read_ntu_rows(*_tree,*ntu,found,a_out)) { 1295 a_out << "tools::xml::aidas::read_ntu :" 1296 << " for ntuple name " << sout(sname) 1297 << " unable to read rows." << std::endl; 1298 delete ntu; 1299 return raxml_out(); 1300 } 1301 if(found) break; 1302 1303 }} 1304 1305 if(a_verbose) { 1306 a_out << "tools::xml::aidas::read_ntu :" 1307 << " name " << sout(sname) 1308 << " done." << std::endl; 1309 } 1310 1311 std::string sclass = aida::ntuple::s_class(); 1312 return raxml_out(new handle<aida::ntuple>(ntu),sclass,spath,sname); 1313 } 1314 1315 /////////////////////////////////////////////////////////////// 1316 /// read cloud //////////////////////////////////////////////// 1317 /////////////////////////////////////////////////////////////// 1318 1319 static bool read_cloud_data(tree& a_tree, 1320 histo::c1d& aCloud,bool a_verbose, 1321 std::ostream& a_out){ 1322 const std::string& tagName = a_tree.tag_name(); 1323 1324 std::string svalue; 1325 1326 if(tagName==s_annotation()) { //FIXME 1327 1328 return true; 1329 1330 } else if(tagName==s_entries1d()) { 1331 1332 {looper _for(a_tree); 1333 while(element* _elem = _for.next_element()) { 1334 if(_elem->name()==s_entry1d()) { 1335 double x; 1336 if(!_elem->attribute_value(s_valueX(),x)) return false; 1337 double w = 1; 1338 if(_elem->attribute_value(s_weight(),svalue)) { 1339 if(!to<double>(svalue,w)) return false; 1340 } 1341 if(!aCloud.fill(x,w)) return false; 1342 } 1343 }} 1344 return true; 1345 1346 } else if(tagName==s_histogram1d()) { 1347 1348 raxml_out ro = read_h1d(a_tree,a_out,a_verbose,0); 1349 if(ro.cls()==histo::h1d::s_class()) { 1350 histo::h1d* h = (histo::h1d*)ro.object(); 1351 if(h) { 1352 aCloud.set_histogram(h); 1353 ro.disown(); 1354 } 1355 } 1356 return true; 1357 1358 } 1359 1360 return false; 1361 } 1362 1363 static bool read_cloud_data(tree& a_tree, 1364 histo::c2d& aCloud, 1365 bool a_verbose, 1366 std::ostream& a_out){ 1367 const std::string& tagName = a_tree.tag_name(); 1368 1369 std::string svalue; 1370 1371 if(tagName==s_annotation()) { //FIXME 1372 1373 return true; 1374 1375 } else if(tagName==s_entries2d()) { 1376 1377 {looper _for(a_tree); 1378 while(element* _elem = _for.next_element()) { 1379 if(_elem->name()==s_entry2d()) { 1380 double x; 1381 if(!_elem->attribute_value(s_valueX(),x)) return false; 1382 double y; 1383 if(!_elem->attribute_value(s_valueY(),y)) return false; 1384 double w = 1; 1385 if(_elem->attribute_value(s_weight(),svalue)) { 1386 if(!to<double>(svalue,w)) return false; 1387 } 1388 if(!aCloud.fill(x,y,w)) return false; 1389 } 1390 }} 1391 return true; 1392 1393 } else if(tagName==s_histogram2d()) { 1394 1395 raxml_out ro = read_h2d(a_tree,a_out,a_verbose,0); 1396 if(ro.cls()==histo::h2d::s_class()) { 1397 histo::h2d* h = (histo::h2d*)ro.object(); 1398 if(h) { 1399 aCloud.set_histogram(h); 1400 ro.disown(); 1401 } 1402 } 1403 return true; 1404 1405 } 1406 1407 return false; 1408 } 1409 1410 static bool read_cloud_data(tree& a_tree, 1411 histo::c3d& aCloud, 1412 bool a_verbose, 1413 std::ostream& a_out){ 1414 const std::string& tagName = a_tree.tag_name(); 1415 1416 std::string svalue; 1417 1418 if(tagName==s_annotation()) { //FIXME 1419 1420 return true; 1421 1422 } else if(tagName==s_entries3d()) { 1423 1424 {looper _for(a_tree); 1425 while(element* _elem = _for.next_element()) { 1426 if(_elem->name()==s_entry3d()) { 1427 double x; 1428 if(!_elem->attribute_value(s_valueX(),x)) return false; 1429 double y; 1430 if(!_elem->attribute_value(s_valueY(),y)) return false; 1431 double z; 1432 if(!_elem->attribute_value(s_valueZ(),z)) return false; 1433 double w = 1; 1434 if(_elem->attribute_value(s_weight(),svalue)) { 1435 if(!to<double>(svalue,w)) return false; 1436 } 1437 if(!aCloud.fill(x,y,z,w)) return false; 1438 } 1439 }} 1440 return true; 1441 1442 } else if(tagName==s_histogram3d()) { 1443 1444 raxml_out ro = read_h3d(a_tree,a_out,a_verbose,0); 1445 if(ro.cls()==histo::h3d::s_class()) { 1446 histo::h3d* h = (histo::h3d*)ro.object(); 1447 if(h) { 1448 aCloud.set_histogram(h); 1449 ro.disown(); 1450 } 1451 } 1452 return true; 1453 1454 } 1455 1456 return false; 1457 } 1458 1459 static bool read_dps_data(tree& a_tree,histo::dps& a_dps){ 1460 const std::string& tagName = a_tree.tag_name(); 1461 1462 std::string svalue; 1463 1464 if(tagName==s_annotation()) { //FIXME 1465 1466 return true; 1467 1468 } else if(tagName==s_dataPoint()) { 1469 1470 histo::data_point& point = a_dps.add_point(); 1471 1472 unsigned int coord = 0; 1473 1474 {looper _for(a_tree); 1475 while(element* _elem = _for.next_element()) { 1476 if(_elem->name()==s_measurement()) { 1477 if(coord>=a_dps.dimension()) return false; 1478 double value; 1479 if(!_elem->attribute_value(s_value(),value)) return false; 1480 double errorPlus = 0; 1481 if(_elem->attribute_value(s_errorPlus(),svalue)) { 1482 if(!to<double>(svalue,errorPlus)) return false; 1483 } 1484 double errorMinus = 0; 1485 if(_elem->attribute_value(s_errorMinus(),svalue)) { 1486 if(!to<double>(svalue,errorMinus)) return false; 1487 } 1488 1489 histo::measurement& _m = point.coordinate(coord); 1490 _m.set_value(value); 1491 _m.set_error_plus(errorPlus); 1492 _m.set_error_minus(errorMinus); 1493 1494 coord++; 1495 } 1496 }} 1497 return true; 1498 1499 } 1500 1501 return false; 1502 } 1503 1504 1505 protected: 1506 readers m_readers; 1507 std::vector<raxml_out> m_objects; 1508 }; 1509 1510 }} 1511 1512 #endif