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) {}
bool xrootdFlag
Definition: RawFile.h:63
FILE * inputFile
Definition: RawFile.h:62

◆ RawFile() [2/2]

RawFile::RawFile ( const char *  path)

Usual constructor.

Definition at line 17 of file RawFile.cc.

References open(), and EnsembleCalibrationLA_cfg::path.

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

◆ ~RawFile()

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:52

Member Function Documentation

◆ close()

int RawFile::close ( void  )

Close file if necessary.

Definition at line 52 of file RawFile.cc.

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().

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 }
bool xrootdFlag
Definition: RawFile.h:63
FILE * inputFile
Definition: RawFile.h:62

◆ eof()

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:62

◆ fail()

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

◆ GetPointer()

FILE * RawFile::GetPointer ( )

Get file pointer.

Definition at line 68 of file RawFile.cc.

References inputFile.

68 { return inputFile; }
FILE * inputFile
Definition: RawFile.h:62

◆ ignore()

int RawFile::ignore ( long  offset)

Ignore some bytes.

Definition at line 92 of file RawFile.cc.

References HLT_IsoTrack_cff::offset, and seek().

Referenced by DTDDUFileReader::DTDDUFileReader().

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

◆ isRFIO()

bool RawFile::isRFIO ( )

Castor flag.

◆ isXROOTD()

bool RawFile::isXROOTD ( )

XROOTD flag.

Definition at line 74 of file RawFile.cc.

References xrootdFlag.

74 { return xrootdFlag; }
bool xrootdFlag
Definition: RawFile.h:63

◆ ok()

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:62

◆ open()

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

Open file.

Definition at line 19 of file RawFile.cc.

References gather_cfg::cout, corrVsCorr::filename, inputFile, EnsembleCalibrationLA_cfg::path, ConfigBuilder::prefix, and xrootdFlag.

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

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 }
bool xrootdFlag
Definition: RawFile.h:63
FILE * inputFile
Definition: RawFile.h:62

◆ read()

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

Read from file.

Definition at line 76 of file RawFile.cc.

References data, 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:63
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
FILE * inputFile
Definition: RawFile.h:62

◆ seek()

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

Go somewhere.

Definition at line 84 of file RawFile.cc.

References inputFile, HLT_IsoTrack_cff::offset, 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:63
FILE * inputFile
Definition: RawFile.h:62

◆ tell()

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:63
FILE * inputFile
Definition: RawFile.h:62

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().