Changeset 19809 for trunk/FACT++
- Timestamp:
- 10/27/19 16:44:59 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/root2csv.cc
r19806 r19809 42 42 //("const.*", var<string>(), "Insert a constant number into the given column (--const.mycolumn=5). A special case is `/.../.../`") 43 43 ("dry-run", po_switch(), "Do not create or manipulate any output file") 44 ("no-indirection", po_switch(), "Column of alias of alias need all auto-aliases to be enables. This is slow. If you know that you do not have any, use this for faster processing.") 44 45 ; 45 46 … … 124 125 "automatically allowing to access the columns in a formula with the new name.\n" 125 126 "\n" 127 "Note that in the default configuration, all data which is auto-alias'ed is read " 128 "from the file. This can become quite slow if there is a lot. An alternative is " 129 "to switch on no-indirections with --no-indirection. The ensures that only " 130 "references leaves are read, which can signiifcantly accelerate reading. " 131 "The disadvantage is that adding a column which reference an alias which " 132 "itself references an alias will fail.\n" 133 "\n" 126 134 "Sometimes it might also be convenient to skip a leaf, i.e. not writing the " 127 135 "coresponding column in the output file. This can be done with " … … 222 230 } 223 231 224 void GetLeaves( vector<string> &list, const TTreeFormula &f)232 void GetLeaves(set<string> &list, const TTreeFormula &f) 225 233 { 226 234 int i=0; … … 230 238 if (!l) 231 239 return; 232 list.emplace_back(l->GetName()); 240 241 list.emplace(l->GetName()); 233 242 } 234 243 } … … 257 266 const bool dryrun = conf.Get<bool>("dry-run"); 258 267 const bool skip = conf.Get<bool>("skip"); 268 const bool noindirect = conf.Get<bool>("no-indirection"); 259 269 260 270 const uint16_t verbose = conf.Get<uint16_t>("verbose"); … … 396 406 */ 397 407 408 set<string> leaflist; 409 398 410 // ------------------------- Setup all branches in tree ------------------- 399 411 … … 402 414 while ((o=Next())) 403 415 { 404 TLeaf *L = c.GetLeaf(o->GetName()); 416 TLeaf *L = dynamic_cast<TLeaf*>(o);//c.GetLeaf(o->GetName()); 417 if (!L) 418 continue; 405 419 406 420 string name = o->GetName(); 407 408 for (auto m=autoalias.cbegin(); m!=autoalias.cend(); m++)409 name = boost::regex_replace(name, boost::regex(m->first), m->second);410 411 if (name!=o->GetName())412 {413 if (verbose>0)414 cout << "Auto-alias: " << name << " = " << o->GetName() << endl;415 if (!c.SetAlias(name.c_str(), o->GetName()))416 cout << "WARNING - Alias could not be established!" << endl;417 }418 419 if (skip)420 continue;421 422 421 if (verbose>2) 423 422 cout << '\n' << L->GetTitle() << " {" << L->GetTypeName() << "}"; 424 423 424 const string tn = L->GetTypeName(); 425 426 // Check if this is a basic type, otherwise skip 427 const auto it = FileEntry::LUT.root(tn); 428 if (it==FileEntry::LUT.cend()) 429 { 430 if (verbose>2) 431 cout << " (-n/a-)"; 432 continue; 433 } 434 435 // Check if this is an array, otherwise skip 425 436 if (L->GetLenStatic()!=L->GetLen()) 426 437 { … … 430 441 } 431 442 432 bool found = false; 443 // Check for renaming via auto-alias 444 for (auto m=autoalias.cbegin(); m!=autoalias.cend(); m++) 445 name = boost::regex_replace(name, boost::regex(m->first), m->second); 446 447 // if renaming has changed name, define alias 448 if (name!=o->GetName()) 449 { 450 if (!c.SetAlias(name.c_str(), o->GetName())) 451 { 452 cerr << "\nERROR - Alias could not be established!\n"; 453 cerr << " " << name << " = " << o->GetName() << endl; 454 return 1; 455 } 456 if (verbose==1 || verbose==2) 457 cout << "\nAuto-alias: " << name << " = " << o->GetName(); 458 if (verbose>2) 459 cout << " <alias:" << name << ">"; 460 461 if (!noindirect) 462 leaflist.emplace(o->GetTitle()); 463 } 464 465 // Check whether the un-aliased column is in the ignore list 466 bool found = skip; 433 467 for (auto b=_ignore.cbegin(); b!=_ignore.cend(); b++) 434 468 { … … 441 475 } 442 476 } 477 478 // Check whether the aliased column is in the ignore list 443 479 for (auto b=_ignore.cbegin(); b!=_ignore.cend(); b++) 444 480 { … … 452 488 } 453 489 454 if (found) 455 continue; 456 457 const string tn = L->GetTypeName(); 458 459 const auto it = FileEntry::LUT.root(tn); 460 if (it==FileEntry::LUT.cend()) 461 { 462 if (verbose>2) 463 cout << " (-n/a-)"; 464 continue; 465 } 466 467 if (verbose==2) 468 cout << '\n' << L->GetTitle() << " {" << L->GetTypeName() << "}"; 469 470 if (verbose>1) 471 cout << " (" << name << ")"; 472 490 if (!found) 491 leaflist.emplace(o->GetTitle()); 492 493 // As it is easier, we setup addresses for all branches 494 // also for the ones not requested. They might later be 495 // requested by a formula. 473 496 vec.emplace_back(o->GetTitle(), name, it->type, L->GetLenStatic()); 474 497 c.SetBranchAddress(o->GetTitle(), vec.back().ptr); … … 477 500 if (verbose>0) 478 501 { 502 cout << '\n'; 479 503 if (skip) 480 504 cout << "Default columns skipped: "; 481 505 cout << vec.size() << " default leaf/leaves setup for reading." << endl; 482 506 } 483 484 507 485 508 // ------------------- Configure manual aliases ---------------------------- … … 498 521 if (!c.SetAlias(name.c_str(), val.c_str())) 499 522 { 500 cerr << "Alias could not be established!" << endl; 523 cerr << "\nERROR - Alias could not be established!\n"; 524 cerr << " " << name << " = " << val << endl; 501 525 return 2; 502 526 } … … 504 528 505 529 // -------------------------- Configure Selector -------------------------- 506 507 vector<string> leaflist;508 c.SetBranchStatus("*", 1);509 530 510 531 TTreeFormulaManager *manager = new TTreeFormulaManager; … … 554 575 cout << '\n' << formulas.size() << " additional columns setup for writing." << endl; 555 576 556 // --------------------- Setup all branches in formulas -------------------557 558 for (auto l=leaflist.cbegin(); l!=leaflist.cend(); l++)559 {560 // Branch address already set561 if (c.GetBranch(l->c_str())->GetAddress())562 continue;563 564 TLeaf *L = c.GetLeaf(l->c_str());565 566 if (verbose>2)567 cout << '\n' << L->GetTitle() << " {" << L->GetTypeName() << "}";568 569 if (L->GetLenStatic()!=L->GetLen())570 {571 if (verbose>2)572 cout << " (-skipped-)";573 continue;574 }575 576 const string tn = L->GetTypeName();577 578 const auto it = FileEntry::LUT.root(tn);579 if (it==FileEntry::LUT.cend())580 {581 if (verbose>2)582 cout << " (-n/a-)";583 continue;584 }585 586 if (verbose==2)587 cout << '\n' << L->GetTitle() << " {" << L->GetTypeName() << "}";588 589 if (verbose>1)590 cout << " (" << *l << ")";591 592 vec.emplace_back(l->c_str(), l->c_str(), it->type, L->GetLenStatic());593 c.SetBranchAddress(l->c_str(), vec.back().ptr);594 }595 if (verbose>1)596 cout << '\n';597 598 577 // ------------------------- Enable branch reading ------------------------ 599 578 600 579 UInt_t datatype = 0; 601 580 const bool has_datatype = c.SetBranchAddress("DataType.fVal", &datatype) >= 0; 581 if (has_datatype && verbose>0) 582 cout << "\nRows with DataType.fVal!=1 will be skipped." << endl; 583 602 584 603 585 // Seting up branch status (must be after all SetBranchAddress) 604 586 c.SetBranchStatus("*", 0); 605 for (auto v=vec.cbegin(); v!=vec.cend(); v++) 606 if (v->type!=FileEntry::kConst) 607 c.SetBranchStatus(v->branch.c_str(), 1); 608 609 if (has_datatype) 610 { 611 c.SetBranchStatus("DataType.fVal", 1); 612 if (verbose>0) 613 cout << "Rows with DataType.fVal!=1 will be skipped." << endl; 614 } 587 588 for (auto it=leaflist.cbegin(); it!=leaflist.cend(); it++) 589 { 590 c.SetBranchStatus(it->c_str(), 1); 591 if (verbose>2) 592 cout << "\nEnable Branch: " << *it; 593 } 594 if (verbose>2) 595 cout << endl; 596 597 /* 598 Next.Reset(); 599 while ((o=Next())) 600 { 601 const TLeaf *L = dynamic_cast<TLeaf*>(o);//c.GetLeaf(o->GetName()); 602 if (!L) 603 continue; 604 605 const TBranch *B = L->GetBranch(); 606 if (!B) 607 continue; 608 609 if (!B->GetAddress()) 610 continue; 611 612 c.SetBranchStatus(B->GetName(), 1); 613 if (verbose>2) 614 cout << "\nEnable Branch: " << B->GetName(); 615 } 616 if (verbose>2) 617 cout << endl; 618 */ 615 619 616 620 // -------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.