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"
28 #include <boost/bind/bind.hpp>
29 #include <boost/function.hpp>
43 using boost::placeholders::_1;
44 using cool::IFolderPtr;
45 using cool::IDatabasePtr;
46 using cool::ChannelSelection;
47 using cool::ValidityKey;
48 using coral::Attribute;
49 using coral::AttributeSpecification;
72 const string& type_name)
75 const Attribute& (
AttributeList::*fetch_attribute)(
const string)
const =
76 &AttributeList::operator[];
82 #define MAKE_FETCHER(type, converter) \
83 if (type_name == #type) \
84 return bind(converter, \
85 bind(fetch_attribute_data<type>, \
86 bind(fetch_attribute, _1, name) \
120 PyErr_Format(PyExc_RuntimeError,
121 "Type '%s' is not in type conversion table. "
122 "Please add it to pythonic_coracool.cxx. "
123 "Can't convert field '%s'.",
135 vector<coral_attribute_fetcher_t>& payload_fetchers)
137 const Py_ssize_t
count = to_fetch ? PySequence_Size(to_fetch) : 0;
139 for (Py_ssize_t
i = 0;
i <
count;
i++)
141 PyObject *py_name = PySequence_GetItem(to_fetch,
i);
142 #if PY_VERSION_HEX < 0x03000000
143 const char *
name = PyString_AsString(py_name);
145 const char *
name = _PyUnicode_AsString(py_name);
147 const string type = attribute_list[
name].specification().typeName();
154 payload_fetchers.push_back(
pf);
165 if (!
function ||
function == Py_None)
return object;
167 PyObject *new_object = PyObject_CallObject(
function,
object);
168 Py_DECREF(old_object);
178 cooldb->databaseId(), cooldb,
true);
180 return coradb->getFolder(
folder);
183 const cool::RecordSpecification
190 unsigned long long value)
192 static const char *
const argtypes =
const_cast<char *
>(
"K");
193 if (iovkey_wrapper && iovkey_wrapper != Py_None)
194 return PyObject_CallFunction(iovkey_wrapper,
argtypes,
value);
195 return PyLong_FromUnsignedLongLong(
value);
204 PyObject *inner_object_converter = NULL,
213 const Py_ssize_t
count = to_fetch ? PySequence_Size(to_fetch) : 0;
220 vector<coral_attribute_fetcher_t> payload_fetchers;
228 unsigned int payload_index = 0;
246 for (Py_ssize_t
i = 0;
i <
count;
i++)
247 PyTuple_SET_ITEM(py_payload,
i, payload_fetchers[
i](*
payload));
256 Py_DECREF(py_payload_tuple);
261 PyTuple_SET_ITEM(py_payload_tuple, payload_index, py_payload);
269 PyTuple_SET_ITEM(
one, 2, PyLong_FromLong(
object->channelId()));
272 PyTuple_SET_ITEM(
one, 3, py_payload_tuple);