00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include "UgliGeometry/UgliDbiGeometry.h"
00017 #include "MessageService/MsgService.h"
00018 #include "DatabaseInterface/DbiOutRowStream.h"
00019 #include "DatabaseInterface/DbiResultSet.h"
00020 #include "DatabaseInterface/DbiValidityRec.h"
00021
00022 #include "UgliGeometry/UgliDbiTableDescr.h"
00023
00024 #include <cassert>
00025 #include <string.h>
00026
00027 ClassImp(UgliDbiGeometry)
00028
00029
00030
00031
00032 CVSID("$Id: UgliDbiGeometry.cxx,v 1.15 2007/03/09 05:59:47 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00033 Bool_t UgliDbiGeometry::fgDefensiveUnpkg = kFALSE;
00034
00035
00036
00037
00038 #include "DatabaseInterface/DbiResultPtr.tpl"
00039 template class DbiResultPtr<UgliDbiGeometry>;
00040
00041 #include "DatabaseInterface/DbiWriter.tpl"
00042 template class DbiWriter<UgliDbiGeometry>;
00043
00044
00045
00046
00047
00048
00049 std::ostream& operator<<(std::ostream& os, const UgliDbiGeometry& udg)
00050 { return udg.FormatToOStream(os); }
00051
00052
00053
00054 void UgliDbiGeometry::Fill(DbiResultSet& rs,
00055 const DbiValidityRec* ) {
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 if (fgDefensiveUnpkg) {
00080
00081
00082
00083 Int_t numCol = rs.NumCols();
00084
00085 for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00086 string colName = rs.CurColName();
00087 if ( colName == "XYISUV" ) {
00088 Short_t tmp; rs >> tmp; fXYisUV = Bool_t(tmp);
00089 }
00090 else if ( colName == "HALLXMIN") rs >> fHallXYZMin[0];
00091 else if ( colName == "HALLXMAX") rs >> fHallXYZMax[0];
00092 else if ( colName == "HALLYMIN") rs >> fHallXYZMin[1];
00093 else if ( colName == "HALLYMAX") rs >> fHallXYZMax[1];
00094 else if ( colName == "HALLZMIN") rs >> fHallXYZMin[2];
00095 else if ( colName == "HALLZMAX") rs >> fHallXYZMax[2];
00096 else {
00097 static int nmsg = 25;
00098 if (nmsg-- > 0) MSG("Ugli",Msg::kWarning)
00099 << "Ignoring column " << rs.CurColNum()
00100 << " (of " << rs.NumCols() << ")"
00101 << " \""<< colName << "\"; not part of "
00102 << ClassName() << endl;
00103 rs.IncrementCurCol();
00104 }
00105 }
00106 }
00107 else {
00108 Short_t tmpxyisuv;
00109 rs >> tmpxyisuv
00110 >> fHallXYZMin[0]
00111 >> fHallXYZMax[0]
00112 >> fHallXYZMin[1]
00113 >> fHallXYZMax[1]
00114 >> fHallXYZMin[2]
00115 >> fHallXYZMax[2];
00116
00117 fXYisUV = Bool_t(tmpxyisuv);
00118
00119 }
00120
00121 }
00122
00123
00124
00125 void UgliDbiGeometry::Store(DbiOutRowStream& ors,
00126 const DbiValidityRec* ) const {
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 const char* tabledescr = GetTableDescr();
00151 vector< pair<string,string> > components =
00152 UgliDbiTableDescr::ParseTableDescr(tabledescr);
00153 int n = components.size();
00154
00155 for (int i=0; i<n; i++) {
00156 pair<string,string> colPair = components[i];
00157 string colName = colPair.first;
00158 if ( colName == "XYISUV" ) ors << (short)fXYisUV;
00159 else if ( colName == "HALLXMIN") ors << fHallXYZMin[0];
00160 else if ( colName == "HALLXMAX") ors << fHallXYZMax[0];
00161 else if ( colName == "HALLYMIN") ors << fHallXYZMin[1];
00162 else if ( colName == "HALLYMAX") ors << fHallXYZMax[1];
00163 else if ( colName == "HALLZMIN") ors << fHallXYZMin[2];
00164 else if ( colName == "HALLZMAX") ors << fHallXYZMax[2];
00165
00166 else if ( colName == "ROW_COUNTER" ) {;}
00167 else if ( colName == "SEQNO" ) {;}
00168 else {
00169 MSG("Ugli",Msg::kFatal)
00170 << "Column name '" << colName << "' not correctly handled" << endl;
00171 assert(0);
00172 }
00173 }
00174 }
00175
00176
00177
00178 void UgliDbiGeometry::Print(Option_t* option) const
00179 {
00180 FormatToOStream(cout,option);
00181 }
00182
00183
00184
00185 std::ostream& UgliDbiGeometry::FormatToOStream(std::ostream& os,
00186 Option_t* option,
00187 const DbiValidityRec* dvr) const
00188 {
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 string opt = option;
00207
00208 if ( opt.find("H") != string::npos ) {
00209 string tabledescr = GetTableDescr();
00210 tabledescr = UgliDbiTableDescr::TextTableDescrLine(tabledescr);
00211 os << tabledescr << endl;
00212 }
00213 else if ( opt.find("h") != string::npos ) {
00214 string tabledescr = GetTableDescr();
00215 vector< pair<string,string> > components =
00216 UgliDbiTableDescr::ParseTableDescr(tabledescr);
00217 for (unsigned int ic = 0; ic < components.size(); ++ic)
00218 os << components[ic].first << '\t';
00219 os << endl;
00220 }
00221
00222 char sep = '\t';
00223 if ( opt.find(",") != string::npos ) sep = ',';
00224
00225 if ( ! dvr ) {
00226 os << "SeqNo" << sep;
00227 }
00228 else {
00229 os << dvr->GetSeqNo() << sep;
00230 }
00231
00232 os << 0 << sep
00233 << (int)fXYisUV << sep
00234 << fHallXYZMin[0] << sep
00235 << fHallXYZMax[0] << sep
00236 << fHallXYZMin[1] << sep
00237 << fHallXYZMax[1] << sep
00238 << fHallXYZMin[2] << sep
00239 << fHallXYZMax[2] << endl;
00240
00241 return os;
00242 }
00243
00244
00245
00246 const char* UgliDbiGeometry::GetTableDescr()
00247 {
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 const char* const_tabledescr = "(\
00268 SEQNO int, \
00269 ROW_COUNTER int, \
00270 XYISUV tinyint, \
00271 HALLXMIN float, \
00272 HALLXMAX float, \
00273 HALLYMIN float, \
00274 HALLYMAX float, \
00275 HALLZMIN float, \
00276 HALLZMAX float, \
00277 primary key (SEQNO,ROW_COUNTER) \
00278 )";
00279
00280 return const_tabledescr;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313