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 isXROOTD ()
 XROOTD 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
 
bool xrootdFlag
 

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 23 of file RawFile.cc.

23 : inputFile(0), rfioFlag(false), xrootdFlag(false) {}
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
FILE * inputFile
Definition: RawFile.h:63
RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 25 of file RawFile.cc.

References open().

25  : inputFile(0), rfioFlag(false), xrootdFlag(false) {
26  open(path);
27 }
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:29
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
FILE * inputFile
Definition: RawFile.h:63
RawFile::~RawFile ( )
virtual

Destructor.

Definition at line 82 of file RawFile.cc.

References close().

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

Member Function Documentation

int RawFile::close ( void  )

Close file if necessary.

Definition at line 66 of file RawFile.cc.

References inputFile, rfio_fclose(), rfioFlag, and xrootdFlag.

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), DTDDUFileReader::~DTDDUFileReader(), DTNewROS8FileReader::~DTNewROS8FileReader(), DTROS25FileReader::~DTROS25FileReader(), DTROS8FileReader::~DTROS8FileReader(), and ~RawFile().

66  {
67  int flag = -1;
68  if (!inputFile) return flag;
69 
70  if (xrootdFlag) {
71  flag = XrdPosix_Fclose(inputFile);
72  }
73  else if (rfioFlag) {
74  flag = rfio_fclose(inputFile);
75  } else {
76  flag = fclose(inputFile);
77  }
78  inputFile = 0;
79  return flag;
80 }
bool rfioFlag
Definition: RawFile.h:64
int rfio_fclose(FILE *fd)
bool xrootdFlag
Definition: RawFile.h:65
FILE * inputFile
Definition: RawFile.h:63
int RawFile::eof ( )

Check end of file.

Definition at line 118 of file RawFile.cc.

References inputFile, rfio_feof(), and rfioFlag.

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

118  {
119  if (rfioFlag) {
120  return rfio_feof(inputFile);
121  } else {
122  return feof(inputFile); // Also for XROOTD
123  }
124 }
bool rfioFlag
Definition: RawFile.h:64
int rfio_feof(FILE *fp)
FILE * inputFile
Definition: RawFile.h:63
bool RawFile::fail ( )

It is not OK.

Definition at line 88 of file RawFile.cc.

References ok().

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

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

Get file pointer.

Definition at line 84 of file RawFile.cc.

References inputFile.

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

Ignore some bytes.

Definition at line 116 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

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

Castor flag.

Definition at line 90 of file RawFile.cc.

References rfioFlag.

90 { return rfioFlag;}
bool rfioFlag
Definition: RawFile.h:64
bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 92 of file RawFile.cc.

References xrootdFlag.

92 { return xrootdFlag;}
bool xrootdFlag
Definition: RawFile.h:65
bool RawFile::ok ( )

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

Definition at line 86 of file RawFile.cc.

References inputFile.

Referenced by fail().

86 { return (inputFile!=0);}
FILE * inputFile
Definition: RawFile.h:63
RawFile * RawFile::open ( const char *  path)

Open file.

Definition at line 29 of file RawFile.cc.

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

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

29  {
30 
31  //cout << " Full path: " << path << endl;
32 
33  char* chaux = new char[strlen(path)+1];
34  strcpy(chaux,path);
35  char* prefix = strtok(chaux,":");
36  //cout << " Prefix: " << prefix << endl;
37 
38  char* filename = prefix;
39  if (strlen(prefix)<strlen(path)) filename = strtok(0,":");
40  //cout << " Filename: " << filename << endl;
41 
42  if (strcmp(prefix,"rfio")==0) rfioFlag = true;
43  if (strcmp(prefix,"castor")==0) rfioFlag = true;
44  if (strcmp(prefix,"root")==0) xrootdFlag = true;
45 
46  if (xrootdFlag) {
47  char chopt[] = "rb";
48  inputFile = XrdPosix_Fopen(path,chopt);
49  } else if (rfioFlag) {
50  char chopt[] = "r";
51  inputFile = rfio_fopen(filename,chopt);
52  } else {
53  char chopt[] = "rb";
54  inputFile = fopen(filename,chopt);
55  }
56  if( !inputFile ) {
57  cout << "RawFile: the input file '" << path << "' is not present" << endl;
58  } else {
59  cout << "RawFile: DAQ file '" << path << "' was succesfully opened" << endl;
60  }
61 
62  return this;
63 
64 }
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
FILE * rfio_fopen(char *path, char *mode)
FILE * inputFile
Definition: RawFile.h:63
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145
int RawFile::read ( void *  data,
size_t  nbytes 
)

Read from file.

Definition at line 94 of file RawFile.cc.

References inputFile, rfio_fread(), rfioFlag, and xrootdFlag.

Referenced by DTDDUFileReader::dmaUnpack(), DTDDUFileReader::DTDDUFileReader(), DTNewROS8FileReader::fillRawData(), DTROS8FileReader::fillRawData(), DTDDUFileReader::fillRawData(), DTROS25FileReader::fillRawData(), and edmIntegrityCheck.PublishToFileSystem::get().

94  {
95  if (xrootdFlag) {
96  return XrdPosix_Fread(data,nbytes,1,inputFile);
97  }
98  else if (rfioFlag) {
99  return rfio_fread(data, nbytes, 1, inputFile);
100  } else {
101  return fread(data, nbytes, 1, inputFile);
102  }
103 }
int rfio_fread(void *, size_t, size_t, void *)
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
FILE * inputFile
Definition: RawFile.h:63
int RawFile::seek ( long  offset,
int  whence 
)

Go somewhere.

Definition at line 105 of file RawFile.cc.

References inputFile, rfio_fseek(), rfioFlag, and xrootdFlag.

Referenced by ignore().

105  {
106  if (xrootdFlag) {
107  return XrdPosix_Fseek(inputFile, offset, whence);
108  }
109  else if (rfioFlag) {
110  return rfio_fseek(inputFile, offset, whence);
111  } else {
112  return fseek(inputFile, offset, whence);
113  }
114 }
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
int rfio_fseek(FILE *fp, long offset, int whence)
FILE * inputFile
Definition: RawFile.h:63
long RawFile::tell ( )

Tell instruction.

Definition at line 126 of file RawFile.cc.

References inputFile, rfio_ftell(), rfioFlag, and xrootdFlag.

126  {
127  if (xrootdFlag) {
128  return XrdPosix_Ftell(inputFile);
129  }
130  else if (rfioFlag) {
131  return rfio_ftell(inputFile);
132  } else {
133  return ftell(inputFile);
134  }
135 }
long rfio_ftell(FILE *fp)
bool rfioFlag
Definition: RawFile.h:64
bool xrootdFlag
Definition: RawFile.h:65
FILE * inputFile
Definition: RawFile.h:63

Member Data Documentation

FILE* RawFile::inputFile
private

Definition at line 63 of file RawFile.h.

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

bool RawFile::rfioFlag
private

Definition at line 64 of file RawFile.h.

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

bool RawFile::xrootdFlag
private

Definition at line 65 of file RawFile.h.

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