STEER/TFndFileManager.h

00001 // @(#)fROOT/STEER:$Name:  $:$Id: TFndFileManager.h,v 1.4 2007/09/05 11:09:42 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 
00004 #ifndef FROOT_TFndFileManager
00005 #define FROOT_TFndFileManager
00006 
00008 //                TFndFileManager                      //
00009 //                                                     //
00010 // Both ROOT and ASCII files can be handled by         //
00011 // this class:                                         //
00012 //           - file existence check                    //
00013 //           - ascii characters search and replace     //
00014 //           - etc...                                  //
00015 //                                                     //
00017 
00018 #include "TNamed.h"
00019 
00020 class TString;
00021 class TFile;
00022 class TObjArray;
00023 
00024 class TFndFileManager : public TNamed
00025 {
00026   //--- Data members
00027  protected:
00028   Bool_t fdebug; 
00029   Bool_t fReady; 
00030   Bool_t fAsciiLoaded; 
00031   Bool_t fRootLoaded; 
00032   const Char_t *fOriginalPath;  
00033   TString *fPath;  
00034   TString *fFileName;
00035 
00036   FILE *fAsciiFile;
00037   TFile *fRootFile;
00038 
00039   //--- Methods
00040  public:
00041   TFndFileManager();
00042   TFndFileManager(const char *path, Bool_t debug = kFALSE);
00043   virtual ~TFndFileManager();     
00044 
00045   virtual void AppendToPath(Char_t *path);
00046   virtual void ResetPath() {fPath->Resize(0); *fPath+=fOriginalPath;}
00047 
00048   Int_t Ascii(Char_t *filename, Char_t *option="r");
00049   Int_t Root(Char_t *filename, Char_t *option="OPEN");
00050   
00051   // --- ascii file operations
00052   void RewindStream(){ rewind(fAsciiFile); }
00053   void ReplaceChar(Char_t *ori_char,Char_t *new_char);
00054   Char_t *GetFirstLine(){ rewind(fAsciiFile); return GetNextLine();}
00055 
00056   const Int_t GetNumOfColumns(Char_t *delimiter);
00057   Char_t *GetNextLine();
00058   Char_t *GetLine(Int_t n);
00059   void GetFirstLine(Float_t *array,Int_t nvar,Char_t *delimiter=""){ rewind(fAsciiFile); GetNextLine(array,nvar,delimiter);}
00060   Int_t GetNextLine(Float_t *array,Int_t nvar,Char_t *delimiter="");
00061 
00062   // --- Get methods
00063   Char_t *GetPath()     {return (Char_t *)fPath->Data();}
00064   Char_t *GetFileName();
00065 
00066   TFile *GetRootFile()  {return fRootFile;}
00067   FILE  *GetAsciiFile() {return fAsciiFile;}
00068 
00069 
00070   virtual void ReadAscii();
00071 
00072   virtual void Close(); // Close all opened files
00073 
00074   void Print(Option_t * = 0) const;     // (overload of TObject method)
00075   virtual void HowTo();
00076 
00077  private:
00078   void BuildFileName(Char_t *filename);
00079   Bool_t CheckExistence(); // output is kTRUE if the file exists
00080 
00081   ClassDef(TFndFileManager,1) 
00082     };
00083 #endif //FROOT_TFndFileManager

Generated on Tue Oct 16 15:40:48 2007 by  doxygen 1.5.2