Changeset 9032 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
07/22/08 17:08:10 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfileio
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfileio/MReadFiles.cc

    r9031 r9032  
    3030#include "MReadFiles.h"
    3131
     32#include <errno.h>
     33
    3234#include <TObjString.h>
    3335
  • trunk/MagicSoft/Mars/mfileio/MReadFiles.h

    r9029 r9032  
    2020    MParList *fParList;    //! Parlist for reinitialization
    2121
     22    virtual Bool_t AnalyzeHeader(MParList &plist)=0;
     23    virtual Bool_t ReadHeader()=0;
     24    virtual Int_t  ReadEvent()=0;
     25
    2226protected:
    2327    MZlib    *fIn;         // the inputfile
    2428
     29    // MReadFiles
    2530    Bool_t ReadLine(TString &line);
    2631
    2732    UInt_t GetNumLine() const { return fNumLine; }
    2833
     34    Bool_t OpenNextFile(Int_t num=-1);
     35    Bool_t CheckFile(TString name) const;
     36
     37    // MTask
    2938    Int_t  PreProcess(MParList *pList);
    3039    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();
    3941
    4042public:
  • trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc

    r8315 r9032  
    1818!   Author(s): Thomas Bretz, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    3131/////////////////////////////////////////////////////////////////////////////
    3232#include "MReadRflFile.h"
    33 
    34 #include <errno.h>
    35 
    36 #include <TSystem.h>
    3733
    3834#include "structures_rfl.h"
     
    236232}
    237233
    238 Int_t MReadRflFile::Process()
     234Int_t MReadRflFile::ReadEvent()
    239235{
    240236    for (;;)
     
    246242
    247243        case kEndOfFile:
    248             if (!OpenNextFile())
    249                 return kFALSE;
     244            Close();
     245            return kCONTINUE; // FIXME: CHECK
     246//            if (!OpenNextFile())
     247//                return kFALSE;
    250248            /* FALLTHROU */
    251249        case kStartOfRun:
     
    265263}
    266264
     265/*
     266Int_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
    267296Int_t MReadRflFile::PreProcess(MParList *plist)
    268297{
     
    279308        return kFALSE;
    280309
    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
     313Bool_t MReadRflFile::ReadHeader()
     314{
    339315    fCurrentVersion = ReadVersion();
    340316    if (fCurrentVersion<0)
    341317    {
    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
    348323    return kTRUE;
    349324}
     325
    350326
    351327/****************************************************/
     
    384360//
    385361MReadRflFile::MReadRflFile(const char *fname, const char *name,
    386                            const char *title) : fIn(NULL), fEntries(0)
     362                           const char *title) : MReadFiles(fname, name, title)
    387363{
    388364    fName  = name  ? name  : "MRead";
    389365    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}
    444367
    445368Bool_t MReadRflFile::SearchFor(Int_t runno, Int_t eventno)
     
    448371        return kFALSE;
    449372
    450     fNumFile = 0;
    451     if (!OpenNextFile())
    452         return kFALSE;
     373    Rewind();
    453374
    454375    while (1)
     
    462383            return kTRUE;
    463384    }
    464 }
     385
     386    Close();
     387}
  • trunk/MagicSoft/Mars/mfileio/MReadRflFile.h

    r8315 r9032  
    22#define MARS_MReadRflFile
    33
    4 #ifndef ROOT_TArrayF
    5 #include <TArrayF.h>
     4#ifndef MARS_MReadFiles
     5#include "MReadFiles.h"
    66#endif
    77
    8 #ifndef MARS_MRead
    9 #include "MRead.h"
    10 #endif
    11 
    12 class MZlib;
    13 class TList;
    148class MRflEvtData;
    159class MRflEvtHeader;
    1610class MRflRunHeader;
    1711
    18 class MReadRflFile : public MRead
     12class MReadRflFile : public MReadFiles
    1913{
    2014private:
     
    2923    };
    3024
    31     MZlib *fIn;              // the inputfile
    32     TList *fFileNames;       // Array which stores the \0-terminated filenames
    33 
    3425    MRflEvtData   *fEvtData;    //!
    3526    MRflEvtHeader *fEvtHeader;  //!
    3627    MRflRunHeader *fRunHeader;  //!
    3728
    38     UInt_t  fNumFile;
    39     UInt_t  fEntries;           // TO BE IMPLEMENTED
    40     TString fFileName;
    41 
    4229    Float_t fCurrentVersion;    //! Version of currently open rfl file
    4330
     31    // MReadRflFile
    4432    float  ReadVersion();
    4533    Bool_t ReadEvtHeader();
     
    4836    Bool_t FlagIsA(const  char *s1, const char *flag);
    4937    Int_t  EvalFlag();
    50     Bool_t OpenNextFile();
    5138
     39    // MReadFiles
     40    Int_t  ReadEvent();
     41    Bool_t ReadHeader();
     42
     43    // MTask
    5244    Int_t PreProcess(MParList *pList);
    53     Int_t Process();
    5445
    5546public:
    56     MReadRflFile(const char *filename=NULL,
    57                  const char *name=NULL,
     47    MReadRflFile(const char *filename=NULL, const char *name=NULL,
    5848                 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; }
    6749
    6850    Bool_t SearchFor(Int_t runno, Int_t eventno);
Note: See TracChangeset for help on using the changeset viewer.