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 210 of file DecayParser.cxx.

211 {
212  if ( this != &rhs ) {
213  m_parents = rhs.m_parents;
214  m_children = rhs.m_children;
215  }
216  return *this;
217 }

◆ 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 (!sc || !PyLong_Check (sc)) {
117  Py_XDECREF (sc);
118  Py_DECREF (res);
119  std::string error = "corrupted return code";
120  throw std::runtime_error (error);
121  }
122 
123  Py_ssize_t status = PyLong_AsSsize_t (sc);
124  if (status != 0) {
125  Py_DECREF (sc);
126  Py_DECREF (res);
127  std::string error = "failed to parse command ["+inputCmd+"]";
128  throw std::runtime_error (error);
129  }
130  Py_DECREF (sc);
131 
132  PyObject *parents = PyTuple_GET_ITEM (res, 1);
133  Py_XINCREF (parents);
134  if (!parents) {
135  Py_DECREF (res);
136  std::string error = "corrupted parents' list";
137  throw std::runtime_error (error);
138  }
139 
140  PyObject *children= PyTuple_GET_ITEM (res, 2);
141  Py_XINCREF (children);
142  if (!children) {
143  Py_DECREF (parents);
144  Py_DECREF (res);
145  std::string error = "corrupted children' list";
146  throw std::runtime_error (error);
147  }
148  Py_DECREF (res);
149 
150  if (parents==Py_None && children==Py_None) {
151  // special case of a single arrow without any parent nor child :
152  // this decay pattern will select every single vertex
153  Py_DECREF (parents);
154  Py_DECREF (children);
155  return;
156  }
157 
158  if (!py_to_cpp (parents, m_parents)) {
159  Py_DECREF (parents);
160  Py_DECREF (children);
161  std::string error = "could not translate parents' list";
162  throw std::runtime_error (error);
163  }
164 
165  if (!py_to_cpp (children, m_children)) {
166  Py_DECREF (parents);
167  Py_DECREF (children);
168  std::string error = "could not translate children' list";
169  throw std::runtime_error (error);
170  }
171 
172  return;
173 }

◆ 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 182 of file DecayParser.cxx.

183 {
184  unsigned int iSlot = 0;
185  for( std::vector<McUtils::Strings>::const_iterator itr = list.begin();
186  itr != list.end();
187  ++itr,++iSlot ) {
188  std::stringstream iSlotStr;
189  iSlotStr << iSlot;
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;
194  ++candidate ) {
195  std::cout << *candidate;
196  if ( candidate+1 != candEnd ) {
197  std::cout << " | ";
198  }
199  }
200  std::cout << " ]" << std::endl;
201  }
202  return;
203 }

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:11
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:182
python.DecayParser.children
children
Definition: DecayParser.py:32
merge.status
status
Definition: merge.py:16
error
Definition: IImpactPoint3dEstimator.h:70
PyObject
_object PyObject
Definition: IPyComponent.h:26