BOSS 8.0.0
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.
 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.
 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/15]

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

◆ ~Operator() [1/3]

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

Definition at line 13 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

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

◆ Operator() [2/15]

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 44 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

47 : m_opType( type ), m_keepChildren( false ), m_toBe( false ), m_old( false ) {
48
49 m_tableName.clear();
50 m_operands.clear();
51 if ( !isCompareOp() )
52 {
53 m_opType = OPTYPEundefined;
54 return;
55 }
56
57 m_compareArgs[0] = leftArg;
58 m_compareArgs[1] = rightArg;
59 m_compareType[0] = leftLiteral;
60 m_compareType[1] = rightLiteral;
61 if ( ( type == OPTYPEisNull ) || ( type == OPTYPEisEmpty ) )
62 {
63 m_compareType[1] = FIELDTYPElit;
64 m_compareArgs[1] = "";
65 }
66 m_toBe = ( ( leftLiteral == FIELDTYPEtoBe ) || ( rightLiteral == FIELDTYPEtoBe ) );
67 m_old = ( ( leftLiteral == FIELDTYPEold ) || ( rightLiteral == FIELDTYPEold ) );
68 }

◆ Operator() [3/15]

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

Constructor for EXISTS.

Definition at line 71 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

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

◆ Operator() [4/15]

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

Constructor for OR, AND, NOT.

Definition at line 83 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

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

◆ Operator() [5/15]

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

Copy an operator, substituting from toBe row as appropriate.

Definition at line 109 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

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

◆ Operator() [6/15]

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

◆ ~Operator() [2/3]

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

◆ Operator() [7/15]

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.

◆ Operator() [8/15]

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

Constructor for EXISTS.

◆ Operator() [9/15]

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

Constructor for OR, AND, NOT.

◆ Operator() [10/15]

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

Copy an operator, substituting from toBe row as appropriate.

◆ Operator() [11/15]

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

◆ ~Operator() [3/3]

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

◆ Operator() [12/15]

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.

◆ Operator() [13/15]

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

Constructor for EXISTS.

◆ Operator() [14/15]

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

Constructor for OR, AND, NOT.

◆ Operator() [15/15]

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

Copy an operator, substituting from toBe row as appropriate.

Member Function Documentation

◆ appendChild() [1/3]

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

Add another child to a conjunction-style operator.

Definition at line 165 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

165 {
166 m_toBe |= child->m_toBe;
167 m_old |= child->m_old;
168 if ( ( m_opType == OPTYPEor ) || ( m_opType == OPTYPEand ) )
169 {
170 m_operands.push_back( child );
171 return true;
172 }
173 else if ( ( m_opType == OPTYPEnot ) && ( m_operands.size() == 0 ) )
174 {
175 m_operands.push_back( child );
176 return true;
177 }
178 throw RdbException( "Assertion::Operator::appendChild: wrong parent operator type" );
179 return false;
180 }

Referenced by Operator().

◆ appendChild() [2/3]

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

Add another child to a conjunction-style operator.

◆ appendChild() [3/3]

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

Add another child to a conjunction-style operator.

◆ getChildren() [1/3]

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

Throw exception if Operator is a comparison operator.

Definition at line 342 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

342 {
343 if ( isCompareOp() ) throw RdbException( "Assertion::Operator::getChildren: wrong type" );
344 return m_operands;
345 }

◆ getChildren() [2/3]

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

Throw exception if Operator is a comparison operator.

◆ getChildren() [3/3]

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

Throw exception if Operator is a comparison operator.

◆ getCompareArgs() [1/3]

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

Throw exception if Operator is not a comparison operator.

Definition at line 204 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

204 {
205 if ( !isCompareOp() )
206 throw RdbException( "Assertion::Operator::getCompareArgs: wrong type" );
207 return &m_compareArgs[0];
208 }

◆ getCompareArgs() [2/3]

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

Throw exception if Operator is not a comparison operator.

◆ getCompareArgs() [3/3]

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

Throw exception if Operator is not a comparison operator.

◆ getCompareArgTypes() [1/3]

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

Get types of comparison args.

Throw exception if Operator is not a comparison operator.

Definition at line 212 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

212 {
213 if ( !isCompareOp() )
214 throw RdbException( "Assertion::Operator::getLiteralness: wrong type" );
215 return &m_compareType[0];
216 }

