8#define likely(x) __builtin_expect((x),1)
9#define unlikely(x) __builtin_expect((x),0)
13#include <CoolKernel/ChannelSelection.h>
14#include <CoolKernel/IFolder.h>
15#include <CoolKernel/IDatabase.h>
17#include "CoralBase/Attribute.h"
18#include "CoralBase/AttributeList.h"
19#include "CoralBase/AttributeListSpecification.h"
42using std::placeholders::_1;
43using cool::IFolderPtr;
44using cool::IDatabasePtr;
45using cool::ChannelSelection;
46using cool::ValidityKey;
47using coral::Attribute;
48using coral::AttributeSpecification;
49using coral::AttributeList;
51typedef std::function<
PyObject* (
const AttributeList&)>
71 const string& type_name)
76 std::string sname =name;
77 #define MAKE_FETCHER(type, converter) \
78 if (type_name == #type) { \
80 return [sname] (const AttributeList& l) -> PyObject* \
81 { return converter(fetch_attribute_data<type>(l[sname])); }; \
114 PyErr_Format(PyExc_RuntimeError,
115 "Type '%s' is not in type conversion table. "
116 "Please add it to pythonic_coracool.cxx. "
117 "Can't convert field '%s'.",
128 const AttributeList& attribute_list,
129 vector<coral_attribute_fetcher_t>& payload_fetchers)
131 const Py_ssize_t
count = to_fetch ? PySequence_Size(to_fetch) : 0;
133 for (Py_ssize_t i = 0; i <
count; i++)
135 PyObject *py_name = PySequence_GetItem(to_fetch, i);
136 const char *name = _PyUnicode_AsString(py_name);
137 const string type = attribute_list[name].specification().typeName();
141 auto pff = pf.target<
PyObject* (*)(
const AttributeList&)>();
145 payload_fetchers.push_back(std::move(pf));
156 if (!function || function == Py_None)
return object;
158 PyObject *new_object = PyObject_CallObject(function,
object);
159 Py_DECREF(old_object);
169 cooldb->databaseId(), cooldb,
true);
171 return coradb->getFolder(folder);
174const cool::RecordSpecification
181 unsigned long long value)
183 static const char *
const argtypes =
const_cast<char *
>(
"K");
184 if (iovkey_wrapper && iovkey_wrapper != Py_None)
185 return PyObject_CallFunction(iovkey_wrapper, argtypes, value);
186 return PyLong_FromUnsignedLongLong(value);
190 ValidityKey since, ValidityKey until,
191 const ChannelSelection &cs = ChannelSelection::all(),
195 PyObject *inner_object_converter = NULL,
204 const Py_ssize_t
count = to_fetch ? PySequence_Size(to_fetch) : 0;
211 vector<coral_attribute_fetcher_t> payload_fetchers;
214 while (objects->hasNext())
219 unsigned int payload_index = 0;
222 for (payload =
object->begin();
224 ++payload, ++payload_index)
237 for (Py_ssize_t i = 0; i <
count; i++)
238 PyTuple_SET_ITEM(py_payload, i, payload_fetchers[i](*payload));
247 Py_DECREF(py_payload_tuple);
252 PyTuple_SET_ITEM(py_payload_tuple, payload_index, py_payload);
260 PyTuple_SET_ITEM(one, 2, PyLong_FromLong(
object->channelId()));
263 PyTuple_SET_ITEM(one, 3, py_payload_tuple);
275 PyList_Append(
result, one);
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
CoraCoolDatabasePtr openDatabase(const std::string &dbconn, cool::IDatabasePtr cooldb, bool readonly=false)
AttrListVec::const_iterator const_iterator
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
CoraCoolFolderPtr fetch_coracool_folder(IDatabasePtr cooldb, const string &folder)
const cool::RecordSpecification get_coracool_payload_spec(IDatabasePtr cooldb, const string &folder)
#define MAKE_FETCHER(type, converter)
const T & fetch_attribute_data(const coral::Attribute &A)
PyObject * browse_coracool(IDatabasePtr cooldb, const string &folder, ValidityKey since, ValidityKey until, const ChannelSelection &cs=ChannelSelection::all(), const char *tag="", PyObject *to_fetch=NULL, PyObject *object_converter=NULL, PyObject *inner_object_converter=NULL, PyObject *iovkey_wrapper=NULL)
coral_attribute_fetcher_t create_attribute_fetcher(const char *name, const string &type_name)
PyObject * qr_PyString_FromStdString(const string &str)
PyObject * apply_function(PyObject *function, PyObject *object)
PyObject * qr_PyString_FromBlob(const coral::Blob &blob)
bool make_fetchers(PyObject *to_fetch, const AttributeList &attribute_list, vector< coral_attribute_fetcher_t > &payload_fetchers)
PyObject * make_iov_key(PyObject *iovkey_wrapper, unsigned long long value)
std::function< PyObject *(const AttributeList &)> coral_attribute_fetcher_t
PyObject * no_coral_conversion_available(const AttributeList &)
hold the test vectors and ease the comparison