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

References close().

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

Member Function Documentation

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

Check end of file.

Definition at line 93 of file RawFile.cc.

References inputFile.

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

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

It is not OK.

Definition at line 71 of file RawFile.cc.

References ok().

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

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

Get file pointer.

Definition at line 67 of file RawFile.cc.

References inputFile.

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

Ignore some bytes.

Definition at line 91 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

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

Castor flag.

bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 73 of file RawFile.cc.

References xrootdFlag.

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

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

Definition at line 69 of file RawFile.cc.

References inputFile.

Referenced by fail().

69 { 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 
29  char* filename = prefix;
30  if (strlen(prefix)<strlen(path)) filename = strtok(nullptr,":");
31  //cout << " Filename: " << filename << endl;
32 
33  if (strcmp(prefix,"root")==0) xrootdFlag = true;
34 
35  if (xrootdFlag) {
36  char chopt[] = "rb";
37  inputFile = XrdPosix_Fopen(path,chopt);
38  } else {
39  char chopt[] = "rb";
40  inputFile = fopen(filename,chopt);
41  }
42  if( !inputFile ) {
43  cout << "RawFile: the input file '" << path << "' is not present" << endl;
44  } else {
45  cout << "RawFile: DAQ file '" << path << "' was succesfully opened" << endl;
46  }
47 
48  return this;
49 
50 }
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 75 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().

75  {
76  if (xrootdFlag) {
77  return XrdPosix_Fread(data,nbytes,1,inputFile);
78  } else {
79  return fread(data, nbytes, 1, inputFile);
80  }
81 }
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 83 of file RawFile.cc.

References inputFile, and xrootdFlag.

Referenced by ignore().

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

Tell instruction.

Definition at line 97 of file RawFile.cc.

References inputFile, and xrootdFlag.

97  {
98  if (xrootdFlag) {
99  return XrdPosix_Ftell(inputFile);
100  } else {
101  return ftell(inputFile);
102  }
103 }
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().