28 bool py_to_cpp (
PyObject* candidates,
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);
133 Py_XINCREF (parents);
137 std::string
error =
"corrupted parents' list";
138 throw std::runtime_error (
error);
142 Py_XINCREF (children);
146 std::string
error =
"corrupted children' list";
147 throw std::runtime_error (
error);
151 if (parents==Py_None && children==Py_None) {
155 Py_DECREF (children);
161 Py_DECREF (children);
162 std::string
error =
"could not translate parents' list";
163 throw std::runtime_error (
error);
168 Py_DECREF (children);
169 std::string
error =
"could not translate children' list";
170 throw std::runtime_error (
error);
185 unsigned int iSlot = 0;
186 for( std::vector<McUtils::Strings>::const_iterator itr = list.begin();
189 std::stringstream iSlotStr;
191 const McUtils::Strings::const_iterator candEnd = itr->end();
192 std::cout <<
"slot #" << iSlotStr.str() <<
": candidates= [ ";
193 for( McUtils::Strings::const_iterator candidate = itr->begin();
194 candidate != candEnd;
196 std::cout << *candidate;
197 if ( candidate+1 != candEnd ) {
201 std::cout <<
" ]" << std::endl;
213 if (
this != &rhs ) {
226 if (!Py_IsInitialized()) {
230 const std::string
n =
"McParticleUtils.DecayParser";
231 PyObject *
module = PyImport_ImportModule (
const_cast<char*
>(
n.c_str()));
232 if (!module || !PyModule_Check (module)) {
234 std::string
error =
"could not import module ["+
n+
"]";
235 throw std::runtime_error (
error);
238 const std::string
fct_name =
"py_parse";
239 PyObject *
fct = PyDict_GetItemString (PyModule_GetDict (module),
240 const_cast<char*
>(
fct_name.c_str()));
246 if (!fct || !PyFunction_Check (fct)) {
247 std::string
error =
"could not get '"+
fct_name+
"' from module ["+
n+
"] or not a function";
248 throw std::runtime_error (
error);
256 std::vector<McUtils::Strings>& parsed)
258 bool all_good =
true;
259 if (candidates==Py_None) {
264 if (!PySequence_Check (candidates)) {
267 Py_ssize_t isz = PySequence_Size (candidates);
273 for (Py_ssize_t i = 0;
i!=isz; ++
i) {
274 PyObject *cand = PySequence_GetItem(candidates, i);
278 if (!PySequence_Check (cand)) {
282 Py_ssize_t jsz = PySequence_Size (cand);
290 for (Py_ssize_t j = 0;
j!=jsz; ++
j) {
291 PyObject *pdgid = PySequence_GetItem(cand, j);
std::pair< std::vector< unsigned int >, bool > res
Convert python string -> C++ string for py2 and py3.
DecayParser()
Default constructor:
void printMcUtilsStrings(const std::vector< McUtils::Strings > &list) const
Print the content of a vector of McUtils::Strings to std::cout.
void dump() const
Const methods:
virtual ~DecayParser()
Destructor:
DecayParser(const std::string &cmd)
Constructor with parameters:
std::vector< McUtils::Strings > m_parents
List of parents : each slot of the vector is a list of candidates So one could have something like : ...
void parse(const std::string &cmd)
Non-const methods:
int pdgId(const std::string &pdgIdString) const
DecayParser & operator=(const DecayParser &obj)
Assignment operator:
PyObject * m_parseFct
python function to parse the input string modeling the decay pattern to look for.
std::vector< McUtils::Strings > m_children
List of children : each slot of the vector is a list of candidates So one could have something like :...
std::pair< std::string, bool > PyGetString(PyObject *s)
Convert python string -> C++ string for py2 and py3.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)