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

UgliDbiScintMdl.cxx

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

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