CMS 3D CMS Logo

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

14 : inputFile(nullptr), xrootdFlag(false) {}
bool xrootdFlag
Definition: RawFile.h:64
FILE * inputFile
Definition: RawFile.h:63
RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 16 of file RawFile.cc.

References open().

16  : inputFile(nullptr), xrootdFlag(false) {
17  open(path);
18 }
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:20
bool xrootdFlag
Definition: RawFile.h:64
FILE * inputFile
Definition: RawFile.h:63
RawFile::~RawFile ( )
virtual

Destructor.

Definition at line 66 of file RawFile.cc.

References close().

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

Member Function Documentation

int RawFile::close ( void  )
int RawFile::eof ( )

Check end of file.

Definition at line 94 of file RawFile.cc.

References inputFile.

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

94  {
95  return feof(inputFile); // Also for XROOTD
96 }
FILE * inputFile
Definition: RawFile.h:63
bool RawFile::fail ( )

It is not OK.

Definition at line 72 of file RawFile.cc.

References ok().

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

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

Get file pointer.

Definition at line 68 of file RawFile.cc.

References inputFile.

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

Ignore some bytes.

Definition at line 92 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

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

Castor flag.

bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 74 of file RawFile.cc.

References xrootdFlag.

74 { return xrootdFlag;}
bool xrootdFlag
Definition: RawFile.h:64
bool RawFile::ok ( )

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

Definition at line 70 of file RawFile.cc.

References inputFile.

Referenced by fail().

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

Open file.

Definition at line 20 of file RawFile.cc.

References gather_cfg::cout, corrVsCorr::filename, inputFile, tablePrinter::prefix, and xrootdFlag.

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

20  {
21 
22  //cout << " Full path: " << path << endl;
23 
24  char* chaux = new char[strlen(path)+1];
25  strcpy(chaux,path);
26  char* prefix = strtok(chaux,":");
27  //cout << " Prefix: " << prefix << endl;
28  delete chaux;
29 
30  char* filename = prefix;
31  if (strlen(prefix)<strlen(path)) filename = strtok(nullptr,":");
32  //cout << " Filename: " << filename << endl;
33 
34  if (strcmp(prefix,"root")==0) xrootdFlag = true;
35 
36  if (xrootdFlag) {
37  char chopt[] = "rb";
38  inputFile = XrdPosix_Fopen(path,chopt);
39  } else {
40  char chopt[] = "rb";
41  inputFile = fopen(filename,chopt);
42  }
43  if( !inputFile ) {
44  cout << "RawFile: the input file '" << path << "' is not present" << endl;
45  } else {
46  cout << "RawFile: DAQ file '" << path << "' was succesfully opened" << endl;
47  }
48 
49  return this;
50 
51 }
bool xrootdFlag
Definition: RawFile.h:64
FILE * inputFile
Definition: RawFile.h:63
int RawFile::read ( void *  data,
size_t  nbytes 
)

Read from file.

Definition at line 76 of file RawFile.cc.

References inputFile, and xrootdFlag.

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

76  {
77  if (xrootdFlag) {
78  return XrdPosix_Fread(data,nbytes,1,inputFile);
79  } else {
80  return fread(data, nbytes, 1, inputFile);
81  }
82 }
bool xrootdFlag
Definition: RawFile.h:64
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
FILE * inputFile
Definition: RawFile.h:63
int RawFile::seek ( long  offset,
int  whence 
)

Go somewhere.

Definition at line 84 of file RawFile.cc.

References inputFile, and xrootdFlag.

Referenced by ignore().

84  {
85  if (xrootdFlag) {
86  return XrdPosix_Fseek(inputFile, offset, whence);
87  } else {
88  return fseek(inputFile, offset, whence);
89  }
90 }
bool xrootdFlag
Definition: RawFile.h:64
FILE * inputFile
Definition: RawFile.h:63
long RawFile::tell ( )

Tell instruction.

Definition at line 98 of file RawFile.cc.

References inputFile, and xrootdFlag.

98  {
99  if (xrootdFlag) {
100  return XrdPosix_Ftell(inputFile);
101  } else {
102  return ftell(inputFile);
103  }
104 }
bool xrootdFlag
Definition: RawFile.h:64
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::xrootdFlag
private

Definition at line 64 of file RawFile.h.

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