8 #include <utl/AugerException.h>
15 SenecaFileParser::SenecaFileParser(
const std::string& FileName,
io::Mode mode) :
43 unsigned char RecordBuffer[48];
47 string msg =
"Seneca IO Exception: Failed to open " + FileName +
53 msg =
"Seneca IO Exception: Failed to open " + FileName +
".\n";
60 string msg =
"Seneca IO Exception: Failed to open " + FileName +
61 " for writing. Currently read only.\n";
67 SenecaFile.open(FileName.c_str(), ios::binary | ios::in);
70 msg =
"Seneca IO Exception: Failed to open " + FileName +
". Does it exist?\n";
85 msg =
"Seneca IO Exception: Error reading from " + FileName +
". Either not a Seneca file or unsupported version.\n";
128 int EventHeaderCheck = 0;
129 unsigned int TempPosition;
142 if (EventHeaderCheck == -990) {
145 if (EventHeaderCheck == -998) {
176 if (!FileOpen || EventHeaderValid==
false)
188 if (!FileOpen || ParticleRecordValid==
false)
194 return &ParticleRecord;
204 else if (thePosition > FileSize)
210 SenecaFile.seekg(thePosition);
217 return SenecaFile.tellg();
222 unsigned char EventHeaderBuffer[48];
228 else if (theEventNumber>NumberEvents)
234 else if (theEventNumber<1)
240 SenecaFile.seekg(EventPositions[theEventNumber-1], ios::beg);
241 SenecaFile.read((
char*)EventHeaderBuffer,48);
242 CurrentPosition=SenecaFile.tellg();
243 if (DecodeEventHeader(EventHeaderBuffer)==
eSuccess)
245 EventHeader.ID=theEventNumber-1;
246 EventHeaderValid=
true;
247 CurrentEvent=theEventNumber-1;
248 NextEvent=theEventNumber;
256 EventHeaderValid=
false;
265 return GotoEvent(NextEvent+1);
270 unsigned char ParticleBuffer[24];
272 if (!FileOpen || EventHeaderValid==
false)
280 SenecaFile.read((
char*)ParticleBuffer,24);
281 CurrentPosition=SenecaFile.tellg();
282 if (DecodeParticleRecord(ParticleBuffer)==
eSuccess)
285 ParticleRecordValid=
true;
293 ParticleRecordValid=
false;
302 if (!SenecaFile.is_open())
306 else if (SenecaFile.eof())
316 EventHeader.ID=SenecaDecodeInt(FileData);
318 if (EventHeader.ID==-990)
320 EventHeader.E0=SenecaDecodeFloat(FileData+3+24);
321 EventHeader.ID0=SenecaDecodeInt(FileData+6+24);
322 EventHeader.Theta=SenecaDecodeFloat(FileData+9+24);
323 EventHeader.Phi=SenecaDecodeFloat(FileData+12+24);
324 EventHeaderValid=
true;
330 EventHeaderValid=
false;
337 FileHeader.ID=SenecaDecodeInt(FileData);
339 if (FileHeader.ID!=0x006e6573)
342 FileHeader.SenecaVersion=atof((
char*)(FileData+7));
344 if (!strncmp((
char*)(FileData+11),
"QGS98",5))
346 else if (!strncmp((
char*)(FileData+11),
"QGS01",5))
348 else if (!strncmp((
char*)(FileData+11),
"SIB21",5))
350 else if (!strncmp((
char*)(FileData+11),
"NEX2",4))
352 else if (!strncmp((
char*)(FileData+11),
"NEX397",6))
357 if (!strncmp((
char*)(FileData+17),
"GHEISHA",7))
359 else if (!strncmp((
char*)(FileData+17),
"GFLUKA",7))
361 else if (!strncmp((
char*)(FileData+17),
"GCALOR",6))
363 else if (!strncmp((
char*)(FileData+17),
"URQMD",5))
368 FileHeader.ID=SenecaDecodeInt(FileData+24);
370 if (FileHeader.ID==-999)
372 FileHeader.HGround=SenecaDecodeFloat(FileData+3+24);
373 FileHeader.HObs=SenecaDecodeFloat(FileData+6+24);
374 FileHeader.HCore=SenecaDecodeFloat(FileData+9+24);
375 FileHeader.HINJ=SenecaDecodeFloat(FileData+12+24);
376 FileHeader.ILowHadr=SenecaDecodeInt(FileData+15+24);
377 FileHeader.IOHadr=SenecaDecodeInt(FileData+18+24);
378 FileHeader.IVersion=SenecaDecodeInt(FileData+21+24);
381 FileHeaderValid=
true;
388 ParticleRecord.ID=SenecaDecodeInt(FileData);
390 if (ParticleRecord.ID==-990 || ParticleRecord.ID==-999 || ParticleRecord.ID==-998)
392 ParticleRecord.Weight=SenecaDecodeFloat(FileData+3);
393 ParticleRecord.X=SenecaDecodeFloat(FileData+6);
394 ParticleRecord.Y=SenecaDecodeFloat(FileData+9);
395 ParticleRecord.T=SenecaDecodeFloat(FileData+12);
396 ParticleRecord.Px=SenecaDecodeFloat(FileData+15);
397 ParticleRecord.Py=SenecaDecodeFloat(FileData+18);
398 ParticleRecord.Pz=SenecaDecodeFloat(FileData+21);
400 ParticleRecordValid=
true;
416 unsigned int mantissa, shift1, shift2, shifted;
417 signed char exponent;
420 if (FileData[0]==0 && FileData[1]==0 && FileData[2]==0)
424 exponent=(
signed char)( (
unsigned char)(FileData[2] & 0x7f) );
425 mantissa=(
unsigned int)FileData[1];
427 mantissa+=(
unsigned int)FileData[0];
429 shift1=(
unsigned int)sign;
430 shift2=(
unsigned int)(exponent+64);
434 shifted=shift1+shift2+mantissa;
436 memcpy(&decoded,&shifted,4);
452 holder=(
unsigned int)FileData[2];
454 holder+=(
unsigned int)FileData[1];
456 holder+=(
unsigned int)FileData[0];
458 if (holder & 0x800000)
460 if (holder & 0x400000)
461 decoded=(
signed int)(holder^0xff000000);
463 decoded=-1*(
signed int)( holder ^ 0x800000 );
466 decoded=(
signed int)holder;
474 if (!SenecaFile.is_open())
476 string msg=
"Seneca IO Exception: No file is open. No number of events.\n";
484 if (!SenecaFile.is_open())
486 string msg=
"Seneca IO Exception: No file is open. No event open.\n";
489 return CurrentEvent+1;
SenecaParticleRecord * GetParticleRecord()
unsigned int GetCurrentEvent()
unsigned int NumberEvents
Status DecodeEventHeader(unsigned char *Record)
unsigned int GetPosition()
Status GotoEvent(unsigned int theEventNumber)
Mode
Available open modes.
unsigned int CurrentEvent
float SenecaDecodeFloat(unsigned char *Buffer)
Base class to report exceptions in IO.
Status
Return code for seek operation.
SenecaHeaderRecord FileHeader
Status DecodeParticleRecord(unsigned char *Record)
SenecaEventHeaderRecord * GetCurrentEventHeader()
Status GotoPosition(unsigned int thePosition)
unsigned long EventPositions[1024]
SenecaHeaderRecord * GetFileHeader()
unsigned int GetCurrentPosition()
unsigned long CurrentPosition
int SenecaDecodeInt(unsigned char *Buffer)
Status DecodeFileHeader(unsigned char *Record)
Status OpenSenecaFile(const std::string &FileName, Mode mode=eRead)
void Buffer(sevt::Station &station, const TimeStamp &eventTime, const StationTriggerData::Algorithm algorithm, const int pldBits, const int start, const int stop)
unsigned int GetNumberEvents()