Changeset 12905 for trunk/FACT++/src
- Timestamp:
- 02/18/12 10:12:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r12887 r12905 17 17 #include "Time.h" 18 18 #include "externals/fits.h" 19 20 #ifdef HAVE_ROOT 21 #include "TFormula.h" 22 #endif 19 23 20 24 using namespace std; … … 72 76 vector<MyColumn> InitColumns(vector<string> list); 73 77 78 double GetDouble(const MyColumn &, size_t) const; 79 74 80 ///Display the selected columns values VS time 75 void Dump(ofstream &, const vector<MyColumn> &, const string & );76 void DumpMinMax(ofstream &, const vector<MyColumn> &, bool);77 void DumpStats(ofstream &, const vector<MyColumn> & );81 void Dump(ofstream &, const vector<MyColumn> &, const string &, size_t, size_t, const string &); 82 void DumpMinMax(ofstream &, const vector<MyColumn> &, size_t, size_t, bool); 83 void DumpStats(ofstream &, const vector<MyColumn> &, size_t, size_t); 78 84 79 85 public: … … 246 252 } 247 253 254 double FitsDumper::GetDouble(const MyColumn &it, size_t i) const 255 { 256 switch (it.col.type) 257 { 258 case 'A': 259 return reinterpret_cast<const char*>(it.ptr)[i]; 260 261 case 'L': 262 return reinterpret_cast<const bool*>(it.ptr)[i]; 263 264 case 'B': 265 return (unsigned int)reinterpret_cast<const uint8_t*>(it.ptr)[i]; 266 267 case 'I': 268 return reinterpret_cast<const int16_t*>(it.ptr)[i]; 269 270 case 'J': 271 return reinterpret_cast<const int32_t*>(it.ptr)[i]; 272 273 case 'K': 274 return reinterpret_cast<const int64_t*>(it.ptr)[i]; 275 276 case 'E': 277 return reinterpret_cast<const float*>(it.ptr)[i]; 278 279 case 'D': 280 return reinterpret_cast<const double*>(it.ptr)[i]; 281 } 282 283 return 0; 284 } 285 248 286 // -------------------------------------------------------------------------- 249 287 // 250 288 //! Perform the actual dump, based on the current parameters 251 289 // 252 void FitsDumper::Dump(ofstream &fout, const vector<MyColumn> &cols, const string &fil ename)290 void FitsDumper::Dump(ofstream &fout, const vector<MyColumn> &cols, const string &filter, size_t first, size_t limit, const string &filename) 253 291 { 254 292 const fits::Table::Keys &fKeyMap = GetKeys(); 255 293 294 TFormula select; 295 if (!filter.empty() && select.Compile(filter.c_str())) 296 throw runtime_error("Syntax Error: TFormula::Compile failed for '"+filter+"'"); 297 256 298 fout << "## --------------------------------------------------------------------------\n"; 257 fout << "## Fits file: \t" << fFilename << '\n';299 fout << "## Fits file: \t" << fFilename << '\n'; 258 300 if (filename!="-") 259 fout << "## File: \t" << filename << '\n'; 260 fout << "## Table: \t" << fKeyMap.find("EXTNAME")->second.value << '\n'; 261 fout << "## NumRows: \t" << GetInt("NAXIS2") << '\n'; 262 fout << "## Comment: \t" << ((fKeyMap.find("COMMENT") != fKeyMap.end()) ? fKeyMap.find("COMMENT")->second.value : "") << '\n'; 301 fout << "## File: \t" << filename << '\n'; 302 fout << "## Table: \t" << fKeyMap.find("EXTNAME")->second.value << '\n'; 303 fout << "## NumRows: \t" << GetInt("NAXIS2") << '\n'; 304 fout << "## Comment: \t" << ((fKeyMap.find("COMMENT") != fKeyMap.end()) ? fKeyMap.find("COMMENT")->second.value : "") << '\n'; 305 if (!filter.empty()) 306 fout << "## Selection: \t" << select.GetExpFormula() << '\n'; 263 307 fout << "## --------------------------------------------------------------------------\n"; 264 308 ListKeywords(fout); … … 266 310 fout << "#\n"; 267 311 312 size_t num = 0; 268 313 for (auto it=cols.begin(); it!=cols.end(); it++) 269 314 { … … 279 324 280 325 fout << ": " << it->col.unit << '\n'; 326 327 num += it->last-it->first+1; 281 328 } 282 329 fout << "#" << endl; … … 284 331 // ----------------------------------------------------------------- 285 332 286 while (GetNextRow()) 333 vector<Double_t> data(num); 334 335 const size_t last = limit ? first + limit : size_t(-1); 336 337 while (GetRow(first++)) 287 338 { 288 339 const size_t row = GetRow(); 289 if (row==GetNumRows()) 290 break; 291 340 if (row==GetNumRows() || row==last) 341 break; 342 343 size_t p = 0; 344 345 ostringstream out; 292 346 for (auto it=cols.begin(); it!=cols.end(); it++) 293 347 { 294 348 string msg; 295 for (uint32_t i=it->first; i<=it->last; i++ )349 for (uint32_t i=it->first; i<=it->last; i++, p++) 296 350 { 297 351 switch (it->col.type) … … 301 355 break; 302 356 case 'B': 303 fout << (unsigned int)reinterpret_cast<const unsigned char*>(it->ptr)[i] << " ";357 out << (unsigned int)reinterpret_cast<const unsigned char*>(it->ptr)[i] << " "; 304 358 break; 305 359 case 'L': 306 fout << reinterpret_cast<const bool*>(it->ptr)[i] << " ";360 out << reinterpret_cast<const bool*>(it->ptr)[i] << " "; 307 361 break; 308 362 case 'I': 309 fout << reinterpret_cast<const int16_t*>(it->ptr)[i] << " ";363 out << reinterpret_cast<const int16_t*>(it->ptr)[i] << " "; 310 364 break; 311 365 case 'J': 312 fout << reinterpret_cast<const int32_t*>(it->ptr)[i] << " ";366 out << reinterpret_cast<const int32_t*>(it->ptr)[i] << " "; 313 367 break; 314 368 case 'K': 315 fout << reinterpret_cast<const int64_t*>(it->ptr)[i] << " ";369 out << reinterpret_cast<const int64_t*>(it->ptr)[i] << " "; 316 370 break; 317 371 case 'E': 318 fout << reinterpret_cast<const float*>(it->ptr)[i] << " ";372 out << reinterpret_cast<const float*>(it->ptr)[i] << " "; 319 373 break; 320 374 case 'D': 321 fout << reinterpret_cast<const double*>(it->ptr)[i] << " ";375 out << reinterpret_cast<const double*>(it->ptr)[i] << " "; 322 376 break; 323 377 default: 324 378 ; 325 379 } 380 381 if (!filter.empty()) 382 data[p] = GetDouble(*it, i); 326 383 } 327 384 328 385 if (it->col.type=='A') 329 fout << "'" << msg << "' "; 330 } 331 fout << endl; 332 } 333 } 334 335 void FitsDumper::DumpMinMax(ofstream &fout, const vector<MyColumn> &cols, bool fNoZeroPlease) 386 out << "'" << msg << "' "; 387 } 388 389 if (!filter.empty() && select.EvalPar(0, data.data())<0.5) 390 continue; 391 392 fout << out.str() << endl; 393 } 394 } 395 396 void FitsDumper::DumpMinMax(ofstream &fout, const vector<MyColumn> &cols, size_t first, size_t limit, bool fNoZeroPlease) 336 397 { 337 398 vector<minMaxStruct> statData(cols.size()); 338 399 339 400 // Loop over all columns in our list of requested columns 340 while (GetNextRow()) 401 const size_t last = limit ? first + limit : size_t(-1); 402 403 while (GetRow(first++)) 341 404 { 342 405 const size_t row = GetRow(); 343 if (row==GetNumRows() )406 if (row==GetNumRows() || row==last) 344 407 break; 345 408 … … 360 423 for (uint32_t i=it->first; i<=it->last; i++) 361 424 { 362 double cValue = 0; 363 switch (it->col.type) 364 { 365 case 'L': 366 cValue = reinterpret_cast<const bool*>(it->ptr)[i]; 367 break; 368 case 'B': 369 cValue = reinterpret_cast<const int8_t*>(it->ptr)[i]; 370 break; 371 case 'I': 372 cValue = reinterpret_cast<const int16_t*>(it->ptr)[i]; 373 break; 374 case 'J': 375 cValue = reinterpret_cast<const int32_t*>(it->ptr)[i]; 376 break; 377 case 'K': 378 cValue = reinterpret_cast<const int64_t*>(it->ptr)[i]; 379 break; 380 case 'E': 381 cValue = reinterpret_cast<const float*>(it->ptr)[i]; 382 break; 383 case 'D': 384 cValue = reinterpret_cast<const double*>(it->ptr)[i]; 385 break; 386 default: 387 ; 388 } 425 const double cValue = GetDouble(*it, i); 389 426 390 427 if (fNoZeroPlease && cValue == 0) … … 469 506 } 470 507 471 void FitsDumper::DumpStats(ofstream &fout, const vector<MyColumn> &cols )508 void FitsDumper::DumpStats(ofstream &fout, const vector<MyColumn> &cols, size_t first, size_t limit) 472 509 { 473 510 // Loop over all columns in our list of requested columns 474 511 vector<vector<char>> statData; 475 512 513 const size_t num = limit==0 || GetNumRows()<limit ? GetNumRows() : limit; 514 476 515 for (auto it=cols.begin(); it!=cols.end(); it++) 477 statData.push_back(vector<char>(it->col.size*GetNumRows()*(it->last-it->first+1))); 478 479 while (GetNextRow()) 516 statData.push_back(vector<char>(it->col.size*num*(it->last-it->first+1))); 517 518 // Loop over all columns in our list of requested columns 519 const size_t last = limit ? first + limit : size_t(-1); 520 521 while (GetRow(first++)) 480 522 { 481 523 const size_t row = GetRow(); 482 if (row==GetNumRows()) 483 break; 524 if (row==GetNumRows() || row==last) 525 break; 526 484 527 485 528 auto statsIt = statData.begin(); … … 576 619 return false; 577 620 621 const string filter = conf.Has("filter") ? conf.Get<string>("filter") : ""; 622 623 const size_t first = conf.Get<size_t>("first"); 624 const size_t limit = conf.Get<size_t>("limit"); 625 578 626 if (conf.Get<bool>("minmax")) 579 627 { 580 DumpMinMax(fout, cols, conf.Get<bool>("nozero"));628 DumpMinMax(fout, cols, first, limit, conf.Get<bool>("nozero")); 581 629 return 0; 582 630 } … … 584 632 if (conf.Get<bool>("stat")) 585 633 { 586 DumpStats(fout, cols );634 DumpStats(fout, cols, first, limit); 587 635 return 0; 588 636 } 589 637 590 Dump(fout, cols, fil ename);638 Dump(fout, cols, filter, first, limit, filename); 591 639 592 640 return 0; … … 626 674 ("nozero,z", po_switch(), "skip 0 values for stats") 627 675 ("force", po_switch(), "Force reading the fits file even if END key is missing") 676 ("first", var<size_t>(size_t(0)), "First number of row to read") 677 ("limit", var<size_t>(size_t(0)), "Limit for the maximum number of rows to read (0=unlimited)") 678 #ifdef HAVE_ROOT 679 ("filter,r", var<string>(""), "Filter to restrict the selection of events (does not work with stat and minmax yet)") 680 #endif 628 681 ; 629 682
Note:
See TracChangeset
for help on using the changeset viewer.