Public Member Functions | Private Attributes | Friends | List of all members
nova::dbi::Column Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-15/Database/cxx/include/Column.h"

Public Member Functions

 Column ()
 
 Column (const dBColumn_t &c)
 
 Column (const ColumnDef &c)
 
 Column (const Column &c)
 
 ~Column ()
 
uint8_t Type () const
 
std::string Value () const
 
bool IsNull () const
 
bool Modified () const
 
void Clear ()
 
void SetType (uint8_t t)
 
void FastSet (std::string v)
 
void FastSet (const char *v)
 
template<class T >
bool Get (T &val) const
 
template<class T >
bool Set (const T &val, bool ignoreAutoIncr=false)
 
template<class T >
bool Update (const T &val)
 
bool operator>= (const Column &c) const
 
bool operator<= (const Column &c) const
 
bool operator> (const Column &c) const
 
bool operator< (const Column &c) const
 
bool operator== (const Column &c) const
 

Private Attributes

bool fModified
 
uint16_t fType
 
char * fValue
 

Friends

std::ostream & operator<< (std::ostream &stream, const Column &col)
 

Detailed Description

Generalized Database Column Interface

Author
Jonathan Paley
Version
Id
Column.h,v 1.24 2013/03/12 19:53:02 jpaley Exp

Definition at line 33 of file Column.h.

Constructor & Destructor Documentation

nova::dbi::Column::Column ( )
inline

Definition at line 36 of file Column.h.

References plot_validation_datamc::c, fType, fValue, nova::dbi::kIntLike, and ~Column().

nova::dbi::Column::Column ( const dBColumn_t c)

Definition at line 25 of file Column.cpp.

References fType, fValue, nova::dbi::dBColumn_t::getColType(), nova::dbi::dBColumn_t::getValue(), nova::dbi::dBColumn_t::hasColType(), nova::dbi::dBColumn_t::hasValue(), nova::dbi::kAutoIncr, nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, and confusionMatrixTree::t.

25  :
26  fModified(false)
27  {
28  fValue = 0;
29  fType = kIntLike;//"string";
30  if (c.hasColType()) {
31  std::string t = c.getColType();
32  if (t == "timestamp") fType = kTimeStamp;
33  else if (t == "date") fType = kDateStamp;
34  else if (t == "bool") fType = kBool;
35  else if (t == "float" || t == "double") fType = kFloatLike;
36  else if (t == "string" || t == "text") fType = kString;
37  else if (t == "autoincr") fType = kAutoIncr;
38  }
39 
40  if (c.hasValue()) {
41  std::string vStr = c.getValue();
42  if (vStr == "" || vStr=="NULL") {
43  fValue=0;
44  }
45  else if (fType == kBool) {
46  fValue = new char[2];
47  if (vStr == "TRUE" || vStr == "t" || vStr == "true" ||
48  vStr == "y" || vStr == "yes" || vStr == "1" || vStr == "on")
49  fValue[0] = '1';
50  else
51  fValue[0] = '0';
52  // Null terminate
53  fValue[1] = '\0';
54  }
55  else {
56  fValue = new char[16];
57  strncpy(fValue,vStr.c_str(),16);
58  fValue[15]='\0';
59  }
60  }
61  }
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
nova::dbi::Column::Column ( const ColumnDef c)

Definition at line 65 of file Column.cpp.

References fType, fValue, nova::dbi::kAutoIncr, nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, confusionMatrixTree::t, and nova::dbi::ColumnDef::Type().

65  :
66  fModified(false)
67  {
68  fValue = 0;
69  fType = kIntLike;
70 
71  std::string t = c.Type();
72  if (t == "timestamp") fType = kTimeStamp;
73  else if (t == "date") fType = kDateStamp;
74  else if (t == "bool") fType = kBool;
75  else if (t == "float" || t == "double") fType = kFloatLike;
76  else if (t == "string" || t == "text") fType = kString;
77  else if (t == "autoincr") fType = kAutoIncr;
78 
79  }
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
nova::dbi::Column::Column ( const Column c)

Definition at line 83 of file Column.cpp.

