Changeset 19329


Ignore:
Timestamp:
Oct 30, 2018, 3:26:46 PM (5 months ago)
Author:
tbretz
Message:
Moved magic numbers to an enum, changed hasMagicNumber into the block length (273 floats for raw data and 312 data for THIN data)
File:
1 edited

Legend:

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

    r19319 r19329  
    4040
    4141
    42 const unsigned int MCorsikaFormat::kMagicNumber = 0x5994;
    43 const unsigned int MCorsikaFormat::kSyncMarker  = 0xd41f8a37;
    44 
    4542// --------------------------------------------------------------------------
    4643//
     
    5855    }
    5956
    60     char *buffer = new char[5];
    61     memset(buffer, 0, 5);
    62     fileIn->read(buffer, 4);
     57    uint32_t magic = 0;
     58    fileIn->read((char*)&magic, 4);
     59
     60    uint32_t blocklength = 0;
    6361
    6462    // This seems to be a new corsika binary identifier
    65     const bool hasMagicNumber = *reinterpret_cast<unsigned int*>(buffer) == kMagicNumber;
    66     if (hasMagicNumber)
    67         fileIn->read(buffer, 4);
    68 
     63    if (magic==kBlockLengthRaw || magic==kBlockLengthThin)
     64    {
     65        blocklength = magic;
     66        fileIn->read((char*)&magic, 4);
     67    }
     68
     69    // Jump back that the "RUNH" is can be read again
    6970    fileIn->seekg(-4, ios::cur);
    7071
    71     if (strcmp(buffer, "RUNH") == 0)
    72     {
    73         delete [] buffer;
    74         gLog << inf2 << "Corsika RAW format detected." << endl;
    75         return new MCorsikaFormatRaw(fileIn, hasMagicNumber);
    76     }
    77 
    78     if (*reinterpret_cast<unsigned int*>(buffer) == kSyncMarker)
    79     {
    80         delete [] buffer;
     72    if (magic==kRUNH)
     73    {
     74        gLog << inf2 << "Corsika RAW" << (blocklength==kBlockLengthThin?"(+THIN)":"") << " format detected." << endl;
     75        return new MCorsikaFormatRaw(fileIn, blocklength);
     76    }
     77
     78    if (magic==kSyncMarker)
     79    {
    8180        gLog << inf2 << "Corsika EventIO format detected." << endl;
    8281        return new MCorsikaFormatEventIO(fileIn);
    8382    }
    8483
    85     gLog << err << "File " << fileName <<
    86             " is neither a CORSIKA raw nor EventIO file" << endl;
     84    gLog << err << "File " << fileName << Form(" (%08x) ", magic);
     85    gLog << "is neither a CORSIKA raw nor EventIO file" << endl;
     86
    8787    delete fileIn;
    88     delete [] buffer;
    8988
    9089    return NULL;
     
    124123{
    125124
    126     int blockHeader = 22932;
    127     while (blockHeader==22932)
     125    uint32_t blockHeader = fBlockLength;
     126    while (blockHeader==fBlockLength)
    128127    {
    129128        fIn->read((char*)&blockHeader, 4);
     
    134133    blockVersion = 0;
    135134    blockIdentifier = 0;
    136     blockLength     = 272 * 4;
     135    blockLength     = fBlockLength/21 - 4;
     136
     137//    cout << "P=" << fIn->tellg() << " L=" <<blockLength << " " << hex << blockHeader << dec << " " << fIn->eof() << endl;
    137138
    138139    switch(blockHeader)
    139140      {
    140       case 1213093202 : // RUNH
     141      case kRUNH:
    141142         blockType = 1200;
    142143         break;
    143       case 1162761554 : // RUNE
     144
     145      case kRUNE:
    144146         blockType = 1210;
    145147         break;
    146       case 1213486661 : // EVTH
     148
     149      case kEVTH:
    147150         if (readState != 10)
    148151            blockType = 1202;     // event header (where readstate := 2)
     
    154157            }
    155158         break;
    156       case 1163155013 : // EVTE
     159
     160      case kEVTE:
    157161         blockType = 1209;
    158162         break;
     163
    159164      default:          // the events, they don't have a specific header
    160165         blockType = 1105;                  // raw data
     
    168173Bool_t MCorsikaFormatRaw::SeekEvtEnd()
    169174{
     175    const uint32_t step   = fBlockLength/21;
     176    const uint32_t offset = fBlockLength?4:0;
     177
     178//    cout << fIn->bad() << " " << fIn->eof() << " " << fIn->tellg() << endl;
     179
    170180    // Search subblockwise backward (Block: 5733*4 = 21*273*4)
    171     for (int i=1; i<22; i++)
    172     {
    173         fIn->seekg(-i*273*4-(fHasMagicNumber?4:0), ios::end);
    174 
    175         char runh[5]="\0\0\0\0";
    176         fIn->read(runh, 4);
    177 
    178         if (!strcmp(runh, "RUNE"))
     181    for (uint32_t i=1; i<22; i++)
     182    {
     183        const int32_t L = i*step + offset;
     184        fIn->seekg(-L, ios::end);
     185
     186        uint32_t magic = 0;
     187        fIn->read((char*)&magic, 4);
     188
     189//        cout << dec << L << " " << fIn->tellg() << " " << hex << magic << endl;
     190
     191        if (magic==kRUNE)
    179192        {
    180193//            fIn->seekg(-4, ios::cur);
Note: See TracChangeset for help on using the changeset viewer.