Changeset 19118 for trunk/FACT++/src/rootifysql.cc
- Timestamp:
- 08/01/18 08:25:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19117 r19118 35 35 ("ignore", vars<string>(), "Ignore the given columns") 36 36 ("display,d", po_switch(), "Displays contents on the screen (most usefull in combination with mysql statements as SHOW or EXPLAIN)") 37 ("write", var<string>(""), "Write output to an ascii file") 37 38 ("null,n", po_switch(), "Redirect the output file to /dev/null (mainly for debugging purposes, e.g. performance studies)") 38 39 ("no-fill", po_switch(), "Do not fill events into the root file (mainly for debugging purposes, e.g. performance studies)") … … 93 94 "$TEST or ${TEST} by '1, 2, 3'. This is useful for the SQL `IN` keyword. " 94 95 "You can also read the values for an enviroment substitution from a file " 95 "(one element per line), e.g. --env.TEST=file.txt\n" 96 "(one element per line), e.g. --env.TEST=file.txt. Lines starting with a # " 97 "are skipped.\n" 96 98 "\n" 97 99 "Comments in the query-file can be placed according to the SQL standard inline " … … 373 375 const bool update = conf.Get<bool>("update"); 374 376 const bool display = conf.Get<bool>("display"); 377 const string write = conf.Get<string>("write"); 375 378 const bool noout = conf.Get<bool>("null"); 376 379 const bool nofill = conf.Get<bool>("no-fill"); … … 420 423 421 424 map<string, vector<string>> envs; 425 422 426 for (const auto &env : conf.GetWildcardOptions("env.*")) 423 envs .emplace(env.substr(4), conf.Vec<string>(env));427 envs[env.substr(4)] = conf.Vec<string>(env); 424 428 425 429 for (const auto &env : conf.GetWildcardOptions("list.*")) 426 430 { 427 const string fname = conf.Get<string>(env); 431 const string fname = conf.Get<string>(env); 432 const string &ident = env.substr(5); 428 433 429 434 ifstream fin(fname); 430 435 if (!fin) 431 436 { 432 cerr << "Could not open environment in '" << fname << "' : " << strerror(errno) << endl;437 cerr << "Could not open environment in '" << fname << "' for ${" << ident << "}: " << strerror(errno) << endl; 433 438 return 3; 434 439 } 435 440 436 const string &ident = env.substr(5);437 438 string repl;439 441 for (string line; getline(fin, line); ) 440 envs[ident].push_back(line); 442 if (Tools::Trim(line)[0]!='#') 443 envs[ident].push_back(line); 444 445 if (verbose>0) 446 cout << "Found " << envs[ident].size() << " list element(s) for ${" << ident << "}" << endl; 441 447 } 442 448 443 449 for (const auto &env : envs) 444 450 { 445 regex rexpr("\\$ \\{"+env.first+"\\}|\\$"+env.first+"\\b");451 regex rexpr("\\$(\\{"+env.first+"\\}|"+env.first+"\\b)"); 446 452 query = regex_replace(query, rexpr, boost::join(env.second, ", ")); 447 453 } … … 460 466 { 461 467 FileStat_t stat; 462 const Int_t exist = !gSystem->GetPathInfo(path, stat);463 const Bool_t write = !gSystem->AccessPathName(path, kWritePermission) && R_ISREG(stat.fMode);464 465 if ((update && !exist) || (update && exist && ! write) || (force && exist && !write))468 const Int_t exist = !gSystem->GetPathInfo(path, stat); 469 const Bool_t _write = !gSystem->AccessPathName(path, kWritePermission) && R_ISREG(stat.fMode); 470 471 if ((update && !exist) || (update && exist && !_write) || (force && exist && !_write)) 466 472 { 467 473 cerr << "File '" << path << "' is not writable." << endl; … … 723 729 } 724 730 731 ofstream fout(write); 732 if (!fout) 733 cout << "WARNING: Writing to '" << write << "' failed: " << strerror(errno) << endl; 734 725 735 if (display) 726 736 { … … 732 742 } 733 743 744 if (!write.empty()) 745 { 746 fout << "#"; 747 for (size_t i=0; i<l.size(); i++) 748 fout << ' ' << l[i].c_str(); 749 fout << endl; 750 } 751 734 752 // ---------------------- Fill TTree with DB data -------------------------- 735 753 size_t count = 0; … … 744 762 for (auto col=row.begin(); col!=row.end(); col++, idx++) 745 763 { 746 if (display )764 if (display || !write.empty()) 747 765 { 748 766 if (idx>0) … … 789 807 if (display) 790 808 cout << sout.str() << endl; 809 if (!write.empty()) 810 fout << sout.str() << '\n'; 791 811 } 792 812
Note:
See TracChangeset
for help on using the changeset viewer.