Changeset 1664 for trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
- Timestamp:
- 11/21/02 16:20:21 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
r1663 r1664 112 112 void MCT1ReadPreProc::AddFile(const char *txt) 113 113 { 114 ifstream *store = fIn; 115 116 fIn = new ifstream(gSystem->ExpandPathName(txt)); 117 118 if (!(*fIn)) 119 { 120 *fLog << warn << "Cannot open file '" << txt << "'... ignored." << endl; 121 fIn = store; 114 const TString fname = gSystem->ExpandPathName(txt); 115 116 if (!CheckHeader(fname)) 117 { 118 *fLog << warn << "WARNING - Problem reading header... ignored." << endl; 122 119 return; 123 120 } 124 121 125 fEntries += GetNumEvents(); 126 127 delete fIn; 128 129 fIn = store; 122 const Int_t n = GetNumEvents(fname); 123 if (n==0) 124 { 125 *fLog << warn << "WARNING - File contains no data... ignored." << endl; 126 return; 127 } 128 129 fEntries += n; 130 131 *fLog << inf << "File " << txt << " contains " << n << " events (Total=" << fEntries << ")" << endl; 130 132 131 133 fFileNames->AddLast(new TNamed(txt, "")); … … 390 392 &dummy/*&outpars.eruntype*/, &outpars.iproc_mjdate); 391 393 392 if (STRUCT_VERSION != structversion) 394 if (fpreprocversion<0.6) 395 { 396 *fLog << err << "Sorry only files from PreProc V0.6 and newer are supported." << endl; 397 return kFALSE; 398 } 399 400 // 401 // This is a stupid way of getting rid of numerical uncertanties when 402 // comparing floating point numbers (Argh...) 403 // 404 TString s1 = Form("%.2f", structversion); 405 TString s2 = Form("%.2f", STRUCT_VERSION); 406 407 if (s1 != s2) 393 408 { 394 409 *fLog << warn << "WARNING: Version of C-structures of file (V"; 395 *fLog << s tructversion<< ") not identical with current structures (V";396 *fLog << STRUCT_VERSION<< ")" << endl;410 *fLog << s1 << ") not identical with current structures (V"; 411 *fLog << s2 << ")" << endl; 397 412 } 398 413 … … 404 419 } 405 420 406 Bool_t MCT1ReadPreProc::ReadRunFooter()421 Int_t MCT1ReadPreProc::ReadRunFooter() 407 422 { 408 423 char cheadertitle[iHEADERTITLELENGTH]; … … 420 435 { 421 436 fIn->seekg(-iHEADERTITLELENGTH, ios::cur); 422 return kFALSE;437 return 0; 423 438 } 424 439 … … 444 459 */ 445 460 446 fNumFilterEvts += filterres.ifilter_passed_evts; 461 if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts) 462 { 463 *fLog << err << "ERROR! Number of events in run (" << (UInt_t)filterres.ifilter_passed_evts; 464 *fLog << ") doesn't match number of read events ("; 465 *fLog << fNumEventsInRun << ")" << endl; 466 *fLog << " File corrupted." << endl; 467 return -1; 468 } 469 470 fNumFilterEvts += fNumEventsInRun; 447 471 fNumRuns++; 448 472 449 *fLog << inf << "Read " << fNumEventsInRun << " events from run." << endl; 450 451 if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts) 452 { 453 *fLog << warn << "WARNING! Number of events in run doesn't match number of read events." << endl; 454 *fLog << " File might be corrupt." << endl; 455 } 456 457 return kTRUE; 473 *fLog << inf << "Read " << fNumEventsInRun << " events from run (Total="; 474 *fLog << fNumFilterEvts << "/" << fEntries << " ["; 475 *fLog << 100*fNumFilterEvts/fEntries << "%], Runs=" << fNumRuns << ")"; 476 *fLog << endl; 477 478 return 1; 458 479 } 459 480 … … 481 502 // open the file which is the first one in the chain 482 503 // 483 const char *name = file->GetName(); 484 485 fIn = new ifstream(gSystem->ExpandPathName(name)); 486 487 if (!(*fIn)) 488 { 489 *fLog << dbginf << "Cannot open file '" << name << "'" << endl; 490 return kFALSE; 491 } 492 493 *fLog << "Open file: '" << name << "'" << endl; 504 const TString name = file->GetName(); 505 const TString fname = gSystem->ExpandPathName(name); 494 506 495 507 // … … 498 510 fFileNames->Remove(file); 499 511 512 *fLog << inf << "Open file: '" << name << "'" << endl; 513 514 if (!CheckHeader(fname)) 515 return kFALSE; 516 517 fIn = new ifstream(fname); 518 500 519 *fLog << inf << "-----------------------------------------------------------------------" << endl; 501 520 502 *fLog << "File contains " << GetNumEvents() << " events." << endl; 503 504 // WORKAROUND for not working seekg(0) in GetNumEvents 505 fIn->close(); 506 fIn->open(gSystem->ExpandPathName(name)); 507 508 Bool_t rc = ReadRunHeader(); 509 510 if (!rc) 521 if (!ReadRunHeader()) 522 { 511 523 *fLog << warn << "Unable to read first run header... skipping file." << endl; 512 513 return rc; 514 } 515 516 Int_t MCT1ReadPreProc::GetNumEvents() 517 { 518 *fLog << inf << "Scanning file for size" << flush; 524 return kFALSE; 525 } 526 527 return kTRUE; 528 } 529 530 Bool_t MCT1ReadPreProc::CheckHeader(const TString fname) const 531 { 532 ifstream fin(fname); 533 if (!fin) 534 { 535 *fLog << dbginf << err << "ERROR - Cannot open file '" << fname << "'" << endl; 536 return kFALSE; 537 } 538 539 char cheadertitle[iHEADERTITLELENGTH]; 540 fin.read(cheadertitle, iHEADERTITLELENGTH); 541 542 Float_t fpreprocversion, structversion, dummy; 543 544 sscanf(cheadertitle, cTITLE_TEMPLATE, 545 &fpreprocversion, &structversion, 546 &dummy, &dummy, &dummy, &dummy); 547 548 if (fpreprocversion < 0.6) 549 { 550 *fLog << dbginf << err << "ERROR - You must use PreProc V0.6 or higher." << endl; 551 return kFALSE; 552 } 553 554 if (STRUCT_VERSION > structversion) 555 { 556 *fLog << warn << "WARNING: Version of C-structures of file (V"; 557 *fLog << structversion << ") newer than current structures (V"; 558 *fLog << STRUCT_VERSION << ")" << endl; 559 } 560 561 *fLog << "Current structures: " << STRUCT_VERSION << " "; 562 *fLog << "Structures in file: " << structversion << " "; 563 *fLog << "Used preproc version: " << fpreprocversion << endl; 564 565 return kTRUE; 566 } 567 568 569 Int_t MCT1ReadPreProc::GetNumEvents(const TString fname) const 570 { 571 *fLog << inf << "Scanning file " << fname << " for size" << flush; 572 573 ifstream fin(fname); 574 if (!fin) 575 { 576 *fLog << dbginf << err << "ERROR - Opening file." << endl; 577 return 0; 578 } 519 579 520 580 const TString m(cEND_EVENTS_TEMPLATE); … … 525 585 Int_t nruns = 0; 526 586 527 while (!f In->eof())528 { 529 f In->seekg(iHEADERTITLELENGTH, ios::cur);530 f In->seekg(sizeof(struct outputpars), ios::cur);587 while (!fin.eof() && fin.peek()!=EOF) 588 { 589 fin.seekg(iHEADERTITLELENGTH, ios::cur); 590 fin.seekg(sizeof(struct outputpars), ios::cur); 531 591 532 592 while (1) 533 593 { 534 if (f In->peek()==cEND_EVENTS_TEMPLATE[0])594 if (fin.peek()==cEND_EVENTS_TEMPLATE[0]) 535 595 { 536 596 char cheadertitle[iHEADERTITLELENGTH]; 537 f In->read(cheadertitle, iHEADERTITLELENGTH);597 fin.read(cheadertitle, iHEADERTITLELENGTH); 538 598 539 599 const TString s = cheadertitle; 540 600 if (s.BeginsWith(test)) 541 601 { 542 f In->seekg(sizeof(struct filterresults), ios::cur);602 fin.seekg(sizeof(struct filterresults), ios::cur); 543 603 nruns++; 544 604 break; 545 605 } 546 606 547 f In->seekg(-iHEADERTITLELENGTH, ios::cur);607 fin.seekg(-iHEADERTITLELENGTH, ios::cur); 548 608 } 549 609 550 f In->seekg(sizeof(struct eventrecord), ios::cur);551 if (f In->eof())610 fin.seekg(sizeof(struct eventrecord), ios::cur); 611 if (fin.eof()) 552 612 break; 613 553 614 nevts++; 554 615 } … … 746 807 // must be an event 747 808 // 748 if (!ReadRunFooter()) 809 switch (ReadRunFooter()) 810 { 811 case -1: 812 return kFALSE; 813 case 0: 749 814 return kTRUE; 815 } 750 816 751 817 *fLog << inf << "Footer found." << endl; 818 819 const char c = fIn->peek(); 752 820 753 821 // 754 822 // No after reading the footer check if we reached the end of the file 755 823 // 756 if (fIn->eof() )824 if (fIn->eof() || c==EOF) 757 825 { 758 826 *fLog << "End of file." << endl; … … 763 831 // If the eof isn't reached a new header must follow. Check for it. 764 832 // 765 if ( fIn->peek()!=cTITLE_TEMPLATE[0])833 if (c!=cTITLE_TEMPLATE[0]) 766 834 { 767 835 *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl; … … 813 881 *fLog << "Number of Events read from file: " << fNumEvents << endl; 814 882 *fLog << "Number of Runs read from file: " << fNumRuns << endl; 883 *fLog << "Number of events detected first: " << fEntries << endl; 815 884 816 885 if (fNumEvents!=fNumFilterEvts)
Note:
See TracChangeset
for help on using the changeset viewer.