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

UgliDbiGeometry.cxx

Go to the documentation of this file.
00001 
00002 // $Id: UgliDbiGeometry.cxx,v 1.15 2007/03/09 05:59:47 rhatcher Exp $
00003 //
00004 // UgliDbiGeometry
00005 //
00006 // Package: UgliGeometry
00007 //
00008 // R. Hatcher  2001-08-08
00009 //
00010 // Concept:
00011 //   
00012 // Purpose:
00013 //
00015 
00016 #include "UgliGeometry/UgliDbiGeometry.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 #include <string.h>
00026 
00027 ClassImp(UgliDbiGeometry)
00028 
00029 //   Definition of static data members
00030 //   *********************************
00031 
00032 CVSID("$Id: UgliDbiGeometry.cxx,v 1.15 2007/03/09 05:59:47 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00033 Bool_t UgliDbiGeometry::fgDefensiveUnpkg = kFALSE;
00034 
00035 //  Instantiate associated Result Pointer class.
00036 //  *******************************************
00037 
00038 #include "DatabaseInterface/DbiResultPtr.tpl"
00039 template class  DbiResultPtr<UgliDbiGeometry>;
00040 
00041 #include "DatabaseInterface/DbiWriter.tpl"
00042 template class  DbiWriter<UgliDbiGeometry>;
00043 
00044 // Definition of member functions (alphabetical order)
00045 // ***************************************************
00046 
00047 //.....................................................................
00048  
00049 std::ostream& operator<<(std::ostream& os, const UgliDbiGeometry& udg)
00050 { return udg.FormatToOStream(os); }
00051 
00052 //.....................................................................
00053 
00054 void UgliDbiGeometry::Fill(DbiResultSet& rs,
00055                            const DbiValidityRec* /* vrec */) {
00056 //
00057 //
00058 //  Purpose:  Fill object from Result Set
00059 //
00060 //  Arguments: 
00061 //    rs           in    Result Set used to fill object
00062 //    vrec         in    Associated validity record (or 0 if filling
00063 //                                                    DbiValidityRec)
00064 //
00065 //  Return:    
00066 //
00067 //  Contact:   R. Hatcher
00068 //
00069 //  Specification:-
00070 //  =============
00071 //
00072 //  o Fill object from current row of Result Set.
00073 
00074 //  Program Notes:-
00075 //  =============
00076 
00077 //  None.
00078 
00079    if (fgDefensiveUnpkg) {
00080 
00081       // unpack allowing for various column names and ordering
00082 
00083       Int_t numCol = rs.NumCols();
00084       //  The first column (SeqNo) has already been processed.
00085       for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00086          string colName = rs.CurColName();
00087          if (      colName == "XYISUV"  ) {
00088             Short_t tmp; rs >> tmp; fXYisUV = Bool_t(tmp);
00089          }
00090          else if ( colName == "HALLXMIN") rs >> fHallXYZMin[0];
00091          else if ( colName == "HALLXMAX") rs >> fHallXYZMax[0];
00092          else if ( colName == "HALLYMIN") rs >> fHallXYZMin[1];
00093          else if ( colName == "HALLYMAX") rs >> fHallXYZMax[1];
00094          else if ( colName == "HALLZMIN") rs >> fHallXYZMin[2];
00095          else if ( colName == "HALLZMAX") rs >> fHallXYZMax[2];
00096          else {
00097             static int nmsg = 25;
00098             if (nmsg-- > 0) MSG("Ugli",Msg::kWarning) 
00099                << "Ignoring column " << rs.CurColNum() 
00100                << " (of " << rs.NumCols() << ")"
00101                << " \""<< colName << "\"; not part of "
00102                << ClassName() << endl;
00103             rs.IncrementCurCol();
00104          }
00105       }
00106    } // end defensive unpacking
00107    else {
00108       Short_t tmpxyisuv;
00109       rs >> tmpxyisuv
00110          >> fHallXYZMin[0]
00111          >> fHallXYZMax[0]
00112          >> fHallXYZMin[1]
00113          >> fHallXYZMax[1]
00114          >> fHallXYZMin[2]
00115          >> fHallXYZMax[2];
00116 
00117          fXYisUV = Bool_t(tmpxyisuv);
00118 
00119     }
00120 
00121 }
00122 
00123 //.....................................................................
00124 
00125 void UgliDbiGeometry::Store(DbiOutRowStream& ors,
00126                             const DbiValidityRec* /* vrec */) const {
00127 //
00128 //
00129 //  Purpose:  Stream object to output row stream
00130 //
00131 //  Arguments: 
00132 //    ors          in     Output row stream.
00133 //    vrec         in     Associated validity record (or 0 if filling
00134 //                                                    DbiValidityRec)
00135 //
00136 //  Return:    
00137 //
00138 //  Contact:   R. Hatcher
00139 //
00140 //  Specification:-
00141 //  =============
00142 //
00143 //  o  Stream object to output row stream.
00144 
00145 //  Program Notes:-
00146 //  =============
00147 
00148 //  None.
00149 
00150    const char* tabledescr = GetTableDescr();
00151    vector< pair<string,string> > components = 
00152       UgliDbiTableDescr::ParseTableDescr(tabledescr);
00153    int n = components.size();
00154 
00155    for (int i=0; i<n; i++) {
00156       pair<string,string> colPair = components[i];
00157       string colName = colPair.first;
00158       if (      colName == "XYISUV"  ) ors << (short)fXYisUV;
00159       else if ( colName == "HALLXMIN") ors << fHallXYZMin[0];
00160       else if ( colName == "HALLXMAX") ors << fHallXYZMax[0];
00161       else if ( colName == "HALLYMIN") ors << fHallXYZMin[1];
00162       else if ( colName == "HALLYMAX") ors << fHallXYZMax[1];
00163       else if ( colName == "HALLZMIN") ors << fHallXYZMin[2];
00164       else if ( colName == "HALLZMAX") ors << fHallXYZMax[2];
00165 
00166       else if ( colName == "ROW_COUNTER"     ) {;}
00167       else if ( colName == "SEQNO"           ) {;}
00168       else {
00169          MSG("Ugli",Msg::kFatal)
00170             << "Column name '" << colName << "' not correctly handled" << endl;
00171          assert(0);
00172       }
00173    }
00174 }
00175 
00176 //.....................................................................
00177  
00178 void UgliDbiGeometry::Print(Option_t* option) const
00179 {
00180     FormatToOStream(cout,option);
00181 }
00182  
00183 //.....................................................................
00184  
00185 std::ostream& UgliDbiGeometry::FormatToOStream(std::ostream& os,
00186                                                Option_t* option,
00187                                                const DbiValidityRec* dvr) const
00188 {
00189 //
00190 //
00191 //  Purpose:  Print the current row to an ostream
00192 //
00193 //  Return:   nothing
00194 //
00195 //  Contact:   R. Hatcher
00196 //
00197 //  Specification:-
00198 //  =============
00199 //
00200  
00201 //  Program Notes:-
00202 //  =============
00203  
00204 //  None.
00205  
00206   string opt = option;
00207 
00208   if ( opt.find("H") != string::npos ) {
00209      string tabledescr = GetTableDescr();
00210      tabledescr = UgliDbiTableDescr::TextTableDescrLine(tabledescr);
00211      os << tabledescr << endl;
00212   }
00213   else if ( opt.find("h") != string::npos ) {
00214     string tabledescr = GetTableDescr();
00215     vector< pair<string,string> > components =
00216         UgliDbiTableDescr::ParseTableDescr(tabledescr);
00217     for (unsigned int ic = 0; ic < components.size(); ++ic)
00218         os << components[ic].first << '\t';
00219     os << endl;
00220   }
00221 
00222   char sep = '\t';
00223   if ( opt.find(",") != string::npos ) sep = ',';
00224 
00225   if ( ! dvr ) {
00226       os << "SeqNo"         << sep;  // no way of knowing the SEQNO?
00227   }
00228   else {
00229       os << dvr->GetSeqNo() << sep;
00230   }
00231 
00232   os   <<  0  << sep  // only ever one row for an agg
00233        << (int)fXYisUV     << sep
00234        << fHallXYZMin[0]   << sep
00235        << fHallXYZMax[0]   << sep
00236        << fHallXYZMin[1]   << sep
00237        << fHallXYZMax[1]   << sep
00238        << fHallXYZMin[2]   << sep
00239        << fHallXYZMax[2]   << endl;
00240 
00241   return os;
00242 }
00243 
00244 //.....................................................................
00245 
00246 const char* UgliDbiGeometry::GetTableDescr()
00247 {
00248 //
00249 //
00250 //  Purpose:  Return a string describing rows in the table
00251 //            Used in creating temporary tables
00252 //
00253 //  Return:   const char* to parenthesized comma separated list
00254 //            of column name and type pairs
00255 //
00256 //  Contact:   R. Hatcher
00257 //
00258 //  Specification:-
00259 //  =============
00260 //
00261 
00262 //  Program Notes:-
00263 //  =============
00264 
00265 //  None.
00266 
00267    const char* const_tabledescr = "(\
00268        SEQNO             int,     \
00269        ROW_COUNTER       int,     \
00270        XYISUV            tinyint, \
00271        HALLXMIN          float,   \
00272        HALLXMAX          float,   \
00273        HALLYMIN          float,   \
00274        HALLYMAX          float,   \
00275        HALLZMIN          float,   \
00276        HALLZMAX          float,   \
00277        primary key (SEQNO,ROW_COUNTER) \
00278        )";
00279 
00280    return const_tabledescr;
00281 }
00282 
00283 /*    Template for New Member Function
00284 
00285 //.....................................................................
00286 
00287 UgliDbiGeometry:: {
00288 //
00289 //
00290 //  Purpose:  
00291 //
00292 //  Arguments: 
00293 //    xxxxxxxxx    in    yyyyyy
00294 //
00295 //  Return:    
00296 //
00297 //  Contact:   R. Hatcher
00298 //
00299 //  Specification:-
00300 //  =============
00301 //
00302 //  o 
00303 
00304 //  Program Notes:-
00305 //  =============
00306 
00307 //  None.
00308 
00309 
00310 }
00311 
00312 */
00313 

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