References fModified, fType, and fValue.

84  {
85  if (!c.fValue)
86  fValue=0;
87  else {
88  fValue = new char[strlen(c.fValue)+1];
89  strcpy(fValue,c.fValue);
90  }
91  fType = c.fType;
92  fModified = c.fModified;
93 
94  }
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
nova::dbi::Column::~Column ( )

Definition at line 98 of file Column.cpp.

References fValue.

Referenced by Column().

99  {
100  if (fValue) delete[] fValue;
101  }
char * fValue
Definition: Column.h:171

Member Function Documentation

void nova::dbi::Column::Clear ( )

Definition at line 104 of file Column.cpp.

References fModified, and fValue.

Referenced by Modified().

105  {
106  if (fValue) {
107  delete fValue;
108  fValue = 0;
109  }
110  // fIsNull = true;
111  fModified = false;
112  }
char * fValue
Definition: Column.h:171
void nova::dbi::Column::FastSet ( std::string  v)
inline

Definition at line 62 of file Column.h.

References fValue.

62  {
63  //fIsNull = false;
64  if (fValue) {
65  delete fValue;
66  fValue=0;
67  }
68  fValue = new char[v.length()+1];//16];
69  strcpy(fValue,v.c_str());//,v.length());//16);
70  // fValue[15]='\0';
71  }
char * fValue
Definition: Column.h:171
void nova::dbi::Column::FastSet ( const char *  v)
inline

Definition at line 73 of file Column.h.

References fValue.

73  {
74  //fIsNull = false;
75  if (fValue) {
76  delete fValue;
77  fValue=0;
78  }
79  fValue = new char[strlen(v)+1];//16];
80  strcpy(fValue,v);//,v.length());//16);
81  // fValue[15]='\0';
82  }
char * fValue
Definition: Column.h:171
template<class T >
bool nova::dbi::Column::Get ( T val) const
inline

Definition at line 85 of file Column.h.

References om::cerr, allTimeWatchdog::endl, fValue, string, and T.

Referenced by calib::TimingCache::GetEpochFromDB(), calib::DriftCache::GetEpochFromDB(), calib::AttenCache::GetEpochFromDB(), calib::AbsCache::GetEpochFromDB(), calib::DriftCache::GetFactor(), dbutils::RunHistory::Load(), runh::BadDataFilter::LoadBadSubruns(), runh::BadDataFilter::LoadBadTimeRanges(), chaninfo::BadChanList::LoadCosmicEff(), nova::dbi::RunHistory::LoadDAQRunHistory(), cmap::CMap::LoadExceptions(), nova::dbi::RunHistory::LoadFEBMasks(), calib::TimingCache::LoadFromDatabase(), calib::AttenCache::LoadFromDatabaseUncalibratedMask(), calib::AbsCache::LoadFromVldDatabase(), nova::dbi::RunHistory::LoadGoodDiBlockMask(), chaninfo::BadChanList::LoadNewData(), nova::dbi::RunHistory::LoadPedestals(), nova::dbi::RunHistory::LoadPixelMasks(), operator<(), operator<=(), operator>(), and operator>=().

85  {
86  if (fValue) {
87  try {
88  val = boost::lexical_cast<T>(std::string(fValue));
89  }
90  catch (boost::bad_lexical_cast &) {
91  std::cerr << "Column::Get(): Bad_lexical_cast! Value = "
92  << fValue << std::endl;
93  return false;
94  }
95  return true;
96  }
97 
98  return false;
99  }
OStream cerr
Definition: OStream.cxx:7
char * fValue
Definition: Column.h:171
double T
Definition: Xdiff_gwt.C:5
enum BeamMode string
bool nova::dbi::Column::IsNull ( ) const
inline

Definition at line 48 of file Column.h.

References fValue.

Referenced by nova::dbi::Table::AddRow().

48 { return (!fValue); }
char * fValue
Definition: Column.h:171
bool nova::dbi::Column::Modified ( ) const
inline

Definition at line 49 of file Column.h.

References Clear(), and fModified.

Referenced by nova::dbi::Table::WriteToDB().

