ATLAS Offline Software
Loading...
Searching...
No Matches
Control
RootUtils
src
pyroot
PyROOTTFilePythonize.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
10
11
// stdlib includes
12
#include <stdlib.h>
13
#include <stdio.h>
14
15
#include "TFile.h"
16
17
// local includes
18
#include "
RootUtils/PyROOTTFilePythonize.h
"
19
20
namespace
RootUtils
{
21
22
PyBytes::PyBytes
(
size_t
buf_sz) :
23
sz
(buf_sz>0?buf_sz:0),
24
buf
(
sz
)
25
{
26
}
27
28
PyBytes::~PyBytes
()
29
{
30
}
31
32
PyBytes::PyBytes
(
const
PyBytes
& rhs) :
33
sz
(rhs.
sz
),
34
buf
(rhs.
buf
)
35
{
36
}
37
38
PyBytes
&
39
PyBytes::operator=
(
const
PyBytes
& rhs)
40
{
41
if
(
this
!= &rhs) {
42
this->
sz
= rhs.
sz
;
43
this->
buf
= rhs.
buf
;
44
}
45
return
*
this
;
46
}
47
48
Long64_t
49
_pythonize_tell_root_file
(TFile* f)
50
{
51
if
(f) {
52
return
f->GetRelOffset();
53
}
54
fprintf (stderr,
55
"::RootUtils::_pythonize_tell_root_file got a NULL TFile ptr!\n"
);
56
return
0;
57
}
58
59
PyBytes
60
_pythonize_read_root_file
(TFile* f, Int_t len)
61
{
62
if
(!f) {
63
//err
64
return
PyBytes
(0);
65
}
66
67
Long64_t totsz = f->GetSize();
68
Long64_t curpos =
_pythonize_tell_root_file
(f);
69
Long64_t remain = totsz - curpos;
70
remain = (remain>0) ? remain : 0;
71
72
len = (len>remain) ? remain : len;
73
PyBytes
buf(len);
74
if
(f->ReadBuffer((
char
*)buf.buf.data(), buf.sz)) {
75
//err
76
return
PyBytes
(0);
77
}
78
79
f->Seek(buf.sz + curpos);
80
return
buf;
81
}
82
83
}
//> namespace RootUtils
PyROOTTFilePythonize.h
Pythonize the access to TFile so they can be used as file-like python objects.
RootUtils::PyBytes
Definition
PyROOTTFilePythonize.h:31
RootUtils::PyBytes::~PyBytes
~PyBytes()
Definition
PyROOTTFilePythonize.cxx:28
RootUtils::PyBytes::operator=
PyBytes & operator=(const PyBytes &rhs)
Definition
PyROOTTFilePythonize.cxx:39
RootUtils::PyBytes::buf
std::vector< char > buf
the buffer of bytes
Definition
PyROOTTFilePythonize.h:53
RootUtils::PyBytes::sz
size_t sz
the size of the buffer of bytes
Definition
PyROOTTFilePythonize.h:49
RootUtils::PyBytes::PyBytes
PyBytes(size_t buf_sz=0)
wrapper around char* to explicitly mean bytes.
Definition
PyROOTTFilePythonize.cxx:22
RootUtils
Definition
ILogger.h:20
RootUtils::_pythonize_read_root_file
PyBytes _pythonize_read_root_file(TFile *f, Int_t len)
read len bytes from file f
Definition
PyROOTTFilePythonize.cxx:60
RootUtils::_pythonize_tell_root_file
Long64_t _pythonize_tell_root_file(TFile *f)
tell the current position in file f
Definition
PyROOTTFilePythonize.cxx:49
Generated on
for ATLAS Offline Software by
1.14.0