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

UgliDbiStrip.cxx

Go to the documentation of this file.
00001 
00002 // $Id: UgliDbiStrip.cxx,v 1.21 2007/03/09 05:59:47 rhatcher Exp $
00003 //
00004 // UgliDbiStrip
00005 //
00006 // Package: UgliGeometry
00007 //
00008 // R. Hatcher  2001-08-08
00009 //
00010 // Concept:
00011 //   
00012 // Purpose:
00013 //
00015 
00016 #include "UgliGeometry/UgliDbiStrip.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(UgliDbiStrip)
00027 
00028 //   Definition of static data members
00029 //   *********************************
00030 
00031 CVSID("$Id: UgliDbiStrip.cxx,v 1.21 2007/03/09 05:59:47 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00032 Bool_t UgliDbiStrip::fgDefensiveUnpkg = kFALSE;
00033 
00034 //  Instantiate associated Result Pointer class.
00035 //  *******************************************
00036 
00037 #include "DatabaseInterface/DbiResultPtr.tpl"
00038 template class  DbiResultPtr<UgliDbiStrip>;
00039 
00040 #include "DatabaseInterface/DbiWriter.tpl"
00041 template class  DbiWriter<UgliDbiStrip>;
00042 
00043 // Definition of member functions (alphabetical order)
00044 // ***************************************************
00045 
00046 //.....................................................................
00047 
00048 std::ostream& operator<<(std::ostream& os, const UgliDbiStrip& uds)
00049 { return uds.FormatToOStream(os); }
00050 
00051 //.....................................................................
00052 
00053 UInt_t UgliDbiStrip::HashToIndex(const PlexStripEndId seid)
00054 {
00055    // make a natural index
00056 
00057    UInt_t hvalue; 
00058    int ierr = 0;
00059 
00060    // VERY WASTEFUL
00061    // assume 191 strips/plane
00062    // all planes occupied (ie. no sparsification of near spectrometer)
00063 
00064    int strip = seid.GetStrip();
00065 
00066    hvalue = seid.GetPlane()*192 + strip;
00067    if ( strip > 191 ) ierr += BIT(0);
00068 
00069    if (ierr) MSG("Ugli",Msg::kWarning) 
00070       << seid.AsString("c")
00071       << " breaks hashing assumptions " 
00072       << "    err 0x" << hex << ierr << dec 
00073       << endl;
00074 
00075    return hvalue;
00076 }
00077 
00078 //.....................................................................
00079 
00080 void UgliDbiStrip::Fill(DbiResultSet& rs,
00081                                       const DbiValidityRec* vrec) {
00082 //
00083 //
00084 //  Purpose:  Fill object from Result Set
00085 //
00086 //  Arguments: 
00087 //    rs           in    Result Set used to fill object
00088 //    vrec         in    Associated validity record (or 0 if filling
00089 //                                                    DbiValidityRec)
00090 //
00091 //  Return:    
00092 //
00093 //  Contact:   R. Hatcher
00094 //
00095 //  Specification:-
00096 //  =============
00097 //
00098 //  o Fill object from current row of Result Set.
00099 
00100 //  Program Notes:-
00101 //  =============
00102 
00103 //  None.
00104 
00105    Detector::Detector_t det =
00106       (Detector::Detector_t) 
00107       ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00108    
00109    Int_t plane  = -1;
00110    Int_t strip  = -1;
00111    PlaneView::PlaneView_t view             = PlaneView::kUnknown;
00112    PlaneCoverage::PlaneCoverage_t coverage = PlaneCoverage::kUnknown;
00113    Int_t tmp;
00114 
00115    if (fgDefensiveUnpkg) {
00116 
00117       // unpack allowing for various column names and ordering
00118 
00119       Int_t numCol = rs.NumCols();
00120       //  The first column (SeqNo) has already been processed.
00121       for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00122          string colName = rs.CurColName();
00123          if      ( colName == "HASHVAL"       ) rs.IncrementCurCol();
00124          // "HASH" is obsolete
00125          else if ( colName == "HASH"          ) rs.IncrementCurCol();
00126          else if ( colName == "DETECTOR"      ) {
00127             rs >> tmp; det = (Detector::Detector_t)tmp;
00128          }
00129          else if ( colName == "PLANE"         ) rs >> plane;
00130          else if ( colName == "PLNVIEW"       ) { 
00131             rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00132          }
00133          // "VIEW" is obsolete
00134          else if ( colName == "VIEW"          ) { 
00135             rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00136          }
00137          else if ( colName == "COVERAGE"      ) {
00138             rs >> tmp; coverage = (PlaneCoverage::PlaneCoverage_t)tmp;
00139          }
00140          else if ( colName == "STRIP"         ) rs >> strip;
00141          else if ( colName == "TPOSRELMDL"    ) rs >> fTPosRelMdl;
00142          else if ( colName == "LPOSRELMDL"    ) rs >> fLPosRelMdl;
00143          else if ( colName == "ZROTRELMDLRAD" ) rs >> fZRotRelMdlRad;
00144          else if ( colName == "TCURVFORM"     ) rs >> fTCurvForm;
00145          else if ( colName == "TCURVPARM0"    ) rs >> fTCurvParm[0];
00146          else if ( colName == "TCURVPARM1"    ) rs >> fTCurvParm[1];
00147          else if ( colName == "TCURVPARM2"    ) rs >> fTCurvParm[2];
00148          else if ( colName == "TCURVPARM3"    ) rs >> fTCurvParm[3];
00149          else if ( colName == "ZCURVFORM"     ) rs >> fZCurvForm;
00150          else if ( colName == "ZCURVPARM0"    ) rs >> fZCurvParm[0];
00151          else if ( colName == "ZCURVPARM1"    ) rs >> fZCurvParm[1];
00152          else if ( colName == "ZCURVPARM2"    ) rs >> fZCurvParm[2];
00153          else if ( colName == "ZCURVPARM3"    ) rs >> fZCurvParm[3];
00154          else {
00155             static int nmsg = 25;
00156             if (nmsg-- > 0) MSG("Ugli",Msg::kWarning) 
00157                << "Ignoring column " << rs.CurColNum() 
00158                << " (of " << rs.NumCols() << ")"
00159                << " \""<< colName << "\"; not part of "
00160                << ClassName() << endl;
00161             rs.IncrementCurCol();
00162          }
00163       }
00164    } // end defensive unpacking
00165    else {
00166       Int_t hashv, tmpview, tmpcoverage;
00167       rs >> hashv
00168          >> plane
00169          >> strip
00170          >> tmpview
00171          >> tmpcoverage
00172          >> fTPosRelMdl
00173          >> fLPosRelMdl
00174          >> fZRotRelMdlRad
00175          >> fTCurvForm
00176          >> fZCurvForm
00177          >> fTCurvParm[0]
00178          >> fTCurvParm[1]
00179          >> fTCurvParm[2]
00180          >> fTCurvParm[3]
00181          >> fZCurvParm[0]
00182          >> fZCurvParm[1]
00183          >> fZCurvParm[2]
00184          >> fZCurvParm[3];
00185 
00186       view = (PlaneView::PlaneView_t)tmpview;
00187       coverage = (PlaneCoverage::PlaneCoverage_t)tmpcoverage;
00188 
00189    }
00190 
00191    fStripId = 
00192       PlexStripEndId(det,plane,strip,StripEnd::kWhole,
00193                      StripEnd::kWhole,view,coverage);
00194 }
00195 
00196 //.....................................................................
00197 
00198 void UgliDbiStrip::Store(DbiOutRowStream& ors,
00199                          const DbiValidityRec* /* vrec */) const {
00200 //
00201 //
00202 //  Purpose:  Stream object to output row stream
00203 //
00204 //  Arguments: 
00205 //    ors          in     Output row stream.
00206 //    vrec         in     Associated validity record (or 0 if filling
00207 //                                                    DbiValidityRec)
00208 //
00209 //  Return:    
00210 //
00211 //  Contact:   R. Hatcher
00212 //
00213 //  Specification:-
00214 //  =============
00215 //
00216 //  o  Stream object to output row stream.
00217 
00218 //  Program Notes:-
00219 //  =============
00220 
00221 //  None.
00222 
00223    const char* tabledescr = GetTableDescr();
00224    vector< pair<string,string> > components = 
00225       UgliDbiTableDescr::ParseTableDescr(tabledescr);
00226    int n = components.size();
00227 
00228    for (int i=0; i<n; i++) {
00229       pair<string,string> colPair = components[i];
00230       string colName = colPair.first;
00231       if      ( colName == "HASHVAL"       ) ors << (int)GetIndex(0);
00232       // "HASH" is obsolete
00233       else if ( colName == "HASH"          ) ors << (int)GetIndex(0);
00234       else if ( colName == "DETECTOR"      ) 
00235                         ors << (int)fStripId.GetDetector();
00236       else if ( colName == "PLANE"         ) ors << fStripId.GetPlane();
00237       else if ( colName == "PLNVIEW"       ) 
00238                         ors << (int)fStripId.GetPlaneView();
00239       // "VIEW" is obsolete
00240       else if ( colName == "VIEW"          ) 
00241                         ors << (int)fStripId.GetPlaneView();
00242       else if ( colName == "COVERAGE"      ) 
00243                         ors << (int)fStripId.GetPlaneCoverage();
00244       else if ( colName == "STRIP"         ) ors << fStripId.GetStrip();
00245       else if ( colName == "TPOSRELMDL"    ) ors << fTPosRelMdl;
00246       else if ( colName == "LPOSRELMDL"    ) ors << fLPosRelMdl;
00247       else if ( colName == "ZROTRELMDLRAD" ) ors << fZRotRelMdlRad;
00248       else if ( colName == "TCURVFORM"     ) ors << fTCurvForm;
00249       else if ( colName == "TCURVPARM0"    ) ors << fTCurvParm[0];
00250       else if ( colName == "TCURVPARM1"    ) ors << fTCurvParm[1];
00251       else if ( colName == "TCURVPARM2"    ) ors << fTCurvParm[2];
00252       else if ( colName == "TCURVPARM3"    ) ors << fTCurvParm[3];
00253       else if ( colName == "ZCURVFORM"     ) ors << fZCurvForm;
00254       else if ( colName == "ZCURVPARM0"    ) ors << fZCurvParm[0];
00255       else if ( colName == "ZCURVPARM1"    ) ors << fZCurvParm[1];
00256       else if ( colName == "ZCURVPARM2"    ) ors << fZCurvParm[2];
00257       else if ( colName == "ZCURVPARM3"    ) ors << fZCurvParm[3];
00258 
00259       else if ( colName == "ROW_COUNTER"   ) {;}
00260       else if ( colName == "SEQNO"         ) {;}
00261       else {
00262          MSG("Ugli",Msg::kFatal)
00263             << "Column name '" << colName << "' not correctly handled" << endl;
00264          assert(0);
00265       }
00266    }
00267 }
00268 
00269 //.....................................................................
00270 
00271 void UgliDbiStrip::Print(Option_t* option) const
00272 {
00273     FormatToOStream(cout,option);
00274 }
00275 
00276 //.....................................................................
00277 
00278 std::ostream& UgliDbiStrip::FormatToOStream(std::ostream& os,
00279                                             Option_t* option,
00280                                             const DbiValidityRec* dvr) const
00281 {
00282 //
00283 //
00284 //  Purpose:  Print the current row
00285 //
00286 //  Return:   nothing
00287 //
00288 //  Contact:   R. Hatcher
00289 //
00290 //  Specification:-
00291 //  =============
00292 //
00293 
00294 //  Program Notes:-
00295 //  =============
00296 
00297 //  None.
00298 
00299   string opt = option;
00300 
00301   if ( opt.find("H") != string::npos ) {
00302      string tabledescr = GetTableDescr();
00303      tabledescr = UgliDbiTableDescr::TextTableDescrLine(tabledescr);
00304      os << tabledescr << endl;
00305   }
00306   else if ( opt.find("h") != string::npos ) {
00307     string tabledescr = GetTableDescr();
00308     vector< pair<string,string> > components = 
00309         UgliDbiTableDescr::ParseTableDescr(tabledescr);
00310     for (unsigned int ic = 0; ic < components.size(); ++ic) 
00311         os << components[ic].first << '\t';
00312     os << endl;
00313   }
00314 
00315   char sep = '\t';
00316   if ( opt.find(",") != string::npos ) sep = ',';
00317 
00318   if ( ! dvr ) {
00319       os << "SeqNo"         << sep;  // no way of knowing the SEQNO?
00320   }
00321   else {
00322       os << dvr->GetSeqNo() << sep;
00323   }
00324 
00325   os   << GetStrip() << sep  // within aggregate(=plane) strip => row_counter
00326        << -1         << sep  // Hashval is obsolete
00327        << fStripId.GetPlane()              << sep
00328        << fStripId.GetStrip()              << sep
00329        << (int)fStripId.GetPlaneView()     << sep
00330        << (int)fStripId.GetPlaneCoverage() << sep
00331        << fTPosRelMdl           << sep
00332        << fLPosRelMdl           << sep
00333        << fZRotRelMdlRad        << sep
00334        << fTCurvForm            << sep
00335        << fZCurvForm            << sep
00336        << fTCurvParm[0]         << sep
00337        << fTCurvParm[1]         << sep
00338        << fTCurvParm[2]         << sep
00339        << fTCurvParm[3]         << sep
00340        << fZCurvParm[0]         << sep
00341        << fZCurvParm[1]         << sep
00342        << fZCurvParm[2]         << sep
00343        << fZCurvParm[3]         << endl;
00344 
00345   return os;
00346 }
00347 
00348 //.....................................................................
00349 
00350 const char* UgliDbiStrip::GetTableDescr()
00351 {
00352 //
00353 //
00354 //  Purpose:  Return a string describing rows in the table
00355 //            Used in creating temporary tables
00356 //
00357 //  Return:   const char* to parenthesized comma separated list
00358 //            of column name and type pairs
00359 //
00360 //  Contact:   R. Hatcher
00361 //
00362 //  Specification:-
00363 //  =============
00364 //
00365 
00366 //  Program Notes:-
00367 //  =============
00368 
00369 //  None.
00370 
00371    const char* const_tabledescr = "(\
00372        SEQNO         int,      \
00373        ROW_COUNTER   int,      \
00374        HASHVAL       int,      \
00375        PLANE         smallint, \
00376        STRIP         smallint, \
00377        PLNVIEW       tinyint,  \
00378        COVERAGE      tinyint,  \
00379        TPOSRELMDL    float,    \
00380        LPOSRELMDL    float,    \
00381        ZROTRELMDLRAD float,    \
00382        TCURVFORM     tinyint,  \
00383        ZCURVFORM     tinyint,  \
00384        TCURVPARM0    float,    \
00385        TCURVPARM1    float,    \
00386        TCURVPARM2    float,    \
00387        TCURVPARM3    float,    \
00388        ZCURVPARM0    float,    \
00389        ZCURVPARM1    float,    \
00390        ZCURVPARM2    float,    \
00391        ZCURVPARM3    float,    \
00392        primary key (SEQNO,ROW_COUNTER) \
00393        )";
00394 
00395    return const_tabledescr;
00396 }
00397 
00398 
00399 /*    Template for New Member Function
00400 
00401 //.....................................................................
00402 
00403 UgliDbiStrip:: {
00404 //
00405 //
00406 //  Purpose:  
00407 //
00408 //  Arguments: 
00409 //    xxxxxxxxx    in    yyyyyy
00410 //
00411 //  Return:    
00412 //
00413 //  Contact:   R. Hatcher
00414 //
00415 //  Specification:-
00416 //  =============
00417 //
00418 //  o 
00419 
00420 //  Program Notes:-
00421 //  =============
00422 
00423 //  None.
00424 
00425 
00426 }
00427 
00428 */
00429 

Generated on Mon Feb 15 11:07:48 2010 for loon by  doxygen 1.3.9.1