BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
rdbModel::Assertion::Operator Class Reference

#include <Assertion.h>

Public Member Functions

 Operator ()
 
 ~Operator ()
 
 Operator (OPTYPE type, const std::string &leftArg, const std::string &rightArg, FIELDTYPE leftType, FIELDTYPE rightType)
 
 Operator (OPTYPE type, const std::string &tableName, Operator *child=0)
 Constructor for EXISTS.
 
 Operator (OPTYPE type, const std::vector< Operator * > &children, bool keepChildren=false)
 Constructor for OR, AND, NOT.
 
 Operator (Operator *op, Row *toBe)
 Copy an operator, substituting from toBe row as appropriate.
 
bool appendChild (Operator *child)
 Add another child to a conjunction-style operator.
 
bool validCompareOp (Table *table) const
 
bool isCompareOp () const
 
const std::string * getCompareArgs () const
 Throw exception if Operator is not a comparison operator.
 
const std::string & getTableName () const
 Throw exception if Operaotr is not EXISTS.
 
const FIELDTYPEgetCompareArgTypes () const
 Get types of comparison args.
 
const std::vector< Operator * > & getChildren () const
 Throw exception if Operator is a comparison operator.
 
OPTYPE getOpType () const
 
bool getToBe () const
 True if operator or sub-operator refers to future row.
 
bool getOld () const
 True if operator or sub-operator refers to existing row.
 
bool verify (Row &old, Row &toBe, Table *t) const
 Evaluate operator on argument Rows.
 

Detailed Description

Constructor & Destructor Documentation

◆ Operator() [1/5]

rdbModel::Assertion::Operator::Operator ( )
inline

◆ ~Operator()

rdbModel::Assertion::Operator::~Operator ( )

Definition at line 12 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

12 {
13 if (!m_keepChildren) {
14 while (m_operands.size() ) {
15 Operator* op = m_operands.back();
16 m_operands.pop_back();
17 delete op;
18 }
19 }
20 }

◆ Operator() [2/5]

rdbModel::Assertion::Operator::Operator ( OPTYPE type,
const std::string & leftArg,
const std::string & rightArg,
FIELDTYPE leftType,
FIELDTYPE rightType )

Constructor for comparison. If the operator is OPTTYPEisNull or OPTYPEisEmpty rightArg and rightLiteral are ignored.

Definition at line 39 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

43 : m_opType(type), m_keepChildren(false), m_toBe(false), m_old(false) {
44
45 m_tableName.clear();
46 m_operands.clear();
47 if (!isCompareOp()) {
48 m_opType = OPTYPEundefined;
49 return;
50 }
51
52 m_compareArgs[0] = leftArg;
53 m_compareArgs[1] = rightArg;
54 m_compareType[0] = leftLiteral;
55 m_compareType[1] = rightLiteral;
56 if ((type == OPTYPEisNull) || (type ==OPTYPEisEmpty)) {
57 m_compareType[1] = FIELDTYPElit;
58 m_compareArgs[1] = "";
59 }
60 m_toBe = ((leftLiteral == FIELDTYPEtoBe) ||
61 (rightLiteral == FIELDTYPEtoBe));
62 m_old = ((leftLiteral == FIELDTYPEold) ||
63 (rightLiteral == FIELDTYPEold));
64 }
@ FIELDTYPEtoBe
Definition Rdb.h:24
@ FIELDTYPEold
Definition Rdb.h:23
@ FIELDTYPElit
Definition Rdb.h:22

◆ Operator() [3/5]

rdbModel::Assertion::Operator::Operator ( OPTYPE type,
const std::string & tableName,
Operator * child = 0 )

Constructor for EXISTS.

Definition at line 67 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

68 : m_opType(type),
69 m_tableName(tableName),
70 m_keepChildren(false)
71 {
72 if (type != OPTYPEexists) {
73 m_opType = OPTYPEundefined;
74 return;
75 }
76 m_operands.clear();
77 m_operands.push_back(child);
78 }

◆ Operator() [4/5]

rdbModel::Assertion::Operator::Operator ( OPTYPE type,
const std::vector< Operator * > & children,
bool keepChildren = false )

Constructor for OR, AND, NOT.

Definition at line 81 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

