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