Changeset 9889 for trunk/Mars


Ignore:
Timestamp:
08/24/10 12:41:43 (14 years ago)
Author:
rohlfs
Message:
The RUNE block is first searched at the end of the file
Location:
trunk/Mars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/Changelog

    r9886 r9889  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2010/08/24 Reiner Rohlfs
     22
     23   * mcorsika/MCorsikaFormat.[h,cc]
     24     - in method MCorsikaFormatEventIO::SeekEvtEnd() the RUNE block
     25       is first searched at the end of the file. It it is not found
     26       the whole file is scanned for the RUNE block. Once it is
     27       found it can be accessed directly at the next call of this
     28       function.
     29
    2030
    2131 2010/08/20 Daniela Dorner
  • trunk/Mars/mcorsika/MCorsikaFormat.cc

    r9616 r9889  
    233233
    234234        unsigned short fileType = blockHeader[1] & 0xFFFF;
    235         if (/*memcmp(blockHeader+5, id, 4) == 0 && */
    236             type == fileType                       )
    237             {
    238 //*fLog << all << "found " << id << " type: " << type << endl;
     235        if (type == fileType                       )
    239236            break;
    240             }
    241237
    242238         if (type == 1202 && fileType == 1210)
     
    248244        // a unknown block, we jump to the next one
    249245//*fLog << "unknown: " <<  id << " type: " << fileType << " sub-blocks: " <<  (blockHeader[3]>>29);
    250 //*fLog <<  " length: " << (blockHeader[3] & 0x3fffffff) << endl;
     246//*fLog <<  " length: " << (blockHeader[3] & 0x3fffffff) <<   "  pos: " << fIn->tellg() << endl;
    251247        int length = blockHeader[3] & 0x3fffffff;
    252         fIn->seekg(length - 2 * sizeof(int), ios::cur);   
     248       
     249        fIn->seekg(length - 2 * (Int_t)(sizeof(int)), ios::cur);   
    253250    }
    254251
     
    261258void MCorsikaFormatEventIO::UnreadLastHeader()
    262259{
    263     fIn->seekg( (int)(-6 * sizeof(int)), ios::cur);
     260    fIn->seekg( -6 * (Int_t)(sizeof(int)), ios::cur);
    264261}
    265262
     
    268265Bool_t MCorsikaFormatEventIO::SeekEvtEnd()
    269266{
    270     if (SeekNextBlock("RUNE", 1210))
    271     {
    272         UnreadLastHeader();
     267    if (fRunePos != 0)
     268        {
     269        fIn->seekg(fRunePos, ios::beg);
    273270        return kTRUE;
    274     }
    275 
     271        }
     272    else
     273        {
     274        // it is the first time we are looking for the RUNE block
     275
     276        // is the RUNE block at the very end of the file?
     277        std::streampos currentPos = fIn->tellg();
     278
     279        fIn->seekg(-32, ios::end);
     280        unsigned int blockHeader[4];
     281        fIn->read((char*)blockHeader, 4 * sizeof(int));
     282        if ( blockHeader[0]               == 0xd41f8a37 &&
     283            (blockHeader[1] & 0xffff)     == 1210       &&
     284            (blockHeader[3] & 0x3fffffff) == 16)
     285            {
     286            // this seams to be a RUNE (1210)  block
     287            fIn->seekg( -4 * (Int_t)(sizeof(int)), ios::cur);
     288            fRunePos = fIn->tellg();
     289            return kTRUE;
     290            }
     291
     292        // we do not find a RUNE block at the end of the file
     293        // we have to search in the file
     294        fIn->seekg(currentPos, ios::beg);
     295        if (SeekNextBlock("RUNE", 1210))
     296            {
     297            UnreadLastHeader();
     298            fRunePos = fIn->tellg();
     299            return kTRUE;
     300            }
     301        }
    276302    return kFALSE;
    277303}
     
    328354    return kTRUE;
    329355}
    330 
    331356// --------------------------------------------------------------------------
    332357//                                                                           
     
    357382        unsigned short fileType = blockHeader[1] & 0xFFFF;
    358383        if (fileType == 1204)
    359 {
    360 *fLog << all << "found new top level block 1204" << endl;
    361384            return kTRUE;
    362 }
     385
    363386        if (fileType == 1209)
    364387            {
    365388            // we found an eventEnd block, reset file pointer
    366             fIn->seekg( (Int_t)(-4 * sizeof(Int_t)), ios::cur);
     389            fIn->seekg( -4 * (Int_t)(sizeof(Int_t)), ios::cur);
    367390            length = 0;
    368391            return kFALSE;
     
    371394
    372395        // a unknown block, we jump to the next one
    373 *fLog << all << "found block " << fileType << endl;
    374396        fIn->seekg(length, ios::cur);   
    375397    }
  • trunk/Mars/mcorsika/MCorsikaFormat.h

    r9616 r9889  
    2424public:
    2525   MCorsikaFormat(MLog * log, std::istream * in)
    26         : fIn(in) {fLog = log;}
     26        : fIn(in) {fLog = log; }
    2727   virtual ~MCorsikaFormat();
    2828
     
    6969{
    7070private:
     71        std::streampos fRunePos; // file position of the RUNE block
    7172
    7273public:
    7374   MCorsikaFormatEventIO(MLog * log, std::istream * in)
    74         : MCorsikaFormat(log, in) {}
     75        : MCorsikaFormat(log, in) {fRunePos = 0;}
    7576
    7677   Bool_t SeekNextBlock(const char * id, unsigned short type);
Note: See TracChangeset for help on using the changeset viewer.