49 { return fModified; }
bool nova::dbi::Column::operator< ( const Column c) const

Definition at line 284 of file Column.cpp.

References a, b, nova::dbi::Util::DateAsStringToTime_t(), fType, fValue, Get(), nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, and nova::dbi::Util::TimeAsStringToTime_t().

Referenced by Update().

285  {
286  if (c.fType != fType) return false;
287 
288  std::string val1 = fValue;
289  std::string val2 = c.fValue;
290 
291  if (fType == kBool) {
292  bool a = (val1 == "1");
293  bool b = (val2 == "1");
294  return a < b;
295  }
296 
297  if (fType == kIntLike) {
298  long a = boost::lexical_cast<long>(val1);
299  long b = boost::lexical_cast<long>(val2);
300  return (a < b);
301  }
302 
303  if (fType == kFloatLike) {
304  double a = boost::lexical_cast<double>(val1);
305  double b = boost::lexical_cast<double>(val2);
306  return (a < b);
307  }
308 
309  if (fType == kString)
310  return (val1 < val2);
311 
312  if (fType == kTimeStamp) {
313  string a, b;
314  if (this->Get(a) && c.Get(b)) {
315  time_t tta, ttb;
316  if (Util::TimeAsStringToTime_t(a,tta) &&
318  return (tta < ttb);
319  }
320  else
321  return false;
322  }
323 
324  if (fType == kDateStamp) {
325  string a, b;
326  if (this->Get(a) && c.Get(b)) {
327  time_t tta, ttb;
328  if (Util::DateAsStringToTime_t(a,tta) &&
330  return (tta < ttb);
331  }
332  else
333  return false;
334  }
335 
336  return false;
337 
338  }
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
Definition: Util.cpp:86
static bool DateAsStringToTime_t(std::string date, time_t &t)
Definition: Util.cpp:111
bool Get(T &val) const
Definition: Column.h:85
const double a
const hit & b
Definition: hits.cxx:21
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
bool nova::dbi::Column::operator<= ( const Column c) const

Definition at line 227 of file Column.cpp.

References a, b, nova::dbi::Util::DateAsStringToTime_t(), fType, fValue, Get(), nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, and nova::dbi::Util::TimeAsStringToTime_t().

Referenced by Update().

228  {
229  if (c.fType != fType) return false;
230 
231  std::string val1 = fValue;
232  std::string val2 = c.fValue;
233 
234  if (fType == kBool) {
235  bool a = (val1 == "1");
236  bool b = (val2 == "1");
237  return a <= b;
238  }
239 
240  if (fType == kIntLike) {
241  long a = boost::lexical_cast<long>(val1);
242  long b = boost::lexical_cast<long>(val2);
243  return (a <= b);
244  }
245 
246  if (fType == kFloatLike) {
247  double a = boost::lexical_cast<double>(val1);
248  double b = boost::lexical_cast<double>(val2);
249  return (a <= b);
250  }
251 
252  if (fType == kString)
253  return (val1 <= val2);
254 
255  if (fType == kTimeStamp) {
256  string a, b;
257  if (this->Get(a) && c.Get(b)) {
258  time_t tta, ttb;
259  if (Util::TimeAsStringToTime_t(a,tta) &&
261  return (tta <= ttb);
262  }
263  else
264  return false;
265  }
266 
267  if (fType == kDateStamp) {
268  string a, b;
269  if (this->Get(a) && c.Get(b)) {
270  time_t tta, ttb;
271  if (Util::DateAsStringToTime_t(a,tta) &&
273  return (tta <= ttb);
274  }
275  else
276  return false;
277  }
278 
279  return false;
280 
281  }
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
Definition: Util.cpp:86
static bool DateAsStringToTime_t(std::string date, time_t &t)
Definition: Util.cpp:111
bool Get(T &val) const
Definition: Column.h:85
const double a
const hit & b
Definition: hits.cxx:21
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
bool nova::dbi::Column::operator== ( const Column c) const

Definition at line 340 of file Column.cpp.

References fType, and fValue.

Referenced by Update().

341  {
342  if (c.fType != fType) return false;
343 
344  if (fValue == 0 && (fValue==c.fValue)) return true;
345 
346  return (strcmp(fValue,c.fValue)==0);
347 
348  }
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
bool nova::dbi::Column::operator> ( const Column c) const

Definition at line 171 of file Column.cpp.

References a, b, nova::dbi::Util::DateAsStringToTime_t(), fType, fValue, Get(), nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, nova::dbi::Util::TimeAsStringToTime_t(), and Type().

Referenced by Update().

172  {
173  if (c.Type() != fType) return false;
174 
175  std::string val1 = fValue;
176  std::string val2 = c.fValue;
177 
178  if (fType == kBool) {
179  bool a = (val1 == "1");
180  bool b = (val2 == "1");
181  return (a&!b);
182  }
183 
184  if (fType == kIntLike) {
185  long a = boost::lexical_cast<long>(val1);
186  long b = boost::lexical_cast<long>(val2);
187  return (a > b);
188  }
189 
190  if (fType == kFloatLike) {
191  double a = boost::lexical_cast<double>(val1);
192  double b = boost::lexical_cast<double>(val2);
193  return (a > b);
194  }
195 
196  if (fType == kString)
197  return (val1 > val2);
198 
199  if (fType == kTimeStamp) {
200  string a, b;
201  if (this->Get(a) && c.Get(b)) {
202  time_t tta, ttb;
203  if (Util::TimeAsStringToTime_t(a,tta) &&
205  return (tta > ttb);
206  }
207  else
208  return false;
209  }
210 
211  if (fType == kDateStamp) {
212  string a, b;
213  if (this->Get(a) && c.Get(b)) {
214  time_t tta, ttb;
215  if (Util::DateAsStringToTime_t(a,tta) &&
217  return (tta > ttb);
218  }
219  else
220  return false;
221  }
222  return false;
223 
224  }
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
Definition: Util.cpp:86
static bool DateAsStringToTime_t(std::string date, time_t &t)
Definition: Util.cpp:111
bool Get(T &val) const
Definition: Column.h:85
const double a
const hit & b
Definition: hits.cxx:21
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
bool nova::dbi::Column::operator>= ( const Column c) const

Definition at line 115 of file Column.cpp.

References a, b, nova::dbi::Util::DateAsStringToTime_t(), fType, fValue, Get(), nova::dbi::kBool, nova::dbi::kDateStamp, nova::dbi::kFloatLike, nova::dbi::kIntLike, nova::dbi::kString, nova::dbi::kTimeStamp, string, nova::dbi::Util::TimeAsStringToTime_t(), and Type().

Referenced by Update().

116  {
117  if (c.Type() != fType) return false;
118 
119  std::string val1 = fValue;
120  std::string val2 = c.fValue;
121 
122  if (fType == kBool) {
123  bool a = (val1 == "1");
124  bool b = (val2 == "1");
125  return ((a == b) || (a&!b));
126  }
127 
128  if (fType == kIntLike) {
129  long a = boost::lexical_cast<long>(val1);
130  long b = boost::lexical_cast<long>(val2);
131  return (a >= b);
132  }
133 
134  if (fType == kFloatLike) {
135  double a = boost::lexical_cast<double>(val1);
136  double b = boost::lexical_cast<double>(val2);
137  return (a >= b);
138  }
139 
140  if (fType == kString)
141  return (val1 >= val2);
142 
143  if (fType == kTimeStamp) {
144  string a, b;
145  if (this->Get(a) && c.Get(b)) {
146  time_t tta, ttb;
147  if (Util::TimeAsStringToTime_t(a,tta) &&
149  return (tta >= ttb);
150  }
151  else
152  return false;
153  }
154 
155  if (fType == kDateStamp) {
156  string a, b;
157  if (this->Get(a) && c.Get(b)) {
158  time_t tta, ttb;
159  if (Util::DateAsStringToTime_t(a,tta) &&
161  return (tta >= ttb);
162  }
163  else
164  return false;
165  }
166  return false;
167 
168  }
static bool TimeAsStringToTime_t(std::string ts, time_t &t)
Definition: Util.cpp:86
static bool DateAsStringToTime_t(std::string date, time_t &t)
Definition: Util.cpp:111
bool Get(T &val) const
Definition: Column.h:85
const double a
const hit & b
Definition: hits.cxx:21
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
template<class T >
bool nova::dbi::Column::Set ( const T val,
bool  ignoreAutoIncr = false 
)
inline

Definition at line 102 of file Column.h.

References om::cerr, allTimeWatchdog::endl, fType, fValue, nova::dbi::kAutoIncr, nova::dbi::kBool, string, and febshutoff_auto::val.

Referenced by Update().

102  {
103  if (!ignoreAutoIncr && fType==kAutoIncr) {
104  std::cerr << "Cannot set a column of type \"autoincr\"!"
105  << std::endl;
106  return false;
107  }
108  try {
109  if (fValue) {
110  delete fValue;
111  fValue=0;
112  }
113  std::string tstr = boost::lexical_cast<std::string>(val);
114  if (tstr == "" || tstr=="NULL") {
115  return true;
116  }
117  if (fType == kBool) {
118  fValue = new char[1];
119  // fIsNull = false;
120  if (tstr == "TRUE" || tstr == "t" || tstr == "true" ||
121  tstr == "y" || tstr == "yes" || tstr == "1" || tstr == "on")
122  fValue[0] = '1';
123  else
124  fValue[1] = '0';
125  return true;
126  }
127  else {
128  fValue = new char[tstr.length()];
129  strcpy(fValue,tstr.c_str());
130  return true;
131  }
132  }
133  catch (boost::bad_lexical_cast &) {
134  std::cerr << "Column::Set(): Bad lexical cast! Value = "
135  << val << std::endl;
136  return false;
137  }
138  return false;
139  }
OStream cerr
Definition: OStream.cxx:7
uint16_t fType
Definition: Column.h:161
char * fValue
Definition: Column.h:171
enum BeamMode string
void nova::dbi::Column::SetType ( uint8_t  t)
inline

Definition at line 55 of file Column.h.

References fType, and confusionMatrixTree::t.

uint8_t nova::dbi::Column::Type ( ) const
inline

Definition at line 43 of file Column.h.

References fType.

Referenced by operator>(), and operator>=().

43 { return fType;}
uint16_t fType
Definition: Column.h:161
template<class T >
bool nova::dbi::Column::Update ( const T val)
inline

Definition at line 142 of file Column.h.

References col, fModified, operator<(), operator<<, operator<=(), operator==(), operator>(), operator>=(), Set(), and runNovaSAM::stream.

Referenced by progbar.ProgressBar::Finish(), and progbar.ProgressBar::Start().

142  {
143  if (Set(val)) {
144  fModified = true; return true; }
145  else
146  return false;
147  }
bool Set(const T &val, bool ignoreAutoIncr=false)
Definition: Column.h:102
std::string nova::dbi::Column::Value ( ) const
inline

Definition at line 44 of file Column.h.

References fValue, and string.

44  {
45  if (!fValue) return std::string("");
46  else return std::string(fValue); }
char * fValue
Definition: Column.h:171
enum BeamMode string

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Column col 
)
friend

Definition at line 177 of file Column.h.

Referenced by Update().

177  {
178  if (!col.fValue) {
179  stream << "NULL";
180  }
181  else {
182  if (col.fType == kBool) {
183  if (col.fValue[0] == '1')
184  stream << "true";
185  else
186  stream << "false";
187  }
188  else {
189  bool needsQuotes = (col.fType == kString ||
190  col.fType == kTimeStamp ||
191  col.fType == kDateStamp );
192  if (needsQuotes) stream << "\'";
193  stream << col.fValue;
194  if (needsQuotes) stream << "\'";
195  }
196  }
197  return stream;
198  }
Int_t col[ntarg]
Definition: Style.C:29

Member Data Documentation

bool nova::dbi::Column::fModified
private

Definition at line 160 of file Column.h.

Referenced by Clear(), Column(), Modified(), and Update().

uint16_t nova::dbi::Column::fType
private
char* nova::dbi::Column::fValue
private

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