Changeset 1600 for trunk/MagicSoft/Mars/mfileio
- Timestamp:
- 11/13/02 17:03:19 (22 years ago)
- Location:
- trunk/MagicSoft/Mars/mfileio
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h
r1574 r1600 6 6 7 7 #pragma link C++ class MChain+; 8 #pragma link C++ class MRead+; 8 9 #pragma link C++ class MReadTree+; 9 10 #pragma link C++ class MReadMarsFile+; -
trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
r1599 r1600 42 42 // 43 43 ///////////////////////////////////////////////////////////////////////////// 44 45 44 #include "MCT1ReadPreProc.h" 46 45 … … 81 80 // 82 81 MCT1ReadPreProc::MCT1ReadPreProc(const char *fname, const char *name, 83 const char *title) : fIn(NULL) 84 { 85 fName = name ? name : "M CT1ReadPreProc";82 const char *title) : fIn(NULL), fEntries(0) 83 { 84 fName = name ? name : "MRead"; 86 85 fTitle = title ? title : "Task to loop over events in CT1 ascii file"; 87 86 … … 113 112 void MCT1ReadPreProc::AddFile(const char *txt) 114 113 { 115 TNamed *name = new TNamed(txt, ""); 116 fFileNames->AddLast(name); 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; 122 return; 123 } 124 125 fEntries += GetNumEvents(); 126 127 delete fIn; 128 129 fIn = store; 130 131 fFileNames->AddLast(new TNamed(txt, "")); 117 132 } 118 133 … … 123 138 // data members 124 139 // 125 void MCT1ReadPreProc::Process Header(const struct outputpars &outpars)126 { 127 fNumPixels = outpars.inumpixels; // number of pixels in the camera128 129 if (fNumPixels>iMAXNUMPIX || fNumPixels==0) 130 fNumPixels=iMAXNUMPIX;140 void MCT1ReadPreProc::ProcessRunHeader(const struct outputpars &outpars) 141 { 142 if (outpars.inumpixels != iMAXNUMPIX) 143 *fLog << warn << "WARNING! File doesn't contain " << iMAXNUMPIX << " Pixels... maybe corrupt." << endl; 144 145 fNumEventsInRun = 0; 131 146 132 147 // … … 166 181 *fLog << "Source: RA=" << outpars.dsourcera_hours << "h DEC="; 167 182 *fLog << outpars.dsourcedec_deg << "deg" << endl; 168 169 *fLog << "Pixels: " << fNumPixels << endl;170 183 171 184 //int inummuonpixels; // number of pixels in the muon shield … … 262 275 263 276 // FIXME? Is x-y echanged between Mars CT1 geometry and CT1 definition? 264 fSrcPos->SetXY(outpars.fypointcorr_deg/fGeom->GetConvMm2Deg(), 265 outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg()); 277 fSrcPos->SetXY(-outpars.fypointcorr_deg/fGeom->GetConvMm2Deg(), 278 -outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg()); 279 fSrcPos->SetReadyToSave(); 266 280 267 281 /* … … 342 356 343 357 fIsMcFile = outpars.bmontecarlo==TRUE; 358 359 fPedest->SetReadyToSave(); 344 360 } 345 361 … … 348 364 // Read CT1 PreProc File Header: 349 365 // 350 Bool_t MCT1ReadPreProc::Read Header()366 Bool_t MCT1ReadPreProc::ReadRunHeader() 351 367 { 352 368 char cheadertitle[iHEADERTITLELENGTH]; … … 381 397 fIn->read((Byte_t*)&outpars, sizeof(struct outputpars)); 382 398 383 Process Header(outpars);399 ProcessRunHeader(outpars); 384 400 385 401 return kTRUE; 386 402 } 387 403 388 Bool_t MCT1ReadPreProc::Read Footer()404 Bool_t MCT1ReadPreProc::ReadRunFooter() 389 405 { 390 406 char cheadertitle[iHEADERTITLELENGTH]; … … 400 416 401 417 if (!s.BeginsWith(m(0,p))) 402 return kFALSE; 418 { 419 fIn->seekg(-iHEADERTITLELENGTH, ios::cur); 420 return kFALSE; 421 } 403 422 404 423 *fLog << inf << cheadertitle << flush; … … 423 442 */ 424 443 444 fNumFilterEvts += filterres.ifilter_passed_evts; 445 fNumRuns++; 446 447 *fLog << inf << "Read " << fNumEventsInRun << " events from run." << endl; 448 449 if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts) 450 { 451 *fLog << warn << "WARNING! Number of events in run doesn't match number of read events." << endl; 452 *fLog << " File might be corrupt." << endl; 453 } 454 425 455 return kTRUE; 426 456 } … … 468 498 *fLog << inf << "-----------------------------------------------------------------------" << endl; 469 499 470 //*fLog << "File contains " << GetNumEvents() << " events." << endl; 471 472 Bool_t rc = ReadHeader(); 500 *fLog << "File contains " << GetNumEvents() << " events." << endl; 501 502 // WORKAROUND for not working seekg(0) in GetNumEvents 503 fIn->close(); 504 fIn->open(gSystem->ExpandPathName(name)); 505 506 Bool_t rc = ReadRunHeader(); 473 507 474 508 if (!rc) 475 *fLog << warn << "Unable to read header... skipping file." << endl;509 *fLog << warn << "Unable to read first run header... skipping file." << endl; 476 510 477 511 return rc; … … 480 514 Int_t MCT1ReadPreProc::GetNumEvents() 481 515 { 482 Int_t n = 0; 516 *fLog << inf << "Scanning file for size" << flush; 517 518 const TString m(cEND_EVENTS_TEMPLATE); 519 const Int_t p = m.First('%'); 520 const TString test = m(0, p); 521 522 Int_t nevts = 0; 523 Int_t nruns = 0; 483 524 484 525 while (!fIn->eof()) 485 526 { 486 if (fIn->get()!=cEND_EVENTS_TEMPLATE[0]) 487 continue; 488 489 char cheadertitle[iHEADERTITLELENGTH]; 490 fIn->read(cheadertitle, iHEADERTITLELENGTH-1); 491 492 TString s = cheadertitle; 493 TString m = cEND_EVENTS_TEMPLATE; 494 Int_t p = m.First('%'); 495 496 if (!s.BeginsWith(m(1,p-1))) 497 continue; 498 499 int num; 500 501 sscanf(cheadertitle, &cEND_EVENTS_TEMPLATE[1], &num); 502 503 n += num; 504 } 505 506 fIn->seekg(0); 507 508 return n; 527 fIn->seekg(iHEADERTITLELENGTH, ios::cur); 528 fIn->seekg(sizeof(struct outputpars), ios::cur); 529 530 while (1) 531 { 532 if (fIn->peek()==cEND_EVENTS_TEMPLATE[0]) 533 { 534 char cheadertitle[iHEADERTITLELENGTH]; 535 fIn->read(cheadertitle, iHEADERTITLELENGTH); 536 537 const TString s = cheadertitle; 538 if (s.BeginsWith(test)) 539 { 540 fIn->seekg(sizeof(struct filterresults), ios::cur); 541 nruns++; 542 break; 543 } 544 545 fIn->seekg(-iHEADERTITLELENGTH, ios::cur); 546 } 547 548 fIn->seekg(sizeof(struct eventrecord), ios::cur); 549 if (fIn->eof()) 550 break; 551 nevts++; 552 } 553 *fLog << "." << flush; 554 } 555 556 *fLog << "done." << endl; 557 *fLog << "Found " << nevts << " events in " << nruns << " runs." << endl; 558 559 return nevts; 509 560 } 510 561 … … 542 593 // look for the source position in the camera 543 594 // 544 fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam" );595 fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", "Source"); 545 596 if (!fSrcPos) 546 597 return kFALSE; … … 566 617 if (!fMcTrig) 567 618 return kFALSE; 619 620 fNumFilterEvts = 0; 621 fNumRuns = 0; 568 622 569 623 return kTRUE; … … 582 636 int isecfrac_200ns; // fractional part of isecs_since_midday 583 637 short snot_ok_flags; // the bits in these two bytes are flags for additional information on the event: Everything OK =: all Bits = 0 584 int ipreproc_alt_arcs; // "should be" alt according to preproc (arcseconds)585 int ipreproc_az_arcs; // "should be" az according to preproc (arcseconds)586 638 587 639 // for ALT-AZ mount telescopes: rotation angle of the field of … … 602 654 float fhourangle; 603 655 */ 604 /*605 *fLog << event.isecs_since_midday << "s ";606 *fLog << event.ipreproc_alt_arcs << "s ";607 *fLog << event.ipreproc_az_arcs << "s ";608 *fLog << event.ifieldrot_arcs << "s ";609 *fLog << event.fhourangle << endl;610 */611 656 612 657 // … … 614 659 // too the list with it's id, number of photons and error 615 660 // 616 fNphot->InitSize( fNumPixels);661 fNphot->InitSize(iMAXNUMPIX); 617 662 618 663 // number of photoelectrons measured in each pixel only the 619 664 // actual number of pixels (outputpars.inumpixels) is written out 620 665 // short spixsig_10thphot[iMAXNUMPIX]; 621 for (Int_t i=0; i<fNumPixels; i++) 622 { 623 if (event.spixsig_10thphot[i]>0) 624 fNphot->AddPixel(i, 0.1*event.spixsig_10thphot[i], 625 (*fPedest)[i].GetMeanRms()); 626 } 666 for (Int_t i=0; i<iMAXNUMPIX; i++) 667 { 668 if (event.spixsig_10thphot[i]==0) 669 continue; 670 671 fNphot->AddPixel(i, 0.1*event.spixsig_10thphot[i], 672 (*fPedest)[i].GetMeanRms()); 673 } 674 fNphot->SetReadyToSave(); 675 676 // int ipreproc_alt_arcs; // "should be" alt according to preproc (arcseconds) 677 // int ipreproc_az_arcs; // "should be" az according to preproc (arcseconds) 627 678 628 679 fMcEvt->SetTheta(TMath::Pi()*(0.5-1./180*event.ialt_arcs/3600)); // altitude (arcseconds) 629 680 fMcEvt->SetPhi(TMath::Pi()/180*event.iaz_arcs/3600); // azimuth (arcseconds) 681 682 fMcEvt->SetReadyToSave(); 630 683 631 684 if (!fIsMcFile) … … 636 689 fMcEvt->SetImpact(event.imcimpact_m*100); // simulated impact 637 690 638 fMcTrig->SetFirstLevel(event.imctriggerflag); // MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */ 691 fMcTrig->SetFirstLevel(event.imctriggerflag); // MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */ 692 fMcTrig->SetReadyToSave(); 639 693 640 694 //float fmcsize_phel; // Simulated SIZE … … 655 709 656 710 // 657 // If the first character isn't the first of the footer it must be 658 // an event 659 // 660 if (fIn->peek()!=cEND_EVENTS_TEMPLATE[0]) 661 return kTRUE; 662 663 // 664 // Remember the current position if the first character faked a 665 // footer 666 // 667 const Int_t pos = fIn->tellg(); 668 669 // 670 // Try reading the footer. If it isn't succefull jump back... 671 // must be an event 672 // 673 if (!ReadFooter()) 674 { 675 fIn->seekg(pos, ios::beg); 676 return kTRUE; 677 } 678 679 *fLog << inf << "Footer found." << endl; 680 681 // 682 // No after reading the footer check if we reached the end of the file 683 // 684 if (fIn->eof()) 685 { 686 *fLog << "End of file." << endl; 687 return kFALSE; 688 } 689 690 // 691 // If the eof isn't reached a new header must follow. Check for it. 692 // 693 if (fIn->peek()!=cTITLE_TEMPLATE[0]) 694 { 695 *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl; 696 return kFALSE; 697 } 698 699 *fLog << "-----------------------------------------------------------------------" << endl; 700 if (ReadHeader()) 701 return kTRUE; 702 703 *fLog << inf << "Error reading run header in file... skipping rest of file." << endl; 704 return kFALSE; 711 // Because we can have 0-event runs in the file we loop as often 712 // as we don't find a new footer-header combination. 713 // 714 while (1) 715 { 716 // 717 // If the first character isn't the first of the footer it must be 718 // an event 719 // 720 if (fIn->peek()!=cEND_EVENTS_TEMPLATE[0]) 721 return kTRUE; 722 723 // 724 // Try reading the footer. If it isn't succefull... 725 // must be an event 726 // 727 if (!ReadRunFooter()) 728 return kTRUE; 729 730 *fLog << inf << "Footer found." << endl; 731 732 // 733 // No after reading the footer check if we reached the end of the file 734 // 735 if (fIn->eof()) 736 { 737 *fLog << "End of file." << endl; 738 return kFALSE; 739 } 740 741 // 742 // If the eof isn't reached a new header must follow. Check for it. 743 // 744 if (fIn->peek()!=cTITLE_TEMPLATE[0]) 745 { 746 *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl; 747 return kFALSE; 748 } 749 750 *fLog << "-----------------------------------------------------------------------" << endl; 751 if (!ReadRunHeader()) 752 return kTRUE; 753 } 705 754 } 706 755 … … 726 775 struct eventrecord event; 727 776 728 const int size1 = sizeof(event)-sizeof(event.spixsig_10thphot); 729 const int size2 = sizeof(event.spixsig_10thphot[0])*fNumPixels; 730 731 // read the eventrecord with the recorded number of stored pixels 732 fIn->read((Byte_t*)&event, size1+size2); 733 734 if (fIn->eof()) 735 return kFALSE; 777 // read the eventrecord from the file 778 fIn->read((Byte_t*)&event, sizeof(struct eventrecord)); 736 779 737 780 ProcessEvent(event); 738 781 739 fNumEvent++; 782 fNumEvents++; 783 fNumEventsInRun++; 740 784 741 785 return kTRUE; 742 786 } 743 787 788 Bool_t MCT1ReadPreProc::PostProcess() 789 { 790 *fLog << all; 791 *fLog << "Number events passed the filter: " << fNumFilterEvts << endl; 792 *fLog << "Number of Events read from file: " << fNumEvents << endl; 793 *fLog << "Number of Runs read from file: " << fNumRuns << endl; 794 795 if (fNumEvents!=fNumFilterEvts) 796 { 797 *fLog << warn << "WARNING! Number of events in file doesn't match number of read events..." << endl; 798 *fLog << " File might be corrupt." << endl; 799 } 800 801 return kTRUE; 802 } -
trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
r1583 r1600 2 2 #define MARS_MCT1ReadPreProc 3 3 4 #ifndef MARS_M Task5 #include "M Task.h"4 #ifndef MARS_MRead 5 #include "MRead.h" 6 6 #endif 7 7 … … 18 18 struct eventrecord; 19 19 20 class MCT1ReadPreProc : public M Task20 class MCT1ReadPreProc : public MRead 21 21 { 22 22 private: 23 ifstream *fIn; // the inputfile 24 MGeomCam *fGeom; // camera geometry 25 MCerPhotEvt *fNphot; // the data container for all data. 26 MPedestalCam *fPedest; // ct1 pedestals 27 MMcEvt *fMcEvt; // monte carlo data container for MC files 28 MMcTrig *fMcTrig; // mc data container for trigger information 29 MSrcPosCam *fSrcPos; // source position in the camera 30 TList *fFileNames; // Array which stores the \0-terminated filenames 31 MBlindPixels *fBlinds; // Array holding blind pixels 23 ifstream *fIn; // the inputfile 24 TList *fFileNames; // Array which stores the \0-terminated filenames 32 25 33 Int_t fNumPixels; 34 Bool_t fIsMcFile; 26 MGeomCam *fGeom; // camera geometry 27 MCerPhotEvt *fNphot; // the data container for all data. 28 MPedestalCam *fPedest; // ct1 pedestals 29 MMcEvt *fMcEvt; // monte carlo data container for MC files 30 MMcTrig *fMcTrig; // mc data container for trigger information 31 MSrcPosCam *fSrcPos; // source position in the camera 32 MBlindPixels *fBlinds; // Array holding blind pixels 35 33 36 UInt_t fNumEvents; 37 UInt_t fNumEvent; 34 Bool_t fIsMcFile; // Flag whether current run is a MC run 35 36 UInt_t fNumEvents; // number of events counted in all runs in all files 37 UInt_t fNumEventsInRun; // number of events in the counted in th ecurrent run 38 UInt_t fNumRuns; // number of processed runs of all files 39 UInt_t fEntries; // entries of all files succesfully added 40 UInt_t fNumFilterEvts; // number of events mentioned in the runs footers 38 41 39 42 Bool_t OpenNextFile(); … … 42 45 43 46 void ReadPedestals(); 44 Bool_t Read Header();45 Bool_t Read Footer();47 Bool_t ReadRunHeader(); 48 Bool_t ReadRunFooter(); 46 49 Bool_t CheckFilePosition(); 47 void Process Header(const struct outputpars &outpars);50 void ProcessRunHeader(const struct outputpars &outpars); 48 51 void ProcessEvent(const struct eventrecord &event); 49 52 50 53 public: 51 54 MCT1ReadPreProc(const char *filename=NULL, 52 const char *name=NULL,53 const char *title=NULL);55 const char *name=NULL, 56 const char *title=NULL); 54 57 55 58 ~MCT1ReadPreProc(); … … 59 62 Bool_t PreProcess(MParList *pList); 60 63 Bool_t Process(); 64 Bool_t PostProcess(); 65 66 UInt_t GetEntries() { return fEntries; } 61 67 62 68 ClassDef(MCT1ReadPreProc, 0) // Reads the CT1 data file -
trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
r1583 r1600 54 54 MReadMarsFile::MReadMarsFile() : fRun(NULL) 55 55 { 56 fName = "MRead MarsFile";56 fName = "MRead"; 57 57 fTitle = "Task to loop over all events in a tree of a Mars file."; 58 58 } … … 67 67 : MReadTree(tname, fname) 68 68 { 69 fName = name ? name : "MRead MarsFile";69 fName = name ? name : "MRead"; 70 70 fTitle = title ? title : "Task to loop over all events in a tree of a Mars file."; 71 71 -
trunk/MagicSoft/Mars/mfileio/MReadTree.cc
r1583 r1600 55 55 #include <TFile.h> // TFile::GetName 56 56 #include <TSystem.h> // gSystem->ExpandPath 57 #include <TGProgressBar.h>57 //#include <TGProgressBar.h> 58 58 #include <TChainElement.h> 59 59 #include <TOrdCollection.h> … … 75 75 // 76 76 MReadTree::MReadTree() 77 : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE) , fProgress(NULL)78 { 79 fName = "MRead Tree";77 : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE) 78 { 79 fName = "MRead"; 80 80 fTitle = "Task to loop over all events in one single tree"; 81 81 … … 99 99 MReadTree::MReadTree(const char *tname, const char *fname, 100 100 const char *name, const char *title) 101 : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE) , fProgress(NULL)102 { 103 fName = name ? name : "MRead Tree";101 : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE) 102 { 103 fName = name ? name : "MRead"; 104 104 fTitle = title ? title : "Task to loop over all events in one single tree"; 105 105 … … 415 415 if (TestBit(kChainWasChanged)) 416 416 { 417 *fLog << inf << "Scanning chain... " << flush; 417 418 fNumEntries = (UInt_t)fChain->GetEntries(); 419 *fLog << fNumEntries << " events found." << endl; 418 420 ResetBit(kChainWasChanged); 419 421 } … … 566 568 567 569 // 568 // If a progress bar is given set its range.569 //570 if (fProgress)571 fProgress->SetRange(0, fNumEntries);572 573 //574 570 // Now we can start notifying. Reset tree makes sure, that TChain thinks 575 571 // that the correct file is not yet initialized and reinitilizes it -
trunk/MagicSoft/Mars/mfileio/MReadTree.h
r1572 r1600 2 2 #define MARS_MReadTree 3 3 4 #ifndef MARS_M Task5 #include "M Task.h"4 #ifndef MARS_MRead 5 #include "MRead.h" 6 6 #endif 7 7 8 8 class MChain; 9 9 class TBranch; 10 class TGProgressBar;11 10 12 class MReadTree : public M Task11 class MReadTree : public MRead 13 12 { 14 13 private: … … 27 26 28 27 private: 29 TGProgressBar *fProgress; //! Possible display of status30 31 28 void SetBranchStatus(const TList *list, Bool_t status); 32 29 void SetBranchStatus(TObject *branch, Bool_t status); … … 50 47 void EnableBranch(const char *name); 51 48 void VetoBranch(const char *name); 52 53 void SetProgressBar(TGProgressBar *bar) { fProgress = bar; }54 49 55 50 Bool_t GetEvent(); -
trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
r1583 r1600 130 130 // - Branches are automatically deleted by the tree destructor 131 131 // 132 133 *fLog << inf << "Output File closed and deleted." << endl; 132 134 } 133 135 -
trunk/MagicSoft/Mars/mfileio/Makefile
r1574 r1600 32 32 33 33 SRCFILES = MChain.cc \ 34 MRead.cc \ 34 35 MReadTree.cc \ 35 36 MReadMarsFile.cc \
Note:
See TracChangeset
for help on using the changeset viewer.