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

UgliDbiSteelPln.cxx

Go to the documentation of this file.
00001 
00002 // $Id: UgliDbiSteelPln.cxx,v 1.20 2007/03/09 05:59:47 rhatcher Exp $
00003 //
00004 // UgliDbiSteelPln
00005 //
00006 // Package: UgliGeometry
00007 //
00008 // R. Hatcher  2001-08-08
00009 //
00010 // Concept:
00011 //   
00012 // Purpose:
00013 //
00015 
00016 #include "TMath.h"
00017 
00018 #include "UgliGeometry/UgliDbiSteelPln.h"
00019 #include "MessageService/MsgService.h"
00020 #include "DatabaseInterface/DbiOutRowStream.h"
00021 #include "DatabaseInterface/DbiResultSet.h"
00022 #include "DatabaseInterface/DbiValidityRec.h"
00023 
00024 #include "UgliGeometry/UgliDbiTableDescr.h"
00025 
00026 #include <cassert>
00027 
00028 ClassImp(UgliDbiSteelPln)
00029 
00030 //   Definition of static data members
00031 //   *********************************
00032 
00033 CVSID("$Id: UgliDbiSteelPln.cxx,v 1.20 2007/03/09 05:59:47 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00034 Bool_t UgliDbiSteelPln::fgDefensiveUnpkg = kFALSE;
00035 
00036 //  Instantiate associated Result Pointer class.
00037 //  *******************************************
00038 
00039 #include "DatabaseInterface/DbiResultPtr.tpl"
00040 template class  DbiResultPtr<UgliDbiSteelPln>;
00041 
00042 #include "DatabaseInterface/DbiWriter.tpl"
00043 template class  DbiWriter<UgliDbiSteelPln>;
00044 
00045 // Definition of member functions (alphabetical order)
00046 // ***************************************************
00047 
00048 
00049 //.....................................................................
00050 
00051 std::ostream& operator<<(std::ostream& os, const UgliDbiSteelPln& udsp)
00052 { return udsp.FormatToOStream(os); }
00053 
00054 //.....................................................................
00055 
00056 void UgliDbiSteelPln::Fill(DbiResultSet& rs,
00057                                       const DbiValidityRec* vrec) {
00058 //
00059 //
00060 //  Purpose:  Fill object from Result Set
00061 //
00062 //  Arguments: 
00063 //    rs           in    Result Set used to fill object
00064 //    vrec         in    Associated validity record (or 0 if filling
00065 //                                                    DbiValidityRec)
00066 //
00067 //  Return:    
00068 //
00069 //  Contact:   R. Hatcher
00070 //
00071 //  Specification:-
00072 //  =============
00073 //
00074 //  o Fill object from current row of Result Set.
00075 
00076 //  Program Notes:-
00077 //  =============
00078 
00079 //  None.
00080 
00081    Detector::Detector_t det =
00082       (Detector::Detector_t) 
00083       ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00084    
00085    Int_t plane                             = -1;
00086    PlaneView::PlaneView_t view             = PlaneView::kUnknown;
00087    PlaneCoverage::PlaneCoverage_t coverage = PlaneCoverage::kUnknown;
00088    Int_t tmp;
00089 
00090    if (fgDefensiveUnpkg) {
00091 
00092       // unpack allowing for various column names and ordering
00093 
00094       Int_t numCol = rs.NumCols();
00095       //  The first column (SeqNo) has already been processed.
00096       for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00097          string colName = rs.CurColName();
00098          if      ( colName == "HASHVAL"   ) rs.IncrementCurCol();
00099          // "HASH" is obsolete
00100          else if ( colName == "HASH"      ) rs.IncrementCurCol();
00101          else if ( colName == "PLANE"     ) rs >> plane;
00102          else if ( colName == "PLNVIEW"   ) { 
00103             rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00104          }
00105          // "VIEW" is obsolete
00106          else if ( colName == "VIEW"      ) { 
00107             rs >> tmp; view = (PlaneView::PlaneView_t)tmp;
00108          }
00109          else if ( colName == "COVERAGE"  ) {
00110             rs >> tmp; coverage = (PlaneCoverage::PlaneCoverage_t)tmp;
00111          }
00112          else if ( colName == "MELTCODE"  )  rs >> fMeltCode;
00113          else if ( colName == "THICKNESS" )  rs >> fThickness;
00114          else if ( colName == "TOTALZ"    )  rs >> fTotalZ;
00115          else if ( colName == "X0"        )  rs >> fX0;
00116          else if ( colName == "Y0"        )  rs >> fY0;
00117          else if ( colName == "ZBACK"     )  rs >> fZBack;
00118          else if ( colName == "THETAXRAD" )  rs >> fThetaXYZRad[0];
00119          else if ( colName == "THETAYRAD" )  rs >> fThetaXYZRad[1];
00120          else if ( colName == "THETAZRAD" )  rs >> fThetaXYZRad[2];
00121          else if ( colName == "PHIYRAD"   )  rs >> fPhiXYZRad[1];
00122          else if ( colName == "PHIXRAD"   )  rs >> fPhiXYZRad[0];
00123          else if ( colName == "PHIZRAD"   )  rs >> fPhiXYZRad[2];
00124          else {
00125             static int nmsg = 25;
00126             if (nmsg-- > 0) MSG("Ugli",Msg::kWarning) 
00127                << "Ignoring column " << rs.CurColNum() 
00128                << " (of " << rs.NumCols() << ")"
00129                << " \""<< colName << "\"; not part of "
00130                << ClassName() << endl;
00131             rs.IncrementCurCol();
00132          }
00133       }
00134    } // end defensive unpacking
00135    else {
00136       Int_t hashv, tmpview, tmpcoverage;
00137       rs >> hashv
00138          >> plane
00139          >> tmpview
00140          >> tmpcoverage
00141          >> fMeltCode
00142          >> fThickness
00143          >> fTotalZ
00144          >> fX0
00145          >> fY0
00146          >> fZBack
00147          >> fThetaXYZRad[0]
00148          >> fPhiXYZRad[0] 
00149          >> fThetaXYZRad[1]
00150          >> fPhiXYZRad[1]
00151          >> fThetaXYZRad[2]
00152          >> fPhiXYZRad[2];
00153 
00154       view = (PlaneView::PlaneView_t)tmpview;
00155       coverage = (PlaneCoverage::PlaneCoverage_t)tmpcoverage;
00156 
00157    }      
00158    fPlaneId = PlexPlaneId(det,plane,kTRUE,view,coverage);
00159 
00160 }
00161 
00162 //.....................................................................
00163 
00164 void UgliDbiSteelPln::Store(DbiOutRowStream& ors,
00165                             const DbiValidityRec* /* vrec */) const {
00166 //
00167 //
00168 //  Purpose:  Stream object to output row stream
00169 //
00170 //  Arguments: 
00171 //    ors          in     Output row stream.
00172 //    vrec         in     Associated validity record (or 0 if filling
00173 //                                                    DbiValidityRec)
00174 //
00175 //  Return:    
00176 //
00177 //  Contact:   R. Hatcher
00178 //
00179 //  Specification:-
00180 //  =============
00181 //
00182 //  o  Stream object to output row stream.
00183 
00184 //  Program Notes:-
00185 //  =============
00186 
00187 //  None.
00188 
00189    const char* tabledescr = GetTableDescr();
00190    vector< pair<string,string> > components = 
00191       UgliDbiTableDescr::ParseTableDescr(tabledescr);
00192    int n = components.size();
00193 
00194    for (int i=0; i<n; i++) {
00195       pair<string,string> colPair = components[i];
00196       string colName = colPair.first;
00197       if      ( colName == "HASHVAL"   )  ors << (int)GetIndex(0);
00198       // "HASH" is obsolete
00199       else if ( colName == "HASH"      )  ors << (int)GetIndex(0);
00200       else if ( colName == "PLANE"     )  ors << fPlaneId.GetPlane();
00201       else if ( colName == "PLNVIEW"   )  ors << (int)fPlaneId.GetPlaneView();
00202       // "VIEW" is obsolete
00203       else if ( colName == "VIEW"      )  ors << (int)fPlaneId.GetPlaneView();
00204       else if ( colName == "COVERAGE"  )  ors << (int)fPlaneId.GetPlaneCoverage();
00205       else if ( colName == "MELTCODE"  )  ors << fMeltCode;
00206       else if ( colName == "THICKNESS" )  ors << fThickness;
00207       else if ( colName == "TOTALZ"    )  ors << fTotalZ;
00208       else if ( colName == "X0"        )  ors << fX0;
00209       else if ( colName == "Y0"        )  ors << fY0;
00210       else if ( colName == "ZBACK"     )  ors << fZBack;
00211       else if ( colName == "THETAXRAD" )  ors << fThetaXYZRad[0];
00212       else if ( colName == "THETAYRAD" )  ors << fThetaXYZRad[1];
00213       else if ( colName == "THETAZRAD" )  ors << fThetaXYZRad[2];
00214       else if ( colName == "PHIYRAD"   )  ors << fPhiXYZRad[1];
00215       else if ( colName == "PHIXRAD"   )  ors << fPhiXYZRad[0];
00216       else if ( colName == "PHIZRAD"   )  ors << fPhiXYZRad[2];
00217 
00218       else if ( colName == "ROW_COUNTER"     ) {;}
00219       else if ( colName == "SEQNO"           ) {;}
00220       else {
00221          MSG("Ugli",Msg::kFatal)
00222             << "Column name '" << colName << "' not correctly handled" << endl;
00223          assert(0);
00224       }
00225    }
00226 }
00227 
00228 //.....................................................................
00229 
00230 void UgliDbiSteelPln::Print(Option_t* option) const
00231 {
00232     FormatToOStream(cout,option);
00233 }
00234 
00235 //.....................................................................
00236 
00237 std::ostream& UgliDbiSteelPln::FormatToOStream(std::ostream& os,
00238                                                Option_t* option,
00239                                                const DbiValidityRec* dvr) const
00240 {
00241 //
00242 //
00243 //  Purpose:  Print the current row to an ostream
00244 //
00245 //  Return:   nothing
00246 //
00247 //  Contact:   R. Hatcher
00248 //
00249 //  Specification:-
00250 //  =============
00251 //
00252 
00253 //  Program Notes:-
00254 //  =============
00255 
00256 //  None.
00257 
00258   string opt = option;
00259 
00260   if ( opt.find("H") != string::npos ) {
00261      string tabledescr = GetTableDescr();
00262      tabledescr = UgliDbiTableDescr::TextTableDescrLine(tabledescr);
00263      os << tabledescr << endl;
00264   }
00265   else if ( opt.find("h") != string::npos ) {
00266     string tabledescr = GetTableDescr();
00267     vector< pair<string,string> > components = 
00268         UgliDbiTableDescr::ParseTableDescr(tabledescr);
00269     for (unsigned int ic = 0; ic < components.size(); ++ic) 
00270         os << components[ic].first << '\t';
00271     os << endl;
00272   }
00273 
00274   char sep = '\t';
00275   if ( opt.find(",") != string::npos ) sep = ',';
00276 
00277   if ( ! dvr ) {
00278       os << "SeqNo"         << sep;  // no way of knowing the SEQNO?
00279   }
00280   else {
00281       os << dvr->GetSeqNo() << sep;
00282   }
00283 
00284   os   <<  0  << sep  // only ever one row for an agg (AggregateNo=plane#)
00285        << -1  << sep  // Hashval is obsolete
00286        << GetPlane()       << sep 
00287        << (int)fPlaneId.GetPlaneView()     << sep 
00288        << (int)fPlaneId.GetPlaneCoverage() << sep 
00289        << fMeltCode        << sep 
00290        << fThickness       << sep 
00291        << fTotalZ          << sep 
00292        << fX0              << sep 
00293        << fY0              << sep 
00294        << fZBack           << sep 
00295        << fThetaXYZRad[0]  << sep 
00296        << fPhiXYZRad[0]    << sep 
00297        << fThetaXYZRad[1]  << sep
00298        << fPhiXYZRad[1]    << sep 
00299        << fThetaXYZRad[2]  << sep
00300        << fPhiXYZRad[2]    << endl;
00301   
00302   return os;
00303 }
00304 
00305 //.....................................................................
00306 
00307 const char* UgliDbiSteelPln::GetTableDescr()
00308 {
00309 //
00310 //
00311 //  Purpose:  Return a string describing rows in the table
00312 //            Used in creating temporary tables
00313 //
00314 //  Return:   const char* to parenthesized comma separated list
00315 //            of column name and type pairs
00316 //
00317 //  Contact:   R. Hatcher
00318 //
00319 //  Specification:-
00320 //  =============
00321 //
00322 
00323 //  Program Notes:-
00324 //  =============
00325 
00326 //  None.
00327 
00328    const char* const_tabledescr = "(\
00329        SEQNO         int,      \
00330        ROW_COUNTER   int,      \
00331        HASHVAL       int,      \
00332        PLANE         smallint, \
00333        PLNVIEW       tinyint,  \
00334        COVERAGE      tinyint,  \
00335        MELTCODE      int,      \
00336        THICKNESS     float,    \
00337        TOTALZ        float,    \
00338        X0            float,    \
00339        Y0            float,    \
00340        ZBACK         float,    \
00341        THETAXRAD     float,    \
00342        PHIXRAD       float,    \
00343        THETAYRAD     float,    \
00344        PHIYRAD       float,    \
00345        THETAZRAD     float,    \
00346        PHIZRAD       float,    \
00347        primary key (SEQNO,ROW_COUNTER) \
00348        )";
00349 
00350    return const_tabledescr;
00351 }
00352 
00353 
00354 /*    Template for New Member Function
00355 
00356 //.....................................................................
00357 
00358 UgliDbiSteelPln:: {
00359 //
00360 //
00361 //  Purpose:  
00362 //
00363 //  Arguments: 
00364 //    xxxxxxxxx    in    yyyyyy
00365 //
00366 //  Return:    
00367 //
00368 //  Contact:   R. Hatcher
00369 //
00370 //  Specification:-
00371 //  =============
00372 //
00373 //  o 
00374 
00375 //  Program Notes:-
00376 //  =============
00377 
00378 //  None.
00379 
00380 
00381 }
00382 
00383 */
00384 

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