3#include "rdbModel/Tables/Assertion.h"
4#include "facilities/Timestamp.h"
5#include "facilities/Util.h"
6#include "rdbModel/Rdb.h"
7#include "rdbModel/RdbException.h"
8#include "rdbModel/Tables/Column.h"
9#include "rdbModel/Tables/Datatype.h"
10#include "rdbModel/Tables/Table.h"
14 if ( !m_keepChildren )
16 while ( m_operands.size() )
19 m_operands.pop_back();
28 , m_myTable( orig->m_myTable )
37 if ( !m_keepOp )
delete m_op;
45 const std::string& rightArg,
FIELDTYPE leftLiteral,
47 : m_opType(
type ), m_keepChildren( false ), m_toBe( false ), m_old( false ) {
57 m_compareArgs[0] = leftArg;
58 m_compareArgs[1] = rightArg;
59 m_compareType[0] = leftLiteral;
60 m_compareType[1] = rightLiteral;
64 m_compareArgs[1] =
"";
72 : m_opType(
type ), m_tableName( tableName ), m_keepChildren( false ) {
79 m_operands.push_back( child );
85 : m_opType(
type ), m_keepChildren( keepChildren ) {
92 unsigned int nChild = children.size();
98 for (
unsigned int iChild = 0; iChild < nChild; iChild++ )
100 m_toBe |= ( children[iChild]->m_toBe );
101 m_old |= ( children[iChild]->m_old );
102 m_operands.push_back( children[iChild] );
110 : m_opType( op->m_opType )
111 , m_tableName( op->m_tableName )
112 , m_keepChildren( false )
114 , m_old( op->m_old ) {
124 unsigned nChild = op->m_operands.size();
125 for (
unsigned iChild = 0; iChild < nChild; iChild++ )
140 for (
unsigned i = 0; i < 2; i++ )
148 {
throw RdbException(
"Assertion::Operator constructor can't resolve field" ); }
149 m_compareArgs[i] =
f->m_val;
154 m_compareArgs[i] = op->m_compareArgs[i];
155 m_compareType[i] = op->m_compareType[i];
160 default:
throw RdbException(
"Assertion::Operator constructor - Unknown OP type" );
166 m_toBe |= child->m_toBe;
167 m_old |= child->m_old;
170 m_operands.push_back( child );
173 else if ( ( m_opType ==
OPTYPEnot ) && ( m_operands.size() == 0 ) )
175 m_operands.push_back( child );
178 throw RdbException(
"Assertion::Operator::appendChild: wrong parent operator type" );
193 return col0->
okValue( m_compareArgs[1],
false );
199 return col1->
okValue( m_compareArgs[0],
false );
206 throw RdbException(
"Assertion::Operator::getCompareArgs: wrong type" );
207 return &m_compareArgs[0];
214 throw RdbException(
"Assertion::Operator::getLiteralness: wrong type" );
215 return &m_compareType[0];
221 throw RdbException(
"Assertion::Operator::getTableName: wrong type" );
229 unsigned nChild = m_operands.size();
230 for (
unsigned i = 0; i < nChild; i++ )
232 if ( m_operands[i]->
verify( old, toBe,
t ) )
return true;
238 unsigned nChild = m_operands.size();
239 for (
unsigned i = 0; i < nChild; i++ )
241 if ( !( m_operands[i]->
verify( old, toBe,
t ) ) )
return false;
261 return ( (
f->m_val ).size() == 0 );
265 throw RdbException(
"Assertion::Operator::verify missing isNull field" );
276 default:
return false;
281 bool Assertion::Operator::verifyCompare(
Row& old,
Row& toBe,
Table*
t )
const {
285 std::string values[2];
289 for (
unsigned i = 0; i < 2; i++ )
291 switch ( m_compareType[i] )
301 std::string(
"Assertion::Operator::verifyCompare missing field " ) +
305 values[i] =
f->m_val;
306 colname =
f->m_colname;
311 FieldVal*
f = toBe.
find( m_compareArgs[i] );
312 if ( !
f ) {
throw RdbException(
"Assertion::Operator::verifyCompare missing field" ); }
314 colname =
f->m_colname;
317 default:
throw RdbException(
"Assertion::Operator::verifyCompare bad arg type" );
320 if ( colname.size() > 0 )
322 Column* c =
t->getColumnByName( colname );
323 Datatype* d = c->getDatatype();
325 switch ( d->getType() )
339 return compareString( &values[0], m_opType );
363 return m_op->verify( old, toBe, m_myTable );
366 bool Assertion::Operator::compareTs(
const std::string* vals,
OPTYPE type )
const {
368 Timestamp left, right;
371 left = Timestamp( *vals );
372 right = Timestamp( *( vals + 1 ) );
374 {
throw RdbException(
"Assertion::Operator::CompareTs illegal input" ); }
384 default:
throw RdbException(
"Assertion::Operator::compareTs bad OPTYPE" );
389 bool Assertion::Operator::compareInt(
const std::string* vals,
OPTYPE type )
const {
390 using facilities::Util;
394 int i = Util::stringToInt( *vals );
395 i = Util::stringToInt( *( vals + 1 ) );
396 }
catch ( facilities::WrongType ex )
397 {
throw RdbException(
"Assertion::Operator::compareInt illegal input" ); }
398 return compareFloat( vals, type );
402 bool Assertion::Operator::compareFloat(
const std::string* vals,
OPTYPE type )
const {
403 using facilities::Util;
407 left = Util::stringToDouble( *vals );
408 right = Util::stringToDouble( *( vals + 1 ) );
409 }
catch ( facilities::WrongType ex )
410 {
throw RdbException(
"Assertion::Operator::compareFloat illegal input" ); }
419 default:
throw RdbException(
"Assertion::Operator::compareFloat bad OPTYPE" );
426 bool Assertion::Operator::compareString(
const std::string* vals,
OPTYPE type )
const {
429 case OPTYPEequal:
return ( ( *vals ).compare( *( vals + 1 ) ) == 0 );
430 case OPTYPEnotEqual:
return ( ( *vals ).compare( *( vals + 1 ) ) != 0 );
431 default:
throw RdbException(
"Assertion::Operator::compareString Unsupported OPTYPE" );
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
bool appendChild(Operator *child)
Add another child to a conjunction-style operator.
const std::vector< Operator * > & getChildren() const
Throw exception if Operator is a comparison operator.
const std::string & getTableName() const
Throw exception if Operaotr is not EXISTS.
const std::string * getCompareArgs() const
Throw exception if Operator is not a comparison operator.
bool validCompareOp(Table *table) const
const FIELDTYPE * getCompareArgTypes() const
Get types of comparison args.
bool verify(Row &old, Row &toBe, Table *t) const
Evaluate operator on argument Rows.
Visitor::VisitorState accept(Visitor *v)
bool verify(Row &old, Row &toBe) const
Assertion(Operator *op=0, Table *myTable=0, bool keepOp=false)
bool isCompatible(const Column *otherCol) const
Return true if otherCol and this have compatible datatypes.
bool okValue(const std::string &val, bool set=true) const
FieldVal * find(std::string colname)
Column * getColumnByName(const std::string &name) const