Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BfldDbiPlaneMap.cxx

Go to the documentation of this file.
00001 
00002 // $Id: BfldDbiPlaneMap.cxx,v 1.17 2008/03/14 05:14:13 rhatcher Exp $
00003 //
00004 // BfldDbiPlaneMap
00005 //
00006 // Package: BField
00007 //
00008 // Concept: DBI table to record when what maps to use for which planes
00009 //          in the detector (at any given VldContext)
00010 //
00011 //
00012 // Author: R. Hatcher 2003-05-29
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 //  Instantiate associated Result Pointer class.
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 //   Definition of static data members
00044 //   *********************************
00045 
00046 Bool_t BfldDbiPlaneMap::fgDefensiveUnpkg = kTRUE;
00047 
00048 // Definition of member functions (alphabetical order)
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 //  Purpose:  Fill object from Result Set
00074 //
00075 //  Arguments: 
00076 //    rs           in    Result Set used to fill object
00077 //    vrec         in    Associated validity record (or 0 if filling
00078 //                                                    DbiValidityRec)
00079 //
00080 //  Return:    
00081 //
00082 //  Contact:   R. Hatcher
00083 //
00084 //  Specification:-
00085 //  =============
00086 //
00087 //  o Fill object from current row of Result Set.
00088 
00089 //  Program Notes:-
00090 //  =============
00091 
00092 //  None.
00093 
00094 
00095    UShort_t ipln = 1023;
00096 
00097    if (fgDefensiveUnpkg) {
00098 
00099       // unpack allowing for various column names and ordering
00100 
00101       Int_t tmpshape = fDetailShape;
00102 
00103       Int_t numCol = rs.NumCols();
00104       //  The first column (SeqNo) has already been processed.
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          // old column names
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          // new column names
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          // yet newer names
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          // new columns
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          // new (more descriptive) names
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          // newest columns
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          } // end of conditional if/elseif/else/
00177       } // end of loop
00178       fDetailShape = (MapShape_t)tmpshape;
00179    } // end defensive unpacking
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* /* vrec */) const {
00322 //
00323 //
00324 //  Purpose:  Stream object to output row stream
00325 //
00326 //  Arguments: 
00327 //    ors          in     Output row stream.
00328 //    vrec         in     Associated validity record (or 0 if filling
00329 //                                                    DbiValidityRec)
00330 //
00331 //  Return:    
00332 //
00333 //  Contact:   R. Hatcher
00334 //
00335 //  Specification:-
00336 //  =============
00337 //
00338 //  o  Stream object to output row stream.
00339 
00340 //  Program Notes:-
00341 //  =============
00342 
00343 //  None.
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       // translate into U,V space and make same test as kSquare
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;  // fall through so we don't need to repeat the test
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;  // not legal
00459     break;
00460   }
00461   return false;  // not legal
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 /* defIndex */) 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 * /* option */) 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 ) {  // -1 because we're doing A+B pairs
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;   // do in pairs
00520     indxlabel++; // move pair label index onward
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 //  Purpose:  Return a string describing rows in the table
00539 //            Used in creating temporary tables
00540 //
00541 //  Return:   const char* to parenthesized comma separated list
00542 //            of column name and type pairs
00543 //
00544 //  Contact:   R. Hatcher
00545 //
00546 //  Specification:-
00547 //  =============
00548 //
00549 
00550 //  Program Notes:-
00551 //  =============
00552 
00553 //  None.
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 /*    Template for New Member Function
00597 
00598 //.....................................................................
00599 
00600 BfldDbiPlaneMap:: {
00601 //
00602 //
00603 //  Purpose:  
00604 //
00605 //  Arguments: 
00606 //    xxxxxxxxx    in    yyyyyy
00607 //
00608 //  Return:    
00609 //
00610 //  Contact:   R. Hatcher
00611 //
00612 //  Specification:-
00613 //  =============
00614 //
00615 //  o 
00616 
00617 //  Program Notes:-
00618 //  =============
00619 
00620 //  None.
00621 
00622 
00623 }
00624 
00625 */
00626 

Generated on Mon Feb 15 11:06:25 2010 for loon by  doxygen 1.3.9.1