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

15 : 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 17 of file RawFile.cc.

References open().

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

Destructor.

Definition at line 67 of file RawFile.cc.

References close().

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

Member Function Documentation

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

Check end of file.

Definition at line 95 of file RawFile.cc.

References inputFile.

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

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

It is not OK.

Definition at line 73 of file RawFile.cc.

References ok().

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

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

Get file pointer.

Definition at line 69 of file RawFile.cc.

References inputFile.

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

Ignore some bytes.

Definition at line 93 of file RawFile.cc.

References seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

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

Castor flag.

bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 75 of file RawFile.cc.

References xrootdFlag.

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

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

Definition at line 71 of file RawFile.cc.

References inputFile.

Referenced by fail().

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

Open file.

Definition at line 21 of file RawFile.cc.

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

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

21  {
22 
23  //cout << " Full path: " << path << endl;
24 
25  std::unique_ptr<char[]> chaux{ new char[strlen(path)+1] };
26  strcpy(chaux.get(),path);
27  char* saveptr;
28  char* prefix = strtok_r(chaux.get(),":",&saveptr);
29  //cout << " Prefix: " << prefix << endl;
30 
31  char* filename = prefix;
32  if (strlen(prefix)<strlen(path)) filename = strtok_r(nullptr,":",&saveptr);
33  //cout << " Filename: " << filename << endl;
34 
35  if (strcmp(prefix,"root")==0) xrootdFlag = true;
36 
37  if (xrootdFlag) {
38  char chopt[] = "rb";
39  inputFile = XrdPosix_Fopen(path,chopt);
40  } else {
41  char chopt[] = "rb";
42  inputFile = fopen(filename,chopt);
43  }
44  if( !inputFile ) {
45  cout << "RawFile: the input file '" << path << "' is not present" << endl;
46  } else {
47  cout << "RawFile: DAQ file '" << path << "' was succesfully opened" << endl;
48  }
49 
50  return this;
51 
52 }
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 77 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().

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

References inputFile, and xrootdFlag.

Referenced by ignore().

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

Tell instruction.

Definition at line 99 of file RawFile.cc.

References inputFile, and xrootdFlag.

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