Changeset 9616 for trunk/MagicSoft/Mars/mcorsika
- Timestamp:
- 07/23/10 10:48:12 (15 years ago)
- Location:
- trunk/MagicSoft/Mars/mcorsika
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
r9571 r9616 34 34 ///////////////////////////////////////////////////////////////////////////// 35 35 #include "MCorsikaEvtHeader.h" 36 #include "MCorsikaFormat.h" 36 37 37 38 #include <iomanip> … … 121 122 // return FALSE if there is no header anymore, else TRUE 122 123 // 123 Int_t MCorsikaEvtHeader::ReadEvt( std::istream &fin)124 Int_t MCorsikaEvtHeader::ReadEvt(MCorsikaFormat * fInFormat) 124 125 { 125 char evth[4]; 126 fin.read(evth, 4); 127 if (memcmp(evth, "EVTH", 4)) 128 { 129 fin.seekg(-4, ios::cur); 126 127 if (!fInFormat->SeekNextBlock("EVTH", 1202)) 130 128 return kFALSE; 131 }132 129 133 130 Float_t f[273]; 134 fin.read((char*)&f, 273*4); 131 if (!fInFormat->ReadData(272, f)) 132 return kFALSE; 135 133 136 134 fEvtNumber = TMath::Nint(f[0]); … … 160 158 if (n!=1) 161 159 { 162 *fLog << err << "ERROR- Currently only one impact parameter per event is supported." << endl;163 return kFALSE;160 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl; 161 *fLog << warn << "WARNING - This error is replaced by a warning." << endl; 164 162 } 165 163 … … 167 165 fY = -f[97]; //fY = f[117]; 168 166 169 fin.seekg(1088-273*4, ios::cur); 170 171 return !fin.eof(); 167 return !fInFormat->Eof(); 172 168 } 173 169 … … 175 171 // this member function is for reading the event end block 176 172 177 Bool_t MCorsikaEvtHeader::ReadEvtEnd( std::istream &fin)173 Bool_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat) 178 174 { 175 176 if (!fInFormat->SeekNextBlock("EVTE", 1209)) 177 return kFALSE; 178 179 179 //fin.seekg(-1088,ios::cur); 180 180 181 181 Float_t f[2]; 182 fin.read((char*)&f, 2*4); 182 183 if (!fInFormat->ReadData(2, f)) 184 return kFALSE; 183 185 184 186 const UInt_t evtnum = TMath::Nint(f[0]); … … 192 194 fWeightedNumPhotons = f[1]; 193 195 194 fin.seekg(1080,ios::cur); 195 196 return !fin.eof(); 196 return !fInFormat->Eof(); 197 197 } 198 198 -
trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h
r9331 r9616 13 13 //class ifstream; 14 14 #include <iosfwd> 15 16 class MCorsikaFormat; 15 17 16 18 class MCorsikaEvtHeader : public MParContainer … … 60 62 Double_t GetImpact() const; 61 63 62 Int_t ReadEvt( istream& fin); // read in event header block63 Bool_t ReadEvtEnd( istream& fin); // read in event end block64 Int_t ReadEvt(MCorsikaFormat * fInFormat); // read in event header block 65 Bool_t ReadEvtEnd(MCorsikaFormat * fInFormat); // read in event end block 64 66 65 67 ClassDef(MCorsikaEvtHeader, 1) // Parameter Conatiner for raw EVENT HEADER -
trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc
r9314 r9616 49 49 #include "MStatusDisplay.h" 50 50 51 #include "MCorsikaFormat.h" 51 52 #include "MCorsikaRunHeader.h" 52 53 #include "MCorsikaEvtHeader.h" … … 97 98 : fRunHeader(0), fEvtHeader(0), fEvent(0), /*fEvtData(0),*/ fForceMode(kFALSE), 98 99 fFileNames(0), fNumFile(0), fNumEvents(0), fNumTotalEvents(0), 99 fIn(0), fParList(0)100 fIn(0), fInFormat(0), fParList(0) 100 101 { 101 102 fName = name ? name : "MRead"; … … 118 119 if (fIn) 119 120 delete fIn; 121 if (fInFormat) 122 delete fInFormat; 120 123 } 121 124 … … 161 164 Bool_t MCorsikaRead::ReadEvtEnd() 162 165 { 163 if (!f RunHeader->SeekEvtEnd(*fIn))166 if (!fInFormat->SeekEvtEnd()) 164 167 { 165 168 *fLog << (fForceMode?warn:err) << "Error: RUNE section not found in file." << endl; … … 168 171 } 169 172 170 if (!fRunHeader->ReadEvtEnd( *fIn))173 if (!fRunHeader->ReadEvtEnd(fInFormat)) 171 174 { 172 175 *fLog << (fForceMode?warn:err) << "Error: Reading RUNE section failed." << endl; … … 184 187 Int_t MCorsikaRead::OpenNextFile(Bool_t print) 185 188 { 189 186 190 // 187 191 // open the input stream and check if it is really open (file exists?) … … 191 195 fIn = NULL; 192 196 197 if (fInFormat) 198 delete fInFormat; 199 fInFormat = NULL; 200 193 201 // 194 202 // Check for the existance of a next file to read … … 204 212 205 213 const char *expname = gSystem->ExpandPathName(name); 206 fIn = new ifstream(expname); 207 208 const Bool_t noexist = !(*fIn); 209 if (noexist) 210 { 211 *fLog << err << "Cannot open file " << expname << ": "; 212 *fLog << (errno!=0?strerror(errno):"Insufficient memory for decompression") << endl; 213 } 214 else 215 { 216 *fLog << inf << "Open file: '" << name << "'" << endl; 217 218 if (fDisplay) 219 { 220 // Show the number of the last event after 221 // which we now open a new file 222 TString txt = GetFileName(); 223 txt += " @ "; 224 txt += GetNumExecutions()-1; 225 fDisplay->SetStatusLine2(txt); 226 } 227 } 228 214 fInFormat = CorsikaFormatFactory(fLog, expname); 229 215 delete [] expname; 230 216 231 if ( noexist)217 if (fInFormat == NULL) 232 218 return kERROR; 233 219 220 *fLog << inf << "Open file: '" << name << "'" << endl; 221 222 if (fDisplay) 223 { 224 // Show the number of the last event after 225 // which we now open a new file 226 TString txt = GetFileName(); 227 txt += " @ "; 228 txt += GetNumExecutions()-1; 229 fDisplay->SetStatusLine2(txt); 230 } 231 234 232 fNumFile++; 235 233 … … 237 235 // Read RUN HEADER (see specification) from input stream 238 236 // 239 if (!fRunHeader->ReadEvt( *fIn))237 if (!fRunHeader->ReadEvt(fInFormat)) 240 238 return kERROR; 241 239 // if (!fEvtHeader->ReadRunHeader(*fIn, *fRunHeader)) 242 240 // return kERROR; 243 241 244 const streampos pos = fIn->tellg();242 fInFormat->StorePos(); 245 243 if (!ReadEvtEnd()) 246 244 return kERROR; 247 fIn ->seekg(pos, ios::beg);245 fInFormat->ResetPos(); 248 246 249 247 … … 395 393 // Read a single event from the stream 396 394 // 397 Bool_t MCorsikaRead::ReadEvent( istream &fin)395 Bool_t MCorsikaRead::ReadEvent() 398 396 { 399 397 // … … 401 399 // if there is no next event anymore stop eventloop 402 400 // 403 Int_t rc = fEvtHeader->ReadEvt(f in); //read event header block401 Int_t rc = fEvtHeader->ReadEvt(fInFormat); //read event header block 404 402 if (!rc) 405 403 return kFALSE; 406 404 407 rc = fEvent->ReadCorsikaEvt(f in);405 rc = fEvent->ReadCorsikaEvt(fInFormat); 408 406 409 407 /* … … 418 416 */ 419 417 420 return rc==kTRUE ? fEvtHeader->ReadEvtEnd(f in) : rc;418 return rc==kTRUE ? fEvtHeader->ReadEvtEnd(fInFormat) : rc; 421 419 } 422 420 … … 433 431 while (1) 434 432 { 435 if (fIn )433 if (fInFormat) 436 434 { 437 435 // Read a single event from file 438 const Bool_t rc = ReadEvent( *fIn);436 const Bool_t rc = ReadEvent(); 439 437 440 438 // kFALSE means: end of file (try next one) … … 442 440 return rc; 443 441 444 if (!fRunHeader->ReadEvtEnd(*fIn)) 442 443 fInFormat->UnreadLastHeader(); 444 if (!fRunHeader->ReadEvtEnd(fInFormat)) 445 445 if (!fForceMode) 446 446 return kERROR; -
trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.h
r9518 r9616 13 13 class MCorsikaEvtHeader; 14 14 class MPhotonEvent; 15 class MCorsikaFormat; 15 16 16 17 class MCorsikaRead : public MRead … … 29 30 30 31 ifstream *fIn; //! input stream (file to read from) 32 MCorsikaFormat * fInFormat; //! access to input corsika data 31 33 32 34 MParList *fParList; //! tasklist to call ReInit from … … 40 42 Int_t OpenNextFile(Bool_t print=kTRUE); 41 43 Bool_t CalcNumTotalEvents(); 42 Bool_t ReadEvent( istream &fin);44 Bool_t ReadEvent(); 43 45 44 46 Int_t PreProcess(MParList *pList); -
trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
r9378 r9616 46 46 47 47 #include "MCorsikaRunHeader.h" 48 #include "MCorsikaFormat.h" 48 49 49 50 #include <fstream> … … 78 79 // Read in one run header from the binary file 79 80 // 80 Bool_t MCorsikaRunHeader::ReadEvt(istream& fin) 81 { 82 char runh[4]; 83 fin.read(runh, 4); 84 if (memcmp(runh, "RUNH", 4)) 85 { 86 *fLog << err << "ERROR - Wrong identifier: RUNH expected." << endl; 87 return kFALSE; 88 } 89 90 Float_t f[272*4]; 91 fin.read((char*)f, 272*4); 81 Bool_t MCorsikaRunHeader::ReadEvt(MCorsikaFormat * fInFormat) 82 { 83 if (!fInFormat->SeekNextBlock("RUNH", 1200)) 84 return kFALSE; 85 86 Float_t f[272]; 87 if (!fInFormat->ReadData(272, f)) 88 return kFALSE; 92 89 93 90 fRunNumber = TMath::Nint(f[0]); … … 157 154 // f[145] Muon multiple scattering flag 158 155 159 char evth[4]; 160 fin.read(evth, 4); 161 if (memcmp(evth, "EVTH", 4)) 162 { 163 *fLog << err << "ERROR - Wrong identifier: EVTH expected." << endl; 164 return kFALSE; 165 } 156 if (!fInFormat->SeekNextBlock("EVTH", 1202)) 157 return kFALSE; 166 158 167 159 Float_t g[273]; 168 fin.read((char*)&g, 273*4);169 if (fin.eof())170 return kFALSE; 171 172 f in.seekg(-274*4, ios::cur);160 if (!fInFormat->ReadData(272, g)) 161 return kFALSE; 162 163 fInFormat->UnreadLastData(); 164 fInFormat->UnreadLastHeader(); 173 165 174 166 const Int_t n = TMath::Nint(g[96]); // Number i of uses of each cherenkov event 175 167 if (n!=1) 176 168 { 177 *fLog << err << "ERROR- Currently only one impact parameter per event is supported." << endl;178 return kFALSE;169 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl; 170 *fLog << warn << "WARNING - This error is replaced by a warning." << endl; 179 171 } 180 172 … … 223 215 } 224 216 225 Bool_t MCorsikaRunHeader::ReadEvtEnd(istream& fin) 226 { 227 char runh[4]; 228 fin.read(runh, 4); 229 if (memcmp(runh, "RUNE", 4)) 230 { 231 *fLog << err << "ERROR - Wrong identifier: RUNE expected." << endl; 232 return kFALSE; 233 } 217 Bool_t MCorsikaRunHeader::ReadEvtEnd(MCorsikaFormat * fInFormat) 218 { 219 220 if (!fInFormat->SeekNextBlock("RUNE", 1210)) 221 return kFALSE; 234 222 235 223 Float_t f[2]; 236 fin.read((char*)f, 2*4); 224 if (!fInFormat->ReadData(2, f)) 225 return kFALSE; 237 226 238 227 const UInt_t runnum = TMath::Nint(f[0]); … … 245 234 246 235 fNumEvents = TMath::Nint(f[1]); 247 248 fin.seekg(270*4, ios::cur); // skip the remaining data of this block249 236 250 237 return kTRUE; -
trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
r9595 r9616 10 10 #include "MTime.h" 11 11 #endif 12 13 class MCorsikaFormat; 12 14 13 15 class MCorsikaRunHeader : public MParContainer … … 119 121 120 122 // I/O 121 Bool_t ReadEvt( istream& fin);122 Bool_t ReadEvtEnd( istream& fin);123 Bool_t ReadEvt(MCorsikaFormat * fInFormat); 124 Bool_t ReadEvtEnd(MCorsikaFormat * fInFormat); 123 125 Bool_t SeekEvtEnd(istream &fin); 124 126 -
trunk/MagicSoft/Mars/mcorsika/Makefile
r9518 r9616 22 22 23 23 SRCFILES = MCorsikaRunHeader.cc \ 24 MCorsikaFormat.cc \ 24 25 MCorsikaEvtHeader.cc \ 25 26 MCorsikaRead.cc
Note:
See TracChangeset
for help on using the changeset viewer.