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

DbiWriter.tpl

Go to the documentation of this file.
00001 
00002 // $id: DbiWriter.tpl,v 1.11 2005/11/11 09:27:26 west Exp $
00003 //
00004 // DbiWriter
00005 //
00006 // Package: Dbi (Database Interface).
00007 
00008 #include <cassert>
00009 #include <fstream>
00010 
00011 #include "DatabaseInterface/DbiCascader.h"
00012 #include "DatabaseInterface/DbiOutRowStream.h"
00013 #include "DatabaseInterface/DbiResultPtr.h"
00014 #include "DatabaseInterface/DbiSqlValPacket.h"
00015 #include "DatabaseInterface/DbiTableProxy.h"
00016 #include "DatabaseInterface/DbiWriter.h"
00017 #include "LeakChecker/Lea.h"
00018 #include "MessageService/MsgService.h"
00019 
00020 
00021 ClassImpT(DbiWriter,T)
00022 
00023 //   Definition of static data members
00024 //   *********************************
00025 
00026 //CVSID("$Id: DbiWriter.tpl,v 1.16 2008/06/03 06:20:01 nwest Exp $");
00027 
00028 //    Definition of all member functions (static or otherwise)
00029 //    *******************************************************
00030 //
00031 //    -  ordered: ctors, dtor, operators then in alphabetical order.
00032 
00033 //.....................................................................
00034 
00035 template<class T>
00036 DbiWriter<T>::DbiWriter() :
00037 fAggregateNo(-2),
00038 fDbNo(0),
00039 fPacket(new DbiSqlValPacket),
00040 fRequireGlobalSeqno(0),
00041 fTableProxy(&DbiWriter<T>::GetTableProxy()),
00042 fTableName(fTableProxy->GetTableName()),
00043 fUseOverlayCreationDate(kFALSE),
00044 fValidRec(0),
00045 fLogEntry(fTableName)
00046 {
00047 //
00048 //  Purpose:  Default Constructor
00049 //
00050 //  Contact:   N. West
00051 //
00052 //  Specification:-
00053 //  =============
00054 //
00055 //  o Create Writer.
00056 
00057 
00058 //  Program Notes:-
00059 //  =============
00060 
00061 //  Creates an unusable DbiWriter - only present to keep rootcint happy.
00062 
00063   LEA_CTOR    //Leak Checker
00064 
00065   MSG("Dbi", Msg::kVerbose) 
00066         << "Creating default DbiWriter for " << fTableName << endl;
00067 
00068 }
00069 //.....................................................................
00070 
00071 template<class T>
00072 DbiWriter<T>::DbiWriter(const VldRange& vr,
00073                         Int_t aggNo,
00074                         Dbi::Task task,
00075                         VldTimeStamp creationDate,
00076                         UInt_t dbNo,
00077                         const std::string& logComment,
00078                         const std::string& tableName) :
00079 fAggregateNo(aggNo),
00080 fDbNo(dbNo),
00081 fPacket(new DbiSqlValPacket),
00082 fRequireGlobalSeqno(0),
00083 fTableProxy(&DbiWriter<T>::GetTableProxy(tableName)),
00084 fTableName(fTableProxy->GetTableName()),
00085 fUseOverlayCreationDate(creationDate == VldTimeStamp(0,0)),
00086 fValidRec(0),
00087 fLogEntry(fTableName,logComment,vr.GetDetectorMask(),vr.GetSimMask(),task)
00088 {
00089 //
00090 //  Purpose:  Constructor
00091 //
00092 //  Arguments:
00093 //    vr            in       Validity range of validity set.
00094 //    aggNo         in       Aggregate number of validity set.
00095 //    task          in       Task of validity set.
00096 //    creationDate  in       Creation date of validity set.
00097 //    dbNo          in       Database number in cascade (starting at 0).
00098 //    logComment    in       Reason for update.
00099 //    tableName     in       Table name (default: "" - get table name from object type)
00100 //
00101 //  Return:    n/a
00102 //
00103 //  Contact:   N. West
00104 //
00105 //  Specification:-
00106 //  =============
00107 //
00108 //  o Create Writer.
00109 
00110 
00111 //  Program Notes:-
00112 //  =============
00113 
00114 //  None.
00115 
00116   LEA_CTOR    //Leak Checker
00117 
00118   MSG("Dbi", Msg::kVerbose)
00119         << "Creating DbiWriter for " << fTableName << endl;
00120 
00121   Open(vr,aggNo,task,creationDate,dbNo,logComment);
00122 
00123 }
00124 
00125 //.....................................................................
00126 
00127 template<class T>
00128 DbiWriter<T>::DbiWriter(const VldRange& vr,
00129                         Int_t aggNo,
00130                         Dbi::Task task,
00131                         VldTimeStamp creationDate,
00132                         const std::string& dbName,
00133                         const std::string& logComment,
00134                         const std::string& tableName) :
00135 fAggregateNo(aggNo),
00136 fPacket(new DbiSqlValPacket),
00137 fRequireGlobalSeqno(0),
00138 fTableProxy(&DbiWriter<T>::GetTableProxy(tableName)),
00139 fTableName(fTableProxy->GetTableName()),
00140 fUseOverlayCreationDate(creationDate == VldTimeStamp(0,0)),
00141 fValidRec(0),
00142 fLogEntry(fTableName,logComment,vr.GetDetectorMask(),vr.GetSimMask(),task)
00143 {
00144 //
00145 //  Purpose:  Constructor
00146 //
00147 //  Arguments:
00148 //    vr            in       Validity range of validity set.
00149 //    aggNo         in       Aggregate number of validity set.
00150 //    task          in       Task of validity set.
00151 //    creationDate  in       Creation date of validity set.
00152 //    dbName        in       Database name.
00153 //    logComment    in       Reason for update.
00154 //    tableName     in       Table name (default: "" - get table name from object type)
00155 //
00156 //  Return:    n/a
00157 //
00158 //  Contact:   N. West
00159 //
00160 //  Specification:-
00161 //  =============
00162 //
00163 //  o Create Writer.
00164 
00165 
00166 //  Program Notes:-
00167 //  =============
00168 
00169 //  None.
00170 
00171   LEA_CTOR    //Leak Checker
00172 
00173   MSG("Dbi", Msg::kVerbose)
00174         << "Creating DbiWriter for " << fTableName << endl;
00175 
00176   Open(vr,aggNo,task,creationDate,dbName,logComment);
00177 
00178 }
00179 
00180 //.....................................................................
00181 
00182 template<class T>
00183 DbiWriter<T>::DbiWriter(const DbiValidityRec& vrec,
00184                         UInt_t dbNo,
00185                         const std::string& logComment) :
00186 fAggregateNo(0),
00187 fDbNo(dbNo),
00188 fPacket(new DbiSqlValPacket),
00189 fRequireGlobalSeqno(0),
00190 fTableProxy(0),
00191 fUseOverlayCreationDate(kFALSE),
00192 fValidRec(new DbiValidityRec(vrec)),
00193 fLogEntry(fTableName,logComment,vrec.GetVldRange().GetDetectorMask(),
00194           vrec.GetVldRange().GetSimMask(),vrec.GetTask())
00195 {
00196 //
00197 //  Purpose:  Constructor
00198 //
00199 //  Arguments: 
00200 //    vrec          in       Validity record for set.
00201 //                           MUST have an associated DbiTableProxy
00202 //    dbNo          in       Database number in cascade (starting at 0).
00203 //    logComment    in       Reason for update.
00204 //
00205 //
00206 //  Return:    n/a
00207 //
00208 //  Contact:   N. West
00209 //
00210 //  Specification:-
00211 //  =============
00212 //
00213 //  o Create Writer.
00214 
00215 
00216 //  Program Notes:-
00217 //  =============
00218 
00219 //  None.
00220 
00221   LEA_CTOR    //Leak Checker
00222 
00223   T pet;
00224   MSG("Dbi", Msg::kVerbose) 
00225         << "Creating DbiWriter for " << pet.GetName() << endl;
00226   
00227   this->Open(vrec,dbNo,logComment);
00228 
00229 }
00230 
00231 //.....................................................................
00232 
00233 template<class T>
00234 DbiWriter<T>::DbiWriter(const DbiValidityRec& vrec,
00235                         const std::string& dbName,
00236                         const std::string& logComment) :
00237 fAggregateNo(0),
00238 
00239 fPacket(new DbiSqlValPacket),
00240 fRequireGlobalSeqno(0),
00241 fTableProxy(0),
00242 fUseOverlayCreationDate(kFALSE),
00243 fValidRec(new DbiValidityRec(vrec)),
00244 fLogEntry(fTableName,logComment,vrec.GetVldRange().GetDetectorMask(),
00245           vrec.GetVldRange().GetSimMask(),vrec.GetTask())
00246 {
00247 //
00248 //  Purpose:  Constructor
00249 //
00250 //  Arguments: 
00251 //    vrec          in       Validity record for set.
00252 //                           MUST have an associated DbiTableProxy
00253 //    dbName        in       Database name.
00254 //    logComment    in       Reason for update.
00255 //
00256 //
00257 //  Return:    n/a
00258 //
00259 //  Contact:   N. West
00260 //
00261 //  Specification:-
00262 //  =============
00263 //
00264 //  o Create Writer.
00265 
00266 
00267 //  Program Notes:-
00268 //  =============
00269 
00270 //  None.
00271 
00272   LEA_CTOR    //Leak Checker
00273 
00274   T pet;
00275   MSG("Dbi", Msg::kVerbose) 
00276         << "Creating DbiWriter for " << pet.GetName() << endl;
00277   
00278   this->Open(vrec,dbName,logComment);
00279 
00280 }
00281 
00282 //.....................................................................
00283 
00284 template<class T>
00285 DbiWriter<T>::~DbiWriter() {
00286 //
00287 //
00288 //  Purpose: Destructor
00289 
00290   LEA_DTOR    //Leak Checker
00291 
00292   MSG("Dbi", Msg::kVerbose) << "Destroying DbiWriter" << endl;
00293 
00294   Reset();
00295   delete fPacket;
00296   fPacket = 0;
00297   delete fValidRec;
00298   fValidRec = 0;
00299 
00300 }
00301 
00302 
00303 //.....................................................................
00304 
00305 template<class T>
00306 DbiWriter<T>& DbiWriter<T>::operator<<(const T& row) {
00307 //
00308 //
00309 //  Purpose:  Stream row into this DbiWriter.
00310 
00311   if ( ! this->IsOpen() ) return *this;
00312 
00313   Int_t AggNoRow =  row.GetAggregateNo();
00314   if (  fAggregateNo != AggNoRow ) {
00315     MSG("Dbi",Msg::kError)
00316       << "Cannot store row data for table  " 
00317       << fTableName
00318       << ", current set has aggregate no.: " << fAggregateNo 
00319       << ", but it has: " << AggNoRow
00320       << " \n  closing DbiWriter" << endl;
00321     this->Abort();
00322     return *this;
00323   }
00324   if ( ! fPacket->AddDataRow(*fTableProxy,fValidRec,row) ) {
00325     MSG("Dbi",Msg::kError) << "Closing DbiWriter due to above error." << endl;
00326     this->Abort();
00327   }
00328      
00329   return *this;
00330 
00331 }
00332 
00333 //.....................................................................
00334 
00335 template<class T>
00336 Bool_t DbiWriter<T>::CanOutput(Bool_t reportErrors) const {
00337 //
00338 //
00339 //  Purpose:  Return true if open and ready to receive/output  data. 
00340 
00341   if ( ! this->IsOpen(reportErrors) ) return kFALSE;
00342 
00343   if ( this->NeedsLogEntry() && ! fLogEntry.HasReason() ) {
00344     if ( reportErrors ) MSG("Dbi",Msg::kError)
00345       << "Cannot output validity set for table " 
00346       << fTableName
00347       << ", writing to Master DB but no log comment has been supplied." << endl;
00348     return kFALSE;
00349   }
00350 
00351   UInt_t nstmts = fPacket->GetNumSqlStmts();
00352 
00353   if ( nstmts == 0 ) {
00354     // not even a VLD insert
00355     if ( reportErrors ) MSG("Dbi",Msg::kError)
00356       << "Cannot output validity set for table " 
00357       << fTableName
00358       << ", no data has been written." << endl;
00359     return kFALSE;
00360   }
00361 
00362   if ( nstmts == 1 ) {
00363     // if VLD insert present but no data rows, just issue a stern warning
00364     // as it may be intended to obscure now invalid data
00365     string stmt = fPacket->GetStmt(0);
00366     bool isvldentry = 
00367       (stmt.find("INSERT INTO") != string::npos ) &&
00368       (stmt.find("VLD VALUES")  != string::npos);
00369     if ( isvldentry ) {
00370       if ( reportErrors ) MSG("Dbi",Msg::kWarning)
00371         << "VLD entry but no data for " 
00372         << fTableName << endl;
00373     }
00374     else {
00375       // this should never, ever happen ... but let's be paranoid
00376       if ( reportErrors ) {
00377         MSG("Dbi",Msg::kError) 
00378           << "Cannot output validity set for table " 
00379           << fTableName
00380           << ", (no VLD info) no data has been written." << endl;
00381         fPacket->Print();
00382       }
00383       return kFALSE;
00384     }
00385   }
00386 
00387   return kTRUE;
00388 }
00389 
00390 
00391 //.....................................................................
00392 
00393 template<class T>
00394 Bool_t DbiWriter<T>::Close(const char* fileSpec) {
00395 //
00396 //
00397 //  Purpose:  Close current validity set and write it to the database.
00398 //
00399 //  Arguments:
00400 //
00401 //  fileSpec       in   File pointer.  If not null write to file instead of database.
00402 //
00403 //  Return:    kTRUE is I/O successful.
00404 //
00405 //  Contact:   N. West
00406 //
00407 //  Specification:-
00408 //  =============
00409 //
00410 //  o Close current validity set and write it to the database.
00411 
00412 //  Program Notes:-
00413 //  =============
00414 
00415 //  None.
00416 
00417   Bool_t ok = kFALSE;
00418   
00419 // Skip output unless good data to output.
00420 
00421   if ( CanOutput() ) {
00422 
00423 //  Find the next free sequence number.  It must be global if writing to a
00424 //  to a file, otherwise it can be local if DB isn't authorising.
00425     int seqNoType = fileSpec ? 1 : fRequireGlobalSeqno;
00426     Int_t seqNo = fTableProxy->GetCascader().AllocateSeqNo(fTableName,seqNoType,fDbNo);
00427     if ( seqNo <= 0 ) {
00428       MSG("Dbi",Msg::kError)
00429         << "Cannot get sequence number for table " 
00430         << fTableName << endl;
00431     }
00432     
00433     else {
00434 
00435 //  Use overlay creation date if required.
00436       if ( fUseOverlayCreationDate &&  fValidRec 
00437           ) fPacket->SetCreationDate(fTableProxy->QueryOverlayCreationDate(*fValidRec,fDbNo));
00438 
00439 //  Set SEQNO and perform I/O.
00440       fPacket->SetSeqNo(seqNo);
00441       if ( fileSpec ) {
00442         ofstream fs(fileSpec,ios_base::app);
00443         if ( ! fs ) MSG("Dbm", Msg::kError) << "Unable to open " << fileSpec << endl;
00444         else        ok = fPacket->Write(fs,true);
00445       }
00446       else {
00447         ok = fPacket->Store(fDbNo);
00448       }
00449 
00450 //  Record update if I/O successful and required.
00451       if ( ok && this->WritingToMaster() ) {
00452        if ( this->NeedsLogEntry() || fLogEntry.HasReason() )
00453         ok = fLogEntry.Write(fDbNo,seqNo);
00454       }
00455     }
00456   } 
00457   
00458 //  Clear out ready for any further I/O.
00459 
00460   fPacket->Clear();
00461 
00462   return ok;
00463 }
00464 //.....................................................................
00465 
00466 template<class T>
00467 void DbiWriter<T>::CompleteOpen(UInt_t dbNo,
00468                                 const std::string& logComment) {
00469 //
00470 //
00471 //  Purpose:  Complete the open process
00472 //
00473 //  Arguments: 
00474 //    dbNo          in       Database number in cascade (starting at 0).
00475 //    logComment    in       Reason for update.
00476 //
00477 //
00478 //  Specification:-
00479 //  =============
00480 //
00481 //  o Complete reinitialisation for new I/O 
00482 
00483 //  Program Notes:-
00484 //  =============
00485 
00486 //  Assumes that fTableProxy, fUseOverlayCreationDate, fValidRec are 
00487 //  already initialised.
00488 
00489 
00490   fDbNo = dbNo;
00491   if ( (int) fDbNo < 0 ) {
00492     MSG("Dbi",Msg::kError) << "Bad database name/number selected. " << endl;
00493     this->Reset();
00494     return;
00495   }
00496 
00497   fAggregateNo = fValidRec->GetAggregateNo();
00498   fTableName   = fTableProxy->GetTableName(),
00499 
00500 // Recreate validity packet.
00501   fPacket->Recreate(fTableName,
00502                     fValidRec->GetVldRange(),
00503                     fAggregateNo,
00504                     fValidRec->GetTask(),
00505                     fValidRec->GetCreationDate());
00506 
00507 // Recreate log entry.
00508   const VldRange&  vr = fValidRec->GetVldRange();
00509   fLogEntry.Recreate(fTableName,
00510                      logComment,
00511                      vr.GetDetectorMask(),
00512                      vr.GetSimMask(),
00513                      fValidRec->GetTask());
00514 
00515 }
00516 
00517 //.....................................................................
00518 
00519 template<class T>
00520 DbiTableProxy& DbiWriter<T>::GetTableProxy() {
00521 //
00522 //
00523 //  Purpose:  Private static function to find default associated 
00524 //            DbiTableProxy.
00525 
00526 //  Program Notes:-
00527 //  =============
00528 
00529 //  As DbiResultPtr classes are in 1:1 correspondance with DbiWriter
00530 //  classes, DbiWriter uses the static methods from DbiResultPtr
00531 //  to find the associated DbiTableProxy.
00532 
00533   return DbiResultPtr<T>::GetTableProxy();
00534 }
00535 
00536 //.....................................................................
00537 
00538 template<class T>
00539 DbiTableProxy& DbiWriter<T>::GetTableProxy(
00540                                            const std::string& tableName){
00541 //
00542 //
00543 //  Purpose:  Private static function to find an alternative 
00544 //            associated DbiTableProxy.
00545 //
00546 //  Arguments: 
00547 //    tableName    in    Alternative table name
00548 //
00549 //  Return:   Associated DbiTableProxy. 
00550 //
00551 //  Contact:   N. West
00552 //
00553 //  Specification:-
00554 //  =============
00555 //
00556 //  o Ask Registry for alternative  Table Proxy and return it.
00557 
00558 //  As DbiResultPtr classes are in 1:1 correspondance with DbiWriter
00559 //  classes, DbiWriter uses the static methods from DbiResultPtr
00560 //  to find the associated DbiTableProxy.
00561 
00562   return DbiResultPtr<T>::GetTableProxy(tableName);
00563 
00564 }
00565 //.....................................................................
00566 
00567 template<class T>
00568 Bool_t DbiWriter<T>::IsOpen(Bool_t reportErrors) const {
00569 //
00570 //
00571 //  Purpose:  Return true if open and ready to receive data.
00572 
00573   if ( ! DbiTableProxyRegistry::IsActive()  ) {
00574     if ( reportErrors ) MSG("Dbi",Msg::kError)
00575       << "Cannot use DbiWriter, the DBI has been shutdown." << endl;
00576   }
00577   else if (    !fValidRec
00578             ||  fPacket->GetNumSqlStmts() < 1 ) {
00579     if ( reportErrors ) MSG("Dbi",Msg::kError)
00580       << "Cannot do I/O on DbiWriter for " 
00581       << fTableName
00582       <<", it is currently closed." << endl;
00583   }
00584   else return kTRUE;
00585 
00586   return kFALSE;
00587 
00588 }
00589 //.....................................................................
00590 
00591 template<class T>
00592 Bool_t DbiWriter<T>::NeedsLogEntry() const {
00593 //
00594 //
00595 //  Purpose:  Return true if a log entry is required.
00596 
00597   // Some tables are created automatically so don't require entries.
00598   string tableName(fTableName);
00599   if (    tableName.substr(0,7)  == "BEAMMON"
00600        || tableName.substr(0,16) == "BFLDDBICOILSTATE"
00601        || tableName.substr(0,3)  == "CAL"
00602        || tableName.substr(0,20) == "CANDDIGITBADCHANNELS"
00603        || tableName.substr(0,3)  == "DBU"
00604        || tableName.substr(0,3)  == "DCS"
00605        || tableName.substr(0,6)  == "PULSER"
00606        || tableName.substr(0,9)  == "SPILLTIME" ) return kFALSE;
00607 
00608   // All other tables need entries if writing to a Master database.
00609 
00610   return this->WritingToMaster();
00611 
00612 }
00613 
00614 //.....................................................................
00615 
00616 template<class T>
00617 Bool_t DbiWriter<T>::Open (const VldRange& vr,
00618                            Int_t aggNo,
00619                            Dbi::Task task,
00620                            VldTimeStamp creationDate,
00621                            UInt_t dbNo,
00622                            const std::string& logComment) {
00623 //
00624 //
00625 //  Purpose:  Output any existing data and open new validity set.
00626 //
00627 //  Arguments: 
00628 //    vr            in       Validity range of validity set.
00629 //    aggNo         in       Aggregate number of validity set.
00630 //    task          in       Task of validity set.
00631 //    creationDate  in       Creation date of validity set.
00632 //    dbNo          in       Database number in cascade (starting at 0).
00633 //    logComment    in       Reason for update.
00634 //
00635 //  Return:    kTRUE if no errors detected.
00636 //
00637 //  Contact:   N. West
00638 //
00639 //  Specification:-
00640 //  =============
00641 //
00642 //  o Output any existing data and open new validity set.
00643 
00644 //  Program Notes:-
00645 //  =============
00646 
00647 //  None.
00648 
00649   bool ok = true;
00650 
00651   if ( ! DbiTableProxyRegistry::IsActive() ) return kFALSE;
00652   if ( this->CanOutput(kFALSE) ) ok = Close();
00653 
00654 // Test for special creation date.
00655   fUseOverlayCreationDate = creationDate == VldTimeStamp(0,0);
00656 
00657 //  Create a validity record.
00658   delete fValidRec;
00659   fValidRec = new DbiValidityRec(vr,task,aggNo,0,0,kFALSE,creationDate);
00660 
00661 // Get a proxy.
00662   fTableProxy = &DbiWriter<T>::GetTableProxy(fTableName); 
00663 
00664 // Complete opening.
00665   this->CompleteOpen(dbNo,logComment);
00666   return ok;
00667 
00668 }
00669 //.....................................................................
00670 
00671 template<class T>
00672 Bool_t DbiWriter<T>::Open (const VldRange& vr,
00673                            Int_t aggNo,
00674                            Dbi::Task task,
00675                            VldTimeStamp creationDate,
00676                            const string& dbName,
00677                            const std::string& logComment) {
00678 //
00679 //
00680 //  Purpose:  Output any existing data and open new validity set.
00681 //
00682 //  Arguments: 
00683 //    vr            in       Validity range of validity set.
00684 //    aggNo         in       Aggregate number of validity set.
00685 //    task          in       Task of validity set.
00686 //    creationDate  in       Creation date of validity set.
00687 //    dbName        in       Database name.
00688 //    logComment    in       Reason for update.
00689 //
00690 //  Return:    kTRUE if no errors detected.
00691 
00692   this->SetDbName(dbName);
00693   return this->Open(vr,
00694                     aggNo,
00695                     task,
00696                     creationDate,
00697                     fDbNo,
00698                     logComment);
00699 
00700 }
00701 
00702 //.....................................................................
00703 
00704 template<class T>
00705 Bool_t DbiWriter<T>::Open(const DbiValidityRec& vrec,
00706                           UInt_t dbNo,
00707                           const std::string& logComment) {
00708 
00709 //
00710 //  Purpose:  Output any existing data and open new validity set.
00711 //
00712 //  Arguments: 
00713 //    vrec          in       Validity record for set.
00714 //                           MUST have an associated DbiTableProxy
00715 //    dbNo          in       Database number in cascade (starting at 0).
00716 //    logComment    in       Reason for update.
00717 //
00718 //
00719 //  Return:    kTRUE if no errors detected.
00720 //
00721 //  Contact:   N. West
00722 //
00723 //  Specification:-
00724 //  =============
00725 //
00726 //  o Output any existing data and open new validity set.
00727 
00728 
00729 //  Program Notes:-
00730 //  =============
00731 
00732 //  None.
00733 
00734   bool ok = true;
00735 
00736   if ( ! DbiTableProxyRegistry::IsActive() ) return kFALSE;
00737   if ( this->CanOutput(kFALSE) ) ok = Close();
00738 
00739   
00740 // Check that vrec is associated with the right table, but waive
00741 // test for DbiConfigSet so that it can be used with any.
00742   const DbiTableProxy& proxyDefault = DbiWriter<T>::GetTableProxy();
00743   const DbiTableProxy& proxyVrec    = *vrec.GetTableProxy();
00744   if (    proxyDefault.GetTableName() != "DBICONFIGSET"
00745        &&    proxyVrec.GetTableName() != proxyDefault.GetTableName() ) {
00746     MSG("Dbi",Msg::kError) 
00747        << "Unable to create DbiWriter from query:" << endl
00748        << vrec
00749        << " was filled by " << proxyVrec.GetTableName() 
00750        << " not by " << proxyDefault.GetTableName() << endl;
00751     this->Reset();
00752     return false;
00753   }
00754   else { 
00755 //  Have to cast away const - DbiWriter needs a modifiable DbiTableProxy.
00756     fTableProxy = const_cast<DbiTableProxy*>(&proxyVrec);
00757   }
00758 
00759   fUseOverlayCreationDate = vrec.GetCreationDate() == VldTimeStamp(0,0);
00760 
00761   delete fValidRec;
00762   fValidRec = new DbiValidityRec(vrec);
00763 
00764 // Complete opening.
00765   this->CompleteOpen(dbNo,logComment);
00766   return ok;
00767 
00768 }
00769 
00770 //.....................................................................
00771 
00772 template<class T>
00773 Bool_t DbiWriter<T>::Open(const DbiValidityRec& vrec,
00774                           const string& dbName,
00775                           const std::string& logComment) {
00776 
00777 //
00778 //  Purpose:  Output any existing data and open new validity set.
00779 //
00780 //  Arguments: 
00781 //    vrec          in       Validity record for set.
00782 //                           MUST have an associated DbiTableProxy
00783 //    dbName        in       Database name.
00784 //    logComment    in       Reason for update.
00785 //
00786 //
00787 //  Return:    kTRUE if no errors detected.
00788 
00789   this->SetDbName(dbName);
00790   return this->Open(vrec,
00791                     fDbNo,
00792                     logComment);
00793 
00794 }
00795 
00796 //.....................................................................
00797 
00798 template<class T>
00799 void DbiWriter<T>::Reset() {
00800 //
00801 //
00802 //  Purpose:  Clear out data and reset ready for any further I/O.
00803 //
00804 //  Arguments: None.
00805 //
00806 //  Return:    None.
00807 //
00808 //  Contact:   N. West
00809 //
00810 //  Specification:-
00811 //  =============
00812 //
00813 //  o Clear out data and reset ready for any further I/O.
00814 
00815 //  Program Notes:-
00816 //  =============
00817 
00818 //  None.
00819 
00820   fAggregateNo = 0;
00821   fDbNo        = 0;
00822   fPacket->Clear();
00823   fTableProxy  = &DbiWriter<T>::GetTableProxy();
00824   fTableName   = fTableProxy->GetTableName();
00825 
00826   delete fValidRec;
00827   fValidRec    = 0;
00828 
00829 }
00830 //.....................................................................
00831 
00832 template<class T>
00833 void DbiWriter<T>::SetDbName(const string& dbName) {
00834 //
00835 //
00836 //  Purpose:  Set Database entry by name.  Default: entry 0.
00837 
00838   if ( dbName == "" ) {
00839     fDbNo = 0;
00840   }
00841   else {
00842     fDbNo =  DbiTableProxyRegistry::Instance().GetCascader().GetDbNo(dbName);
00843   }
00844 }
00845 
00846 //.....................................................................
00847 
00848 template<class T>
00849 void DbiWriter<T>::SetLogComment(const std::string& reason) {
00850 //
00851 //
00852 //  Purpose:  Set log comment.
00853 
00854   fLogEntry.SetReason(reason);
00855 
00856 }
00857 
00858 //.....................................................................
00859 
00860 template<class T>
00861 DbiTableProxy& DbiWriter<T>::TableProxy() const  {
00862 //
00863 //
00864 //  Purpose:  Return DbiTableProxy.
00865 //
00866 
00867   assert( DbiTableProxyRegistry::IsActive() );
00868   return *fTableProxy;
00869 }
00870 
00871 //.....................................................................
00872 
00873 template<class T>
00874 Bool_t DbiWriter<T>::WritingToMaster() const {
00875 //
00876 //
00877 //  Purpose:  Return true if writing permanent data to a Master Database.
00878 
00879 
00880   DbiCascader& cascader = DbiTableProxyRegistry::Instance().GetCascader();
00881   return  (    fDbNo == (UInt_t) cascader.GetAuthorisingDbNo()
00882             && ! cascader.IsTemporaryTable(fTableName,fDbNo));
00883 
00884 }
00885 
00886 /*    Template for New Member Function
00887 
00888 //.....................................................................
00889 
00890 template<class T>
00891 DbiWriter<T>:: {
00892 //
00893 //
00894 //  Purpose:  
00895 //
00896 //  Arguments: 
00897 //    xxxxxxxxx    in    yyyyyy
00898 //
00899 //  Return:    
00900 //
00901 //  Contact:   N. West
00902 //
00903 //  Specification:-
00904 //  =============
00905 //
00906 //  o 
00907 
00908 //  Program Notes:-
00909 //  =============
00910 
00911 //  None.
00912 
00913 
00914 }
00915 
00916 */
00917 

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