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

DbiResultPtr.tpl

Go to the documentation of this file.
00001 // $Id: DbiResultPtr.tpl,v 1.10 2009/04/18 07:59:14 west Exp $
00002 
00003 #include <cassert>
00004 
00005 #include "DatabaseInterface/DbiResultKey.h"
00006 #include "DatabaseInterface/DbiResultPtr.h"
00007 #include "DatabaseInterface/DbiSqlContext.h"
00008 #include "DatabaseInterface/DbiTableProxy.h"
00009 #include "DatabaseInterface/DbiTimerManager.h"
00010 #include "LeakChecker/Lea.h"
00011 #include "MessageService/MsgService.h"
00012 #include "Validity/VldTimeStamp.h"
00013 
00014 #include <cstdlib>
00015 
00016 ClassImpT(DbiResultPtr,T)
00017 
00018 //   Definition of static data members
00019 //   *********************************
00020 
00021 //CVSID("$Id: DbiResultPtr.tpl,v 1.10 2009/04/18 07:59:14 west Exp $");
00022 
00023 template<class T>
00024 map<string,DbiTableProxy*>  DbiResultPtr<T>::fgNameToProxy;
00025 
00026 template<class T>
00027 DbiTableProxy* DbiResultPtr<T>::fgTableProxy = 0;
00028 
00029 
00030 //    Definition of all member functions (static or otherwise)
00031 //    *******************************************************
00032 //
00033 //    -  ordered: ctors, dtor, operators then in alphabetical order.
00034 
00035 //.....................................................................
00036 
00037 template<class T>
00038 DbiResultPtr<T>::DbiResultPtr() :
00039 fAbortTest(Dbi::kDisabled),
00040 fTableProxy(DbiResultPtr<T>::GetTableProxy()),
00041 fResult(0),
00042 fDetType(Detector::kUnknown),
00043 fSimType(SimFlag::kUnknown )
00044 {
00045 //
00046 //
00047 //  Purpose:  Default constructor
00048 //
00049 //  Arguments: None
00050 //
00051 //  Return:    n/a
00052 //
00053 //  Contact:   N. West
00054 //
00055 //  Specification:-
00056 //  =============
00057 //
00058 //  o Create ResultPtr.
00059 
00060 
00061 //  Program Notes:-
00062 //  =============
00063 
00064 //  None.
00065 
00066   LEA_CTOR    //Leak Checker
00067 
00068   T pet;
00069   MSG("Dbi", Msg::kVerbose) 
00070         << "Creating DbiResultPtr for " << pet.GetName()
00071         << " Table Proxy at " << &fTableProxy << endl;
00072 }
00073 //.....................................................................
00074 
00075 template<class T>
00076 DbiResultPtr<T>::DbiResultPtr(const DbiResultPtr& that) :
00077 fAbortTest(that.fAbortTest),
00078 fTableProxy(that.fTableProxy),
00079 fResult(that.fResult),
00080 fDetType(that.fDetType),
00081 fSimType(that.fSimType)
00082 {
00083 //
00084 //
00085 //  Purpose:  Copy constructor
00086 
00087   LEA_CTOR    //Leak Checker
00088 
00089   T pet;
00090   MSG("Dbi", Msg::kVerbose) 
00091         << "Creating copy DbiResultPtr for " << pet.GetName()
00092         << " Table Proxy at " << &fTableProxy << endl;
00093   if ( fResult ) fResult->Connect();
00094 
00095 }
00096 
00097 //.....................................................................
00098 
00099 template<class T>
00100 DbiResultPtr<T>::DbiResultPtr(const VldContext& vc, 
00101                               Dbi::Task task,
00102                               Dbi::AbortTest abortTest,
00103                               Bool_t findFullTimeWindow) :
00104 fAbortTest(abortTest),
00105 fTableProxy(DbiResultPtr<T>::GetTableProxy()),
00106 fResult(0),
00107 fDetType(vc.GetDetector()),
00108 fSimType(vc.GetSimFlag())
00109 {
00110 //
00111 //
00112 //  Purpose:  Construct and apply context specific query to default table.
00113 //
00114 //  Arguments: 
00115 //    vc           in    The Validity Context of the new query
00116 //    task         in    The task of the new query
00117 //    abortTest    in    Test which if failed triggers abort.
00118 //    findFullTimeWindow
00119 //                 in    Attempt to find full validity of query 
00120 //                        i.e. beyond Dbi::GetTimeGate
00121 //
00122 //  Return:    n/a
00123 //
00124 //  Contact:   N. West
00125 //
00126 //  Specification:-
00127 //  =============
00128 //
00129 //  o Create ResultPtr.
00130 
00131 
00132 //  Program Notes:-
00133 //  =============
00134 
00135 //  None.
00136 
00137   LEA_CTOR    //Leak Checker
00138 
00139   T pet;
00140   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultPtr for " 
00141                           << pet.GetName() << " Table Proxy at " 
00142                           << &fTableProxy << endl;
00143   NewQuery(vc, task, findFullTimeWindow);
00144 
00145 }
00146 
00147 //.....................................................................
00148 
00149 template<class T>
00150 DbiResultPtr<T>::DbiResultPtr(const string& tableName,
00151                               const VldContext& vc, 
00152                               Dbi::Task task,
00153                               Dbi::AbortTest abortTest,
00154                               Bool_t findFullTimeWindow) :
00155 fAbortTest(abortTest),
00156 fTableProxy(DbiResultPtr<T>::GetTableProxy(tableName)),
00157 fResult(0),
00158 fDetType(vc.GetDetector()),
00159 fSimType(vc.GetSimFlag())
00160 {
00161 //
00162 //
00163 //  Purpose:  Construct and apply context specific query to alternative table.
00164 //
00165 //  Arguments: 
00166 //    tableName    in    Name of table to use.
00167 //    vc           in    The Validity Context of the new query
00168 //    task         in    The task of the new query
00169 //    abortTest    in    Test which if failed triggers abort.
00170 //    findFullTimeWindow
00171 //                 in    Attempt to find full validity of query 
00172 //                        i.e. beyond Dbi::GetTimeGate
00173 //  Return:    n/a
00174 //
00175 //  Contact:   N. West
00176 //
00177 //  Specification:-
00178 //  =============
00179 //
00180 //  o Create ResultPtr.
00181 
00182 
00183 //  Program Notes:-
00184 //  =============
00185 
00186 //  None.
00187 
00188   LEA_CTOR    //Leak Checker
00189 
00190   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultPtr for " 
00191                           << tableName << " Table Proxy at " 
00192                           << &fTableProxy << endl;
00193   NewQuery(vc, task, findFullTimeWindow);
00194 
00195 }
00196 //.....................................................................
00197 
00198 template<class T>
00199 DbiResultPtr<T>::DbiResultPtr(const string& tableName,
00200                               const DbiSqlContext& context,
00201                               const Dbi::Task& task, 
00202                               const string& data,
00203                               const string& fillOpts,
00204                               Dbi::AbortTest abortTest) :
00205 fAbortTest(abortTest),
00206 fTableProxy(DbiResultPtr<T>::GetTableProxy(tableName)),
00207 fResult(0),
00208 fDetType(context.GetDetector()),
00209 fSimType(context.GetSimFlag())
00210 {
00211 //
00212 //
00213 //  Purpose:  Apply an extended context query to alternative table.
00214 //
00215 //  Arguments: 
00216 //    tableName    in    Name of table to use.
00217 //    context      in    The Validity Context (see DbiSqlContext)
00218 //    task         in    The task of the query. Default: Dbi::kAnyTask, 
00219 //    data         in    Optional SQL extension to secondary query. Default: "".
00220 //    fillOpts     in    Optional fill options (available to DbiTableRow)
00221 //                       Default: "".
00222 //    abortTest    in    Test which if failed triggers abort.
00223 //
00224 //  Return:    n/a
00225 //
00226 //  Contact:   N. West
00227 //
00228 //  Specification:-
00229 //  =============
00230 //
00231 //  o Create ResultPtr.
00232 
00233 
00234 //  Program Notes:-
00235 //  =============
00236 
00237 //  None.
00238 
00239   LEA_CTOR    //Leak Checker
00240 
00241   T pet;
00242   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultPtr for " 
00243            << tableName << " Table Proxy at " 
00244            << &fTableProxy << endl
00245            << "Extended context " << context.GetString() << endl;
00246 
00247   NewQuery(context,task,data,fillOpts);
00248 
00249 }
00250 
00251 //.....................................................................
00252 
00253 template<class T>
00254 DbiResultPtr<T>::DbiResultPtr(const string& tableName,
00255                               const DbiValidityRec& vrec,
00256                               Dbi::AbortTest abortTest) :
00257 fAbortTest(abortTest),
00258 fTableProxy(DbiResultPtr<T>::GetTableProxy(tableName)),
00259 fResult(0)
00260 {
00261 //
00262 //
00263 //  Purpose:  Apply context specific query to alternative table.
00264 //
00265 //  Arguments: 
00266 //    tableName    in    Name of table to use.
00267 //    vrec         in    The validity record that satisfies the query.
00268 //    abortTest    in    Test which if failed triggers abort.
00269 //
00270 //  Return:    n/a
00271 //
00272 //  Contact:   N. West
00273 //
00274 //  Specification:-
00275 //  =============
00276 //
00277 //  o Create ResultPtr.
00278 
00279 
00280 //  Program Notes:-
00281 //  =============
00282 
00283 //  None.
00284 
00285   LEA_CTOR    //Leak Checker
00286 
00287   this->SetContext(vrec);
00288   T pet;
00289   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultPtr for " 
00290                           << tableName << " Table Proxy at " 
00291                           << &fTableProxy << endl;
00292   NewQuery(vrec);
00293 
00294 }
00295 //.....................................................................
00296 
00297 template<class T>
00298 DbiResultPtr<T>::DbiResultPtr(const string& tableName,
00299                               UInt_t seqNo,
00300                               UInt_t dbNo,
00301                               Dbi::AbortTest abortTest) :
00302 fAbortTest(abortTest),
00303 fTableProxy(DbiResultPtr<T>::GetTableProxy(tableName)),
00304 fResult(0)
00305 {
00306 //
00307 //
00308 //  Purpose:  Apply context specific query to alternative table.
00309 //
00310 //  Arguments: 
00311 //    tableName    in    Name of table to use.
00312 //    seqno        in    The SEQNO of validity record that satisfies the query.
00313 //    dbNo         in    The database number holding the validity record
00314 //    abortTest    in    Test which if failed triggers abort.
00315 //
00316 //  Return:    n/a
00317 //
00318 //  Contact:   N. West
00319 //
00320 //  Specification:-
00321 //  =============
00322 //
00323 //  o Create ResultPtr.
00324 
00325 
00326 //  Program Notes:-
00327 //  =============
00328 
00329 //  None.
00330 
00331   LEA_CTOR    //Leak Checker
00332 
00333   
00334   T pet;
00335   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultPtr for " 
00336                           << tableName << " Table Proxy at " 
00337                           << &fTableProxy << endl;
00338   NewQuery(seqNo,dbNo);
00339 
00340 }
00341 
00342 //.....................................................................
00343 
00344 template<class T>
00345 DbiResultPtr<T>::~DbiResultPtr() {
00346 //
00347 //
00348 //  Purpose: Destructor
00349 //
00350 //  Arguments: 
00351 //    None.
00352 //
00353 //  Return:    n/a
00354 //
00355 //  Contact:   N. West
00356 //
00357 //  Specification:-
00358 //  =============
00359 //
00360 //  o  Disconnect any associated Results and destroy DbiResultPtr.
00361 
00362 
00363 //  Program Notes:-
00364 //  =============
00365 
00366 //  None.
00367 
00368   LEA_DTOR    //Leak Checker
00369 
00370   MSG("Dbi", Msg::kVerbose) << "Destroying DbiResultPtr" << endl;
00371   Disconnect();
00372 
00373 }
00374 //.....................................................................
00375 
00376 template<class T>
00377 Bool_t DbiResultPtr<T>::ApplyAbortTest() {
00378 //
00379 //
00380 //  Purpose:  Apply abort test and return true if must abort.
00381 
00382   if (    fAbortTest == Dbi::kDisabled
00383        || this->GetNumRows() > 0 ) return kFALSE;
00384 
00385   bool tableExists = fTableProxy.TableExists();
00386 
00387   if ( ! tableExists ) {
00388     MSG("Dbi",Msg::kFatal) << "Fatal error: table " 
00389                            << fTableProxy.GetTableName() << " does not exist"
00390                            << endl;
00391     return kTRUE;
00392   }
00393   if ( fAbortTest == Dbi::kDataMissing) {
00394     MSG("Dbi",Msg::kFatal) << "Fatal error: no data found in existing table  " 
00395                            << fTableProxy.GetTableName() << endl;
00396     return kTRUE;
00397   }
00398 
00399   return kFALSE;
00400 }
00401 
00402 //.....................................................................
00403 
00404 template<class T>
00405 void DbiResultPtr<T>::Disconnect() {
00406 //
00407 //
00408 //  Purpose: Disconnect previous results. 
00409 //
00410 //  Arguments: None.
00411 //
00412 //  Return:   None. 
00413 //
00414 //  Contact:   N. West
00415 //
00416 //  Specification:-
00417 //  =============
00418 //
00419 //  o  Disconnect any previous results. 
00420 
00421 //  Program Notes:-
00422 //  =============
00423 
00424 //  The Disconnect message is sent to DbiResult so that DbiCache
00425 //  knows when its DbiResult objects are free of clients.
00426 
00427   if ( fResult && DbiTableProxyRegistry::IsActive() ) {
00428     fResult->Disconnect();
00429   }
00430   fResult = 0;
00431 
00432 }
00433 //.....................................................................
00434 
00435 template<class T>
00436 const DbiResultKey* DbiResultPtr<T>::GetKey() const {
00437 //
00438 //
00439 //  Purpose:  Return associated result key or an empty one if none exists.
00440 //
00441 
00442   return fResult ? fResult->GetKey() : DbiResultKey::GetEmptyKey();
00443 
00444 }
00445 //.....................................................................
00446 
00447 template<class T>
00448 Int_t DbiResultPtr<T>::GetResultID() const {
00449 //
00450 //
00451 //  Purpose:  Return the ID of the current DbiResult.
00452 //
00453   return fResult ? fResult->GetID() : 0;
00454 
00455 }
00456 //.....................................................................
00457 
00458 template<class T>
00459 DbiTableProxy& DbiResultPtr<T>::GetTableProxy() {
00460 //
00461 //
00462 //  Purpose:  Private static function to find default associated 
00463 //            DbiTableProxy.
00464 //
00465 //  Arguments: None.
00466 //    
00467 //
00468 //  Return:   Associated DbiTableProxy. 
00469 //
00470 //  Contact:   N. West
00471 //
00472 //  Specification:-
00473 //  =============
00474 //
00475 //  o Ask Registry for default Table Proxy and return it.
00476 
00477 //  Program Notes:-
00478 //  =============
00479 
00480 //  This function creates an example Table Row object which
00481 //  DbiTableProxy can copy and then use to make futher copies when 
00482 //  processing Result Sets.
00483 
00484   if ( ! fgTableProxy ) {
00485     T pet;
00486     fgTableProxy = &DbiTableProxyRegistry::Instance()
00487                                      .GetTableProxy(pet.GetName(),&pet);
00488   }
00489   return *fgTableProxy;
00490 }
00491 
00492 //.....................................................................
00493 
00494 template<class T>
00495 DbiTableProxy& DbiResultPtr<T>::GetTableProxy(const string& tableName){
00496 //
00497 //
00498 //  Purpose:  Private static function to find an alternative 
00499 //            associated DbiTableProxy.
00500 //
00501 //  Arguments: 
00502 //    tableName    in    Alternative table name
00503 //
00504 //  Return:   Associated DbiTableProxy. 
00505 //
00506 //  Contact:   N. West
00507 //
00508 //  Specification:-
00509 //  =============
00510 //
00511 //  o Ask Registry for alternative  Table Proxy and return it.
00512 
00513 //  Program Notes:-
00514 //  =============
00515 
00516 //  This function creates an example Table Row object which
00517 //  DbiTableProxy can copy and then use to make futher copies when 
00518 //  processing Result Sets.
00519 
00520 
00521 // Check for request for default table.
00522   if ( tableName == "" ) return  DbiResultPtr::GetTableProxy();
00523 
00524 // See if we have seen this name before.
00525   map<string,DbiTableProxy*>::const_iterator itr
00526                                         = fgNameToProxy.find(tableName);
00527   if ( itr != fgNameToProxy.end() ) return *( (*itr).second );
00528   
00529 // No, so ask the Registry for it and save it for next time.
00530   T pet;
00531   DbiTableProxy* proxy = &DbiTableProxyRegistry::Instance()
00532                                      .GetTableProxy(tableName,&pet);
00533   fgNameToProxy[tableName] = proxy;
00534   return *proxy;
00535 }
00536 
00537 //.....................................................................
00538 
00539 template<class T>
00540 UInt_t DbiResultPtr<T>::GetNumRows() const {
00541 //
00542 //
00543 //  Purpose:  Get number or rows in query.
00544 //
00545 //  Arguments: None.
00546 //    
00547 //
00548 //  Return:    Number of rows found in query, = 0 if no or failed query.
00549 //
00550 //  Contact:   N. West
00551 //
00552 //  Specification:-
00553 //  =============
00554 //
00555 //  o Return number of rows found in query, = 0 if no or failed query.
00556 
00557 
00558 //  Program Notes:-
00559 //  =============
00560 
00561 //  None.
00562 
00563   return ( fResult && DbiTableProxyRegistry::IsActive() ) 
00564           ? fResult->GetNumRows() : 0;
00565 
00566 }
00567 //.....................................................................
00568 
00569 template<class T>
00570 const T* DbiResultPtr<T>::GetRow(UInt_t rowNum) const {
00571 //
00572 //
00573 //  Purpose: Return pointer to concrete Table Row object at given row.  
00574 //
00575 //  Arguments: 
00576 //    rowNum       in    Required row number
00577 //
00578 //  Return:        Pointer to concrete Table Row object at given row, 
00579 //                 =0 if none 
00580 //
00581 //  Contact:   N. West
00582 //
00583 //  Specification:-
00584 //  =============
00585 //
00586 //  o Return pointer to concrete Table Row object at given row or 
00587 //    0 if none.
00588 
00589 //  Program Notes:-
00590 //  =============
00591 
00592 // None.
00593 
00594   return ( fResult && DbiTableProxyRegistry::IsActive() ) ?
00595       dynamic_cast<const T*>(fResult->GetTableRow(rowNum))
00596     : 0;
00597 }
00598 //.....................................................................
00599 
00600 template<class T>
00601 const T* DbiResultPtr<T>::GetRowByIndex(UInt_t index) const {
00602 //
00603 //
00604 //  Purpose: Return pointer to concrete Table Row object at given index.
00605 //
00606 //  Arguments: 
00607 //    rowNum       in    Required index number.
00608 //
00609 //  Return:        Pointer to concrete Table Row object at given index, 
00610 //                 =0 if none 
00611 //
00612 //  Contact:   N. West
00613 //
00614 //  Specification:-
00615 //  =============
00616 //
00617 //  o Return pointer to concrete Table Row object at given index or 
00618 //    0 if none.
00619 
00620 //  Program Notes:-
00621 //  =============
00622 
00623 //  None.
00624 
00625   return ( fResult && DbiTableProxyRegistry::IsActive() ) ?
00626       dynamic_cast<const T*>(fResult->GetTableRowByIndex(index))
00627     : 0;
00628 }
00629 
00630 //.....................................................................
00631 
00632 template<class T>
00633 const DbiValidityRec* DbiResultPtr<T>::GetValidityRec(
00634                               const DbiTableRow* row) const {
00635 //
00636 //
00637 //  Purpose:  Return associated DbiValidityRec (if any).
00638 //
00639 //  Contact:   N. West
00640 
00641   return ( fResult && DbiTableProxyRegistry::IsActive() )
00642       ? &(fResult->GetValidityRec(row)) : 0 ;
00643  
00644 }
00645 
00646 //.....................................................................
00647 
00648 template<class T>
00649 UInt_t DbiResultPtr<T>::NextQuery(Bool_t forwards) {
00650 //
00651 //
00652 //  Purpose:  Get next validity range for previous query.
00653 //
00654 //  Arguments: 
00655 //    forwards     in    true to step direction forwards (default)
00656 //
00657 //  Contact:   N. West
00658 //
00659 //  Specification:-
00660 //  =============
00661 //
00662 //  o Take the validity range of the current query and step across 
00663 //    the boundary to the adjacent range.
00664 
00665 
00666 // Door stops.
00667   static VldTimeStamp startOfTime(0,0);
00668   static VldTimeStamp endOfTime(0x7FFFFFFF,0);
00669 
00670   if ( ! fResult ) return 0;
00671 
00672   MSG("Dbi",Msg::kSynopsis)  << "\n\nStarting next query: direction " 
00673                              << ( forwards ?  "forwards" : "backwards" ) << "\n" << endl;
00674 
00675   const DbiValidityRec& vrec = fResult->GetValidityRec();
00676   const VldRange& vrnge      = vrec.GetVldRange();
00677 
00678   // If we are heading towards the final boundary, just return the same query.
00679   if (   forwards && vrnge.GetTimeEnd()   == endOfTime )   return fResult->GetNumRows();
00680   if ( ! forwards && vrnge.GetTimeStart() == startOfTime ) return fResult->GetNumRows();
00681 
00682   // Step across boundary and construct new context.
00683   // The end time limit is exclusive, so stepping to the end
00684   // does cross the boundary
00685   time_t ts = forwards ? vrnge.GetTimeEnd().GetSec()
00686                        : vrnge.GetTimeStart().GetSec() - 1;
00687   VldContext vc(fDetType,fSimType,VldTimeStamp(ts,0));
00688 
00689   return this->NewQuery(vc,vrec.GetTask(), true);
00690 
00691 }
00692 
00693 
00694 //.....................................................................
00695 
00696 template<class T>
00697 UInt_t DbiResultPtr<T>::NewQuery(VldContext vc, 
00698                                  Dbi::Task task,
00699                                  Bool_t findFullTimeWindow) {
00700 //
00701 //
00702 //  Purpose:  Apply new query.
00703 //
00704 //  Arguments: 
00705 //    vc           in    The Validity Context of the new query
00706 //    task         in    The task of the new query
00707 //    findFullTimeWindow
00708 //                 in    Attempt to find full validity of query 
00709 //                        i.e. beyond Dbi::GetTimeGate
00710 //
00711 //
00712 //  Return:    The number of rows retrieved by query.  =0 if error.
00713 //
00714 //  Contact:   N. West
00715 //
00716 //  Specification:-
00717 //  =============
00718 //
00719 //  o Disconnect any previous results and apply new query to
00720 //    associated database table
00721 
00722 //  Program Notes:-
00723 //  =============
00724 
00725 //  None.
00726 
00727   if ( ! DbiTableProxyRegistry::IsActive() ) {
00728     fResult = 0;
00729     return 0;
00730   }
00731   fDetType = vc.GetDetector();
00732   fSimType = vc.GetSimFlag();
00733 
00734   MSG("Dbi",Msg::kSynopsis)  << "\n\nStarting context query: " 
00735                              << vc  << " task " << task << "\n" << endl;
00736 
00737   DbiTimerManager::gTimerManager.RecBegin(fTableProxy.GetTableName(), sizeof(T));
00738   Disconnect();
00739   fResult = fTableProxy.Query(vc,task,findFullTimeWindow);
00740   fResult->Connect();
00741   DbiTimerManager::gTimerManager.RecEnd(fResult->GetNumRows());
00742 
00743   if ( this->ApplyAbortTest() ) {
00744     MSG("Dbi",Msg::kFatal) << "while applying validity context query for "
00745                            << vc.AsString() << " with task " << task << endl;
00746     abort();
00747   }
00748   MSG("Dbi",Msg::kSynopsis)  << "\nCompleted context query: " 
00749                              << vc  << " task " << task 
00750                              << " Found:  " << fResult->GetNumRows() << " rows\n" << endl;
00751   return fResult->GetNumRows();
00752 
00753 }
00754 //.....................................................................
00755 
00756 template<class T>
00757 UInt_t DbiResultPtr<T>::NewQuery(const DbiSqlContext& context,
00758                                  const Dbi::Task& task, 
00759                                  const string& data,
00760                                  const string& fillOpts) {
00761 //
00762 //
00763 //  Purpose:  Apply new query.
00764 //
00765 //  Arguments: 
00766 //    context      in    The Validity Context (see DbiSqlContext)
00767 //    task         in    The task of the query. Default: 0
00768 //    data         in    Optional SQL extension to secondary query. Default: "".
00769 //    fillOpts     in    Optional fill options (available to DbiTableRow)
00770 //
00771 //
00772 //  Return:    The number of rows retrieved by query.  =0 if error.
00773 //
00774 //  Contact:   N. West
00775 //
00776 //  Specification:-
00777 //  =============
00778 //
00779 //  o Disconnect any previous results and apply new query to
00780 //    associated database table
00781 
00782 //  Program Notes:-
00783 //  =============
00784 
00785 //  None.
00786 
00787   if ( ! DbiTableProxyRegistry::IsActive() ) {
00788     fResult = 0;
00789     return 0;
00790   }
00791   fDetType = context.GetDetector();
00792   fSimType = context.GetSimFlag();
00793 
00794   MSG("Dbi",Msg::kSynopsis)  << "\n\nStarting extended context query: " 
00795                              << context.GetString()  << " task " << task 
00796                              << " data " << data << " fillOpts " << fillOpts << "\n" <<endl;
00797 
00798   DbiTimerManager::gTimerManager.RecBegin(fTableProxy.GetTableName(), sizeof(T));
00799   Disconnect();
00800   fResult = fTableProxy.Query(context.GetString(),task,data,fillOpts);
00801   fResult->Connect();
00802   DbiTimerManager::gTimerManager.RecEnd(fResult->GetNumRows());
00803   if ( this->ApplyAbortTest() ) {
00804     MSG("Dbi",Msg::kFatal) << "while applying extended context query for "
00805                            <<  context.c_str()<< " with task " << task 
00806                            << " secondary query SQL: " << data
00807                            << "  and fill options: " << fillOpts << endl;
00808     abort();
00809   }
00810 
00811   MSG("Dbi",Msg::kSynopsis)  << "\n\nCompleted extended context query: " 
00812                              << context.GetString()  << " task " << task 
00813                              << " data " << data << " fillOpts" << fillOpts 
00814                              << " Found:  " << fResult->GetNumRows() << " rows\n" << endl;
00815 
00816   return fResult->GetNumRows();
00817 
00818 }
00819 //.....................................................................
00820 
00821 template<class T>
00822 UInt_t DbiResultPtr<T>::NewQuery(const DbiValidityRec& vrec) {
00823 //
00824 //
00825 //  Purpose:  Apply new query.
00826 //
00827 //  Arguments: 
00828 //    vrec         in    The validity record that satisfies the query.
00829 //
00830 //
00831 //  Return:    The number of rows retrieved by query.  =0 if error.
00832 //
00833 //  Contact:   N. West
00834 //
00835 //  Specification:-
00836 //  =============
00837 //
00838 //  o Disconnect any previous results and apply new query to
00839 //    associated database table
00840 
00841 //  Program Notes:-
00842 //  =============
00843 
00844 //  None.
00845 
00846   if ( ! DbiTableProxyRegistry::IsActive() ) {
00847     fResult = 0;
00848     return 0;
00849   }
00850   MSG("Dbi",Msg::kSynopsis)  << "\n\nStarting DbiValidityRec query: " 
00851                              << vrec << "\n" << endl;
00852 
00853   this->SetContext(vrec);
00854   DbiTimerManager::gTimerManager.RecBegin(fTableProxy.GetTableName(), sizeof(T));
00855   Disconnect();
00856 
00857 // Play safe and don't allow result to be used; it's validity may not
00858 // have been trimmed by neighbouring records.
00859   fResult = fTableProxy.Query(vrec,kFALSE);
00860   fResult->Connect();
00861   DbiTimerManager::gTimerManager.RecEnd(fResult->GetNumRows());
00862   if ( this->ApplyAbortTest() ) {
00863     MSG("Dbi",Msg::kFatal) << "while applying validity rec query for "
00864                            << vrec << endl;
00865     abort();
00866   }
00867   MSG("Dbi",Msg::kSynopsis)  << "\n\nCompletedDbiValidityRec query: " 
00868                              << vrec 
00869                              << " Found:  " << fResult->GetNumRows() << " rows\n"  << endl;
00870   return fResult->GetNumRows();
00871 
00872 }
00873 //.....................................................................
00874 
00875 template<class T>
00876 UInt_t DbiResultPtr<T>::NewQuery(UInt_t seqNo,UInt_t dbNo) {
00877 //
00878 //
00879 //  Purpose:  Apply new query.
00880 //    seqno        in    The SEQNO of validity record that satisfies the query.
00881 //    dbNo         in    The database number holding the validity record
00882 //
00883 //  Arguments: 
00884 //
00885 //
00886 //  Return:    The number of rows retrieved by query.  =0 if error.
00887 //
00888 //  Contact:   N. West
00889 //
00890 //  Specification:-
00891 //  =============
00892 //
00893 //  o Disconnect any previous results and apply new query to
00894 //    associated database table
00895 
00896 //  Program Notes:-
00897 //  =============
00898 
00899 //  None.
00900 
00901   if ( ! DbiTableProxyRegistry::IsActive() ) {
00902     fResult = 0;
00903     return 0;
00904   }
00905   MSG("Dbi",Msg::kSynopsis)  << "\n\nStarting SeqNo query: " 
00906                              << seqNo << "\n" << endl;
00907   DbiTimerManager::gTimerManager.RecBegin(fTableProxy.GetTableName(), sizeof(T));
00908   Disconnect();
00909   fResult = fTableProxy.Query(seqNo,dbNo);
00910   fResult->Connect();
00911   DbiTimerManager::gTimerManager.RecEnd(fResult->GetNumRows());
00912   if ( this->ApplyAbortTest() ) {
00913     MSG("Dbi",Msg::kFatal) << "while applying SEQNO query for "
00914                            << seqNo << " on database " << dbNo << endl;
00915     abort();
00916   }
00917   this->SetContext(fResult->GetValidityRec());
00918   MSG("Dbi",Msg::kSynopsis)  << "\n\nCompleted SeqNo query: " 
00919                              << seqNo
00920                              << " Found:  " << fResult->GetNumRows() << " rows\n" << endl;
00921   return fResult->GetNumRows();
00922 
00923 }
00924 
00925 //.....................................................................
00926 
00927 template<class T>
00928 Bool_t DbiResultPtr<T>::ResultsFromDb() const {
00929 //
00930 //
00931 //  Purpose: Return true if at least part of result comes directly from
00932 //           database (as opposed to memory or level 2 disk cache). 
00933 
00934   return fResult ? fResult->ResultsFromDb() : kFALSE;
00935 
00936 }
00937 //.....................................................................
00938 
00939 template<class T>
00940 void DbiResultPtr<T>::SetContext(const DbiValidityRec& vrec) {
00941 //
00942 //
00943 //  Purpose:  Attempt to construct context detector type and sim flag
00944 //
00945 //  Arguments: 
00946 //    vrec         in    DbiValidityRec from which to construct context
00947 //
00948 //
00949 //  Contact:   N. West
00950 //
00951 
00952 //  Program Notes:-
00953 //  =============
00954 
00955 //  Queries that step to an adjacent validity range need a detector 
00956 //  type and simulation flag from which to construct a context. However
00957 //  queries can be made using a DbiValidityRec and then only a VldRange
00958 //  is known so all we can do is choose representative values from
00959 //  its detector and simulation masks.
00960 
00961   const VldRange& vrng = vrec.GetVldRange();
00962   Int_t detMask        = vrng.GetDetectorMask();
00963   Int_t simMask        = vrng.GetSimMask();
00964 
00965   fDetType = Detector::kUnknown;
00966   if      ( detMask & Detector::kFar )      fDetType = Detector::kFar;
00967   else if ( detMask & Detector::kNear)      fDetType = Detector::kNear;
00968   else if ( detMask & Detector::kCalDet)    fDetType = Detector::kCalDet;
00969   else if ( detMask & Detector::kCalib)     fDetType = Detector::kCalib;
00970   else if ( detMask & Detector::kTestStand) fDetType = Detector::kTestStand;
00971   else if ( detMask & Detector::kMapper)    fDetType = Detector::kMapper;
00972 
00973   fSimType = SimFlag::kUnknown;
00974   if      ( simMask & SimFlag::kData)        fSimType = SimFlag::kData;
00975   else if ( simMask & SimFlag::kMC)          fSimType = SimFlag::kMC;
00976   else if ( simMask & SimFlag::kReroot)      fSimType = SimFlag::kReroot;
00977   else if ( simMask & SimFlag::kDaqFakeData) fSimType = SimFlag::kDaqFakeData;
00978 
00979 }
00980 
00981 //.....................................................................
00982 
00983 template<class T>
00984 DbiTableProxy& DbiResultPtr<T>::TableProxy() const  {
00985 //
00986 //
00987 //  Purpose:  Return associated DbiTableProxy (if any).
00988 //
00989 //  Contact:   N. West
00990 
00991   assert( DbiTableProxyRegistry::IsActive() );
00992   return fTableProxy; 
00993 }
00994 
00995 /*    Template for New Member Function
00996 
00997 //.....................................................................
00998 
00999 template<class T>
01000 DbiResultPtr<T>:: {
01001 //
01002 //
01003 //  Purpose:  
01004 //
01005 //  Arguments: 
01006 //    xxxxxxxxx    in    yyyyyy
01007 //
01008 //  Return:    
01009 //
01010 //  Contact:   N. West
01011 //
01012 //  Specification:-
01013 //  =============
01014 //
01015 //  o 
01016 
01017 //  Program Notes:-
01018 //  =============
01019 
01020 //  None.
01021 
01022 
01023 }
01024 
01025 */
01026 

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