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

UgliDbiScintMdlStruct.cxx

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

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