29 std::vector<McUtils::Strings>&
parsed);
61 std::cout <<
"--- Parents ---" << std::endl;
64 std::cout <<
"--- Children ---" << std::endl;
72 std::stringstream( pdgIdString ) >> iPDG;
82 if ( inputCmd.empty() ) {
98 std::string
error =
"problem while parsing command [" + inputCmd +
"]";
99 throw std::runtime_error (
error);
102 if (!PyTuple_Check (
res)) {
104 std::string
error =
"expected a python tuple";
105 throw std::runtime_error (
error);
108 if (PyTuple_GET_SIZE (
res) != 3) {
110 std::string
error =
"expected a python tuple of size 3";
111 throw std::runtime_error (
error);
116 #if PY_MAJOR_VERSION < 3
117 if (!
sc || !PyInt_Check (
sc)) {
119 if (!
sc || !PyLong_Check (
sc)) {
123 std::string
error =
"corrupted return code";
124 throw std::runtime_error (
error);
127 #if PY_MAJOR_VERSION < 3
128 Py_ssize_t
status = PyInt_AsSsize_t (
sc);
130 Py_ssize_t
status = PyLong_AsSsize_t (
sc);
135 std::string
error =
"failed to parse command ["+inputCmd+
"]";
136 throw std::runtime_error (
error);
144 std::string
error =
"corrupted parents' list";
145 throw std::runtime_error (
error);
153 std::string
error =
"corrupted children' list";
154 throw std::runtime_error (
error);
169 std::string
error =
"could not translate parents' list";
170 throw std::runtime_error (
error);
176 std::string
error =
"could not translate children' list";
177 throw std::runtime_error (
error);
192 unsigned int iSlot = 0;
193 for( std::vector<McUtils::Strings>::const_iterator itr =
list.begin();
196 std::stringstream iSlotStr;
198 const McUtils::Strings::const_iterator candEnd = itr->end();
199 std::cout <<
"slot #" << iSlotStr.str() <<
": candidates= [ ";
200 for( McUtils::Strings::const_iterator candidate = itr->begin();
201 candidate != candEnd;
203 std::cout << *candidate;
204 if ( candidate+1 != candEnd ) {
208 std::cout <<
" ]" << std::endl;
220 if (
this != &rhs ) {
233 if (!Py_IsInitialized()) {
237 const std::string
n =
"McParticleUtils.DecayParser";
238 PyObject *
module = PyImport_ImportModule (
const_cast<char*
>(
n.c_str()));
241 std::string
error =
"could not import module ["+
n+
"]";
242 throw std::runtime_error (
error);
245 const std::string
fct_name =
"py_parse";
247 const_cast<char*
>(
fct_name.c_str()));
253 if (!
fct || !PyFunction_Check (
fct)) {
254 std::string
error =
"could not get '"+
fct_name+
"' from module ["+
n+
"] or not a function";
255 throw std::runtime_error (
error);
263 std::vector<McUtils::Strings>&
parsed)
265 bool all_good =
true;
274 Py_ssize_t isz = PySequence_Size (
candidates);
280 for (Py_ssize_t
i = 0;
i!=isz; ++
i) {
285 if (!PySequence_Check (cand)) {
289 Py_ssize_t jsz = PySequence_Size (cand);
297 for (Py_ssize_t j = 0; j!=jsz; ++j) {
298 PyObject *pdgid = PySequence_GetItem(cand, j);