EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbOutRowStream.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbOutRowStream.cxx
1 
2 #include <sstream>
3 
4 #include "FairDbFieldType.h"
5 #include "FairDbOutRowStream.h"
6 #include "FairDbTableMetaData.h"
7 #include "FairDbString.h"
8 #include "ValTimeStamp.h"
9 
11 
12 #define OUT(t,v) \
13  if ( ! StoreDefaultIfInvalid(t) ) { \
14  ostringstream out; \
15  out << v; \
16  Store(out.str()); \
17  } \
18 
19 // If writing unsigned dat as signed, convert bit pattern to signed,
20 // extending sign bit if necessary.
21 // For BIGINT (size 8) make an exception. It's used only as
22 // an alternative to unsigned int so can written without conversion.
23 #define OUT2(t,v) \
24  const FairDbFieldType& fType = this->ColFieldType(this->CurColNum()); \
25  if ( fType.IsSigned() && fType.GetSize() != 8 ) { \
26  Int_t v_signed = (Int_t) v; \
27  if ( fType.GetType() == FairDb::kTiny && v & 0x80 ) v_signed |= 0xffffff00; \
28  if ( fType.GetType() == FairDb::kShort && v & 0x8000 ) v_signed |= 0xffff0000; \
29  OUT(FairDb::kInt,v_signed); } \
30  else { \
31  OUT(t,v); \
32  } \
33 
34 
36  FairDbRowStream(metaData),
37  fBadData(kFALSE),
38  fCSV()
39 {
40 
41 
42 }
43 
44 
45 //.....................................................................
46 
48 {
49 
50 }
51 
52 //.....................................................................
53 
55 {
56  OUT(FairDb::kBool,src);
57  return *this;
58 }
59 
61 {
62  OUT(FairDb::kChar,src);
63  return *this;
64 }
65 
67 {
68  OUT(FairDb::kString,src);
69  return *this;
70 }
71 
73 {
74  OUT(FairDb::kShort,src);
75  return *this;
76 }
77 
79 {
80  OUT2(FairDb::kUShort,src);
81  return *this;
82 }
83 
85 {
86  OUT(FairDb::kInt,src);
87  return *this;
88 }
89 
91 {
92  OUT2(FairDb::kUInt,src);
93  return *this;
94 }
95 
97 {
98  OUT(FairDb::kFloat,src);
99  return *this;
100 }
101 
103 {
104  OUT(FairDb::kDouble,src);
105  return *this;
106 }
107 
109 {
110  OUT(FairDb::kString,src);
111  return *this;
112 }
113 
115 {
117  Store(FairDb::MakeDateTimeString(src).Data());
118  }
119  return *this;
120 }
121 
122 
124 {
125 
126  FairDbFieldType typeSupplied(type);
127  FairDbFieldType typeRequired(CurColFieldType());
128  if ( typeSupplied.IsCompatible(typeRequired) ) { return kFALSE; }
129 
130  string udef = typeRequired.UndefinedValue();
131  cout
132  << "In table " << TableNameTc()
133  << " column "<< CurColNum()
134  << " (" << CurColName() << ")"
135  << " of type " << typeRequired.AsString()
136  << " is incompatible with user type " << typeSupplied.AsString()
137  << ", value \"" << udef
138  << "\" will be substituted." << endl;
139  Store(udef.c_str());
140  fBadData = kTRUE;
141  return kTRUE;
142 
143 }
144 void FairDbOutRowStream::Store(const string& str)
145 {
146 
147  UInt_t concept = CurColFieldType().GetConcept();
148  string delim = "";
149  if ( concept == FairDb::kString
150  || concept == FairDb::kDate
151  || concept == FairDb::kChar ) { delim = "\'"; }
152 
153  if ( CurColNum()> 1 ) { fCSV += ','; }
154  fCSV += delim;
155  if ( concept != FairDb::kString ) { fCSV += str; }
156 // When exporting strings, take care of special characters.
157  else {
158  FairUtilString::MakePrintable(str.c_str(),fCSV);
159  }
160  fCSV += delim;
161  IncrementCurCol();
162 }
163