00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include "UgliGeometry/UgliDbiScintMdl.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(UgliDbiScintMdl)
00027
00028
00029
00030
00031 CVSID("$Id: UgliDbiScintMdl.cxx,v 1.24 2007/03/09 05:59:47 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00032 Bool_t UgliDbiScintMdl::fgDefensiveUnpkg = kFALSE;
00033
00034
00035
00036
00037 #include "DatabaseInterface/DbiResultPtr.tpl"
00038 template class DbiResultPtr<UgliDbiScintMdl>;
00039
00040 #include "DatabaseInterface/DbiWriter.tpl"
00041 template class DbiWriter<UgliDbiScintMdl>;
00042
00043
00044
00045
00046
00047
00048
00049 std::ostream& operator<<(std::ostream& os, const UgliDbiScintMdl& udsm)
00050 { return udsm.FormatToOStream(os); }
00051
00052
00053
00054 UInt_t UgliDbiScintMdl::HashToIndex(const PlexScintMdlId scintmdlid)
00055 {
00056
00057
00058 UInt_t hvalue;
00059 int ierr = 0;
00060
00061
00062
00063
00064 int module = scintmdlid.GetModule();
00065 int plane = scintmdlid.GetPlane();
00066
00067 hvalue = (plane << 3) + module;
00068 if ( module > 7 ) ierr += BIT(0);
00069
00070
00071 const int mxplns = 768;
00072 if ( hvalue > (mxplns<<3)-1 ) ierr += BIT(1);
00073
00074 if (ierr) {
00075 MSG("Ugli",Msg::kWarning)
00076 << " module " << scintmdlid.AsString()
00077 << " breaks hashing assumptions "
00078 << " err 0x" << hex << ierr << dec
00079 << " : scintmdlid " << scintmdlid
00080 << " = hash " << hvalue
00081 << endl;
00082 }
00083
00084 return hvalue;
00085
00086 }
00087
00088
00089
00090 void UgliDbiScintMdl::Fill(DbiResultSet& rs,
00091 const DbiValidityRec* vrec) {
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 Detector::Detector_t det =
00116 (Detector::Detector_t)
00117 ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00118
00119 Int_t plane = -1;
00120 Int_t module = -1;
00121 PlaneView::PlaneView_t view = PlaneView::kUnknown;
00122 PlaneCoverage::PlaneCoverage_t coverage = PlaneCoverage::kUnknown;
00123 Int_t tmp;
00124
00125 if (fgDefensiveUnpkg) {
00126
00127
00128
00129 Int_t numCol = rs.NumCols();
00130
00131 for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00132 string colName = rs.CurColName();
00133 if ( colName == "HASHVAL" ) rs.IncrementCurCol();
00134
00135 else if ( colName == "HASH" ) rs.IncrementCurCol();
00136 else if ( colName == "DETECTOR" ) {
00137 rs >> tmp; det = (Detector::Detector_t)tmp;
00138 }
00139 else if ( colName == "PLANE" ) rs >> plane;
00140 else if ( colName == "PLNVIEW" ) {
00141 rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00142 }
00143
00144 else if ( colName == "VIEW" ) {
00145 rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00146 }
00147 else if ( colName == "COVERAGE" ) {
00148 rs >> tmp; coverage = (PlaneCoverage::PlaneCoverage_t)tmp;
00149 }
00150 else if ( colName == "MDLINPLANE" ) rs >> module;
00151
00152 else if ( colName == "MODULE" ) rs >> module;
00153 else if ( colName == "WIDTH" ) rs >> fWidth;
00154 else if ( colName == "TPOSRELPLN" ) rs >> fTPosRelPln;
00155 else if ( colName == "LPOSRELPLN" ) rs >> fLPosRelPln;
00156 else if ( colName == "ZROTRELPLNRAD" ) rs >> fZRotRelPlnRad;
00157 else if ( colName == "CLEARLENEAST" ) rs >> fClearLenEast;
00158 else if ( colName == "CLEARLENWEST" ) rs >> fClearLenWest;
00159 else if ( colName == "WLSLENEAST" ) rs >> fWlsLenEast;
00160 else if ( colName == "WLSLENWEST" ) rs >> fWlsLenWest;
00161 else {
00162 static int nmsg = 25;
00163 if (nmsg-- > 0) MSG("Ugli",Msg::kWarning)
00164 << "Ignoring column " << rs.CurColNum()
00165 << " (of " << rs.NumCols() << ")"
00166 << " \""<< colName << "\"; not part of "
00167 << ClassName() << endl;
00168 rs.IncrementCurCol();
00169 }
00170 }
00171 }
00172 else {
00173 Int_t hashv;
00174 rs >> hashv
00175 >> plane
00176 >> module
00177 >> fWidth
00178 >> fTPosRelPln
00179 >> fLPosRelPln
00180 >> fZRotRelPlnRad
00181 >> fClearLenEast
00182 >> fClearLenWest
00183 >> fWlsLenEast
00184 >> fWlsLenWest;
00185
00186 }
00187
00188 fModuleId = PlexScintMdlId(det,plane,module,view,coverage);
00189
00190 }
00191
00192
00193
00194 void UgliDbiScintMdl::Store(DbiOutRowStream& ors,
00195 const DbiValidityRec* ) const {
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 const char* tabledescr = GetTableDescr();
00220 vector< pair<string,string> > components =
00221 UgliDbiTableDescr::ParseTableDescr(tabledescr);
00222 int n = components.size();
00223
00224 for (int i=0; i<n; i++) {
00225 pair<string,string> colPair = components[i];
00226 string colName = colPair.first;
00227 if ( colName == "HASHVAL" ) ors << (int)GetIndex(0);
00228
00229 else if ( colName == "HASH" ) ors << (int)GetIndex(0);
00230 else if ( colName == "DETECTOR" )
00231 ors << (int)fModuleId.GetDetector();
00232 else if ( colName == "PLANE" ) ors << fModuleId.GetPlane();
00233 else if ( colName == "PLNVIEW" )
00234 ors << (int)fModuleId.GetPlaneView();
00235
00236 else if ( colName == "VIEW" )
00237 ors << (int)fModuleId.GetPlaneView();
00238 else if ( colName == "COVERAGE" )
00239 ors << (int)fModuleId.GetPlaneCoverage();
00240 else if ( colName == "MDLINPLANE" ) ors << fModuleId.GetModule();
00241
00242 else if ( colName == "MODULE" ) ors << fModuleId.GetModule();
00243 else if ( colName == "WIDTH" ) ors << fWidth;
00244 else if ( colName == "TPOSRELPLN" ) ors << fTPosRelPln;
00245 else if ( colName == "LPOSRELPLN" ) ors << fLPosRelPln;
00246 else if ( colName == "ZROTRELPLNRAD" ) ors << fZRotRelPlnRad;
00247 else if ( colName == "CLEARLENEAST" ) ors << fClearLenEast;
00248 else if ( colName == "CLEARLENWEST" ) ors << fClearLenWest;
00249 else if ( colName == "WLSLENEAST" ) ors << fWlsLenEast;
00250 else if ( colName == "WLSLENWEST" ) ors << fWlsLenWest;
00251
00252 else if ( colName == "ROW_COUNTER" ) {;}
00253 else if ( colName == "SEQNO" ) {;}
00254 else {
00255 MSG("Ugli",Msg::kFatal)
00256 << "Column name '" << colName << "' not correctly handled" << endl;
00257 assert(0);
00258 }
00259 }
00260 }
00261
00262
00263
00264 void UgliDbiScintMdl::Print(Option_t* option) const
00265 {
00266 FormatToOStream(cout,option);
00267 }
00268
00269
00270
00271 std::ostream& UgliDbiScintMdl::FormatToOStream(std::ostream& os,
00272 Option_t* option,
00273 const DbiValidityRec* dvr) const
00274 {
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 string opt = option;
00293
00294 if ( opt.find("H") != string::npos ) {
00295 string tabledescr = GetTableDescr();
00296 tabledescr = UgliDbiTableDescr::TextTableDescrLine(tabledescr);
00297 os << tabledescr << endl;
00298 }
00299 else if ( opt.find("h") != string::npos ) {
00300 string tabledescr = GetTableDescr();
00301 vector< pair<string,string> > components =
00302 UgliDbiTableDescr::ParseTableDescr(tabledescr);
00303 for (unsigned int ic = 0; ic < components.size(); ++ic)
00304 os << components[ic].first << '\t';
00305 os << endl;
00306 }
00307
00308 char sep = '\t';
00309 if ( opt.find(",") != string::npos ) sep = ',';
00310
00311 if ( ! dvr ) {
00312 os << "SeqNo" << sep;
00313 }
00314 else {
00315 os << dvr->GetSeqNo() << sep;
00316 }
00317
00318 os << GetModule() << sep
00319 << -1 << sep
00320 << GetPlane() << sep
00321 << GetModule() << sep
00322 << fWidth << sep
00323 << fTPosRelPln << sep
00324 << fLPosRelPln << sep
00325 << fZRotRelPlnRad << sep
00326 << fClearLenEast << sep
00327 << fClearLenWest << sep
00328 << fWlsLenEast << sep
00329 << fWlsLenWest << endl;
00330
00331 return os;
00332 }
00333
00334
00335
00336 const char* UgliDbiScintMdl::GetTableDescr()
00337 {
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 const char* const_tabledescr = "(\
00358 SEQNO int, \
00359 ROW_COUNTER int, \
00360 HASHVAL int, \
00361 PLANE smallint, \
00362 MDLINPLANE smallint, \
00363 WIDTH float, \
00364 TPOSRELPLN float, \
00365 LPOSRELPLN float, \
00366 ZROTRELPLNRAD float, \
00367 CLEARLENEAST float, \
00368 CLEARLENWEST float, \
00369 WLSLENEAST float, \
00370 WLSLENWEST float, \
00371 primary key (SEQNO,ROW_COUNTER) \
00372 )";
00373
00374 return const_tabledescr;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408