ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DecayParser Class Reference

#include <DecayParser.h>

Collaboration diagram for DecayParser:

Public Member Functions

 DecayParser (const std::string &cmd)
 Constructor with parameters: More...
 
virtual ~DecayParser ()
 Destructor: More...
 
const std::vector< McUtils::Strings > & getParents () const
 I/O operators. More...
 
const std::vector< McUtils::Strings > & getChildren () const
 
void dump () const
 Const methods: More...
 
int pdgId (const std::string &pdgIdString) const
 
void parse (const std::string &cmd)
 Non-const methods:
More...
 

Protected Member Functions

 DecayParser ()
 Default constructor: More...
 
 DecayParser (const DecayParser &rhs)
 Copy constructor: More...
 
DecayParseroperator= (const DecayParser &obj)
 Assignment operator: More...
 
void printMcUtilsStrings (const std::vector< McUtils::Strings > &list) const
 Print the content of a vector of McUtils::Strings to std::cout. More...
 

Protected Attributes

PyObjectm_parseFct
 python function to parse the input string modeling the decay pattern to look for. More...
 
std::vector< McUtils::Stringsm_parents
 List of parents : each slot of the vector is a list of candidates So one could have something like : [ ["22","23"] ] to model a decay of a gamma or a Z0. More...
 
std::vector< McUtils::Stringsm_children
 List of children : each slot of the vector is a list of candidates So one could have something like : [ ["11","13"], ["-11","-13" ] ] to model a decay into a pair of electrons or muons. More...
 

Detailed Description

Definition at line 33 of file DecayParser.h.

Constructor & Destructor Documentation

◆ DecayParser() [1/3]

DecayParser::DecayParser ( const std::string &  cmd)

Constructor with parameters:

Public methods:

Constructors

Definition at line 39 of file DecayParser.cxx.

39  :
40  m_parseFct (0),
41  m_parents ( ),
42  m_children ( )
43 {
44  m_parseFct = ::fetch_py_parse_fct();
45  parse(cmd);
46 }

◆ ~DecayParser()

DecayParser::~DecayParser ( )
virtual

Destructor:

Destructor.

Definition at line 51 of file DecayParser.cxx.

52 {
53  Py_XDECREF (m_parseFct);
54 }

◆ DecayParser() [2/3]

DecayParser::DecayParser ( )
protected

Default constructor:

◆ DecayParser() [3/3]

DecayParser::DecayParser ( const DecayParser rhs)
protected

Copy constructor:

Member Function Documentation

◆ dump()

void DecayParser::dump ( ) const

Const methods:

Definition at line 59 of file DecayParser.cxx.

60 {
61  std::cout << "--- Parents ---" << std::endl;
63 
64  std::cout << "--- Children ---" << std::endl;
66 }

◆ getChildren()

const std::vector< McUtils::Strings > & DecayParser::getChildren ( ) const
inline

Definition at line 126 of file DecayParser.h.

127 {
128  return m_children;
129 }

◆ getParents()

const std::vector< McUtils::Strings > & DecayParser::getParents ( ) const
inline

I/O operators.

Inline methods:

Definition at line 119 of file DecayParser.h.

120 {
121  return m_parents;
122 }

◆ operator=()

DecayParser & DecayParser::operator= ( const DecayParser obj)
protected

Assignment operator:

Definition at line 218 of file DecayParser.cxx.

219 {
220  if ( this != &rhs ) {
221  m_parents = rhs.m_parents;
222  m_children = rhs.m_children;
223  }
224  return *this;
225 }

◆ parse()

void DecayParser::parse ( const std::string &  cmd)

Non-const methods:

Definition at line 80 of file DecayParser.cxx.

