ATLAS Offline Software
PyStore.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // Py::Store.h
8 // Header file for class Py::Store
9 // Author: S.Binet<binet@cern.ch>
11 #ifndef PERFMONEVENT_PY_STORE_H
12 #define PERFMONEVENT_PY_STORE_H
13 
14 // Python includes
15 // Work around a compilation warning.
16 #ifdef _POSIX_C_SOURCE
17 # undef _POSIX_C_SOURCE
18 #endif
19 #ifdef _XOPEN_SOURCE
20 # undef _XOPEN_SOURCE
21 #endif
22 #include "Python.h"
23 
24 // STL includes
25 #include <string>
26 #include <vector>
27 
28 // PerfMonEvent includes
31 
32 // Forward declaration
33 
34 namespace Py {
35 
36 class Store
37 {
38 
40  // Public methods:
42  public:
43 
45  Store();
46 
48  Store( const std::size_t bufSize );
49 
51  ~Store();
52 
54  // Const methods:
56 
58  const PyObject* pydict() const { Py_INCREF(m_store); return m_store; }
59 
61  std::size_t bufferSize() const { return m_bufSize; }
62 
64  std::string repr();
65 
67  // Non-const methods:
69 
72  void setBufferSize( std::size_t bufferSize );
73 
75  //PyObject* pydict() { Py_INCREF(m_store); return m_store; }
76 
78  template< typename T >
79  void book( const std::string& key,
80  const std::string& dataName )
81  {
82  //PyObject* buf = Py::cnv<T>::toPy( T() );
83  //PyObject* buf = PyList_New(0);
84  //PyObject* buf = Py::cnv<T>::to( T() );
85  this->book_impl( key, dataName, 'd' );
86  //Py_XDECREF(buf);
87  }
88 
90  template< typename T >
91  void fill( const std::string& key,
92  const std::string& dataName,
93  const T& data )
94  {
95 // std::cerr << "PyStore::fill( " << key << ", " << dataName
96 // << ", " << typeid(data).name() << " => "
97 // << ClassName<T>::name() << "\n";
98  PyObject* pyData = Py::cnv<T>::toPy( data );
99  this->fill_impl( key, dataName, pyData );
100  // fill_impl steals pyData reference...
101  return;
102  }
103 
105  void clear_store();
106 
108  void py_book( const std::string& key,
109  const std::string& dataName,
110  char dataType = 'd' )
111  { return this->book_impl( key, dataName, dataType ); }
112 
113  void py_fill( const std::string& key,
114  const std::string& dataName,
115  PyObject* data )
116  { return this->fill_impl( key, dataName, data ); }
118 
120  // Private methods:
122  private:
123 
125  void book_impl( const std::string& key,
126  const std::string& dataName,
127  char dataType = 'd' );
128 
130  void fill_impl( const std::string& key,
131  const std::string& dataName,
132  PyObject* data );
133 
135  // Private data:
137  private:
138 
141  std::size_t m_bufSize;
142 
145  //arrayobject* m_aobj;
146 
147 };
148 
149 } // end namespace Py
150 
151 #endif //> PERFMONEVENT_PY_DATASTORE_H
Py::Store::book_impl
void book_impl(const std::string &key, const std::string &dataName, char dataType='d')
register a variable with the store
Definition: PyStore.cxx:123
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Py::Store::m_bufSize
std::size_t m_bufSize
the buffer size of all buckets (ie: the pre-reserved length of all PyArrays)
Definition: PyStore.h:141
Py::Store::repr
std::string repr()
python representation
Definition: PyStore.cxx:67
Py::Store::py_book
void py_book(const std::string &key, const std::string &dataName, char dataType='d')
python API
Definition: PyStore.h:108
Py::Store::fill_impl
void fill_impl(const std::string &key, const std::string &dataName, PyObject *data)
fill some already registered node with data
Definition: PyStore.cxx:159
Py::cnv
helper method to convert a type to a Py::Object
Definition: PyDataStore.h:28
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
Py::Store
Definition: PyStore.h:37
Py::Store::pydict
const PyObject * pydict() const
retrieve the underlying python dictionary
Definition: PyStore.h:58
Py::Store::m_store
PyObject * m_store
data store: a python dictionary
Definition: PyStore.h:144
Py::Store::book
void book(const std::string &key, const std::string &dataName)
retrieve the underlying python dictionary
Definition: PyStore.h:79
Py::Store::bufferSize
std::size_t bufferSize() const
retrieve the current buffer size
Definition: PyStore.h:61
Py::Store::Store
Store()
Constructor with parameters:
Definition: PyStore.cxx:46
PyStoreCnvUtils.h
Py::Store::fill
void fill(const std::string &key, const std::string &dataName, const T &data)
fill some already registered node with data
Definition: PyStore.h:91
Py::Store::clear_store
void clear_store()
clear buckets (but keeps registered/booked keys around)
Definition: PyStore.cxx:89
Py::Store::py_fill
void py_fill(const std::string &key, const std::string &dataName, PyObject *data)
Definition: PyStore.h:113
Py
Definition: PyDataStore.h:24
Py::Store::~Store
~Store()
Destructor:
Definition: PyStore.cxx:58
PyStoreUtils.h
PyObject
_object PyObject
Definition: IPyComponent.h:26
Py::Store::setBufferSize
void setBufferSize(std::size_t bufferSize)
reset the buffer size.
Definition: PyStore.cxx:76
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37