BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/rdbModel/include/rdbModel/Tables/Assertion.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/rdbModel/rdbModel/Tables/Assertion.h,v 1.1.1.1
2// 2005/10/17 06:10:53 maqm Exp $
3#ifndef RDBMODEL_ASSERTION_H
4#define RDBMODEL_ASSERTION_H
5#include "rdbModel/Management/Visitor.h"
6#include "rdbModel/Rdb.h"
7#include "rdbModel/Tables/Column.h"
8#include <string>
9#include <vector>
10
11namespace rdbModel {
12
13 class Table;
14
31
32 /**
33 Assertions are used in at least two ways:
34 1. As part of a table description. The assertion describes a condition
35 which should be evaluated upon a particular event, such as when
36 a new element is to be inserted. Such assertions stick around
37 for the life of the application instance. If the assertion is
38 checked often, a pre-compiled version (dependent on the type
39 of connection) can save some time.
40 2. As a WHERE clause in a client-institued UPDATE or SELECT. These
41 are only around long enough to do the UPDATE or SELECT.
42
43 The bulk of the information comprising an assertion is kept in a
44 tree whose nodes are "operations". An operation may be either
45 a comparison ( =, <=, etc. and also "is null") or an operation which
46 has child operations: OR, AND, NOT, for all, there exists, hence
47 a node is a leaf node iff it's a comparison.
48
49 Once an operation has been incorporated into an Assertion or into
50 another operation, it is 'owned' by this parent. Deleting the parent
51 will cause its children to be deleted. Hence applications building
52 assertions out of operators should never delete those operators.
53
54
55 */
56 class Assertion {
57 public:
58 class Operator; // nested class declared below
59
60 public:
61 // when does this assertion get applied?
62 /*
63 enum WHEN {
64 WHENundefined = 0,
65 WHENglobalCheck = 1,
66 WHENchangeRow,
67 WHENwhere // as a WHERE clause, used and then discarded
68 };
69 */
70
71 class Operator {
72 public:
73 Operator() : m_opType( OPTYPEundefined ){};
74 ~Operator();
75
76 /// Constructor for comparison. If the operator is OPTTYPEisNull
77 /// or OPTYPEisEmpty rightArg and rightLiteral are ignored.
78 Operator( OPTYPE type, const std::string& leftArg, const std::string& rightArg,
79 FIELDTYPE leftType, FIELDTYPE rightType );
80
81 /// Constructor for EXISTS
82 Operator( OPTYPE type, const std::string& tableName, Operator* child = 0 );
83
84 /// Constructor for OR, AND, NOT
85 Operator( OPTYPE type, const std::vector<Operator*>& children,
86 bool keepChildren = false );
87
88 /// Copy an operator, substituting from toBe row as appropriate
89 Operator( Operator* op, Row* toBe );
90
91 /// Add another child to a conjunction-style operator
92 bool appendChild( Operator* child );
93
94 /// Check whether columns or column and literal to be compared
95 /// have compatible types
96 bool validCompareOp( Table* table ) const;
97
98 /// True if operator is isNull, isEmpty or any of the usual arithmetic
99 /// comparisons
100 bool isCompareOp() const { return ( m_opType >= OPTYPEisNull ); }
101
102 /// Throw exception if Operator is not a comparison operator
103 const std::string* getCompareArgs() const;
104
105 /// Throw exception if Operaotr is not EXISTS
106 const std::string& getTableName() const;
107
108 /// Get types of comparison args
109 const FIELDTYPE* getCompareArgTypes() const;
110
111 /// Throw exception if Operator is a comparison operator
112 const std::vector<Operator*>& getChildren() const;
113
114 OPTYPE getOpType() const { return m_opType; }
115
116 /// True if operator or sub-operator refers to future row
117 bool getToBe() const { return m_toBe; }
118
119 /// True if operator or sub-operator refers to existing row
120 bool getOld() const { return m_old; }
121
122 /// Evaluate operator on argument Rows
123 bool verify( Row& old, Row& toBe, Table* t ) const;
124
125 private:
126 /// Handling specific to 2-arg compare operators
127 bool verifyCompare( Row& old, Row& toBe, Table* t ) const;
128
129 /// Handling specific to timestamp data
130 bool compareTs( const std::string* vals, OPTYPE type ) const;
131
132 /// Handling specific to integer data
133 bool compareInt( const std::string* vals, OPTYPE type ) const;
134
135 /// Handling specific to floating point data
136 bool compareFloat( const std::string* vals, OPTYPE type ) const;
137
138 /// Handling specific to string data
139 bool compareString( const std::string* vals, OPTYPE type ) const;
140
141 OPTYPE m_opType;
142
143 /** Following two lines apply only to compare operators (includes
144 isNull, isEmpty)
145
146 In order to format properly in an SQL query, need to
147 keep track of whether compare arg is literal, column name
148 referring to current row under consideration, or column
149 name referring to proposed row (in case this is part of an
150 assertion about relation of existing rows to proposed row)
151 */
152 std::string m_compareArgs[2];
153 FIELDTYPE m_compareType[2];
154
155 /// Following used only for EXISTS
156 std::string m_tableName;
157
158 bool m_keepChildren;
159
160 /// Following is used only for non-compare operators
161 std::vector<Operator*> m_operands; // #allowed depends on opType
162
163 /// Following is true if this operator or suboperator has an arg.
164 /// column name referring to a "toBe" row
165 bool m_toBe;
166
167 /// Following is true if this operator or suboperator has an arg.
168 /// column name referring to a row already in the table
169 bool m_old;
170 };
171
172 /**
173 Normally, operator associated with the assertion will be deleted
174 when the assertion itself is deleted, but this won't happen if
175 keepOp is set to true.
176 */
177 Assertion( Operator* op = 0, Table* myTable = 0, bool keepOp = false )
178 : m_op( op ), m_myTable( myTable ), m_keepOp( keepOp ) {
179 m_compiled.clear();
180 m_name.clear();
181 };
182
183 /**
184 Copy original assertion, but, wherever a colRef is a "toBe",
185 substitute with value from toBe row. toBe is not const because
186 we may need to sort it.
187 */
188 Assertion( const Assertion* orig, Row* toBe );
189
190 ~Assertion();
191 // WHEN getWhen() const {return m_when;}
193
194 Operator* getOperator() const { return m_op; }
195 ///
196 const std::string& getPrecompiled() const { return m_compiled; }
197
198 /// True if associated operator or descendant refers to future row
199 /// (in which case can't call MySql::compileAssertion)
200 bool getToBe() const { return m_op->getToBe(); }
201
202 /// Returns true if associated operator or descendant refers to
203 /// existing row
204 bool getOld() const { return m_op->getOld(); }
205
206 const std::string& getName() const { return m_name; }
207 void setName( const std::string& name ) { m_name = name; }
208
209 /** @a verify checks if assertion (which may refer to one or both of
210 an old row and a proposed row) holds for these arguments.
211 Caller is responsible for fetching old row fields out of dbs if
212 necessary
213 May throw RdbException
214 */
215 bool verify( Row& old, Row& toBe ) const;
216
217 private:
218 /// The heart of an Assertion is an Operator
219 Operator* m_op;
220 Table* m_myTable;
221 /// m_keepOp indicates whether or not we're responsible for cleaning
222 /// up resources
223 bool m_keepOp;
224 /// Assertions have names so that they can be referenced elsewhere
225 std::string m_name;
226
227 /// Let's hope that, independent of connection type, std::string is
228 /// a reasonable choice for "compiled" form of the assertion
229 std::string m_compiled;
230 };
231} // namespace rdbModel
232#endif
**********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
Definition KarLud.h:35
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.
bool getToBe() const
True if operator or sub-operator refers to future row.
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 getOld() const
True if operator or sub-operator refers to existing row.
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)
Assertion(Operator *op=0, Table *myTable=0, bool keepOp=false)
int t()
Definition t.c:1