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

FabPlnInstall.cxx

Go to the documentation of this file.
00001 
00002 // $Id: FabPlnInstall.cxx,v 1.12 2008/03/04 21:44:34 rhatcher Exp $
00003 //
00004 // FabPlnInstall
00005 //
00006 // Package: Fabrication
00007 //
00008 // R. Hatcher  2002-11-06
00009 //
00010 // Concept: DBI table to record when planes were installed/commissioned
00011 //          in the detector and what components went into them.
00012 //   
00013 // Purpose:
00014 //
00016 
00017 #include "Fabrication/FabPlnInstall.h"
00018 #include "MessageService/MsgService.h"
00019 #include "DatabaseInterface/DbiOutRowStream.h"
00020 #include "DatabaseInterface/DbiResultSet.h"
00021 #include "DatabaseInterface/DbiValidityRec.h"
00022 
00023 //#include "UgliGeometry/UgliDbiTableDescr.h"
00024 
00025 #include <cassert>
00026 #include <string.h>
00027 
00028 using std::string;
00029 using std::vector;
00030 
00031 ClassImp(FabPlnInstall)
00032 
00033 //   Definition of static data members
00034 //   *********************************
00035 
00036 CVSID("$Id: FabPlnInstall.cxx,v 1.12 2008/03/04 21:44:34 rhatcher Exp $ CVSID_DBIRESULTPTR ");
00037 Bool_t FabPlnInstall::fgDefensiveUnpkg = kFALSE;
00038 
00039 //  Instantiate associated Result Pointer class.
00040 //  *******************************************
00041 
00042 #include "DatabaseInterface/DbiResultPtr.tpl"
00043 template class  DbiResultPtr<FabPlnInstall>;
00044 
00045 #include "DatabaseInterface/DbiWriter.tpl"
00046 template class  DbiWriter<FabPlnInstall>;
00047 
00048 // Definition of member functions (alphabetical order)
00049 // ***************************************************
00050 
00051 
00052 //.....................................................................
00053 
00054 void FabPlnInstall::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 
00080    UShort_t ipln = 1023;
00081 
00082    if (fgDefensiveUnpkg) {
00083 
00084       // unpack allowing for various column names and ordering
00085 
00086       Int_t numCol = rs.NumCols();
00087       //  The first column (SeqNo) has already been processed.
00088       for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00089          string colName = rs.CurColName();
00090          if (      colName == "INSTALLDATE"  ) rs >> fInstallDate;
00091 
00092          else if ( colName == "MODULEID1")     rs >> fScintMdlMfgId[0];
00093          else if ( colName == "MODULEID2")     rs >> fScintMdlMfgId[1];
00094          else if ( colName == "MODULEID3")     rs >> fScintMdlMfgId[2];
00095          else if ( colName == "MODULEID4")     rs >> fScintMdlMfgId[3];
00096          else if ( colName == "MODULEID5")     rs >> fScintMdlMfgId[4];
00097          else if ( colName == "MODULEID6")     rs >> fScintMdlMfgId[5];
00098          else if ( colName == "MODULEID7")     rs >> fScintMdlMfgId[6];
00099          else if ( colName == "MODULEID8")     rs >> fScintMdlMfgId[7];
00100 
00101          else if ( colName == "STEELID1")      rs >> fSteelSlabMfgId[0];
00102          else if ( colName == "STEELID2")      rs >> fSteelSlabMfgId[1];
00103          else if ( colName == "STEELID3")      rs >> fSteelSlabMfgId[2];
00104          else if ( colName == "STEELID4")      rs >> fSteelSlabMfgId[3];
00105          else if ( colName == "STEELID5")      rs >> fSteelSlabMfgId[4];
00106          else if ( colName == "STEELID6")      rs >> fSteelSlabMfgId[5];
00107          else if ( colName == "STEELID7")      rs >> fSteelSlabMfgId[6];
00108          else if ( colName == "STEELID8")      rs >> fSteelSlabMfgId[7];
00109 
00110          else if ( colName == "PLANENUM")      rs >> ipln;
00111          else {
00112             static int nmsg = 25;
00113             if (nmsg-- > 0) MSG("Fab",Msg::kWarning) 
00114                << "Ignoring column " << rs.CurColNum() 
00115                << " (of " << rs.NumCols() << ")"
00116                << " \""<< colName << "\"; not part of "
00117                << ClassName() << endl;
00118             rs.IncrementCurCol();
00119          }
00120       }
00121    } // end defensive unpacking
00122    else {
00123       rs >> fInstallDate
00124          >> fScintMdlMfgId[0]
00125          >> fScintMdlMfgId[1]
00126          >> fScintMdlMfgId[2]
00127          >> fScintMdlMfgId[3]
00128          >> fScintMdlMfgId[4]
00129          >> fScintMdlMfgId[5]
00130          >> fScintMdlMfgId[6]
00131          >> fScintMdlMfgId[7]
00132          >> fSteelSlabMfgId[0]
00133          >> fSteelSlabMfgId[1]
00134          >> fSteelSlabMfgId[2]
00135          >> fSteelSlabMfgId[3]
00136          >> fSteelSlabMfgId[4]
00137          >> fSteelSlabMfgId[5]
00138          >> fSteelSlabMfgId[6]
00139          >> fSteelSlabMfgId[7]
00140          >> ipln;
00141     }
00142 
00143     // trim off lead/trailing blanks
00144     for (UInt_t i=0; i < 8; ++i ) {
00145       fScintMdlMfgId[i]  = 
00146         ToUpper(fScintMdlMfgId[i]).Strip(TString::kBoth).Data();
00147       fSteelSlabMfgId[i] = 
00148         ToUpper(fSteelSlabMfgId[i]).Strip(TString::kBoth).Data();
00149     }
00150 
00151     Detector::Detector_t det =
00152       (Detector::Detector_t) 
00153       ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00154 
00155     fPlaneId = PlexPlaneId(det,ipln,kTRUE); // steel can be uninstrumented
00156 
00157 }
00158 
00159 //.....................................................................
00160 
00161 void FabPlnInstall::Store(DbiOutRowStream& ors,
00162                           const DbiValidityRec* /* vrec */) const {
00163 //
00164 //
00165 //  Purpose:  Stream object to output row stream
00166 //
00167 //  Arguments: 
00168 //    ors          in     Output row stream.
00169 //    vrec         in     Associated validity record (or 0 if filling
00170 //                                                    DbiValidityRec)
00171 //
00172 //  Return:    
00173 //
00174 //  Contact:   R. Hatcher
00175 //
00176 //  Specification:-
00177 //  =============
00178 //
00179 //  o  Stream object to output row stream.
00180 
00181 //  Program Notes:-
00182 //  =============
00183 
00184 //  None.
00185 
00186   //const char* tabledescr = GetTableDescr();
00187    //   vector< pair<string,string> > components = 
00188    //      UgliDbiTableDescr::ParseTableDescr(tabledescr);
00189    //   int n = components.size();
00190    vector< pair<string,string> > components;
00191    components.push_back(pair<string,string>("SEQNO","int"));
00192    components.push_back(pair<string,string>("INSTALLDATE","datetime"));
00193    components.push_back(pair<string,string>("MODULEID1","tinytext"));
00194    components.push_back(pair<string,string>("MODULEID2","tinytext"));
00195    components.push_back(pair<string,string>("MODULEID3","tinytext"));
00196    components.push_back(pair<string,string>("MODULEID4","tinytext"));
00197    components.push_back(pair<string,string>("MODULEID5","tinytext"));
00198    components.push_back(pair<string,string>("MODULEID6","tinytext"));
00199    components.push_back(pair<string,string>("MODULEID7","tinytext"));
00200    components.push_back(pair<string,string>("MODULEID8","tinytext"));
00201    components.push_back(pair<string,string>("STEELID1","tinytext"));
00202    components.push_back(pair<string,string>("STEELID2","tinytext"));
00203    components.push_back(pair<string,string>("STEELID3","tinytext"));
00204    components.push_back(pair<string,string>("STEELID4","tinytext"));
00205    components.push_back(pair<string,string>("STEELID5","tinytext"));
00206    components.push_back(pair<string,string>("STEELID6","tinytext"));
00207    components.push_back(pair<string,string>("STEELID7","tinytext"));
00208    components.push_back(pair<string,string>("STEELID8","tinytext"));
00209    components.push_back(pair<string,string>("PLANENUM","int"));
00210    int n = components.size();
00211 
00212    for (int i=0; i<n; i++) {
00213       pair<string,string> colPair = components[i];
00214       string colName = colPair.first;
00215       if (      colName == "INSTALLDATE") ors << fInstallDate;
00216 
00217       // note! indexing uses zero-based, but naming is 1..8
00218       else if ( colName == "MODULEID1")   ors << fScintMdlMfgId[0];
00219       else if ( colName == "MODULEID2")   ors << fScintMdlMfgId[1];
00220       else if ( colName == "MODULEID3")   ors << fScintMdlMfgId[2];
00221       else if ( colName == "MODULEID4")   ors << fScintMdlMfgId[3];
00222       else if ( colName == "MODULEID5")   ors << fScintMdlMfgId[4];
00223       else if ( colName == "MODULEID6")   ors << fScintMdlMfgId[5];
00224       else if ( colName == "MODULEID7")   ors << fScintMdlMfgId[6];
00225       else if ( colName == "MODULEID8")   ors << fScintMdlMfgId[7];
00226 
00227       else if ( colName == "STEELID1")    ors << fSteelSlabMfgId[0];
00228       else if ( colName == "STEELID2")    ors << fSteelSlabMfgId[1];
00229       else if ( colName == "STEELID3")    ors << fSteelSlabMfgId[2];
00230       else if ( colName == "STEELID4")    ors << fSteelSlabMfgId[3];
00231       else if ( colName == "STEELID5")    ors << fSteelSlabMfgId[4];
00232       else if ( colName == "STEELID6")    ors << fSteelSlabMfgId[5];
00233       else if ( colName == "STEELID7")    ors << fSteelSlabMfgId[6];
00234       else if ( colName == "STEELID8")    ors << fSteelSlabMfgId[7];
00235 
00236       else if ( colName == "PLANENO")     ors << fPlaneId.GetPlane();
00237 
00238       else if ( colName == "ROW_COUNTER"     ) {;}
00239       else if ( colName == "SEQNO"           ) {;}
00240       else {
00241          MSG("Fab",Msg::kFatal)
00242             << "Column name '" << colName << "' not correctly handled" << endl;
00243          assert(0);
00244       }
00245    }
00246 }
00247 
00248 //.....................................................................
00249 string FabPlnInstall::GetScintMdlMfgId(UShort_t indx) const
00250 { 
00251   if (indx > fScintMdlMfgId.size()) return "no-scint-id";
00252   return fScintMdlMfgId[indx];
00253 }
00254 
00255 //.....................................................................
00256 string FabPlnInstall::GetSteelSlabMfgId(UShort_t indx) const
00257 { 
00258   if (indx > fSteelSlabMfgId.size()) return "no-slab-id";
00259   return fSteelSlabMfgId[indx];
00260 }
00261 
00262 //.....................................................................
00263 Int_t FabPlnInstall::GetAggregateNo() const
00264 { 
00265   //return (int)fPlaneId.GetDetector()*100000000 + fPlaneId.GetPlane();
00266   return fPlaneId.GetPlane();
00267 }
00268 
00269 //.....................................................................
00270 UInt_t FabPlnInstall::GetIndex(UInt_t /* defIndex */) const
00271 { 
00272   return fPlaneId.GetPlane();
00273 }
00274 
00275 //.....................................................................
00276 std::ostream& operator<<(std::ostream& os, const FabPlnInstall& pi)
00277 { return pi.FormatToOStream(os); }
00278 
00279 //.....................................................................
00280 void FabPlnInstall::Print(Option_t *option) const
00281 { FormatToOStream(cout,option); }
00282 
00283 //.....................................................................
00284 std::ostream& FabPlnInstall::FormatToOStream(std::ostream& os,
00285                                              Option_t * /* option */) const
00286 {
00287   os << GetName() << " " 
00288      << fPlaneId.AsString("c") << " "
00289      << fInstallDate.AsString("sql") << endl;
00290   for (int i=0; i<8; ++i) {
00291     os << "  [" << i << "]  ";
00292     // left justification doesn't work consistently
00293     // not on std::strings and for some reason sometimes not at all
00294     // (but breaking it up like this seems to work sometimes)
00295     os.fill(' ');
00296     os << setw(16);
00297     os.setf(ios::left);  
00298     os << fScintMdlMfgId[i].c_str();
00299     os << " ";
00300     os.fill(' ');
00301     os << setw(16);
00302     os.setf(ios::left);  
00303     os << fSteelSlabMfgId[i].c_str();
00304     os << endl;
00305   }
00306   os.setf(ios::right);
00307   return os;
00308 }
00309 
00310 //.....................................................................
00311 
00312 const char* FabPlnInstall::GetTableDescr()
00313 {
00314 //
00315 //
00316 //  Purpose:  Return a string describing rows in the table
00317 //            Used in creating temporary tables
00318 //
00319 //  Return:   const char* to parenthesized comma separated list
00320 //            of column name and type pairs
00321 //
00322 //  Contact:   R. Hatcher
00323 //
00324 //  Specification:-
00325 //  =============
00326 //
00327 
00328 //  Program Notes:-
00329 //  =============
00330 
00331 //  None.
00332 
00333    const char* const_tabledescr = "(\
00334        SEQNO             int,      \
00335        ROW_COUNTER       int,      \
00336        INSTALLDATE       datetime, \
00337        MODULEID1         tinytext, \
00338        MODULEID2         tinytext, \
00339        MODULEID3         tinytext, \
00340        MODULEID4         tinytext, \
00341        MODULEID5         tinytext, \
00342        MODULEID6         tinytext, \
00343        MODULEID7         tinytext, \
00344        MODULEID8         tinytext, \
00345        STEELID1          tinytext, \
00346        STEELID2          tinytext, \
00347        STEELID3          tinytext, \
00348        STEELID4          tinytext, \
00349        STEELID5          tinytext, \
00350        STEELID6          tinytext, \
00351        STEELID7          tinytext, \
00352        STEELID8          tinytext, \
00353        PLANENUM          int,      \
00354        primary key (SEQNO,ROW_COUNTER) \
00355        )";
00356 
00357    return const_tabledescr;
00358 }
00359 
00360 /*    Template for New Member Function
00361 
00362 //.....................................................................
00363 
00364 FabPlnInstall:: {
00365 //
00366 //
00367 //  Purpose:  
00368 //
00369 //  Arguments: 
00370 //    xxxxxxxxx    in    yyyyyy
00371 //
00372 //  Return:    
00373 //
00374 //  Contact:   R. Hatcher
00375 //
00376 //  Specification:-
00377 //  =============
00378 //
00379 //  o 
00380 
00381 //  Program Notes:-
00382 //  =============
00383 
00384 //  None.
00385 
00386 
00387 }
00388 
00389 */
00390 

Generated on Mon Feb 15 11:06:39 2010 for loon by  doxygen 1.3.9.1