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