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() [1/2]

RawFile::RawFile ( )

Default constructor.

Definition at line 15 of file RawFile.cc.

15 : inputFile(nullptr), xrootdFlag(false) {}

◆ RawFile() [2/2]

RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 17 of file RawFile.cc.

17 : inputFile(nullptr), xrootdFlag(false) { open(path); }

References open(), and castor_dqm_sourceclient_file_cfg::path.

◆ ~RawFile()

RawFile::~RawFile ( )
virtual

Destructor.

Definition at line 66 of file RawFile.cc.

66 { close(); }

References close().

Member Function Documentation

◆ close()

int RawFile::close ( void  )

Close file if necessary.

Definition at line 52 of file RawFile.cc.

52  {
53  int flag = -1;
54  if (!inputFile)
55  return flag;
56 
57  if (xrootdFlag) {
58  flag = XrdPosix_Fclose(inputFile);
59  } else {
60  flag = fclose(inputFile);
61  }
62  inputFile = nullptr;
63  return flag;
64 }

References RemoveAddSevLevel::flag, inputFile, and xrootdFlag.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), DTDDUFileReader::~DTDDUFileReader(), DTNewROS8FileReader::~DTNewROS8FileReader(), DTROS25FileReader::~DTROS25FileReader(), DTROS8FileReader::~DTROS8FileReader(), and ~RawFile().

◆ eof()

int RawFile::eof ( )

Check end of file.

Definition at line 94 of file RawFile.cc.

94  {
95  return feof(inputFile); // Also for XROOTD
96 }

References inputFile.

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

◆ fail()

bool RawFile::fail ( )

◆ GetPointer()

FILE * RawFile::GetPointer ( )

Get file pointer.

Definition at line 68 of file RawFile.cc.

68 { return inputFile; }

References inputFile.

◆ ignore()

int RawFile::ignore ( long  offset)

Ignore some bytes.

Definition at line 92 of file RawFile.cc.

92 { return seek(offset, SEEK_CUR); }

References hltrates_dqm_sourceclient-live_cfg::offset, and seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

◆ isRFIO()

bool RawFile::isRFIO ( )

Castor flag.

◆ isXROOTD()

bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 74 of file RawFile.cc.

74 { return xrootdFlag; }

References xrootdFlag.

◆ ok()

bool RawFile::ok ( )

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

Definition at line 70 of file RawFile.cc.

70 { return (inputFile != nullptr); }

References inputFile.

Referenced by fail().

◆ open()

RawFile * RawFile::open ( const char *  path)

Open file.

Definition at line 19 of file RawFile.cc.

19  {
20  //cout << " Full path: " << path << endl;
21 
22  std::unique_ptr<char[]> chaux{new char[strlen(path) + 1]};
23  strcpy(chaux.get(), path);
24  char* saveptr;
25  char* prefix = strtok_r(chaux.get(), ":", &saveptr);
26  //cout << " Prefix: " << prefix << endl;
27 
28  char* filename = prefix;
29  if (strlen(prefix) < strlen(path))
30  filename = strtok_r(nullptr, ":", &saveptr);
31  //cout << " Filename: " << filename << endl;
32 
33  if (strcmp(prefix, "root") == 0)
34  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 }

References gather_cfg::cout, corrVsCorr::filename, inputFile, castor_dqm_sourceclient_file_cfg::path, ZMuMuAnalysisNtupler_cff::prefix, and xrootdFlag.

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

◆ read()

int RawFile::read ( void *  data,
size_t  nbytes 
)

Read from file.

Definition at line 76 of file RawFile.cc.

76  {
77  if (xrootdFlag) {
78  return XrdPosix_Fread(data, nbytes, 1, inputFile);
79  } else {
80  return fread(data, nbytes, 1, inputFile);
81  }
82 }

References data, inputFile, and xrootdFlag.

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

◆ seek()

int RawFile::seek ( long  offset,
int  whence 
)

Go somewhere.

Definition at line 84 of file RawFile.cc.

84  {
85  if (xrootdFlag) {
86  return XrdPosix_Fseek(inputFile, offset, whence);
87  } else {
88  return fseek(inputFile, offset, whence);
89  }
90 }

References inputFile, hltrates_dqm_sourceclient-live_cfg::offset, and xrootdFlag.

Referenced by ignore().

◆ tell()

long RawFile::tell ( )

Tell instruction.

Definition at line 98 of file RawFile.cc.

98  {
99  if (xrootdFlag) {
100  return XrdPosix_Ftell(inputFile);
101  } else {
102  return ftell(inputFile);
103  }
104 }

References inputFile, and xrootdFlag.

Member Data Documentation

◆ inputFile

FILE* RawFile::inputFile
private

Definition at line 62 of file RawFile.h.

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

◆ xrootdFlag

bool RawFile::xrootdFlag
private

Definition at line 63 of file RawFile.h.

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

RawFile::xrootdFlag
bool xrootdFlag
Definition: RawFile.h:63
RawFile::inputFile
FILE * inputFile
Definition: RawFile.h:62
gather_cfg.cout
cout
Definition: gather_cfg.py:144
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
RawFile::open
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:19
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
RawFile::ok
bool ok()
It is OK (i.e. file was correctly opened)
Definition: RawFile.cc:70
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
RawFile::seek
int seek(long offset, int whence)
Go somewhere.
Definition: RawFile.cc:84
RawFile::close
int close()
Close file if necessary.
Definition: RawFile.cc:52
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
ZMuMuAnalysisNtupler_cff.prefix
prefix
Definition: ZMuMuAnalysisNtupler_cff.py:14