CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
RawFile Class Reference

#include <RawFile.h>

Public Member Functions

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

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.

21 : inputFile(0), rfioFlag(false) {}
bool rfioFlag
Definition: RawFile.h:61
FILE * inputFile
Definition: RawFile.h:60
RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 23 of file RawFile.cc.

References open().

23  : inputFile(0), rfioFlag(false) {
24  open(path);
25 }
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:27
bool rfioFlag
Definition: RawFile.h:61
FILE * inputFile
Definition: RawFile.h:60
RawFile::~RawFile ( )
virtual

Destructor.

Definition at line 72 of file RawFile.cc.

References close().

72 {close();}
int close()
Close file if necessary.
Definition: RawFile.cc:60

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 lumiQTWidget.ApplicationWindow::fileQuit(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), DTDDUFileReader::~DTDDUFileReader(), DTROS25FileReader::~DTROS25FileReader(), DTROS8FileReader::~DTROS8FileReader(), and ~RawFile().

60  {
61  int flag = -1;
62  if (!inputFile) return flag;
63  if (rfioFlag) {
64  flag = rfio_fclose(inputFile);
65  } else {
66  flag = fclose(inputFile);
67  }
68  inputFile = 0;
69  return flag;
70 }
long int flag
Definition: mlp_lapack.h:47
bool rfioFlag
Definition: RawFile.h:61
int rfio_fclose(FILE *fd)
FILE * inputFile
Definition: RawFile.h:60
int RawFile::eof ( )

Check end of file.

Definition at line 100 of file RawFile.cc.

References inputFile, rfio_feof(), and rfioFlag.

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

100  {
101  if (rfioFlag) {
102  return rfio_feof(inputFile);
103  } else {
104  return feof(inputFile);
105  }
106 }
bool rfioFlag
Definition: RawFile.h:61
int rfio_feof(FILE *fp)
FILE * inputFile
Definition: RawFile.h:60
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().

78 { return !ok();}
bool ok()
It is OK (i.e. file was correctly opened)
Definition: RawFile.cc:76
FILE * RawFile::GetPointer ( )

Get file pointer.

Definition at line 74 of file RawFile.cc.

References inputFile.

74 { return inputFile;}
FILE * inputFile
Definition: RawFile.h:60
int RawFile::ignore ( long  offset)

Ignore some bytes.

Definition at line 98 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

98 { return seek(offset, SEEK_CUR);}
int seek(long offset, int whence)
Go somewhere.
Definition: RawFile.cc:90
unsigned int offset(bool)
bool RawFile::isRFIO ( )

Castor flag.

Definition at line 80 of file RawFile.cc.

References rfioFlag.

80 { return rfioFlag;}
bool rfioFlag
Definition: RawFile.h:61
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().

76 { return (inputFile!=0);}
FILE * inputFile
Definition: RawFile.h:60
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().

27  {
28 
29  //cout << " Full path: " << path << endl;
30 
31  char* chaux = new char[strlen(path)+1];
32  strcpy(chaux,path);
33  char* prefix = strtok(chaux,":");
34  //cout << " Prefix: " << prefix << endl;
35 
36  char* filename = prefix;
37  if (strlen(prefix)<strlen(path)) filename = strtok(0,":");
38  //cout << " Filename: " << filename << endl;
39 
40  if (strcmp(prefix,"rfio")==0) rfioFlag = true;
41  if (strcmp(prefix,"castor")==0) rfioFlag = true;
42 
43  if (rfioFlag) {
44  char chopt[] = "r";
45  inputFile = rfio_fopen(filename,chopt);
46  } else {
47  char chopt[] = "rb";
48  inputFile = fopen(filename,chopt);
49  }
50  if( !inputFile ) {
51  cout << "RawFile: the input file '" << filename << "' is not present" << endl;
52  } else {
53  cout << "RawFile: DAQ file '" << filename << "' was succesfully opened" << endl;
54  }
55 
56  return this;
57 
58 }
bool rfioFlag
Definition: RawFile.h:61
FILE * rfio_fopen(char *path, char *mode)
FILE * inputFile
Definition: RawFile.h:60
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
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(), DTROS8FileReader::fillRawData(), DTDDUFileReader::fillRawData(), and DTROS25FileReader::fillRawData().

82  {
83  if (rfioFlag) {
84  return rfio_fread(data, nbytes, 1, inputFile);
85  } else {
86  return fread(data, nbytes, 1, inputFile);
87  }
88 }
int rfio_fread(void *, size_t, size_t, void *)
bool rfioFlag
Definition: RawFile.h:61
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
FILE * inputFile
Definition: RawFile.h:60
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().

90  {
91  if (rfioFlag) {
92  return rfio_fseek(inputFile, offset, whence);
93  } else {
94  return fseek(inputFile, offset, whence);
95  }
96 }
bool rfioFlag
Definition: RawFile.h:61
unsigned int offset(bool)
int rfio_fseek(FILE *fp, long offset, int whence)
FILE * inputFile
Definition: RawFile.h:60
long RawFile::tell ( )

Tell instruction.

Definition at line 108 of file RawFile.cc.

References inputFile, rfio_ftell(), and rfioFlag.

108  {
109  if (rfioFlag) {
110  return rfio_ftell(inputFile);
111  } else {
112  return ftell(inputFile);
113  }
114 }
long rfio_ftell(FILE *fp)
bool rfioFlag
Definition: RawFile.h:61
FILE * inputFile
Definition: RawFile.h:60

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().