00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include "BField/BfldDbiPlaneMap.h"
00017 #include "MessageService/MsgService.h"
00018 #include "DatabaseInterface/DbiOutRowStream.h"
00019 #include "DatabaseInterface/DbiResultSet.h"
00020 #include "DatabaseInterface/DbiValidityRec.h"
00021
00022 #include "TMath.h"
00023
00024 #include <cassert>
00025 #include <string.h>
00026
00027 using std::string;
00028 using std::vector;
00029
00030 ClassImp(BfldDbiPlaneMap)
00031
00032 CVSID("$Id: BfldDbiPlaneMap.cxx,v 1.17 2008/03/14 05:14:13 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00033
00034
00035
00036
00037 #include "DatabaseInterface/DbiResultPtr.tpl"
00038 template class DbiResultPtr<BfldDbiPlaneMap>;
00039
00040 #include "DatabaseInterface/DbiWriter.tpl"
00041 template class DbiWriter<BfldDbiPlaneMap>;
00042
00043
00044
00045
00046 Bool_t BfldDbiPlaneMap::fgDefensiveUnpkg = kTRUE;
00047
00048
00049
00050
00051
00052
00053
00054 BfldDbiPlaneMap::BfldDbiPlaneMap()
00055 : fPlaneId(),
00056 fDetailSize(0), fDetailShape(kCircle), fBHCurve(0),
00057 fBHFactor(0), fBHCutoff(0),
00058 fSlotFactor(0), fSlotCutoff(0), fBdotScale(1.0)
00059 {
00060 for ( int indx = 0; indx < kEndOfList; ++indx ) {
00061 fMapVariant[indx] = 0;
00062 fScale[indx] = 0.0;
00063 }
00064 LEA_CTOR;
00065 }
00066
00067
00068
00069 void BfldDbiPlaneMap::Fill(DbiResultSet& rs,
00070 const DbiValidityRec* vrec) {
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 UShort_t ipln = 1023;
00096
00097 if (fgDefensiveUnpkg) {
00098
00099
00100
00101 Int_t tmpshape = fDetailShape;
00102
00103 Int_t numCol = rs.NumCols();
00104
00105 for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00106 string colName = rs.CurColName();
00107
00108 if ( colName == "PLANENUM") rs >> ipln;
00109
00110
00111 else if ( colName == "MAPVAR") rs >> fMapVariant[0];
00112 else if ( colName == "SCALE") rs >> fScale[0];
00113 else if ( colName == "MAPVAR_2ND") rs >> fMapVariant[1];
00114 else if ( colName == "SCALE_2ND") rs >> fScale[1];
00115
00116
00117 else if ( colName == "MAPVAR1ON") rs >> fMapVariant[0];
00118 else if ( colName == "SCALE1ON") rs >> fScale[0];
00119 else if ( colName == "MAPVAR2ON") rs >> fMapVariant[1];
00120 else if ( colName == "SCALE2ON") rs >> fScale[1];
00121 else if ( colName == "MAPVAR1OFF") rs >> fMapVariant[2];
00122 else if ( colName == "SCALE1OFF") rs >> fScale[2];
00123 else if ( colName == "MAPVAR2OFF") rs >> fMapVariant[3];
00124 else if ( colName == "SCALE2OFF") rs >> fScale[3];
00125
00126 else if ( colName == "MAPON1") rs >> fMapVariant[0];
00127 else if ( colName == "SCALEON1") rs >> fScale[0];
00128 else if ( colName == "MAPON2") rs >> fMapVariant[1];
00129 else if ( colName == "SCALEON2") rs >> fScale[1];
00130 else if ( colName == "MAPOFF1") rs >> fMapVariant[2];
00131 else if ( colName == "SCALEOFF1") rs >> fScale[2];
00132 else if ( colName == "MAPOFF2") rs >> fMapVariant[3];
00133 else if ( colName == "SCALEOFF2") rs >> fScale[3];
00134
00135
00136 else if ( colName == "MAPDETAIL1") rs >> fMapVariant[4];
00137 else if ( colName == "SCALEDETAIL1") rs >> fScale[4];
00138 else if ( colName == "MAPDETAIL2") rs >> fMapVariant[5];
00139 else if ( colName == "SCALEDETAIL2") rs >> fScale[5];
00140 else if ( colName == "MAPPLNGAP1") rs >> fMapVariant[6];
00141 else if ( colName == "SCALEPLNGAP1") rs >> fScale[6];
00142 else if ( colName == "MAPPLNGAP2") rs >> fMapVariant[7];
00143 else if ( colName == "SCALEPLNGAP2") rs >> fScale[7];
00144
00145
00146 else if ( colName == "MAPDETAILGAP1") rs >> fMapVariant[6];
00147 else if ( colName == "SCALEDETAILGAP1") rs >> fScale[6];
00148 else if ( colName == "MAPDETAILGAP2") rs >> fMapVariant[7];
00149 else if ( colName == "SCALEDETAILGAP2") rs >> fScale[7];
00150
00151
00152 else if ( colName == "MAPFULLGAP1") rs >> fMapVariant[8];
00153 else if ( colName == "SCALEFULLGAP1") rs >> fScale[8];
00154 else if ( colName == "MAPFULLGAP2") rs >> fMapVariant[9];
00155 else if ( colName == "SCALEFULLGAP2") rs >> fScale[9];
00156
00157 else if ( colName == "DETAILSIZE") rs >> fDetailSize;
00158 else if ( colName == "DETAILSHAPE") rs >> tmpshape;
00159
00160 else if ( colName == "BDOTSCALE") rs >> fBdotScale;
00161
00162 else if ( colName == "BHCURVEINDEX") rs >> fBHCurve;
00163 else if ( colName == "BHFACTOR") rs >> fBHFactor;
00164 else if ( colName == "BHCUTOFF") rs >> fBHCutoff;
00165 else if ( colName == "SLOTFACTOR") rs >> fSlotFactor;
00166 else if ( colName == "SLOTCUTOFF") rs >> fSlotCutoff;
00167
00168 else {
00169 static int nmsg = 25;
00170 if (nmsg-- > 0) MSG("Bfld",Msg::kWarning)
00171 << "Ignoring column " << rs.CurColNum()
00172 << " (of " << rs.NumCols() << ")"
00173 << " \""<< colName << "\"; not part of "
00174 << ClassName() << endl;
00175 rs.IncrementCurCol();
00176 }
00177 }
00178 fDetailShape = (MapShape_t)tmpshape;
00179 }
00180 else {
00181 Int_t numCol = rs.NumCols() - (rs.HasRowCounter() ? 1 : 0);
00182 if ( 4 == numCol ) {
00183 rs >> ipln
00184 >> fMapVariant[0]
00185 >> fScale[0];
00186 }
00187 else if ( 6 == numCol ) {
00188 rs >> ipln
00189 >> fMapVariant[0]
00190 >> fScale[0]
00191 >> fMapVariant[1]
00192 >> fScale[1];
00193 }
00194 else if ( 7 == numCol ) {
00195 rs >> ipln
00196 >> fMapVariant[0]
00197 >> fScale[0]
00198 >> fMapVariant[1]
00199 >> fScale[1]
00200 >> fBHCurve;
00201 }
00202 else if ( 11 == numCol ) {
00203 rs >> ipln
00204 >> fMapVariant[0]
00205 >> fScale[0]
00206 >> fMapVariant[1]
00207 >> fScale[1]
00208 >> fBHCurve
00209 >> fBHFactor
00210 >> fBHCutoff
00211 >> fSlotFactor
00212 >> fSlotCutoff;
00213 }
00214 else if ( 15 == numCol ) {
00215 rs >> ipln
00216 >> fMapVariant[0]
00217 >> fScale[0]
00218 >> fMapVariant[1]
00219 >> fScale[1]
00220 >> fMapVariant[2]
00221 >> fScale[2]
00222 >> fMapVariant[3]
00223 >> fScale[3]
00224 >> fBHCurve
00225 >> fBHFactor
00226 >> fBHCutoff
00227 >> fSlotFactor
00228 >> fSlotCutoff;
00229 }
00230 else if ( 25 == numCol ) {
00231 int tmpshape;
00232 rs >> ipln
00233 >> fMapVariant[0]
00234 >> fScale[0]
00235 >> fMapVariant[1]
00236 >> fScale[1]
00237 >> fMapVariant[2]
00238 >> fScale[2]
00239 >> fMapVariant[3]
00240 >> fScale[3]
00241 >> fMapVariant[4]
00242 >> fScale[4]
00243 >> fMapVariant[5]
00244 >> fScale[5]
00245 >> fMapVariant[6]
00246 >> fScale[6]
00247 >> fMapVariant[7]
00248 >> fScale[7]
00249 >> fDetailSize
00250 >> tmpshape
00251 >> fBHCurve
00252 >> fBHFactor
00253 >> fBHCutoff
00254 >> fSlotFactor
00255 >> fSlotCutoff;
00256 fDetailShape = (MapShape_t)tmpshape;
00257 }
00258 else if ( 30 == numCol ) {
00259 int tmpshape;
00260 rs >> ipln
00261 >> fMapVariant[0]
00262 >> fScale[0]
00263 >> fMapVariant[1]
00264 >> fScale[1]
00265 >> fMapVariant[2]
00266 >> fScale[2]
00267 >> fMapVariant[3]
00268 >> fScale[3]
00269 >> fMapVariant[4]
00270 >> fScale[4]
00271 >> fMapVariant[5]
00272 >> fScale[5]
00273 >> fMapVariant[6]
00274 >> fScale[6]
00275 >> fMapVariant[7]
00276 >> fScale[7]
00277 >> fMapVariant[8]
00278 >> fScale[8]
00279 >> fMapVariant[9]
00280 >> fScale[9]
00281 >> fDetailSize
00282 >> tmpshape
00283 >> fBdotScale
00284 >> fBHCurve
00285 >> fBHFactor
00286 >> fBHCutoff
00287 >> fSlotFactor
00288 >> fSlotCutoff;
00289 fDetailShape = (MapShape_t)tmpshape;
00290 }
00291 else {
00292 static int nmsg = 25;
00293 if (nmsg-- > 0) MSG("Bfld",Msg::kWarning)
00294 << "Table has " << numCol << " columns, but in non-Defensive unpacking "
00295 << "we only know how to deal with 4, 6, 7, 11, 15, 25 or 30."
00296 << endl;
00297 }
00298 }
00299
00300 Detector::Detector_t det =
00301 (Detector::Detector_t)
00302 ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00303
00304 fPlaneId = PlexPlaneId(det,ipln,kTRUE);
00305
00306 #ifdef RWH_DEBUG
00307 if ( ipln == 0 )
00308 MSG("Bfld",Msg::kDebug)
00309 << " BfldDbiPlaneMap plane "
00310 << ipln << " vrec = " << *vrec
00311 << endl
00312 << *this
00313 << endl;
00314 #endif
00315
00316 }
00317
00318
00319
00320 void BfldDbiPlaneMap::Store(DbiOutRowStream& ors,
00321 const DbiValidityRec* ) const {
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 Int_t numCol = ors.NumCols() - (ors.HasRowCounter() ? 1 : 0);
00346 if ( 4 == numCol ) {
00347 ors << fPlaneId.GetPlane() << fMapVariant[0] << fScale[0];
00348 }
00349 else if ( 6 == numCol ) {
00350 ors << fPlaneId.GetPlane()
00351 << fMapVariant[0] << fScale [0]
00352 << fMapVariant[1] << fScale [1];
00353 }
00354 else if ( 8 == numCol ) {
00355 ors << fPlaneId.GetPlane()
00356 << fMapVariant[0] << fScale [0]
00357 << fMapVariant[1] << fScale [1]
00358 << fBHCurve;
00359 }
00360 else if ( 11 == numCol ) {
00361 ors << fPlaneId.GetPlane()
00362 << fMapVariant[0] << fScale [0]
00363 << fMapVariant[1] << fScale [1]
00364 << fBHCurve
00365 << fBHFactor << fBHCutoff
00366 << fSlotFactor << fSlotCutoff;
00367 }
00368 else if ( 15 == numCol ) {
00369 ors << fPlaneId.GetPlane()
00370 << fMapVariant[0] << fScale [0]
00371 << fMapVariant[1] << fScale [1]
00372 << fMapVariant[2] << fScale [2]
00373 << fMapVariant[3] << fScale [3]
00374 << fBHCurve
00375 << fBHFactor << fBHCutoff
00376 << fSlotFactor << fSlotCutoff;
00377 }
00378 else if ( 25 == numCol ) {
00379 ors << fPlaneId.GetPlane()
00380 << fMapVariant[0] << fScale[0]
00381 << fMapVariant[1] << fScale[1]
00382 << fMapVariant[2] << fScale[2]
00383 << fMapVariant[3] << fScale[3]
00384 << fMapVariant[4] << fScale[4]
00385 << fMapVariant[5] << fScale[5]
00386 << fMapVariant[6] << fScale[6]
00387 << fMapVariant[7] << fScale[7]
00388 << fDetailSize << (int)fDetailShape
00389 << fBHCurve
00390 << fBHFactor
00391 << fBHCutoff
00392 << fSlotFactor
00393 << fSlotCutoff;
00394 }
00395 else if ( 25 == numCol ) {
00396 ors << fPlaneId.GetPlane()
00397 << fMapVariant[0] << fScale[0]
00398 << fMapVariant[1] << fScale[1]
00399 << fMapVariant[2] << fScale[2]
00400 << fMapVariant[3] << fScale[3]
00401 << fMapVariant[4] << fScale[4]
00402 << fMapVariant[5] << fScale[5]
00403 << fMapVariant[6] << fScale[6]
00404 << fMapVariant[7] << fScale[7]
00405 << fMapVariant[8] << fScale[8]
00406 << fMapVariant[9] << fScale[9]
00407 << fDetailSize << (int)fDetailShape
00408 << fBdotScale
00409 << fBHCurve
00410 << fBHFactor
00411 << fBHCutoff
00412 << fSlotFactor
00413 << fSlotCutoff;
00414 }
00415 else {
00416 static int nmsg = 25;
00417 if (nmsg-- > 0) MSG("Bfld",Msg::kWarning)
00418 << "Table has " << numCol << " columns, but Store() "
00419 << "we only know how to deal with 4, 6, 7, 11, 15, 25 or 30."
00420 << endl;
00421 }
00422 }
00423
00424
00425 void BfldDbiPlaneMap::SetDetailShape(Int_t ishape)
00426 {
00427 fDetailShape = (MapShape_t)ishape;
00428 }
00429
00430
00431 Bool_t BfldDbiPlaneMap::IsInDetail(Double_t x, Double_t y) const
00432 {
00433 switch ( fDetailShape ) {
00434 case kCircle:
00435 {
00436 Double_t r2 = x*x + y*y;
00437 Double_t r2max = fDetailSize * fDetailSize;
00438 if ( r2 >= r2max ) return false;
00439 return true;
00440 break;
00441 }
00442 case kDiamond:
00443 {
00444
00445 static const Double_t r_sqrt2 = 1.0 / TMath::Sqrt(2.0);
00446 Double_t u = ( x + y ) * r_sqrt2;
00447 Double_t v = (-x + y ) * r_sqrt2;
00448 x = u; y = v;
00449 }
00450 case kSquare:
00451 {
00452 if ( x <= -fDetailSize || x >= fDetailSize ) return false;
00453 if ( y <= -fDetailSize || y >= fDetailSize ) return false;
00454 return true;
00455 break;
00456 }
00457 default:
00458 return false;
00459 break;
00460 }
00461 return false;
00462 }
00463
00464
00465 Int_t BfldDbiPlaneMap::GetAggregateNo() const
00466 {
00467 return (int)fPlaneId.GetDetector()*100000000 + fPlaneId.GetPlane();
00468 }
00469
00470
00471 UInt_t BfldDbiPlaneMap::GetIndex(UInt_t ) const
00472 {
00473 return fPlaneId.GetPlane();
00474 }
00475
00476
00477 std::ostream& operator<<(std::ostream& os, const BfldDbiPlaneMap& plnmap)
00478 { return plnmap.FormatToOStream(os); }
00479
00480
00481 void BfldDbiPlaneMap::Print(Option_t *option) const
00482 { FormatToOStream(cout,option); }
00483
00484
00485 std::ostream& BfldDbiPlaneMap::FormatToOStream(std::ostream& os,
00486 Option_t * ) const
00487 {
00488 os << GetName() << " "
00489 << fPlaneId.AsString("c");
00490
00491 const char* shapename = "unknown";
00492 const char* shapelist[] = { "circle", "square", "diamond" };
00493 if ( fDetailShape >= 0 && fDetailShape <= 2 ) shapename = shapelist[fDetailShape];
00494 os << ", Detail size=" << fDetailSize
00495 << " shape=" << shapename;
00496 os << endl;
00497
00498 int indxlabel = 0;
00499 const char* unknownlabel = "Unknown Map Pair: ";
00500 const char* labels[] = { "Current On: ",
00501 "Current Off: ",
00502 "Steel Detail: ",
00503 "Gap Detail: ",
00504 "Gap Full Plane: " };
00505 int nlabels = sizeof(labels)/sizeof(const char*);
00506
00507 int indx = 0;
00508 while ( indx < kEndOfList-1 ) {
00509 const char* thislabel = unknownlabel;
00510 if ( indxlabel < nlabels ) thislabel = labels[indxlabel];
00511 os << " " << thislabel;
00512 bool do1st = (fMapVariant[indx ]!=0 && fScale[indx ]!=0);
00513 bool do2nd = (fMapVariant[indx+1]!=0 && fScale[indx+1]!=0);
00514 if ( ! do1st && ! do2nd ) os << "no field maps ";
00515 if ( do1st ) os << fScale[indx ] << "*Map_" << fMapVariant[indx ];
00516 if ( do1st && do2nd ) os << " + ";
00517 if ( do2nd ) os << fScale[indx+1] << "*Map_" << fMapVariant[indx+1];
00518 os << endl;
00519 indx += 2;
00520 indxlabel++;
00521 }
00522
00523 os << " BdotScale " << fBdotScale;
00524 os << " BHCurveIndex " << fBHCurve;
00525 os << " BHFactor " << fBHFactor << "/" << fBHCutoff;
00526 os << " SlotFactor " << fSlotFactor << "/" << fSlotCutoff;
00527 os << endl;
00528
00529 return os;
00530 }
00531
00532
00533
00534 const char* BfldDbiPlaneMap::GetTableDescr()
00535 {
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 const char* const_tabledescr = "(\
00556 SEQNO int, \
00557 ROW_COUNTER int, \
00558 PLANENUM int, \
00559 MAPON1 int, \
00560 SCALEON1 float, \
00561 MAPON2 int, \
00562 SCALEON2 float, \
00563 MAPOFF1 int, \
00564 SCALEOFF1 float, \
00565 MAPOFF2 int, \
00566 SCALEOFF2 float, \
00567 MAPDETAIL1 int, \
00568 SCALEDETAIL1 float, \
00569 MAPDETAIL2 int, \
00570 SCALEDETAIL2 float, \
00571 MAPPLNGAP1 int, \
00572 SCALEPLNGAP1 float, \
00573 MAPPLNGAP2 int, \
00574 SCALEPLNGAP2 float, \
00575 MAPFULLGAP1 int, \
00576 SCALEFULLGAP1 float, \
00577 MAPFULLGAP2 int, \
00578 SCALEFULLGAP2 float, \
00579 DETAILSIZE float, \
00580 DETAILSHAPE int, \
00581 BHCURVEINDEX int, \
00582 BDOTSCALE float, \
00583 BHFACTOR float, \
00584 BHCUTOFF float, \
00585 SLOTFACTOR float, \
00586 SLOTCUTOFF float, \
00587 primary key (SEQNO,ROW_COUNTER) \
00588 )";
00589
00590 return const_tabledescr;
00591 }
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626