ATLAS Offline Software
Loading...
Searching...
No Matches
DecayParser Class Reference

#include <DecayParser.h>

Collaboration diagram for DecayParser:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

PyObjectm_parseFct
 python function to parse the input string modeling the decay pattern to look for.
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.
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.

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}
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
void parse(const std::string &cmd)
Non-const methods:
PyObject * m_parseFct
python function to parse the input string modeling the decay pattern to look for.
Definition DecayParser.h:93
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 :...

◆ ~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}
void printMcUtilsStrings(const std::vector< McUtils::Strings > &list) const
Print the content of a vector of McUtils::Strings to std::cout.

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

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

◆ 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 //coverity[COPY_PASTE_ERROR]
136 Py_DECREF (res);
137 std::string error = "corrupted parents' list";
138 throw std::runtime_error (error);
139 }
140
141 PyObject *children= PyTuple_GET_ITEM (res, 2);
142 Py_XINCREF (children);
143 if (!children) {
144 Py_DECREF (parents);
145 Py_DECREF (res);
146 std::string error = "corrupted children' list";
147 throw std::runtime_error (error);
148 }
149 Py_DECREF (res);
150
151 if (parents==Py_None && children==Py_None) {
152 // special case of a single arrow without any parent nor child :
153 // this decay pattern will select every single vertex
154 Py_DECREF (parents);
155 Py_DECREF (children);
156 return;
157 }
158
159 if (!py_to_cpp (parents, m_parents)) {
160 Py_DECREF (parents);
161 Py_DECREF (children);
162 std::string error = "could not translate parents' list";
163 throw std::runtime_error (error);
164 }
165
166 if (!py_to_cpp (children, m_children)) {
167 Py_DECREF (parents);
168 Py_DECREF (children);
169 std::string error = "could not translate children' list";
170 throw std::runtime_error (error);
171 }
172
173 return;
174}
_object PyObject
std::pair< std::vector< unsigned int >, bool > res
static Double_t sc
status
Definition merge.py:16
parents
print ("==> buf:",buf)

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

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

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: