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 (!
sc || !PyLong_Check (
sc)) {
119 std::string
error =
"corrupted return code";
120 throw std::runtime_error (
error);
123 Py_ssize_t
status = PyLong_AsSsize_t (
sc);
127 std::string
error =
"failed to parse command ["+inputCmd+
"]";
128 throw std::runtime_error (
error);
136 std::string
error =
"corrupted parents' list";
137 throw std::runtime_error (
error);
145 std::string
error =
"corrupted children' list";
146 throw std::runtime_error (
error);
161 std::string
error =
"could not translate parents' list";
162 throw std::runtime_error (
error);
168 std::string
error =
"could not translate children' list";
169 throw std::runtime_error (
error);
184 unsigned int iSlot = 0;
185 for( std::vector<McUtils::Strings>::const_iterator itr =
list.begin();
188 std::stringstream iSlotStr;
190 const McUtils::Strings::const_iterator candEnd = itr->end();
191 std::cout <<
"slot #" << iSlotStr.str() <<
": candidates= [ ";
192 for( McUtils::Strings::const_iterator candidate = itr->begin();
193 candidate != candEnd;
195 std::cout << *candidate;
196 if ( candidate+1 != candEnd ) {
200 std::cout <<
" ]" << std::endl;
212 if (
this != &rhs ) {
225 if (!Py_IsInitialized()) {
229 const std::string
n =
"McParticleUtils.DecayParser";
230 PyObject *
module = PyImport_ImportModule (
const_cast<char*
>(
n.c_str()));
233 std::string
error =
"could not import module ["+
n+
"]";
234 throw std::runtime_error (
error);
237 const std::string
fct_name =
"py_parse";
239 const_cast<char*
>(
fct_name.c_str()));
245 if (!
fct || !PyFunction_Check (
fct)) {
246 std::string
error =
"could not get '"+
fct_name+
"' from module ["+
n+
"] or not a function";
247 throw std::runtime_error (
error);
255 std::vector<McUtils::Strings>&
parsed)
257 bool all_good =
true;
266 Py_ssize_t isz = PySequence_Size (
candidates);
272 for (Py_ssize_t
i = 0;
i!=isz; ++
i) {
277 if (!PySequence_Check (cand)) {
281 Py_ssize_t jsz = PySequence_Size (cand);
289 for (Py_ssize_t j = 0; j!=jsz; ++j) {
290 PyObject *pdgid = PySequence_GetItem(cand, j);