Changeset 19329 for trunk/Mars/mcorsika
- Timestamp:
- 10/30/18 15:26:46 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcorsika/MCorsikaFormat.cc
r19319 r19329 40 40 41 41 42 const unsigned int MCorsikaFormat::kMagicNumber = 0x5994;43 const unsigned int MCorsikaFormat::kSyncMarker = 0xd41f8a37;44 45 42 // -------------------------------------------------------------------------- 46 43 // … … 58 55 } 59 56 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; 63 61 64 62 // 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 69 70 fileIn->seekg(-4, ios::cur); 70 71 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 { 81 80 gLog << inf2 << "Corsika EventIO format detected." << endl; 82 81 return new MCorsikaFormatEventIO(fileIn); 83 82 } 84 83 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 87 87 delete fileIn; 88 delete [] buffer;89 88 90 89 return NULL; … … 124 123 { 125 124 126 int blockHeader = 22932;127 while (blockHeader== 22932)125 uint32_t blockHeader = fBlockLength; 126 while (blockHeader==fBlockLength) 128 127 { 129 128 fIn->read((char*)&blockHeader, 4); … … 134 133 blockVersion = 0; 135 134 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; 137 138 138 139 switch(blockHeader) 139 140 { 140 case 1213093202 : // RUNH141 case kRUNH: 141 142 blockType = 1200; 142 143 break; 143 case 1162761554 : // RUNE 144 145 case kRUNE: 144 146 blockType = 1210; 145 147 break; 146 case 1213486661 : // EVTH 148 149 case kEVTH: 147 150 if (readState != 10) 148 151 blockType = 1202; // event header (where readstate := 2) … … 154 157 } 155 158 break; 156 case 1163155013 : // EVTE 159 160 case kEVTE: 157 161 blockType = 1209; 158 162 break; 163 159 164 default: // the events, they don't have a specific header 160 165 blockType = 1105; // raw data … … 168 173 Bool_t MCorsikaFormatRaw::SeekEvtEnd() 169 174 { 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 170 180 // 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) 179 192 { 180 193 // fIn->seekg(-4, ios::cur);
Note:
See TracChangeset
for help on using the changeset viewer.