81 {
82  if ( inputCmd.empty() ) {
83  return;
84  }
85 
86  // Reset the parents and children lists
87  m_parents.clear();
88  m_children.clear();
89 
90 
91 
92  // real parsing takes place now.
93  PyObject *res = PyObject_CallFunction (m_parseFct,
94  (char*)"s",
95  inputCmd.c_str());
96  if (!res) {
97  Py_XDECREF (res);
98  std::string error = "problem while parsing command [" + inputCmd +"]";
99  throw std::runtime_error (error);
100  }
101 
102  if (!PyTuple_Check (res)) {
103  Py_DECREF (res);
104  std::string error = "expected a python tuple";
105  throw std::runtime_error (error);
106  }
107 
108  if (PyTuple_GET_SIZE (res) != 3) {
109  Py_DECREF (res);
110  std::string error = "expected a python tuple of size 3";
111  throw std::runtime_error (error);
112  }
113 
114  PyObject *sc = PyTuple_GET_ITEM (res, 0);
115  Py_XINCREF (sc);
116 #if PY_MAJOR_VERSION < 3
117  if (!sc || !PyInt_Check (sc)) {
118 #else
119  if (!sc || !PyLong_Check (sc)) {
120 #endif
121  Py_XDECREF (sc);
122  Py_DECREF (res);
123  std::string error = "corrupted return code";
124  throw std::runtime_error (error);
125  }
126 
127 #if PY_MAJOR_VERSION < 3
128  Py_ssize_t status = PyInt_AsSsize_t (sc);
129 #else
130  Py_ssize_t status = PyLong_AsSsize_t (sc);
131 #endif
132  if (status != 0) {
133  Py_DECREF (sc);
134  Py_DECREF (res);
135  std::string error = "failed to parse command ["+inputCmd+"]";
136  throw std::runtime_error (error);
137  }
138  Py_DECREF (sc);
139 
140  PyObject *parents = PyTuple_GET_ITEM (res, 1);
141  Py_XINCREF (parents);
142  if (!parents) {
143  Py_DECREF (res);
144  std::string error = "corrupted parents' list";
145  throw std::runtime_error (error);
146  }
147 
148  PyObject *children= PyTuple_GET_ITEM (res, 2);
149  Py_XINCREF (children);
150  if (!children) {
151  Py_DECREF (parents);
152  Py_DECREF (res);
153  std::string error = "corrupted children' list";
154  throw std::runtime_error (error);
155  }
156  Py_DECREF (res);
157 
158  if (parents==Py_None && children==Py_None) {
159  // special case of a single arrow without any parent nor child :
160  // this decay pattern will select every single vertex
161  Py_DECREF (parents);
162  Py_DECREF (children);
163  return;
164  }
165 
166  if (!py_to_cpp (parents, m_parents)) {
167  Py_DECREF (parents);
168  Py_DECREF (children);
169  std::string error = "could not translate parents' list";
170  throw std::runtime_error (error);
171  }
172 
173  if (!py_to_cpp (children, m_children)) {
174  Py_DECREF (parents);
175  Py_DECREF (children);
176  std::string error = "could not translate children' list";
177  throw std::runtime_error (error);
178  }
179 
180  return;
181 }

◆ pdgId()

int DecayParser::pdgId ( const std::string &  pdgIdString) const

Definition at line 68 of file DecayParser.cxx.

69 {
70  int pdgID = 0;
71  int iPDG = 0;
72  std::stringstream( pdgIdString ) >> iPDG;
73  pdgID = iPDG;
74 
75  return pdgID;
76 }

◆ printMcUtilsStrings()

void DecayParser::printMcUtilsStrings ( const std::vector< McUtils::Strings > &  list) const
protected

Print the content of a vector of McUtils::Strings to std::cout.

Protected methods:

Definition at line 190 of file DecayParser.cxx.

191 {
192  unsigned int iSlot = 0;
193  for( std::vector<McUtils::Strings>::const_iterator itr = list.begin();
194  itr != list.end();
195  ++itr,++iSlot ) {
196  std::stringstream iSlotStr;
197  iSlotStr << iSlot;
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;
202  ++candidate ) {
203  std::cout << *candidate;
204  if ( candidate+1 != candEnd ) {
205  std::cout << " | ";
206  }
207  }
208  std::cout << " ]" << std::endl;
209  }
210  return;
211 }

Member Data Documentation

◆ m_children

std::vector<McUtils::Strings> DecayParser::m_children
protected

List of children : each slot of the vector is a list of candidates So one could have something like : [ ["11","13"], ["-11","-13" ] ] to model a decay into a pair of electrons or muons.

Definition at line 105 of file DecayParser.h.

◆ m_parents

std::vector<McUtils::Strings> DecayParser::m_parents
protected

List of parents : each slot of the vector is a list of candidates So one could have something like : [ ["22","23"] ] to model a decay of a gamma or a Z0.

Definition at line 99 of file DecayParser.h.

◆ m_parseFct

PyObject* DecayParser::m_parseFct
protected

python function to parse the input string modeling the decay pattern to look for.

Definition at line 93 of file DecayParser.h.


The documentation for this class was generated from the following files:
DecayParser::m_parseFct
PyObject * m_parseFct
python function to parse the input string modeling the decay pattern to look for.
Definition: DecayParser.h:93
DecayParser::parse
void parse(const std::string &cmd)
Non-const methods:
Definition: DecayParser.cxx:80
python.DecayParser.parents
parents
print ("==> buf:",buf)
Definition: DecayParser.py:31
rerun_display.cmd
string cmd
Definition: rerun_display.py:67
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
DecayParser::m_parents
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 : ...
Definition: DecayParser.h:99
DecayParser::m_children
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 :...
Definition: DecayParser.h:105
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DecayParser::printMcUtilsStrings
void printMcUtilsStrings(const std::vector< McUtils::Strings > &list) const
Print the content of a vector of McUtils::Strings to std::cout.
Definition: DecayParser.cxx:190
python.DecayParser.children
children
Definition: DecayParser.py:32
merge.status
status
Definition: merge.py:17
error
Definition: IImpactPoint3dEstimator.h:70
PyObject
_object PyObject
Definition: IPyComponent.h:26