Changeset 19337


Ignore:
Timestamp:
Oct 30, 2018, 5:21:01 PM (5 months ago)
Author:
tbretz
Message:
Read the block header and footer bytes only when they are expected.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcorsika/MCorsikaFormat.cc

    r19333 r19337  
    122122                                    Int_t & blockLength) const
    123123{
    124 
    125     uint32_t blockHeader = fBlockLength;
    126     while (blockHeader==fBlockLength)
    127     {
    128         fIn->read((char*)&blockHeader, 4);
    129         if (fIn->eof())
    130             return kFALSE;
    131     }
     124    if (fBlockLength)
     125    {
     126        // In the new corsika format each block
     127        // starts and end with the block length
     128        const size_t position = fIn->tellg()%(fBlockLength+8);
     129
     130        // Whenever we are prior to the end of such a block,
     131        // we read and check the end and start tag of this
     132        // and the following block
     133        if (position==fBlockLength+4)
     134        {
     135            uint32_t h[2];
     136            fIn->read((char*)h, 8);
     137            if (fIn->eof())
     138                return kFALSE;
     139
     140            if (h[0]!=fBlockLength || h[1]!=fBlockLength)
     141            {
     142                gLog << err << "ERROR - Block length missing at the end or beginning of a block." << endl;
     143                return kERROR;
     144            }
     145        }
     146    }
     147
     148    uint32_t blockHeader = 0;
     149    fIn->read((char*)&blockHeader, 4);
     150    if (fIn->eof())
     151        return kFALSE;
    132152
    133153    blockVersion    = 0;
Note: See TracChangeset for help on using the changeset viewer.