Changeset 19879 for trunk/FACT++
- Timestamp:
- 12/01/19 20:33:03 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/csv2root.cc
r19878 r19879 35 35 ("rename.*", var<string>(), "Can be used to rename a column") 36 36 ("delimiter", var<string>(";:, \t"), "List of possible delimiters") 37 ("null", po_switch(), "Enable detection of NULL and replace it with 0") 38 ("empty", po_switch(), "Enable detection of empty fields (two immediately consecutive delimiters) and replace them with 0") 37 39 ("dry-run", po_switch(), "Do not create or manipulate any output file") 38 40 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") … … 147 149 const bool force = conf.Get<bool>("force"); 148 150 const bool update = conf.Get<bool>("update"); 151 const bool detectnull = conf.Get<bool>("null"); 152 const bool detectempty = conf.Get<bool>("empty"); 149 153 // const bool dryrun = conf.Get<bool>("dry-run"); 150 154 const bool noheader = conf.Get<bool>("no-header"); … … 343 347 continue; 344 348 349 if (detectempty) 350 { 351 string delim = delimiter; 352 353 354 for (int i=0; i<delimiter.size(); i++) 355 if (delimiter[i]!=' ') 356 { 357 boost::regex rexpr1("(["+delimiter+"])(["+delimiter+"])"); 358 buf = boost::regex_replace(string(buf.Data()), rexpr1, "\\10\\2"); 359 360 boost::regex rexpr2("^(["+delimiter+"])"); 361 buf = boost::regex_replace(string(buf.Data()), rexpr2, "0\\1"); 362 363 boost::regex rexpr3("(["+delimiter+"])$"); 364 buf = boost::regex_replace(string(buf.Data()), rexpr3, "\\10"); 365 } 366 } 367 345 368 TObjArray *arr = buf.Tokenize(delimiter); 346 369 if (arr->GetEntries()!=numcol) 347 370 { 348 cerr << "Column count mismatch in line " << line+1 << "!" << endl; 371 cerr << buf << endl; 372 cerr << "Column count [" << arr->GetEntries() << "] mismatch in line " << line+1 << "!" << endl; 349 373 return 7; 350 374 } … … 354 378 try 355 379 { 380 if (detectnull && arr->At(i)->GetName()==string("NULL")) 381 { 382 vec[i] = 0; 383 continue; 384 } 385 356 386 vec[i] = stof(arr->At(i)->GetName()); 357 387 } 358 388 catch (const exception &e) 359 389 { 360 cerr << "Conversion of '" << arr->At(i)->GetName() << "' failed!" << endl; 390 cerr << buf << endl; 391 cerr << "Conversion of field " << i << " '" << arr->At(i)->GetName() << "' in line " << line+1 << " failed!" << endl; 361 392 return 8; 362 393 }
Note:
See TracChangeset
for help on using the changeset viewer.