IORawData
DTCommissioning
plugins
RawFile.cc
Go to the documentation of this file.
1
6
#include <
IORawData/DTCommissioning/plugins/RawFile.h
>
7
#include <cstring>
8
#include <cstdio>
9
#include <memory>
10
11
#include <XrdPosix/XrdPosixExtern.hh>
12
13
using namespace
std
;
14
15
RawFile::RawFile
() :
inputFile
(nullptr), xrootdFlag(
false
) {}
16
17
RawFile::RawFile
(
const
char
*
path
) :
inputFile
(nullptr), xrootdFlag(
false
) {
open
(
path
); }
18
19
RawFile
*
RawFile::open
(
const
char
*
path
) {
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
}
51
52
int
RawFile::close
() {
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
}
65
66
RawFile::~RawFile
() {
close
(); }
67
68
FILE*
RawFile::GetPointer
() {
return
inputFile
; }
69
70
bool
RawFile::ok
() {
return
(
inputFile
!=
nullptr
); }
71
72
bool
RawFile::fail
() {
return
!
ok
(); }
73
74
bool
RawFile::isXROOTD
() {
return
xrootdFlag
; }
75
76
int
RawFile::read
(
void
*
data
,
size_t
nbytes) {
77
if
(
xrootdFlag
) {
78
return
XrdPosix_Fread(
data
, nbytes, 1,
inputFile
);
79
}
else
{
80
return
fread(
data
, nbytes, 1,
inputFile
);
81
}
82
}
83
84
int
RawFile::seek
(
long
offset
,
int
whence) {
85
if
(
xrootdFlag
) {
86
return
XrdPosix_Fseek(
inputFile
,
offset
, whence);
87
}
else
{
88
return
fseek(
inputFile
,
offset
, whence);
89
}
90
}
91
92
int
RawFile::ignore
(
long
offset
) {
return
seek
(
offset
, SEEK_CUR); }
93
94
int
RawFile::eof
() {
95
return
feof(
inputFile
);
// Also for XROOTD
96
}
97
98
long
RawFile::tell
() {
99
if
(
xrootdFlag
) {
100
return
XrdPosix_Ftell(
inputFile
);
101
}
else
{
102
return
ftell(
inputFile
);
103
}
104
}
RawFile::xrootdFlag
bool xrootdFlag
Definition:
RawFile.h:63
funct::false
false
Definition:
Factorize.h:34
RawFile::inputFile
FILE * inputFile
Definition:
RawFile.h:62
RawFile::GetPointer
FILE * GetPointer()
Get file pointer.
Definition:
RawFile.cc:68
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
RawFile::eof
int eof()
Check end of file.
Definition:
RawFile.cc:94
RawFile::isXROOTD
bool isXROOTD()
XROOTD flag.
Definition:
RawFile.cc:74
RawFile.h
RawFile::RawFile
RawFile()
Default constructor.
Definition:
RawFile.cc:15
corrVsCorr.filename
filename
Definition:
corrVsCorr.py:123
RawFile::tell
long tell()
Tell instruction.
Definition:
RawFile.cc:98
RawFile::ignore
int ignore(long offset)
Ignore some bytes.
Definition:
RawFile.cc:92
dtResolutionTest_cfi.inputFile
inputFile
Definition:
dtResolutionTest_cfi.py:14
RawFile::open
RawFile * open(const char *path)
Open file.
Definition:
RawFile.cc:19
std
Definition:
JetResolutionObject.h:76
data
char data[epos_bytes_allocation]
Definition:
EPOS_Wrapper.h:79
RawFile::~RawFile
virtual ~RawFile()
Destructor.
Definition:
RawFile.cc:66
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
RawFile::read
int read(void *data, size_t nbytes)
Read from file.
Definition:
RawFile.cc:76
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::fail
bool fail()
It is not OK.
Definition:
RawFile.cc:72
RawFile::close
int close()
Close file if necessary.
Definition:
RawFile.cc:52
RawFile
Definition:
RawFile.h:14
RemoveAddSevLevel.flag
flag
Definition:
RemoveAddSevLevel.py:116
ZMuMuAnalysisNtupler_cff.prefix
prefix
Definition:
ZMuMuAnalysisNtupler_cff.py:14
Generated for CMSSW Reference Manual by
1.8.16