83 :
84 m_opType(type), m_keepChildren(keepChildren) {
85
86 m_toBe = false;
87 m_old = false;
88 if ((type == OPTYPEor) || (type == OPTYPEand) || (type = OPTYPEnot)) {
89 m_tableName.clear();
90 unsigned int nChild = children.size();
91 if (!nChild) {
92 m_opType = OPTYPEundefined;
93 return;
94 }
95 for (unsigned int iChild = 0; iChild < nChild; iChild++) {
96 m_toBe |= (children[iChild]->m_toBe);
97 m_old |= (children[iChild]->m_old);
98 m_operands.push_back(children[iChild]);
99 }
100 }
101 else m_opType = OPTYPEundefined;
102 }

◆ Operator() [5/5]

rdbModel::Assertion::Operator::Operator ( Operator * op,
Row * toBe )

Copy an operator, substituting from toBe row as appropriate.

Definition at line 106 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

107 : m_opType(op->m_opType), m_tableName(op->m_tableName),
108 m_keepChildren(false), m_toBe(false), m_old(op->m_old) {
109 m_operands.clear();
110
111 switch (m_opType) {
112 // OPTYPEor, and, not and exists all have child operators
113 case OPTYPEor:
114 case OPTYPEand:
115 case OPTYPEnot:
116 case OPTYPEexists:
117 {
118 unsigned nChild = op->m_operands.size();
119 for (unsigned iChild = 0; iChild < nChild; iChild++) {
120 Operator* child = new Operator((op->m_operands)[iChild], toBe);
121 appendChild(child);
122 }
123 break;
124 }
125 case OPTYPEequal:
126 case OPTYPEnotEqual:
127 case OPTYPElessThan:
131 case OPTYPEisEmpty:
132 case OPTYPEisNull: {
133 for (unsigned i = 0; i < 2; i++) {
134 if ((op->m_compareType[i] == FIELDTYPEtoBe) ||
135 (op->m_compareType[i] == FIELDTYPEtoBeDef) ) {
136 // have to supply value from row
137 FieldVal* f = toBe->find(op->m_compareArgs[i]);
138 if (!f) {
139 throw RdbException
140 ("Assertion::Operator constructor can't resolve field");
141 }
142 m_compareArgs[i] = f->m_val;
143 m_compareType[i] = FIELDTYPElit;
144 }
145 else { // just copy what's there
146 m_compareArgs[i] = op->m_compareArgs[i];
147 m_compareType[i] =op->m_compareType[i];
148 }
149 }
150 break;
151 }
152 default:
153 throw RdbException("Assertion::Operator constructor - Unknown OP type");
154 }
155 }
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
bool appendChild(Operator *child)
Add another child to a conjunction-style operator.
@ FIELDTYPEtoBeDef
Definition Rdb.h:28

Member Function Documentation

◆ appendChild()

bool rdbModel::Assertion::Operator::appendChild ( Operator * child)

Add another child to a conjunction-style operator.

Definition at line 158 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

158 {
159 m_toBe |= child->m_toBe;
160 m_old |= child->m_old;
161 if ((m_opType == OPTYPEor) || (m_opType == OPTYPEand) ) {
162 m_operands.push_back(child);
163 return true;
164 }
165 else if ((m_opType == OPTYPEnot) && (m_operands.size() == 0) ) {
166 m_operands.push_back(child);
167 return true;
168 }
169 throw RdbException("Assertion::Operator::appendChild: wrong parent operator type");
170 return false;
171 }

Referenced by Operator().

◆ getChildren()

const std::vector< Assertion::Operator * > & rdbModel::Assertion::Operator::getChildren ( ) const

Throw exception if Operator is a comparison operator.

Definition at line 338 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

338 {
339 if (isCompareOp())
340 throw RdbException("Assertion::Operator::getChildren: wrong type");
341 return m_operands;
342 }

◆ getCompareArgs()

const std::string * rdbModel::Assertion::Operator::getCompareArgs ( ) const

Throw exception if Operator is not a comparison operator.

Definition at line 193 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

193 {
194 if (!isCompareOp())
195 throw RdbException("Assertion::Operator::getCompareArgs: wrong type");
196 return &m_compareArgs[0];
197 }

◆ getCompareArgTypes()

const FIELDTYPE * rdbModel::Assertion::Operator::getCompareArgTypes ( ) const

Get types of comparison args.

Throw exception if Operator is not a comparison operator.

Definition at line 201 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

201 {
202 if (!isCompareOp())
203 throw RdbException("Assertion::Operator::getLiteralness: wrong type");
204 return &m_compareType[0];
205 }

◆ getOld()

bool rdbModel::Assertion::Operator::getOld ( ) const
inline

True if operator or sub-operator refers to existing row.

