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

UgliDbiScintPlnStruct.cxx

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

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