BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/rdbModel/rdbModel-00-01-01/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 2005/10/17 06:10:53 maqm Exp $
2#ifndef RDBMODEL_ASSERTION_H
3#define RDBMODEL_ASSERTION_H
4#include <vector>
5#include <string>
6#include "rdbModel/Rdb.h"
9
10namespace rdbModel{
11
12 class Table;
13
14 enum OPTYPE {
22 OPTYPEequal, // first of 2-operand compare ops
29 };
30
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,
79 const std::string& rightArg,
80 FIELDTYPE leftType, FIELDTYPE rightType);
81
82 /// Constructor for EXISTS
83 Operator(OPTYPE type, const std::string& tableName, Operator* child=0);
84
85 /// Constructor for OR, AND, NOT
86 Operator(OPTYPE type, const std::vector<Operator*>& children,
87 bool keepChildren = false);
88
89 /// Copy an operator, substituting from toBe row as appropriate
90 Operator(Operator* op, Row* toBe);
91
92 /// Add another child to a conjunction-style operator
93 bool appendChild(Operator* child);
94
95 /// Check whether columns or column and literal to be compared
96 /// have compatible types
97 bool validCompareOp(Table* table) const;
98
99 /// True if operator is isNull, isEmpty or any of the usual arithmetic
100 /// comparisons
101 bool isCompareOp() const {return (m_opType >= OPTYPEisNull);}
102
103 /// Throw exception if Operator is not a comparison operator
104 const std::string* getCompareArgs() const;
105
106 /// Throw exception if Operaotr is not EXISTS
107 const std::string& getTableName() const;
108
109 /// Get types of comparison args
110 const FIELDTYPE* getCompareArgTypes() const;
111
112 /// Throw exception if Operator is a comparison operator
113 const std::vector<Operator* >& getChildren() const;
114
115 OPTYPE getOpType() const {return m_opType;}
116
117 /// True if operator or sub-operator refers to future row
118 bool getToBe() const {return m_toBe;}
119
120 /// True if operator or sub-operator refers to existing row
121 bool getOld() const {return m_old;}
122
123 /// Evaluate operator on argument Rows
124 bool verify(Row& old, Row& toBe, Table* t) const;
125
126
127
128 private:
129 /// Handling specific to 2-arg compare operators
130 bool verifyCompare(Row& old, Row& toBe, Table* t) const;
131
132 /// Handling specific to timestamp data
133 bool compareTs(const std::string* vals, OPTYPE type) const;
134
135 /// Handling specific to integer data
136 bool compareInt(const std::string* vals, OPTYPE type) const;
137
138 /// Handling specific to floating point data
139 bool compareFloat(const std::string* vals, OPTYPE type) const;
140
141 /// Handling specific to string data
142 bool compareString(const std::string* vals, OPTYPE type) const;
143
144 OPTYPE m_opType;
145
146 /** Following two lines apply only to compare operators (includes
147 isNull, isEmpty)
148
149 In order to format properly in an SQL query, need to
150 keep track of whether compare arg is literal, column name
151 referring to current row under consideration, or column
152 name referring to proposed row (in case this is part of an
153 assertion about relation of existing rows to proposed row)
154 */
155 std::string m_compareArgs[2];
156 FIELDTYPE m_compareType[2];
157
158 /// Following used only for EXISTS
159 std::string m_tableName;
160
161 bool m_keepChildren;
162
163 /// Following is used only for non-compare operators
164 std::vector<Operator* > m_operands; // #allowed depends on opType
165
166 /// Following is true if this operator or suboperator has an arg.
167 /// column name referring to a "toBe" row
168 bool m_toBe;
169
170 /// Following is true if this operator or suboperator has an arg.
171 /// column name referring to a row already in the table
172 bool m_old;
173 };
174
175 /**
176 Normally, operator associated with the assertion will be deleted
177 when the assertion itself is deleted, but this won't happen if
178 keepOp is set to true.
179 */
180 Assertion(Operator* op = 0, Table* myTable=0, bool keepOp=false) :
181 m_op(op), m_myTable(myTable), m_keepOp(keepOp)
182 { m_compiled.clear(); m_name.clear();};
183
184 /**
185 Copy original assertion, but, wherever a colRef is a "toBe",
186 substitute with value from toBe row. toBe is not const because
187 we may need to sort it.
188 */
189 Assertion(const Assertion* orig, Row* toBe);
190
191 ~Assertion();
192 // WHEN getWhen() const {return m_when;}
194
195 Operator* getOperator() const {return m_op;}
196 ///
197 const std::string& getPrecompiled() const {return m_compiled;}
198
199 /// True if associated operator or descendant refers to future row
200 /// (in which case can't call MySql::compileAssertion)
201 bool getToBe() const {return m_op->getToBe();}
202
203 /// Returns true if associated operator or descendant refers to
204 /// existing row
205 bool getOld() const {return m_op->getOld();}
206
207 const std::string& getName() const {return m_name;}
208 void setName(const std::string& name) {m_name = name;}
209
210 /** @a verify checks if assertion (which may refer to one or both of
211 an old row and a proposed row) holds for these arguments.
212 Caller is responsible for fetching old row fields out of dbs if
213 necessary
214 May throw RdbException
215 */
216 bool verify(Row& old, Row& toBe) const;
217
218 private:
219 /// The heart of an Assertion is an Operator
220 Operator* m_op;
221 Table* m_myTable;
222 /// m_keepOp indicates whether or not we're responsible for cleaning
223 /// up resources
224 bool m_keepOp;
225 /// Assertions have names so that they can be referenced elsewhere
226 std::string m_name;
227
228 /// Let's hope that, independent of connection type, std::string is
229 /// a reasonable choice for "compiled" form of the assertion
230 std::string m_compiled;
231
232 };
233}
234#endif
235
**********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
TTree * t
Definition: binning.cxx:23
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.
Assertion(Operator *op=0, Table *myTable=0, bool keepOp=false)
FIELDTYPE
Definition: Rdb.h:21