BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/rdbModel/include/rdbModel/Tables/Column.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/rdbModel/rdbModel/Tables/Column.h,v 1.1.1.1 2005/10/17
2// 06:10:53 maqm Exp $
3#ifndef RDBMODEL_COLUMN_H
4#define RDBMODEL_COLUMN_H
5#include "rdbModel/Management/Visitor.h"
6#include <string>
7#include <utility>
8#include <vector>
9// #include "rdbModel/Tables/Table.h"
10
11namespace rdbModel {
12
13 // class Table;
14 class Datatype;
15 class Enum;
16 class Table;
17 class XercesBuilder;
18
19 /**
20 * rdbModel representation of a(n SQL-like) table description
21 */
22 class Column {
23 // class ColumnSource; // embedded class, described below
24
25 public:
26 /// Source of value. Note timestamp with value current time should
27 /// be indicated by contents value CONTENTSupdateTime or (if only
28 /// upon insert) CONTENTS enterTime
29 enum FROM {
30 FROMdefault = 1, // enduser can override default, however
32 FROMnow, // datatype must be timestamp - deprecated
35 };
36
37 /// Hints to program in case FROM field is FROMprogram
46
47 Column( Table* myTable = 0 ) : m_myTable( myTable ), m_type( 0 ), m_isPrimaryKey( false ) {
48 m_contents = CONTENTSunspecified;
49 m_default = std::string( "" );
50 };
51 // Column(Table* myTable=0) : m_myTable(myTable), m_type(0), m_source(0) {};
52 ~Column();
53
54 const std::string& getName() const { return m_name; };
55 const std::string& getComment() const { return m_comment; };
56
57 const std::string& getDefault() const { return m_default; }
58
59 const std::string& getTableName() const;
60
61 Datatype* getDatatype() const { return m_type; };
62
63 /// Return pointer to Enum object associated with this column (if
64 /// none, return null pointer).
65 Enum* getEnum() const;
66
67 /** See if supplied value meets constraints of column definition
68 * @arg val std::string representation of value to be checked
69 * @arg set true if value is to be written to column; false
70 * if just being used, e.g. in "where" clause
71 */
72 bool okValue( const std::string& val, bool set = true ) const;
73
74 /// Return true if otherCol and this have compatible datatypes
75 bool isCompatible( const Column* otherCol ) const;
76
77 /// Returns true if column may take on value NULL
78 bool nullAllowed() const { return m_null; }
79
80 bool stickyInsert() const { return m_stickyInsert; }
81
82 bool isPrimaryKey() const { return m_isPrimaryKey; }
83
84 bool isAutoIncrement() const;
85
86 FROM getSourceType() const { return m_from; }
87 CONTENTS getContentsType() const { return m_contents; }
88
89 /**
90 Handle special literal values, depending loosely on column datatype.
91 Most Column objects won't do any interpretation, but, for example,
92 timestamp-like columns may substitute for "NOW"
93 Return true if any substitution was done
94 */
95 bool interpret( const std::string& interpType, std::string& val );
96
98
99 private:
100 friend class rdbModel::XercesBuilder; // needs access to add.. methods
101
102 Table* m_myTable;
103
104 std::string m_name;
105 std::string m_comment;
106 Datatype* m_type;
107
108 std::string m_default;
109 FROM m_from;
110 CONTENTS m_contents;
111
112 /// Can this field have the value NULL?
113 bool m_null;
114 /// For multi-insert, does this column normally keep same value
115 /// for all the inserts?
116 bool m_stickyInsert;
117
118 /// Is this column a primary key?
119 bool m_isPrimaryKey;
120 };
121
122 // Do we want Column* for first component or just the column name?
123 class FieldVal {
124 // Column* m_pCol;
125 public:
126 FieldVal( std::string colname, std::string val, bool isNull = false )
127 : m_colname( colname ), m_val( val ), m_null( isNull ) {}
128 std::string m_colname;
129 std::string m_val;
130 bool m_null; // true if field val is NULL; then will ignore m_val
131 };
132
133 /// Function object used to sort FieldValPar objects by column name
135 public:
136 // bool operator() (const Column* a, const Column* b) {
137 bool operator()( const FieldVal& a, const FieldVal& b ) {
138 return ( ( a.m_colname ).compare( b.m_colname ) < 0 );
139 // return (a.first->getName().compare(b.first->getName()) < 0);
140 }
141 };
142
143 /**
144 @class Row
145 A collection of column names and values.
146 */
147 class Row {
148 public:
149 Row() : m_sorted( false ) { m_fields.clear(); }
150 Row( std::vector<FieldVal>& fields ) : m_fields( fields ), m_sorted( false ) {}
151
152 ~Row() { m_fields.clear(); }
153 void rowSort();
154 void addField( const FieldVal& f ) {
155 m_fields.push_back( f );
156 m_sorted = false;
157 }
158 void clear() { m_fields.clear(); }
159
160 FieldVal* find( std::string colname );
161
162 /// Reorder information suitable for Connection::insert
163 void regroup( std::vector<std::string>& colNames, std::vector<std::string>& colVals,
164 std::vector<std::string>& nullCols ) const;
165
166 private:
167 std::vector<FieldVal> m_fields;
168 bool m_sorted;
169 };
170} // namespace rdbModel
171#endif
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
Definition KarLud.h:35
bool isAutoIncrement() const
Definition Column.cxx:33
Enum * getEnum() const
Definition Column.cxx:14
const std::string & getTableName() const
Definition Column.cxx:16
Visitor::VisitorState accept(Visitor *v)
Definition Column.cxx:50
bool nullAllowed() const
Returns true if column may take on value NULL.
bool isCompatible(const Column *otherCol) const
Return true if otherCol and this have compatible datatypes.
Definition Column.cxx:29
bool interpret(const std::string &interpType, std::string &val)
Definition Column.cxx:35
bool okValue(const std::string &val, bool set=true) const
Definition Column.cxx:18
CONTENTS
Hints to program in case FROM field is FROMprogram.
Function object used to sort FieldValPar objects by column name.
bool operator()(const FieldVal &a, const FieldVal &b)
FieldVal(std::string colname, std::string val, bool isNull=false)
FieldVal * find(std::string colname)
Definition Column.cxx:65
void rowSort()
Definition Column.cxx:57
void regroup(std::vector< std::string > &colNames, std::vector< std::string > &colVals, std::vector< std::string > &nullCols) const
Reorder information suitable for Connection::insert.
Definition Column.cxx:94