- Timestamp:
- 04/18/17 17:05:49 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r18602 r18836 20 20 21 21 #ifdef HAVE_ROOT 22 #include "TFile.h" 23 #include "TTree.h" 22 24 #include "TFormula.h" 23 25 #endif … … 85 87 86 88 ///Display the selected columns values VS time 87 void Dump(ostream &, const vector<string> &, const vector<MyColumn> &, const string &, size_t, size_t, const string&);89 int Dump(ostream &, const vector<string> &, const vector<MyColumn> &, const string &, size_t, size_t, const string &, Configuration &); 88 90 void DumpRoot(ostream &, const vector<string> &, const string &, size_t, size_t, const string &); 89 91 void DumpMinMax(ostream &, const vector<MyColumn> &, size_t, size_t, bool); … … 409 411 // 410 412 #ifdef HAVE_ROOT 411 void FitsDumper::Dump(ostream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit, const string &filename)413 int FitsDumper::Dump(ostream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit, const string &filename, Configuration &conf) 412 414 #else 413 void FitsDumper::Dump(ostream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &, size_t first, size_t limit, const string &filename)415 int FitsDumper::Dump(ostream &fout, const vector<string> &format, const vector<MyColumn> &cols, const string &, size_t first, size_t limit, const string &filename, Configuration &) 414 416 #endif 415 417 { … … 438 440 fout << "#\n"; 439 441 442 #ifdef HAVE_ROOT 443 const bool rootfile = filename.rfind(".root")==filename.size()-5; 444 445 TFile *tfile = 0; 446 if (rootfile) 447 { 448 tfile = new TFile(filename.c_str(), conf.Get<bool>("update")?"UPDATE":(conf.Get<bool>("overwrite")?"RECREATE":"CREATE"), fFilename.c_str(), conf.Get<bool>("force")); 449 if (tfile->IsZombie()) 450 { 451 cerr << "Could not open root file '" << rootfile << "'" << endl; 452 return -2; 453 } 454 } 455 456 // FIXME: Add header values 457 TTree *ttree = tfile ? new TTree(fKeyMap.find("EXTNAME")->second.value.c_str(), Tools::Form("From N=%d [cnt=%d] {filter=%s}", first, limit, filter.c_str()).c_str()) : 0; 458 #endif 459 440 460 size_t num = 0; 441 461 for (auto it=cols.begin(); it!=cols.end(); it++) … … 460 480 461 481 // ----------------------------------------------------------------- 482 483 #ifdef HAVE_ROOT 484 if (ttree) 485 { 486 fout << "## --------------------------------------------------------------------------\n"; 487 488 fout << "#\n"; 489 fout << "# Tree: " << fKeyMap.find("EXTNAME")->second.value << "\n"; 490 fout << "#\n"; 491 492 for (auto it=cols.begin(); it!=cols.end(); it++) 493 { 494 const string branch = it->name+"["+to_string(it->last-it->first+1)+"]"; 495 496 fout << "# Branch: " << branch << "\n"; 497 498 switch (it->col.type) 499 { 500 case 'B': 501 ttree->Branch(branch.c_str(), reinterpret_cast<unsigned char*>(it->ptr)+it->first); 502 break; 503 case 'L': 504 ttree->Branch(branch.c_str(), reinterpret_cast<bool*>(it->ptr)+it->first); 505 break; 506 case 'I': 507 ttree->Branch(branch.c_str(), reinterpret_cast<int16_t*>(it->ptr)+it->first); 508 break; 509 case 'J': 510 ttree->Branch(branch.c_str(), reinterpret_cast<int32_t*>(it->ptr)+it->first); 511 break; 512 case 'K': 513 ttree->Branch(branch.c_str(), reinterpret_cast<int64_t*>(it->ptr)+it->first); 514 break; 515 case 'E': 516 ttree->Branch(branch.c_str(), reinterpret_cast<float*>(it->ptr)+it->first); 517 break; 518 case 'D': 519 ttree->Branch(branch.c_str(), reinterpret_cast<double*>(it->ptr)+it->first); 520 break; 521 default: 522 ; 523 } 524 } 525 526 fout << "#\n"; 527 fout << "## --------------------------------------------------------------------------\n"; 528 } 529 #endif 530 531 532 // ----------------------------------------------------------------- 533 534 462 535 463 536 #ifdef HAVE_ROOT … … 535 608 if (!filter.empty() && select.EvalPar(0, data.data())<0.5) 536 609 continue; 537 #endif 610 611 if (ttree) 612 { 613 ttree->Fill(); 614 continue; 615 } 616 #endif 617 538 618 fout << sout.str() << endl; 539 619 } 620 621 #ifdef HAVE_ROOT 622 if (tfile) 623 { 624 fout << "#\n"; 625 fout << "# " << ttree->GetEntries() << " rows filled into tree.\n"; 626 fout << "#\n"; 627 fout << "## --------------------------------------------------------------------------\n"; 628 fout << endl; 629 630 ttree->Write(); 631 delete tfile; 632 } 633 #endif 634 635 return 0; 540 636 } 541 637 … … 729 825 #endif 730 826 } 827 731 828 732 829 void FitsDumper::DumpMinMax(ostream &fout, const vector<MyColumn> &cols, size_t first, size_t limit, bool fNoZeroPlease) … … 958 1055 int FitsDumper::Exec(Configuration& conf) 959 1056 { 1057 if (conf.Get<bool>("autocal")) 1058 resetCalibration(); 1059 960 1060 if (conf.Get<bool>("list")) 961 1061 List(); … … 1003 1103 1004 1104 ofstream sout; 1005 if (filename!="-" )1105 if (filename!="-" && filename.rfind(".root")!=filename.length()-5) 1006 1106 { 1007 1107 sout.open(filename); … … 1061 1161 } 1062 1162 1063 Dump(fout, format, cols, filter, first, limit, filename); 1064 1065 return 0; 1163 return Dump(fout, format, cols, filter, first, limit, filename, conf); 1066 1164 } 1067 1165 … … 1123 1221 "\n" 1124 1222 " fitsdump col1 -%h\n" 1223 "\n" 1224 "To convert a fits table to a root file, use --outfile, for example\n\n" 1225 " fitsdump --outfile outfile.root [--compression N] [--overwrite|--update]\n\n" 1226 "Note that this option can not be combined with the root mode (--root). " 1227 "According to the FITS standard, all columns (except bytes) are written as " 1228 "signed values.\n" 1125 1229 "\n"; 1126 1230 cout << endl; … … 1154 1258 ("limit", var<size_t>(size_t(0)), "Limit for the maximum number of rows to read (0=unlimited)") 1155 1259 ("tablename,t", var<string>(""), "Name of the table to open. If not specified, first binary table is opened") 1260 ("autocal", po_switch(), "This option can be used to skip the application of the noise calibration when reading back a compressed fits file. This is identical in using zfits instead of factfits.") 1156 1261 #ifdef HAVE_ROOT 1157 1262 ("root,r", po_switch(), "Enable root mode") 1158 1263 ("filter,f", var<string>(""), "Filter to restrict the selection of events (e.g. '[0]>10 && [0]<20'; does not work with stat and minmax yet)") 1264 ("overwrite", po_switch(), "Force overwriting an existing root file ('RECREATE')") 1265 ("update", po_switch(), "Update an existing root file with the new tree ('UPDATE')") 1266 ("compression", var<uint16_t>(1), "zlib compression level for the root file") 1159 1267 #endif 1160 1268 ;
Note:
See TracChangeset
for help on using the changeset viewer.