- Timestamp:
- 11/30/19 15:07:23 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/csv2root.cc
r19802 r19878 26 26 po::options_description control("Root to SQL"); 27 27 control.add_options() 28 ("file", var<string>( )->required(), "The csv input file")28 ("file", var<string>("-"), "The csv input file. The default ('-') is reading from stdin.") 29 29 ("out,o", var<string>(""), "Output root file name") 30 30 ("force,f", po_switch(), "Force overwrite if output file already exists.") … … 34 34 ("no-header,n", po_switch(), "Use if the first line contains no header") 35 35 ("rename.*", var<string>(), "Can be used to rename a column") 36 ("delimiter", var<string>(";:, \t"), "List of possible delimiters") 36 37 ("dry-run", po_switch(), "Do not create or manipulate any output file") 37 38 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") … … 148 149 // const bool dryrun = conf.Get<bool>("dry-run"); 149 150 const bool noheader = conf.Get<bool>("no-header"); 151 const string delimiter = conf.Get<string>("delimiter"); 150 152 151 153 const uint16_t verbose = conf.Get<uint16_t>("verbose"); … … 158 160 if (out.empty()) 159 161 { 160 out = file ;162 out = file.empty() || file=="-" ? "csv2root" : file; 161 163 const auto p = out.find_last_of('.'); 162 164 if (p!=string::npos) 163 out = string(out.substr(0, p))+".root"; 165 out.erase(p); 166 out += ".root"; 164 167 } 165 168 … … 179 182 cout << "Reading from '" << file << "'.\n"; 180 183 181 ifstream fin(file.c_str()); 184 ifstream ifs(file.c_str()); 185 186 istream &fin = file=="-" ? cin : ifs; 182 187 if (!fin.good()) 183 188 { … … 195 200 196 201 buf = buf.Strip(TString::kBoth); 197 TObjArray *title = buf.Tokenize( " ");202 TObjArray *title = buf.Tokenize(delimiter); 198 203 if (title->GetEntries()==0) 199 204 { … … 203 208 204 209 if (title->At(0)->GetName()[0]=='#') 210 { 205 211 title->RemoveAt(0); 212 title->Compress(); 213 } 206 214 207 215 const auto numcol = title->GetEntries(); … … 280 288 } 281 289 } 282 283 290 const auto rename = conf.GetWildcardOptions("rename.*"); 284 291 … … 293 300 boost::regex rexpr(":"); 294 301 col = boost::regex_replace(col, rexpr, ""); 302 303 if (col[0]=='.') 304 col.erase(0, 1); 295 305 296 306 if (verbose>1) … … 333 343 continue; 334 344 335 TObjArray *arr = buf.Tokenize( " ");345 TObjArray *arr = buf.Tokenize(delimiter); 336 346 if (arr->GetEntries()!=numcol) 337 347 { … … 369 379 for (auto it=ttree.begin(); it!=ttree.end(); it++) 370 380 { 371 if (update) 372 { 373 TIter NextBranch((*it)->GetListOfBranches()); 374 TBranch *b=0; 375 while ((b=static_cast<TBranch*>(NextBranch()))) 376 if (b->GetAddress() && b->GetEntries()>0) 377 { 378 (*it)->SetEntries(b->GetEntries()); 379 break; 380 } 381 } 381 TIter NextBranch((*it)->GetListOfBranches()); 382 TBranch *b=0; 383 while ((b=static_cast<TBranch*>(NextBranch()))) 384 if (b->GetAddress() && b->GetEntries()>0) 385 { 386 (*it)->SetEntries(b->GetEntries()); 387 break; 388 } 382 389 383 390 (*it)->Write("", TObject::kOverwrite);
Note:
See TracChangeset
for help on using the changeset viewer.