◆ getCompareArgTypes() [2/3]

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

Get types of comparison args.

◆ getCompareArgTypes() [3/3]

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

Get types of comparison args.

◆ getOld() [1/3]

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

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

Definition at line 120 of file Calibration/rdbModel/include/rdbModel/Tables/Assertion.h.

120{ return m_old; }

◆ getOld() [2/3]

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

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

Definition at line 120 of file InstallArea/x86_64-el9-gcc13-dbg/include/rdbModel/Tables/Assertion.h.

120{ return m_old; }

◆ getOld() [3/3]

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

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

Definition at line 120 of file InstallArea/x86_64-el9-gcc13-opt/include/rdbModel/Tables/Assertion.h.

120{ return m_old; }

◆ getOpType() [1/3]

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

Definition at line 114 of file Calibration/rdbModel/include/rdbModel/Tables/Assertion.h.

114{ return m_opType; }

◆ getOpType() [2/3]

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

Definition at line 114 of file InstallArea/x86_64-el9-gcc13-dbg/include/rdbModel/Tables/Assertion.h.

114{ return m_opType; }

◆ getOpType() [3/3]

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

Definition at line 114 of file InstallArea/x86_64-el9-gcc13-opt/include/rdbModel/Tables/Assertion.h.

114{ return m_opType; }

◆ getTableName() [1/3]

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 219 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

219 {
220 if ( m_opType != OPTYPEexists )
221 throw RdbException( "Assertion::Operator::getTableName: wrong type" );
222 return m_tableName;
223 }

◆ getTableName() [2/3]

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

Throw exception if Operaotr is not EXISTS.

◆ getTableName() [3/3]

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

Throw exception if Operaotr is not EXISTS.

◆ getToBe() [1/3]

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

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

Definition at line 117 of file Calibration/rdbModel/include/rdbModel/Tables/Assertion.h.

117{ return m_toBe; }

◆ getToBe() [2/3]

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

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

Definition at line 117 of file InstallArea/x86_64-el9-gcc13-dbg/include/rdbModel/Tables/Assertion.h.

117{ return m_toBe; }

◆ getToBe() [3/3]

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

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

Definition at line 117 of file InstallArea/x86_64-el9-gcc13-opt/include/rdbModel/Tables/Assertion.h.

117{ return m_toBe; }

◆ isCompareOp() [1/3]

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

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

Definition at line 100 of file Calibration/rdbModel/include/rdbModel/Tables/Assertion.h.

100{ return ( m_opType >= OPTYPEisNull ); }

Referenced by getChildren(), getCompareArgs(), getCompareArgTypes(), and Operator().

◆ isCompareOp() [2/3]

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

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

Definition at line 100 of file InstallArea/x86_64-el9-gcc13-dbg/include/rdbModel/Tables/Assertion.h.

100{ return ( m_opType >= OPTYPEisNull ); }

◆ isCompareOp() [3/3]

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

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

Definition at line 100 of file InstallArea/x86_64-el9-gcc13-opt/include/rdbModel/Tables/Assertion.h.

100{ return ( m_opType >= OPTYPEisNull ); }

◆ validCompareOp() [1/3]

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

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

Definition at line 182 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

182 {
183 if ( m_compareType[0] != FIELDTYPElit )
184 {
185 Column* col0 = myTable->getColumnByName( m_compareArgs[0] );
186 if ( m_compareType[1] != FIELDTYPElit )
187 {
188 Column* col1 = myTable->getColumnByName( m_compareArgs[1] );
189 return col1->isCompatible( col0 );
190 }
191 else
192 { // one column, one literal
193 return col0->okValue( m_compareArgs[1], false );
194 }
195 }
196 else
197 { // 1st arg is a literal; second arg must be column
198 Column* col1 = myTable->getColumnByName( m_compareArgs[1] );
199 return col1->okValue( m_compareArgs[0], false );
200 }
201 }

◆ validCompareOp() [2/3]

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

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

◆ validCompareOp() [3/3]

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

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

◆ verify() [1/3]

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

Evaluate operator on argument Rows.

Definition at line 225 of file Calibration/rdbModel/src/Tables/Assertion.cxx.

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

◆ verify() [2/3]

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

Evaluate operator on argument Rows.

◆ verify() [3/3]

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

Evaluate operator on argument Rows.


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