Ignore:
Timestamp:
11/21/02 16:20:21 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc

    r1663 r1664  
    112112void MCT1ReadPreProc::AddFile(const char *txt)
    113113{
    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;
    122119        return;
    123120    }
    124121
    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;
    130132
    131133    fFileNames->AddLast(new TNamed(txt, ""));
     
    390392           &dummy/*&outpars.eruntype*/,   &outpars.iproc_mjdate);
    391393
    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)
    393408    {
    394409        *fLog << warn << "WARNING: Version of C-structures of file (V";
    395         *fLog << structversion << ") not identical with current structures (V";
    396         *fLog << STRUCT_VERSION << ")" << endl;
     410        *fLog << s1 << ") not identical with current structures (V";
     411        *fLog << s2 << ")" << endl;
    397412    }
    398413
     
    404419}
    405420
    406 Bool_t MCT1ReadPreProc::ReadRunFooter()
     421Int_t MCT1ReadPreProc::ReadRunFooter()
    407422{
    408423    char cheadertitle[iHEADERTITLELENGTH];
     
    420435    {
    421436        fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
    422         return kFALSE;
     437        return 0;
    423438    }
    424439
     
    444459     */
    445460
    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;
    447471    fNumRuns++;
    448472
    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;
    458479}
    459480
     
    481502    // open the file which is the first one in the chain
    482503    //
    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);
    494506
    495507    //
     
    498510    fFileNames->Remove(file);
    499511
     512    *fLog << inf << "Open file: '" << name << "'" << endl;
     513
     514    if (!CheckHeader(fname))
     515        return kFALSE;
     516
     517    fIn = new ifstream(fname);
     518
    500519    *fLog << inf << "-----------------------------------------------------------------------" << endl;
    501520
    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    {
    511523        *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
     530Bool_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
     569Int_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    }
    519579
    520580    const TString m(cEND_EVENTS_TEMPLATE);
     
    525585    Int_t nruns = 0;
    526586
    527     while (!fIn->eof())
    528     {
    529         fIn->seekg(iHEADERTITLELENGTH, ios::cur);
    530         fIn->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);
    531591
    532592        while (1)
    533593        {
    534             if (fIn->peek()==cEND_EVENTS_TEMPLATE[0])
     594            if (fin.peek()==cEND_EVENTS_TEMPLATE[0])
    535595            {
    536596                char cheadertitle[iHEADERTITLELENGTH];
    537                 fIn->read(cheadertitle, iHEADERTITLELENGTH);
     597                fin.read(cheadertitle, iHEADERTITLELENGTH);
    538598
    539599                const TString s = cheadertitle;
    540600                if (s.BeginsWith(test))
    541601                {
    542                     fIn->seekg(sizeof(struct filterresults), ios::cur);
     602                    fin.seekg(sizeof(struct filterresults), ios::cur);
    543603                    nruns++;
    544604                    break;
    545605                }
    546606
    547                 fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
     607                fin.seekg(-iHEADERTITLELENGTH, ios::cur);
    548608            }
    549609
    550             fIn->seekg(sizeof(struct eventrecord), ios::cur);
    551             if (fIn->eof())
     610            fin.seekg(sizeof(struct eventrecord), ios::cur);
     611            if (fin.eof())
    552612                break;
     613
    553614            nevts++;
    554615        }
     
    746807        // must be an event
    747808        //
    748         if (!ReadRunFooter())
     809        switch (ReadRunFooter())
     810        {
     811        case -1:
     812            return kFALSE;
     813        case 0:
    749814            return kTRUE;
     815        }
    750816
    751817        *fLog << inf << "Footer found." << endl;
     818
     819        const char c = fIn->peek();
    752820
    753821        //
    754822        // No after reading the footer check if we reached the end of the file
    755823        //
    756         if (fIn->eof())
     824        if (fIn->eof() || c==EOF)
    757825        {
    758826            *fLog << "End of file." << endl;
     
    763831        // If the eof isn't reached a new header must follow. Check for it.
    764832        //
    765         if (fIn->peek()!=cTITLE_TEMPLATE[0])
     833        if (c!=cTITLE_TEMPLATE[0])
    766834        {
    767835            *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl;
     
    813881    *fLog << "Number of Events read from file: " << fNumEvents << endl;
    814882    *fLog << "Number of Runs read from file:   " << fNumRuns << endl;
     883    *fLog << "Number of events detected first: " << fEntries << endl;
    815884
    816885    if (fNumEvents!=fNumFilterEvts)
Note: See TracChangeset for help on using the changeset viewer.