Definition at line 121 of file Calibration/rdbModel/rdbModel-00-01-01/rdbModel/Tables/Assertion.h.

121{return m_old;}

Referenced by rdbModel::Assertion::getOld().

◆ getOpType()

OPTYPE rdbModel::Assertion::Operator::getOpType ( ) const
inline

Definition at line 115 of file Calibration/rdbModel/rdbModel-00-01-01/rdbModel/Tables/Assertion.h.

115{return m_opType;}

◆ getTableName()

const std::string & rdbModel::Assertion::Operator::getTableName ( ) const

Throw exception if Operaotr is not EXISTS.

Throw exception if Operator is not EXISTS.

Definition at line 208 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

208 {
209 if (m_opType != OPTYPEexists)
210 throw RdbException("Assertion::Operator::getTableName: wrong type");
211 return m_tableName;
212 }

◆ getToBe()

bool rdbModel::Assertion::Operator::getToBe ( ) const
inline

True if operator or sub-operator refers to future row.

Definition at line 118 of file Calibration/rdbModel/rdbModel-00-01-01/rdbModel/Tables/Assertion.h.

118{return m_toBe;}

Referenced by rdbModel::Assertion::getToBe().

◆ isCompareOp()

bool rdbModel::Assertion::Operator::isCompareOp ( ) const
inline

True if operator is isNull, isEmpty or any of the usual arithmetic comparisons

Definition at line 101 of file Calibration/rdbModel/rdbModel-00-01-01/rdbModel/Tables/Assertion.h.

101{return (m_opType >= OPTYPEisNull);}

Referenced by Operator().

◆ validCompareOp()

bool rdbModel::Assertion::Operator::validCompareOp ( Table * table) const

Check whether columns or column and literal to be compared have compatible types

Definition at line 174 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

174 {
175 if (m_compareType[0] != FIELDTYPElit) {
176 Column* col0 = myTable->getColumnByName(m_compareArgs[0]);
177 if (m_compareType[1] != FIELDTYPElit) {
178 Column* col1 = myTable->getColumnByName(m_compareArgs[1]);
179 return col1->isCompatible(col0);
180 }
181 else { // one column, one literal
182 return col0->okValue(m_compareArgs[1], false);
183 }
184 }
185 else { // 1st arg is a literal; second arg must be column
186 Column* col1 = myTable->getColumnByName(m_compareArgs[1]);
187 return col1->okValue(m_compareArgs[0], false);
188 }
189 }

◆ verify()

bool rdbModel::Assertion::Operator::verify ( Row & old,
Row & toBe,
Table * t ) const

Evaluate operator on argument Rows.

Definition at line 215 of file Calibration/rdbModel/rdbModel-00-01-01/src/Tables/Assertion.cxx.

215 {
216 switch(m_opType) {
217 case OPTYPEor: {
218 unsigned nChild = m_operands.size();
219 for (unsigned i = 0; i < nChild; i++) {
220 if (m_operands[i]->verify(old, toBe, t)) return true;
221 }
222 return false;
223 }
224
225 case OPTYPEand: {
226 unsigned nChild = m_operands.size();
227 for (unsigned i = 0; i < nChild; i++) {
228 if (!(m_operands[i]->verify(old, toBe, t))) return false;
229 }
230 return true;
231 }
232 case OPTYPEnot:
233 return (!(m_operands[0]->verify(old, toBe, t)));
234
235
236 case OPTYPEisNull:
237 case OPTYPEisEmpty:
238 // These two are almost the same
239 {
240 Row* r = 0;
241 if ( (m_compareType[0] == FIELDTYPEtoBe) ||
242 (m_compareType[0] == FIELDTYPEtoBeDef) ) r = &toBe;
243 else r = &old;
244
245 FieldVal* f = r->find(m_compareArgs[0]);
246 if (f) {
247 if (m_opType == OPTYPEisNull) return f->m_null;
248 return ((f->m_val).size() == 0);
249 }
250 else { // improper input. Field should have been found
251 throw RdbException("Assertion::Operator::verify missing isNull field");
252 }
253 }
254 // handle all 2-argument compare operators together
255 case OPTYPEequal:
256 case OPTYPEnotEqual:
257 case OPTYPElessThan:
261 return verifyCompare(old, toBe, t);
262
263 default:
264 return false;
265 }
266 return false;
267 }
TTree * t
Definition binning.cxx:23
bool verify(Row &old, Row &toBe, Table *t) const
Evaluate operator on argument Rows.

Referenced by rdbModel::Assertion::verify().


The documentation for this class was generated from the following files: