Changeset 9943 for trunk/Mars/mcorsika
- Timestamp:
- 09/28/10 10:11:31 (14 years ago)
- Location:
- trunk/Mars/mcorsika
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcorsika/MCorsikaEvtHeader.h
r9941 r9943 71 71 72 72 void InitXY() { fX=fTempY[fNumReuse]; fY=-fTempX[fNumReuse]; } 73 void AddXY(Float_t x, Float_t y) { fX+=x; fY+=y; } 73 74 74 75 Int_t ReadEvt(MCorsikaFormat *informat); // read in event header block -
trunk/Mars/mcorsika/MCorsikaFormat.cc
r9941 r9943 72 72 } 73 73 74 void MCorsikaFormat::Read(void *ptr, Int_t i) const 75 { 76 fIn->read((char*)ptr, i); 77 } 78 74 79 // -------------------------------------------------------------------------- 75 80 // … … 122 127 { 123 128 fIn->seekg(fPos, ios::beg); 129 } 130 131 void MCorsikaFormat::Rewind() const 132 { 133 fIn->seekg(0, ios::beg); 124 134 } 125 135 … … 198 208 // returns kFALSE; 199 209 // 200 Int_t MCorsikaFormatRaw::GetNextEvent(Float_t **buffer, UInt_t)210 Int_t MCorsikaFormatRaw::GetNextEvent(Float_t **buffer, Int_t) 201 211 { 202 212 static Float_t data[273]; … … 242 252 Bool_t MCorsikaFormatEventIO::SeekNextBlock(const char * id, unsigned short type) const 243 253 { 244 int blockHeader[7]; 245 254 cout << "Seek " << type << endl; 246 255 while (1) 247 256 { … … 252 261 // - unknown field 253 262 // - id (first 4 bytes of data field) 254 fIn->read((char*)blockHeader, 6 * sizeof(int)); 263 int blockHeader[4]; 264 fIn->read((char*)blockHeader, 4 * sizeof(int)); 255 265 256 266 if (fIn->eof()) 257 267 { 258 gLog << err << "MCorsikaFormatEventIO::SeekNextBlock: ERROR - unexpected end-of-file." << endl;268 gLog << err << "MCorsikaFormatEventIO::SeekNextBlock: ERROR - Unexpected end-of-file seeking " << id << " (" << type << ")." << endl; 259 269 return kFALSE; 260 270 } 261 271 262 272 const unsigned short objType = blockHeader[1] & 0xFFFF; 273 cout << "objType=" << objType << endl; 263 274 if (type == objType) 264 break; 275 { 276 if (!id) 277 break; 278 279 char c[9]; 280 fIn->read(c, 8); 281 282 if (memcmp(c+4, id, 4)==0) 283 break; 284 285 c[8] = 0; 286 gLog << err << "MCorsikaFormatEventIO::SeekNextBlock: ERROR - '" << c+4 << "' doesn't match expected one '" << id << "' in object " << type << endl; 287 return kFALSE; 288 } 265 289 266 290 // we are looking for a event header, but found a runEnd. … … 272 296 // a unknown block, we jump to the next one 273 297 const int length = blockHeader[3] & 0x3fffffff; 274 275 fIn->seekg(length - 2 * (Int_t)(sizeof(int)), ios::cur); 298 fIn->seekg(length, ios::cur); 276 299 } 277 300 … … 336 359 // returns kFALSE; 337 360 // 338 Int_t MCorsikaFormatEventIO::GetNextEvent(Float_t **buffer, UInt_t telescope)361 Int_t MCorsikaFormatEventIO::GetNextEvent(Float_t **buffer, Int_t telescope) 339 362 { 340 363 static Float_t *data = NULL; 341 static Int_t lengthEvent = -1; 342 static Int_t lengthPhotonData = 0; 343 344 while (lengthPhotonData == 0) 364 365 static int lengthPhotonData = 0; 366 static int lengthEvent = 0; 367 368 if (lengthPhotonData>0) 369 { 370 cout << "Return Bunch l2=" << lengthPhotonData << endl; 371 372 lengthPhotonData -= 8 * sizeof(Float_t); 373 *buffer += 8; // Return the pointer to the start of the current photon data 374 return kTRUE; 375 } 376 377 if (data) 345 378 { 346 379 delete [] data; 347 380 data = NULL; 348 349 // If we are at the end of the event signal this and 350 // start next time with a new event 351 if (lengthEvent==0) 381 cout << "Return end-of-tel LE=" << lengthEvent << endl; 382 return kFALSE; 383 } 384 385 if (lengthEvent==0) 386 { 387 cout << "Searching 1204... " << flush; 388 // The length of the block is stored and we use it to determine 389 // when the next top level block is expected 390 const Int_t rc = NextEventObject(lengthEvent); 391 if (rc==kERROR) 392 return kERROR; 393 if (!rc) 352 394 { 353 lengthEvent=-1;354 return kFALSE; // Signal to start with a new event (process task list first)395 cout << "skip EVTE." << endl; 396 return kFALSE; 355 397 } 356 398 357 // Look for the next top level block (an "event", object type 1204) 358 // A top level block contains the data of a full array simulation 359 // (a single re-usage of the shower) 360 if (lengthEvent<0) 361 { 362 // The length of the block is stored and we use it to determine 363 // when the next top level block is expected 364 const Int_t rc = NextEventObject(lengthEvent); 365 if (rc!=kTRUE) 366 return rc; 367 } 368 369 // Look for the next event photon bunch (object type 1205) 370 const Int_t tel = NextPhotonObject(lengthPhotonData); 371 if (tel<0) 372 return kERROR; 373 374 // Decrease the distance to the next "event" by the current photon bunches 375 lengthEvent -= lengthPhotonData + 3 * sizeof(int); 376 377 // If the telescope is not the one we want to read skip the photon data 378 if (UInt_t(tel)!=telescope) 379 { 380 fPrevPos = fIn->tellg(); 381 fIn->seekg(lengthPhotonData, ios::cur); 382 lengthPhotonData=0; 383 continue; 384 } 385 386 const UInt_t cnt = lengthPhotonData / sizeof(Float_t); 387 388 // Read next object (photon bunch) 389 data = new Float_t[cnt]; 390 if (!ReadData(cnt, data, 0)) 391 { 392 delete [] data; 393 data = NULL; 394 return kERROR; 395 } 396 397 // The object containing the photon bunches starts with: 398 // Array[short], Telescope[Short], NumPhotons[Real], NumBunches[Long] 399 // eventLength contains now the number of bytes with photon data not yet evaluated 400 lengthPhotonData -= 3 * sizeof(Float_t); 401 } 402 403 // The photon data itself is 8 floats long. When we return we expect this to be 404 // evaluated already when the function is called the next time. 399 cout << "found new array." << endl; 400 } 401 402 cout << "Searching 1205..." << flush; 403 404 // Look for the next event photon bunch (object type 1205) 405 const Int_t tel = NextPhotonObject(lengthPhotonData); 406 if (tel<0) 407 return kERROR; 408 409 lengthEvent -= lengthPhotonData+12; // Length of data + Length of header 410 411 lengthPhotonData -= 12; // Length of data before the photon bunches 412 fIn->seekg(12, ios::cur); // Skip this data 413 414 cout << " found (tel=" << tel << ",LEN=" << lengthEvent << ",len=" << lengthPhotonData << ")... " << flush; 415 416 if (lengthPhotonData==0) 417 { 418 cout << "empty!" << endl; 419 return kFALSE; 420 } 421 422 const UInt_t cnt = lengthPhotonData / sizeof(Float_t); 423 // Read next object (photon bunch) 424 data = new Float_t[cnt]; 425 if (!ReadData(cnt, data, 0)) 426 { 427 delete [] data; 428 data = NULL; 429 return kERROR; 430 } 431 432 cout << "return!" << endl; 433 405 434 lengthPhotonData -= 8 * sizeof(Float_t); 406 407 // Return the pointer to the start of the current photon data 408 *buffer = data + 3; 435 *buffer = data; // Return the pointer to the start of the current photon data 409 436 410 437 return kTRUE; 438 } 411 439 } 412 440 … … 425 453 // - identification field 426 454 // - length 427 428 455 UInt_t blockHeader[4]; 429 456 fIn->read((char*)blockHeader, 4 * sizeof(Int_t)); … … 440 467 const unsigned short objType = blockHeader[1] & 0xFFFF; 441 468 469 cout << "objType=" << objType << endl; 470 442 471 // Decode length of block 443 472 length = blockHeader[3] & 0x3fffffff; -
trunk/Mars/mcorsika/MCorsikaFormat.h
r9941 r9943 37 37 virtual void StorePos(); 38 38 virtual void ResetPos() const; 39 virtual void Rewind() const; 39 40 40 virtual Int_t GetNextEvent(Float_t **buffer, UInt_t tel=0) = 0;41 virtual Int_t GetNextEvent(Float_t **buffer, Int_t tel=0) = 0; 41 42 virtual Bool_t IsEventioFormat() const = 0; 42 43 … … 44 45 45 46 std::streampos GetCurrPos() const; 47 48 void Read(void *ptr, Int_t i=4) const; 46 49 47 50 static MCorsikaFormat *CorsikaFormatFactory(const char *fileName); … … 62 65 Bool_t SeekEvtEnd(); 63 66 64 Int_t GetNextEvent(Float_t **buffer, UInt_t);67 Int_t GetNextEvent(Float_t **buffer, Int_t); 65 68 Bool_t IsEventioFormat() const {return kFALSE;} 66 69 }; … … 81 84 Bool_t SeekEvtEnd(); 82 85 83 Int_t GetNextEvent(Float_t **buffer, UInt_t tel);86 Int_t GetNextEvent(Float_t **buffer, Int_t tel); 84 87 Bool_t IsEventioFormat() const { return kTRUE; } 85 88 -
trunk/Mars/mcorsika/MCorsikaRead.cc
r9941 r9943 96 96 // 97 97 MCorsikaRead::MCorsikaRead(const char *fname, const char *name, const char *title) 98 : fRunHeader(0), fEvtHeader(0), fEvent(0), fTelescopeIdx( 0), fForceMode(kFALSE),98 : fRunHeader(0), fEvtHeader(0), fEvent(0), fTelescopeIdx(-1), fForceMode(kFALSE), 99 99 fFileNames(0), fNumFile(0), fNumEvents(0), fNumTotalEvents(0), 100 fIn(0), fInFormat(0), fParList(0)100 /*fIn(0),*/ fInFormat(0), fParList(0), fNumTelescopes(1) 101 101 { 102 102 fName = name ? name : "MRead"; … … 117 117 { 118 118 delete fFileNames; 119 if (fIn)120 delete fIn;119 // if (fIn) 120 // delete fIn; 121 121 if (fInFormat) 122 122 delete fInFormat; … … 191 191 // open the input stream and check if it is really open (file exists?) 192 192 // 193 if (fIn)193 /* if (fIn) 194 194 delete fIn; 195 195 fIn = NULL; 196 196 */ 197 197 if (fInFormat) 198 198 delete fInFormat; … … 239 239 // if (!fEvtHeader->ReadRunHeader(*fIn, *fRunHeader)) 240 240 // return kERROR; 241 242 fNumTelescopes = 1; 243 if (fInFormat->IsEventioFormat()) 244 { 245 fInFormat->StorePos(); 246 fInFormat->Rewind(); 247 248 if (!fInFormat->SeekNextBlock(0, 1201)) 249 { 250 *fLog << err << "ERROR - Object 1201 not found in file." << endl; 251 return kERROR; 252 } 253 254 fInFormat->Read(&fNumTelescopes); 255 256 if (fTelescopeIdx>=fNumTelescopes) 257 { 258 *fLog << err << "ERROR - Requested telescope index " << fTelescopeIdx << " exceeds number of telescopes " << fNumTelescopes << " in file." << endl; 259 return kERROR; 260 } 261 262 fTelescopeX.Set(fNumTelescopes); 263 fTelescopeY.Set(fNumTelescopes); 264 fTelescopeZ.Set(fNumTelescopes); 265 fTelescopeR.Set(fNumTelescopes); 266 267 fInFormat->Read(fTelescopeX.GetArray(), 4*fNumTelescopes); 268 fInFormat->Read(fTelescopeY.GetArray(), 4*fNumTelescopes); 269 fInFormat->Read(fTelescopeZ.GetArray(), 4*fNumTelescopes); 270 fInFormat->Read(fTelescopeR.GetArray(), 4*fNumTelescopes); 271 272 *fLog << all; 273 *fLog << "Number of telescopes: " << fNumTelescopes << " (using "; 274 if (fTelescopeIdx>=0) 275 *fLog << "telescope " << fTelescopeIdx; 276 else 277 *fLog << "all telescopes"; 278 *fLog << ")" << endl; 279 280 const Int_t lo = fTelescopeIdx<0 ? 0 : fTelescopeIdx; 281 const Int_t up = fTelescopeIdx<0 ? fNumTelescopes : fTelescopeIdx+1; 282 283 for (int i=lo; i<up; i++) 284 { 285 *fLog << inf << "Telescope #" << setw(4) << i << " [X/Y/Z (R)]: "; 286 *fLog << setw(7) << fTelescopeX[i] << "/"; 287 *fLog << setw(7) << fTelescopeY[i] << "/"; 288 *fLog << setw(7) << fTelescopeZ[i] << " (R=" << setw(4) << fTelescopeR[i] << ")" << endl; 289 } 290 291 fNumTelescope = 0; 292 293 fInFormat->ResetPos(); 294 } 295 241 296 242 297 fInFormat->StorePos(); … … 319 374 } 320 375 321 fNumTotalEvents += fRunHeader->GetNumEvents()*fRunHeader->GetNumReuse(); 376 fNumTotalEvents += fRunHeader->GetNumEvents()*fRunHeader->GetNumReuse()* 377 (fTelescopeIdx<0 ? fNumTelescopes : 1); 322 378 continue; 323 379 } 324 380 break; 325 381 } 326 382 /* 327 383 if (fIn) 328 384 delete fIn; 329 385 fIn = NULL; 330 386 */ 331 387 return rc; 332 388 } … … 356 412 // 357 413 fParList = 0; 358 414 /* 359 415 if (!OpenStream()) 360 416 return kFALSE; 361 417 */ 362 418 // 363 419 // check if all necessary containers exist in the Parameter list. … … 395 451 Int_t MCorsikaRead::ReadEvent() 396 452 { 397 // Store the position to re-read a single event several times 398 // FIXME: Does this work with EventIO, too? 399 if (fEvtHeader->GetNumReuse()>=fRunHeader->GetNumReuse()-1) 400 { 401 fInFormat->StorePos(); 402 fEvtHeader->ResetNumReuse(); 403 404 if (fInFormat->IsEventioFormat()) 453 if (fInFormat->IsEventioFormat()) 454 { 455 if (fNumTelescope==0) 405 456 { 406 // Read the event header407 457 const Int_t rc1 = fEvtHeader->ReadEvt(fInFormat); 408 458 if (rc1!=kTRUE) 409 459 return rc1; 460 461 if (fEvtHeader->GetNumReuse()==fRunHeader->GetNumReuse()-1) 462 fEvtHeader->ResetNumReuse(); 463 fEvtHeader->IncNumReuse(); 464 465 cout << "===== Array " << fEvtHeader->GetNumReuse() << " =====" << endl; 410 466 } 411 467 468 const Int_t rc2 = fEvent->ReadCorsikaEvt(fInFormat, fTelescopeIdx); 469 if (rc2!=kTRUE) 470 return rc2; 471 472 fEvtHeader->InitXY(); 473 474 const Double_t x = fTelescopeX[fNumTelescope]; 475 const Double_t y = fTelescopeY[fNumTelescope]; 476 477 fEvtHeader->AddXY(y, -x); 478 fEvent->AddXY(fEvtHeader->GetX(), fEvtHeader->GetY()); 479 fEvent->SimWavelength(fRunHeader->GetWavelengthMin(), fRunHeader->GetWavelengthMax()); 480 481 fNumTelescope++; 482 fNumTelescope%=fNumTelescopes; 483 484 return kTRUE; 412 485 } 413 486 else 414 487 { 415 if (!fInFormat->IsEventioFormat()) 488 // Store the position to re-read a single event several times 489 if (fEvtHeader->GetNumReuse()<fRunHeader->GetNumReuse()-1) 416 490 fInFormat->ResetPos(); 417 } 418 419 if (!fInFormat->IsEventioFormat()) 420 { 491 else 492 { 493 fInFormat->StorePos(); 494 fEvtHeader->ResetNumReuse(); 495 } 496 421 497 // Read the event header 422 498 const Int_t rc1 = fEvtHeader->ReadEvt(fInFormat); … … 424 500 return rc1; 425 501 426 } 427 428 fEvtHeader->IncNumReuse(); 429 fEvtHeader->InitXY(); 430 431 // In the case of corsika raw data (MMCS only) we have too loop over one event 432 // several times to read all impact parameters (reusage of events) 433 // In case of the eventio format we have to decide, the data of which telescope 434 // we want to extract 435 const Int_t id = fInFormat->IsEventioFormat() ? fTelescopeIdx : fEvtHeader->GetNumReuse()+1; 436 437 // Read the photons corresponding to the i-th core location 438 // EventIO: Number of telescope 439 // Raw: Number of re-use 440 const Int_t rc2 = fEvent->ReadCorsikaEvt(fInFormat, id); 441 if (rc2!=kTRUE) 442 return rc2; 443 444 //---- 445 if (fInFormat->IsEventioFormat()) 446 { 447 fEvent->AddXY(fEvtHeader->GetX(), fEvtHeader->GetY()); 448 fEvent->SimWavelength(fRunHeader->GetWavelengthMin(), fRunHeader->GetWavelengthMax()); 449 return kTRUE; 450 } 451 //---- 452 453 454 // read event end 455 return fEvtHeader->ReadEvtEnd(fInFormat); 502 fEvtHeader->IncNumReuse(); 503 fEvtHeader->InitXY(); 504 505 // In the case of corsika raw data (MMCS only) we have too loop over one event 506 // several times to read all impact parameters (reusage of events) 507 // In case of the eventio format we have to decide, the data of which telescope 508 // we want to extract 509 510 // Read the photons corresponding to the i-th core location 511 // EventIO: Number of telescope 512 // Raw: Number of re-use 513 const Int_t rc2 = fEvent->ReadCorsikaEvt(fInFormat, fEvtHeader->GetNumReuse()+1); 514 if (rc2!=kTRUE) 515 return rc2; 516 517 // read event end 518 return fEvtHeader->ReadEvtEnd(fInFormat); 519 } 456 520 } 457 521 … … 502 566 Int_t MCorsikaRead::PostProcess() 503 567 { 504 const UInt_t n = fNumEvents*fRunHeader->GetNumReuse() ;568 const UInt_t n = fNumEvents*fRunHeader->GetNumReuse()*(fTelescopeIdx<0?fNumTelescopes:1); 505 569 506 570 // … … 517 581 return kTRUE; 518 582 } 583 584 // -------------------------------------------------------------------------- 585 // 586 // Telescope: 1 587 // 588 // In the case of eventio-format select which telescope to extract from the 589 // file. -1 will extract all telescopes 590 // 591 Int_t MCorsikaRead::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 592 { 593 Bool_t rc = kFALSE; 594 if (IsEnvDefined(env, prefix, "Telescope", print)) 595 { 596 rc = kTRUE; 597 fTelescopeIdx = GetEnvValue(env, prefix, "Telescope", fTelescopeIdx); 598 } 599 600 return rc; 601 } -
trunk/Mars/mcorsika/MCorsikaRead.h
r9941 r9943 4 4 #ifndef MARS_MRead 5 5 #include "MRead.h" 6 #endif 7 8 #ifndef ROOT_TArrayF 9 #include <TArrayF.h> 6 10 #endif 7 11 … … 22 26 MPhotonEvent *fEvent; //! event information 23 27 24 UInt_tfTelescopeIdx; // Index of telescope to be extracted28 Int_t fTelescopeIdx; // Index of telescope to be extracted 25 29 Bool_t fForceMode; // Force mode skipping defect RUNE 26 30 … … 30 34 UInt_t fNumTotalEvents; //! total number of events in all files 31 35 32 ifstream *fIn; //! input stream (file to read from)36 // ifstream *fIn; //! input stream (file to read from) 33 37 MCorsikaFormat *fInFormat; //! access to input corsika data 34 38 35 39 MParList *fParList; //! tasklist to call ReInit from 36 40 41 Int_t fNumTelescopes; //! Number of telescopes in array 42 Int_t fNumTelescope; //! Number of telescope currently being read 43 TArrayF fTelescopeX; //! x pos (measured towards north, unit: cm) 44 TArrayF fTelescopeY; //! y pos (measured towards west, unit: cm) 45 TArrayF fTelescopeZ; //! z pos (from detection level, unit: cm) 46 TArrayF fTelescopeR; //! Radii of spheres around tel. (unit: cm) 47 37 48 //UInt_t fInterleave; 38 49 //Bool_t fForce; 39 50 40 virtual Bool_t OpenStream() { return kTRUE; }51 // virtual Bool_t OpenStream() { return kTRUE; } 41 52 42 53 Bool_t ReadEvtEnd(); … … 45 56 Int_t ReadEvent(); 46 57 58 // MTask 47 59 Int_t PreProcess(MParList *pList); 48 60 Int_t Process(); 49 61 Int_t PostProcess(); 62 63 // MParContainer 64 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 50 65 51 66 public: … … 54 69 55 70 void SetForceMode(Bool_t b=kTRUE) { fForceMode=b; } 56 void SetTelescopeIdx( UInt_t idx=0) { fTelescopeIdx = idx; }71 void SetTelescopeIdx(Int_t idx=-1) { fTelescopeIdx = idx; } 57 72 58 73 TString GetFullFileName() const;
Note:
See TracChangeset
for help on using the changeset viewer.