Changeset 9032 for trunk/MagicSoft/Mars
- Timestamp:
- 07/22/08 17:08:10 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mfileio
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfileio/MReadFiles.cc
r9031 r9032 30 30 #include "MReadFiles.h" 31 31 32 #include <errno.h> 33 32 34 #include <TObjString.h> 33 35 -
trunk/MagicSoft/Mars/mfileio/MReadFiles.h
r9029 r9032 20 20 MParList *fParList; //! Parlist for reinitialization 21 21 22 virtual Bool_t AnalyzeHeader(MParList &plist)=0; 23 virtual Bool_t ReadHeader()=0; 24 virtual Int_t ReadEvent()=0; 25 22 26 protected: 23 27 MZlib *fIn; // the inputfile 24 28 29 // MReadFiles 25 30 Bool_t ReadLine(TString &line); 26 31 27 32 UInt_t GetNumLine() const { return fNumLine; } 28 33 34 Bool_t OpenNextFile(Int_t num=-1); 35 Bool_t CheckFile(TString name) const; 36 37 // MTask 29 38 Int_t PreProcess(MParList *pList); 30 39 Int_t Process(); 31 32 private: 33 Bool_t OpenNextFile(); 34 Bool_t CheckFile(TString name) const; 35 36 virtual Bool_t AnalyzeHeader(MParList &plist)=0; 37 virtual Bool_t ReadHeader()=0; 38 virtual Int_t ReadEvent()=0; 40 Int_t PostProcess(); 39 41 40 42 public: -
trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc
r8315 r9032 18 18 ! Author(s): Thomas Bretz, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 320 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 31 31 ///////////////////////////////////////////////////////////////////////////// 32 32 #include "MReadRflFile.h" 33 34 #include <errno.h>35 36 #include <TSystem.h>37 33 38 34 #include "structures_rfl.h" … … 236 232 } 237 233 238 Int_t MReadRflFile:: Process()234 Int_t MReadRflFile::ReadEvent() 239 235 { 240 236 for (;;) … … 246 242 247 243 case kEndOfFile: 248 if (!OpenNextFile()) 249 return kFALSE; 244 Close(); 245 return kCONTINUE; // FIXME: CHECK 246 // if (!OpenNextFile()) 247 // return kFALSE; 250 248 /* FALLTHROU */ 251 249 case kStartOfRun: … … 265 263 } 266 264 265 /* 266 Int_t MReadRflFile::Process() 267 { 268 for (;;) 269 { 270 switch (EvalFlag()) 271 { 272 case kError: 273 return kFALSE; 274 275 case kEndOfFile: 276 if (!OpenNextFile()) 277 return kFALSE; 278 // FALLTHROU 279 case kStartOfRun: 280 case kEndOfRun: 281 continue; 282 283 case kStartOfEvtData: 284 break; 285 } 286 break; 287 } 288 289 if (!ReadEvtHeader()) 290 return kFALSE; 291 292 return ReadEvtData(); 293 } 294 */ 295 267 296 Int_t MReadRflFile::PreProcess(MParList *plist) 268 297 { … … 279 308 return kFALSE; 280 309 281 Rewind(); 282 283 return OpenNextFile(); 284 } 285 286 // -------------------------------------------------------------------------- 287 // 288 // This opens the next file in the list and deletes its name from the list. 289 // 290 Bool_t MReadRflFile::OpenNextFile() 291 { 292 // 293 // open the input stream and check if it is really open (file exists?) 294 // 295 if (fIn) 296 delete fIn; 297 fIn = NULL; 298 299 // 300 // Check for the existence of a next file to read 301 // 302 if (fNumFile >= (UInt_t)fFileNames->GetSize()) 303 { 304 *fLog << inf << GetDescriptor() << ": No unread files anymore..." << endl; 305 return kFALSE; 306 } 307 308 TNamed *file = (TNamed*)fFileNames->At(fNumFile); 309 310 //TNamed *file = (TNamed*)fFileNames->GetFirst(); 311 //if (!file) 312 // return kFALSE; 313 314 // 315 // open the file which is the first one in the chain 316 // 317 fFileName = file->GetName(); 318 TString expname = fFileName; 319 gSystem->ExpandPathName(expname); 320 321 // 322 // Remove this file from the list of pending files 323 // 324 //fFileNames->Remove(file); 325 326 *fLog << inf << "Open file: '" << fFileName << "'" << endl; 327 328 fIn = new MZlib(expname); 329 if (!*fIn) 330 { 331 *fLog << err << "Cannot open file " << expname << ": "; 332 *fLog << strerror(errno) << endl; 333 return kFALSE; 334 } 335 336 *fLog << inf; 337 fLog->Separator(fFileName); 338 310 return MReadFiles::PreProcess(plist); 311 } 312 313 Bool_t MReadRflFile::ReadHeader() 314 { 339 315 fCurrentVersion = ReadVersion(); 340 316 if (fCurrentVersion<0) 341 317 { 342 cout << "ERROR reading signature." << endl; 343 return kFALSE; 344 } 345 cout << "Version " << fCurrentVersion << endl << endl; 346 347 fNumFile++; 318 *fLog << err << "ERROR reading signature." << endl; 319 return kFALSE; 320 } 321 *fLog << inf << "Version " << fCurrentVersion << endl << endl; 322 348 323 return kTRUE; 349 324 } 325 350 326 351 327 /****************************************************/ … … 384 360 // 385 361 MReadRflFile::MReadRflFile(const char *fname, const char *name, 386 const char *title) : fIn(NULL), fEntries(0)362 const char *title) : MReadFiles(fname, name, title) 387 363 { 388 364 fName = name ? name : "MRead"; 389 365 fTitle = title ? title : "Reads a Reflector output file"; 390 391 // 392 // remember file name for opening the file in the preprocessor 393 // 394 fFileNames = new TList; 395 fFileNames->SetOwner(); 396 397 if (fname) 398 AddFile(fname); 399 } 400 401 // -------------------------------------------------------------------------- 402 // 403 // Delete the filename list and the input stream if one exists. 404 // 405 MReadRflFile::~MReadRflFile() 406 { 407 delete fFileNames; 408 if (fIn) 409 delete fIn; 410 } 411 412 // -------------------------------------------------------------------------- 413 // 414 // Add this file as the last entry in the chain 415 // 416 Int_t MReadRflFile::AddFile(const char *txt, int) 417 { 418 const char *name = gSystem->ExpandPathName(txt); 419 420 TString fname(name); 421 delete [] name; 422 /* 423 if (!CheckHeader(fname)) 424 { 425 *fLog << warn << "WARNING - Problem reading header... ignored." << endl; 426 return; 427 } 428 429 const Int_t n = GetNumEvents(fname); 430 if (n==0) 431 { 432 *fLog << warn << "WARNING - File contains no data... ignored." << endl; 433 return; 434 } 435 436 fEntries += n; 437 438 *fLog << inf << "File " << txt << " contains " << n << " events (Total=" << fEntries << ")" << endl; 439 */ 440 fFileNames->AddLast(new TNamed(txt, "")); 441 return 1; 442 } 443 366 } 444 367 445 368 Bool_t MReadRflFile::SearchFor(Int_t runno, Int_t eventno) … … 448 371 return kFALSE; 449 372 450 fNumFile = 0; 451 if (!OpenNextFile()) 452 return kFALSE; 373 Rewind(); 453 374 454 375 while (1) … … 462 383 return kTRUE; 463 384 } 464 } 385 386 Close(); 387 } -
trunk/MagicSoft/Mars/mfileio/MReadRflFile.h
r8315 r9032 2 2 #define MARS_MReadRflFile 3 3 4 #ifndef ROOT_TArrayF5 #include <TArrayF.h>4 #ifndef MARS_MReadFiles 5 #include "MReadFiles.h" 6 6 #endif 7 7 8 #ifndef MARS_MRead9 #include "MRead.h"10 #endif11 12 class MZlib;13 class TList;14 8 class MRflEvtData; 15 9 class MRflEvtHeader; 16 10 class MRflRunHeader; 17 11 18 class MReadRflFile : public MRead 12 class MReadRflFile : public MReadFiles 19 13 { 20 14 private: … … 29 23 }; 30 24 31 MZlib *fIn; // the inputfile32 TList *fFileNames; // Array which stores the \0-terminated filenames33 34 25 MRflEvtData *fEvtData; //! 35 26 MRflEvtHeader *fEvtHeader; //! 36 27 MRflRunHeader *fRunHeader; //! 37 28 38 UInt_t fNumFile;39 UInt_t fEntries; // TO BE IMPLEMENTED40 TString fFileName;41 42 29 Float_t fCurrentVersion; //! Version of currently open rfl file 43 30 31 // MReadRflFile 44 32 float ReadVersion(); 45 33 Bool_t ReadEvtHeader(); … … 48 36 Bool_t FlagIsA(const char *s1, const char *flag); 49 37 Int_t EvalFlag(); 50 Bool_t OpenNextFile();51 38 39 // MReadFiles 40 Int_t ReadEvent(); 41 Bool_t ReadHeader(); 42 43 // MTask 52 44 Int_t PreProcess(MParList *pList); 53 Int_t Process();54 45 55 46 public: 56 MReadRflFile(const char *filename=NULL, 57 const char *name=NULL, 47 MReadRflFile(const char *filename=NULL, const char *name=NULL, 58 48 const char *title=NULL); 59 60 ~MReadRflFile();61 62 Int_t AddFile(const char *fname, int i=0);63 64 Bool_t Rewind() { fNumFile=0; return kTRUE; }65 UInt_t GetEntries() { return fEntries; }66 TString GetFullFileName() const { return fFileName; }67 49 68 50 Bool_t SearchFor(Int_t runno, Int_t eventno);
Note:
See TracChangeset
for help on using the changeset viewer.