CMS 3D CMS Logo

Public Member Functions | Private Attributes

RawFile Class Reference

#include <RawFile.h>

List of all members.

Public Member Functions

int close ()
 Close file if necessary.
int eof ()
 Check end of file.
bool fail ()
 It is not OK.
FILE * GetPointer ()
 Get file pointer.
int ignore (long offset)
 Ignore some bytes.
bool isRFIO ()
 Castor flag.
bool ok ()
 It is OK (i.e. file was correctly opened)
RawFileopen (const char *path)
 Open file.
 RawFile (const char *path)
 Usual constructor.
 RawFile ()
 Default constructor.
int read (void *data, size_t nbytes)
 Read from file.
int seek (long offset, int whence)
 Go somewhere.
long tell ()
 Tell instruction.
virtual ~RawFile ()
 Destructor.

Private Attributes

FILE * inputFile
bool rfioFlag

Detailed Description

Utility class to open, read and manage local and rfio files in a transparent way

Author:
J. Alcaraz - CIEMAT, Madrid

Definition at line 14 of file RawFile.h.


Constructor & Destructor Documentation

RawFile::RawFile ( )

Default constructor.

Definition at line 21 of file RawFile.cc.

: inputFile(0), rfioFlag(false) {}
RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 23 of file RawFile.cc.

References open().

                                 : inputFile(0), rfioFlag(false) {
  open(path);
}
RawFile::~RawFile ( ) [virtual]

Destructor.

Definition at line 72 of file RawFile.cc.

References close().

{close();}

Member Function Documentation

int RawFile::close ( void  )

Close file if necessary.

Definition at line 60 of file RawFile.cc.

References inputFile, rfio_fclose(), and rfioFlag.

Referenced by DTDDUFileReader::~DTDDUFileReader(), DTROS25FileReader::~DTROS25FileReader(), DTROS8FileReader::~DTROS8FileReader(), and ~RawFile().

                   {
  int flag = -1;
  if (!inputFile) return flag;
  if (rfioFlag) {
      flag = rfio_fclose(inputFile);
  } else {
      flag = fclose(inputFile);
  }
  inputFile = 0;
  return flag;
}
int RawFile::eof ( )

Check end of file.

Definition at line 100 of file RawFile.cc.

References inputFile, rfio_feof(), and rfioFlag.

Referenced by DTROS25FileReader::checkEndOfFile(), DTROS8FileReader::checkEndOfFile(), and DTDDUFileReader::checkEndOfFile().

                 {
  if (rfioFlag) {
      return rfio_feof(inputFile);
  } else {
      return feof(inputFile);
  }
}
bool RawFile::fail ( )

It is not OK.

Definition at line 78 of file RawFile.cc.

References ok().

Referenced by DTDDUFileReader::DTDDUFileReader(), DTROS25FileReader::DTROS25FileReader(), and DTROS8FileReader::DTROS8FileReader().

{ return !ok();}
FILE * RawFile::GetPointer ( )

Get file pointer.

Definition at line 74 of file RawFile.cc.

References inputFile.

{ return inputFile;}
int RawFile::ignore ( long  offset)

Ignore some bytes.

Definition at line 98 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

{ return seek(offset, SEEK_CUR);}
bool RawFile::isRFIO ( )

Castor flag.

Definition at line 80 of file RawFile.cc.

References rfioFlag.

{ return rfioFlag;}
bool RawFile::ok ( )

It is OK (i.e. file was correctly opened)

Definition at line 76 of file RawFile.cc.

References inputFile.

Referenced by fail().

{ return (inputFile!=0);}
RawFile * RawFile::open ( const char *  path)

Open file.

Definition at line 27 of file RawFile.cc.

References gather_cfg::cout, lut2db_cfg::filename, inputFile, prof2calltree::prefix, rfio_fopen(), and rfioFlag.

Referenced by DTDDUFileReader::DTDDUFileReader(), DTROS25FileReader::DTROS25FileReader(), DTROS8FileReader::DTROS8FileReader(), and RawFile().

                                       {

  //cout << " Full path: " << path << endl;

  char* chaux = new char[strlen(path)+1];
  strcpy(chaux,path);
  char* prefix = strtok(chaux,":");
  //cout << " Prefix: " << prefix << endl;

  char* filename = prefix;
  if (strlen(prefix)<strlen(path)) filename = strtok(0,":");
  //cout << " Filename: " << filename << endl;

  if (strcmp(prefix,"rfio")==0) rfioFlag = true;
  if (strcmp(prefix,"castor")==0) rfioFlag = true;

  if (rfioFlag) {
    char chopt[] = "r";
    inputFile = rfio_fopen(filename,chopt);
  } else {
    char chopt[] = "rb";
    inputFile = fopen(filename,chopt);
  }
  if( !inputFile ) {
      cout << "RawFile: the input file '" << filename << "' is not present" << endl;
  } else {
      cout << "RawFile: DAQ file '" << filename << "' was succesfully opened" << endl;
  }

  return this;

}
int RawFile::read ( void *  data,
size_t  nbytes 
)

Read from file.

Definition at line 82 of file RawFile.cc.

References inputFile, rfio_fread(), and rfioFlag.

Referenced by DTDDUFileReader::dmaUnpack(), DTDDUFileReader::DTDDUFileReader(), DTDDUFileReader::fillRawData(), DTROS25FileReader::fillRawData(), and DTROS8FileReader::fillRawData().

                                           {
      if (rfioFlag) {
            return rfio_fread(data, nbytes, 1, inputFile);
      } else {
            return fread(data, nbytes, 1, inputFile);
      }
}
int RawFile::seek ( long  offset,
int  whence 
)

Go somewhere.

Definition at line 90 of file RawFile.cc.

References inputFile, rfio_fseek(), and rfioFlag.

Referenced by ignore().

                                         {
      if (rfioFlag) {
            return rfio_fseek(inputFile, offset, whence);
      } else {
            return fseek(inputFile, offset, whence);
      }
}
long RawFile::tell ( )

Tell instruction.

Definition at line 108 of file RawFile.cc.

References inputFile, rfio_ftell(), and rfioFlag.

                   {
  if (rfioFlag) {
      return rfio_ftell(inputFile);
  } else {
      return ftell(inputFile);
  }
}

Member Data Documentation

FILE* RawFile::inputFile [private]

Definition at line 60 of file RawFile.h.

Referenced by close(), eof(), GetPointer(), ok(), open(), read(), seek(), and tell().

bool RawFile::rfioFlag [private]

Definition at line 61 of file RawFile.h.

Referenced by close(), eof(), isRFIO(), open(), read(), seek(), and tell().