DbiWriter< T > Class Template Reference

#include <DbiWriter.h>

List of all members.

Public Member Functions

 DbiWriter ()
 DbiWriter (const VldRange &vr, Int_t aggNo, Dbi::Task task, VldTimeStamp creationDate, const std::string &dbName, const std::string &logComment="", const std::string &tableName="")
 DbiWriter (const VldRange &vr, Int_t aggNo, Dbi::Task task=0, VldTimeStamp creationDate=VldTimeStamp(0, 0), UInt_t dbNo=0, const std::string &logComment="", const std::string &tableName="")
 DbiWriter (const DbiValidityRec &vrec, const std::string &dbName, const std::string &logComment="")
 DbiWriter (const DbiValidityRec &vrec, UInt_t dbNo=0, const std::string &logComment="")
virtual ~DbiWriter ()
DbiTableProxyTableProxy () const
Bool_t IsOpen (Bool_t reportErrors=kTRUE) const
 Open and ready to receive data.
Bool_t CanOutput (Bool_t reportErrors=kTRUE) const
 Open and ready to receive/output data.
void SetDbNo (UInt_t dbNo)
void SetDbName (const string &dbName)
void SetLogComment (const std::string &reason)
void SetRequireGlobalSeqno (Int_t requireGlobal)
void SetOverlayCreationDate ()
void Abort ()
Bool_t Close (const char *fileSpec=0)
Bool_t Open (const VldRange &vr, Int_t aggNo, Dbi::Task task, VldTimeStamp creationDate, const string &dbName, const std::string &logComment="")
Bool_t Open (const VldRange &vr, Int_t aggNo, Dbi::Task task=0, VldTimeStamp creationDate=VldTimeStamp(), UInt_t dbNo=0, const std::string &logComment="")
Bool_t Open (const DbiValidityRec &vrec, const string &dbName, const std::string &logComment="")
Bool_t Open (const DbiValidityRec &vrec, UInt_t dbNo=0, const std::string &logComment="")
DbiWriter< T > & operator<< (const T &row)

Private Member Functions

Bool_t NeedsLogEntry () const
Bool_t WritingToMaster () const
 DbiWriter (const DbiWriter &)
DbiWriteroperator= (const DbiWriter &)
void CompleteOpen (UInt_t dbNo=0, const std::string &logComment="")
void Reset ()

Static Private Member Functions

static DbiTableProxyGetTableProxy ()
static DbiTableProxyGetTableProxy (const std::string &tableName)

Private Attributes

Int_t fAggregateNo
 Aggregate noumber for set.
UInt_t fDbNo
 Database number in cascade.
DbiSqlValPacketfPacket
 The assembled record to be output. Never null.
Int_t fRequireGlobalSeqno
 Controls SEQNO type (see DbiCascader::AllocateSeqNo).
DbiTableProxyfTableProxy
 Proxy to associated table.
std::string fTableName
 Associated table name.
Bool_t fUseOverlayCreationDate
 Use overlay creation date if true.
DbiValidityRecfValidRec
 Validity record. May be =0 if closed.
DbiLogEntry fLogEntry
 Associated log entry (if any) for update.

Detailed Description

template<class T>
class DbiWriter< T >

Id
DbiWriter.h,v 1.24 2006/08/08 10:51:32 west Exp

Definition at line 45 of file DbiWriter.h.


Constructor & Destructor Documentation

template<class T>
DbiWriter< T >::DbiWriter (  ) 
template<class T >
DbiWriter< T >::DbiWriter ( const VldRange vr,
Int_t  aggNo,
Dbi::Task  task,
VldTimeStamp  creationDate,
const std::string &  dbName,
const std::string &  logComment = "",
const std::string &  tableName = "" 
) [inline]

Definition at line 128 of file DbiWriter.tpl.

References DbiWriter< T >::fTableName, Msg::kVerbose, LEA_CTOR, MSG, and DbiWriter< T >::Open().

00134                                                     :
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 }

template<class T >
DbiWriter< T >::DbiWriter ( const VldRange vr,
Int_t  aggNo,
Dbi::Task  task = 0,
VldTimeStamp  creationDate = VldTimeStamp(0,0),
UInt_t  dbNo = 0,
const std::string &  logComment = "",
const std::string &  tableName = "" 
) [inline]

Definition at line 72 of file DbiWriter.tpl.

References DbiWriter< T >::fTableName, Msg::kVerbose, LEA_CTOR, MSG, and DbiWriter< T >::Open().

00078                                                     :
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 }

template<class T >
DbiWriter< T >::DbiWriter ( const DbiValidityRec vrec,
const std::string &  dbName,
const std::string &  logComment = "" 
) [inline]

Definition at line 234 of file DbiWriter.tpl.

References Msg::kVerbose, LEA_CTOR, MSG, and DbiWriter< T >::Open().

00236                                                      :
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 }

template<class T >
DbiWriter< T >::DbiWriter ( const DbiValidityRec vrec,
UInt_t  dbNo = 0,
const std::string &  logComment = "" 
) [inline]

Definition at line 183 of file DbiWriter.tpl.

References Msg::kVerbose, LEA_CTOR, MSG, and DbiWriter< T >::Open().

00185                                                      :
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 }

template<class T >
DbiWriter< T >::~DbiWriter (  )  [inline, virtual]

Definition at line 285 of file DbiWriter.tpl.

References DbiWriter< T >::fPacket, DbiWriter< T >::fValidRec, Msg::kVerbose, LEA_DTOR, MSG, and DbiWriter< T >::Reset().

00285                          {
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 }

template<class T>
DbiWriter< T >::DbiWriter ( const DbiWriter< T > &   )  [private]

Member Function Documentation

template<class T>
void DbiWriter< T >::Abort (  )  [inline]

Definition at line 94 of file DbiWriter.h.

Referenced by DbiWriter< T >::operator<<().

00094 { Reset(); }

template<class T >
Bool_t DbiWriter< T >::CanOutput ( Bool_t  reportErrors = kTRUE  )  const [inline]

Open and ready to receive/output data.

Definition at line 336 of file DbiWriter.tpl.

References DbiWriter< T >::fLogEntry, DbiWriter< T >::fPacket, DbiWriter< T >::fTableName, DbiSqlValPacket::GetNumSqlStmts(), DbiSqlValPacket::GetStmt(), DbiLogEntry::HasReason(), DbiWriter< T >::IsOpen(), Msg::kError, Msg::kWarning, MSG, DbiWriter< T >::NeedsLogEntry(), and DbiSqlValPacket::Print().

Referenced by DbiWriter< T >::Close(), DetailedTimeCal(), load_better_mipcal(), load_mc_mipcal(), main(), LIPlexMaps::MakeCalMIPCalibration(), LIPlexMaps::MakeCalStripAtten(), LIPlexMaps::MakeCalStripToStrip(), LIPlexMaps::MakePlexStripEndToLed(), MakeTimeCal(), and DbiWriter< T >::Open().

00336                                                         {
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 ) {
00345       MSG("Dbi",Msg::kError)
00346         << "Cannot output validity set for table " 
00347         << fTableName
00348         << ", writing to Master DB but no log comment has been supplied."
00349         << endl;
00350     }
00351     return kFALSE;
00352   }
00353 
00354   UInt_t nstmts = fPacket->GetNumSqlStmts();
00355 
00356   if ( nstmts == 0 ) {
00357     // not even a VLD insert
00358     if ( reportErrors ) {
00359       MSG("Dbi",Msg::kError)
00360         << "Cannot output validity set for table " 
00361         << fTableName
00362         << ", no data has been written." << endl;
00363     }
00364     return kFALSE;
00365   }
00366 
00367   if ( nstmts == 1 ) {
00368     // if VLD insert present but no data rows, just issue a stern warning
00369     // as it may be intended to obscure now invalid data
00370     string stmt = fPacket->GetStmt(0);
00371     bool isvldentry = 
00372       (stmt.find("INSERT INTO") != string::npos ) &&
00373       (stmt.find("VLD VALUES")  != string::npos);
00374     if ( isvldentry ) {
00375       if ( reportErrors ) {
00376         MSG("Dbi",Msg::kWarning)
00377           << "VLD entry but no data for " 
00378           << fTableName << endl;
00379       }
00380     }
00381     else {
00382       // this should never, ever happen ... but let's be paranoid
00383       if ( reportErrors ) {
00384         MSG("Dbi",Msg::kError) 
00385           << "Cannot output validity set for table " 
00386           << fTableName
00387           << ", (no VLD info) no data has been written." << endl;
00388         fPacket->Print();
00389       }
00390       return kFALSE;
00391     }
00392   }
00393 
00394   return kTRUE;
00395 }

template<class T >
Bool_t DbiWriter< T >::Close ( const char *  fileSpec = 0  )  [inline]

Definition at line 401 of file DbiWriter.tpl.

References DbiCascader::AllocateSeqNo(), DbiWriter< T >::CanOutput(), DbiSqlValPacket::Clear(), DbiWriter< T >::fDbNo, DbiWriter< T >::fLogEntry, DbiWriter< T >::fPacket, DbiWriter< T >::fRequireGlobalSeqno, DbiWriter< T >::fTableName, DbiWriter< T >::fTableProxy, DbiWriter< T >::fUseOverlayCreationDate, DbiWriter< T >::fValidRec, DbiTableProxy::GetCascader(), DbiLogEntry::HasReason(), Msg::kError, MSG, DbiWriter< T >::NeedsLogEntry(), DbiTableProxy::QueryOverlayCreationDate(), DbiSqlValPacket::SetCreationDate(), DbiSqlValPacket::SetSeqNo(), DbiSqlValPacket::Store(), DbiLogEntry::Write(), DbiSqlValPacket::Write(), and DbiWriter< T >::WritingToMaster().

Referenced by BMFileSummaryFiller::Commit(), DbuDaqFileModule::CommitDbuDaqConfigFilesText(), BMSpillFiller::DBU(), DetailedTimeCal(), PulserDBModule::DoWriteGC(), PulserDBModule::DriftPoint(), BeamMonSwicPedsDbuModule::Dump(), Fill_MBSpill(), PhotonStatSummarizer::FillPmtDatabase(), FitNdNonlinQuad(), load_better_mipcal(), load_mc_mipcal(), LoadBeamMomentum(), LoadCERRange(), LoadCERTimeWin(), LoadOverlapWin(), LoadTOFRange(), lootSpillFile(), main(), LIPlexMaps::MakeCalMIPCalibration(), LIPlexMaps::MakeCalStripAtten(), LIPlexMaps::MakeCalStripToStrip(), MakeFilterChannelList(), LIPlexMaps::MakePlexStripEndToLed(), UgliGeometryReroot::MakeTempDbiGeometry(), UgliGeometryReroot::MakeTempDbiPosInfo(), UgliGeometryReroot::MakeTempDbiScintStruct(), MakeTimeCal(), DbiWriter< T >::Open(), DcsWriter::ProcessRawRecord(), AutoPIDMaker::Reco(), PulserGainFit::RunNearFarFits(), PulserGainFit::RunPinFits(), CoilTools::Write(), DbiConfigStream::Write(), BMCutsFiller::Write(), NDSgateTimeLooter::Write(), FitGC::WriteDB(), ChannelNoiseRates::WriteRates(), PulserFromRawCollectorModule::WriteRawCurveData(), PulserCollectorModule::WriteRawCurveData(), PulserFromRawCollectorModule::WriteRawDriftData(), PulserCollectorModule::WriteRawDriftData(), PulserFromRawCollectorModule::WriteReferenceDriftData(), PulserCollectorModule::WriteReferenceDriftData(), FillBadChannelDB::WriteToDatabase(), ScintCalTimePeriod::WriteToMINOSDbi(), DbuDaqMonitorModule::WriteVaChipPedsEntry(), DbuDaqMonitorModule::WriteVaChipSparsEntry(), and BMWriteHadMuRel::~BMWriteHadMuRel().

00401                                                {
00402 //
00403 //
00404 //  Purpose:  Close current validity set and write it to the database.
00405 //
00406 //  Arguments:
00407 //
00408 //  fileSpec       in   File pointer.  If not null write to file instead of database.
00409 //
00410 //  Return:    kTRUE is I/O successful.
00411 //
00412 //  Contact:   N. West
00413 //
00414 //  Specification:-
00415 //  =============
00416 //
00417 //  o Close current validity set and write it to the database.
00418 
00419 //  Program Notes:-
00420 //  =============
00421 
00422 //  None.
00423 
00424   Bool_t ok = kFALSE;
00425   
00426 // Skip output unless good data to output.
00427 
00428   if ( CanOutput() ) {
00429 
00430 //  Find the next free sequence number.  It must be global if writing to a
00431 //  to a file, otherwise it can be local if DB isn't authorising.
00432     int seqNoType = fileSpec ? 1 : fRequireGlobalSeqno;
00433     Int_t seqNo = fTableProxy->GetCascader().AllocateSeqNo(fTableName,seqNoType,fDbNo);
00434     if ( seqNo <= 0 ) {
00435       MSG("Dbi",Msg::kError)
00436         << "Cannot get sequence number for table " 
00437         << fTableName << endl;
00438     }
00439     
00440     else {
00441 
00442 //  Use overlay creation date if required.
00443       if ( fUseOverlayCreationDate &&  fValidRec 
00444           ) fPacket->SetCreationDate(fTableProxy->QueryOverlayCreationDate(*fValidRec,fDbNo));
00445 
00446 //  Set SEQNO and perform I/O.
00447       fPacket->SetSeqNo(seqNo);
00448       if ( fileSpec ) {
00449         ofstream fs(fileSpec,ios_base::app);
00450         if ( ! fs ) MSG("Dbm", Msg::kError) << "Unable to open " << fileSpec << endl;
00451         else        ok = fPacket->Write(fs,true);
00452       }
00453       else {
00454         ok = fPacket->Store(fDbNo);
00455       }
00456 
00457 //  Record update if I/O successful and required.
00458       if ( ok && this->WritingToMaster() ) {
00459        if ( this->NeedsLogEntry() || fLogEntry.HasReason() )
00460         ok = fLogEntry.Write(fDbNo,seqNo);
00461       }
00462     }
00463   } 
00464   
00465 //  Clear out ready for any further I/O.
00466 
00467   fPacket->Clear();
00468 
00469   return ok;
00470 }

template<class T >
void DbiWriter< T >::CompleteOpen ( UInt_t  dbNo = 0,
const std::string &  logComment = "" 
) [inline, private]

Definition at line 474 of file DbiWriter.tpl.

References DbiWriter< T >::fAggregateNo, DbiWriter< T >::fDbNo, DbiWriter< T >::fLogEntry, DbiWriter< T >::fPacket, DbiWriter< T >::fTableName, DbiWriter< T >::fTableProxy, DbiWriter< T >::fValidRec, DbiValidityRec::GetAggregateNo(), DbiValidityRec::GetCreationDate(), VldRange::GetDetectorMask(), VldRange::GetSimMask(), DbiTableProxy::GetTableName(), DbiValidityRec::GetTask(), DbiValidityRec::GetVldRange(), Msg::kError, MSG, DbiSqlValPacket::Recreate(), DbiLogEntry::Recreate(), and DbiWriter< T >::Reset().

Referenced by DbiWriter< T >::Open().

00475                                                              {
00476 //
00477 //
00478 //  Purpose:  Complete the open process
00479 //
00480 //  Arguments: 
00481 //    dbNo          in       Database number in cascade (starting at 0).
00482 //    logComment    in       Reason for update.
00483 //
00484 //
00485 //  Specification:-
00486 //  =============
00487 //
00488 //  o Complete reinitialisation for new I/O 
00489 
00490 //  Program Notes:-
00491 //  =============
00492 
00493 //  Assumes that fTableProxy, fUseOverlayCreationDate, fValidRec are 
00494 //  already initialised.
00495 
00496 
00497   fDbNo = dbNo;
00498   if ( (int) fDbNo < 0 ) {
00499     MSG("Dbi",Msg::kError) << "Bad database name/number selected. " << endl;
00500     this->Reset();
00501     return;
00502   }
00503 
00504   fAggregateNo = fValidRec->GetAggregateNo();
00505   fTableName   = fTableProxy->GetTableName(),
00506 
00507 // Recreate validity packet.
00508   fPacket->Recreate(fTableName,
00509                     fValidRec->GetVldRange(),
00510                     fAggregateNo,
00511                     fValidRec->GetTask(),
00512                     fValidRec->GetCreationDate());
00513 
00514 // Recreate log entry.
00515   const VldRange&  vr = fValidRec->GetVldRange();
00516   fLogEntry.Recreate(fTableName,
00517                      logComment,
00518                      vr.GetDetectorMask(),
00519                      vr.GetSimMask(),
00520                      fValidRec->GetTask());
00521 
00522 }

template<class T >
DbiTableProxy & DbiWriter< T >::GetTableProxy ( const std::string &  tableName  )  [inline, static, private]

Definition at line 546 of file DbiWriter.tpl.

References DbiWriter< T >::GetTableProxy().

00547                                                                       {
00548 //
00549 //
00550 //  Purpose:  Private static function to find an alternative 
00551 //            associated DbiTableProxy.
00552 //
00553 //  Arguments: 
00554 //    tableName    in    Alternative table name
00555 //
00556 //  Return:   Associated DbiTableProxy. 
00557 //
00558 //  Contact:   N. West
00559 //
00560 //  Specification:-
00561 //  =============
00562 //
00563 //  o Ask Registry for alternative  Table Proxy and return it.
00564 
00565 //  As DbiResultPtr classes are in 1:1 correspondance with DbiWriter
00566 //  classes, DbiWriter uses the static methods from DbiResultPtr
00567 //  to find the associated DbiTableProxy.
00568 
00569   return DbiResultPtr<T>::GetTableProxy(tableName);
00570 
00571 }

template<class T >
DbiTableProxy & DbiWriter< T >::GetTableProxy (  )  [inline, static, private]

Definition at line 527 of file DbiWriter.tpl.

Referenced by DbiWriter< T >::GetTableProxy(), DbiWriter< T >::Open(), and DbiWriter< T >::Reset().

00527                                            {
00528 //
00529 //
00530 //  Purpose:  Private static function to find default associated 
00531 //            DbiTableProxy.
00532 
00533 //  Program Notes:-
00534 //  =============
00535 
00536 //  As DbiResultPtr classes are in 1:1 correspondance with DbiWriter
00537 //  classes, DbiWriter uses the static methods from DbiResultPtr
00538 //  to find the associated DbiTableProxy.
00539 
00540   return DbiResultPtr<T>::GetTableProxy();
00541 }

template<class T >
Bool_t DbiWriter< T >::IsOpen ( Bool_t  reportErrors = kTRUE  )  const [inline]

Open and ready to receive data.

Definition at line 575 of file DbiWriter.tpl.

References DbiWriter< T >::fPacket, DbiWriter< T >::fTableName, DbiWriter< T >::fValidRec, DbiSqlValPacket::GetNumSqlStmts(), DbiTableProxyRegistry::IsActive(), Msg::kError, and MSG.

Referenced by DbiWriter< T >::CanOutput(), LIPlexMaps::MakeCalMIPCalibration(), LIPlexMaps::MakeCalStripAtten(), LIPlexMaps::MakeCalStripToStrip(), LIPlexMaps::MakePlexStripEndToLed(), DbiWriter< T >::operator<<(), PulserGainFit::RunNearFarFits(), PulserGainFit::RunPinFits(), and ScintCalTimePeriod::WriteToMINOSDbi().

00575                                                      {
00576 //
00577 //
00578 //  Purpose:  Return true if open and ready to receive data.
00579 
00580   if ( ! DbiTableProxyRegistry::IsActive()  ) {
00581     if ( reportErrors ) {
00582       MSG("Dbi",Msg::kError)
00583         << "Cannot use DbiWriter, the DBI has been shutdown." << endl;
00584     }
00585   }
00586   else if (    !fValidRec
00587             ||  fPacket->GetNumSqlStmts() < 1 ) {
00588     if ( reportErrors ) {
00589       MSG("Dbi",Msg::kError)
00590         << "Cannot do I/O on DbiWriter for " 
00591         << fTableName
00592         <<", it is currently closed." << endl;
00593     }
00594   }
00595   else return kTRUE;
00596 
00597   return kFALSE;
00598 
00599 }

template<class T >
Bool_t DbiWriter< T >::NeedsLogEntry (  )  const [inline, private]

Definition at line 603 of file DbiWriter.tpl.

References DbiWriter< T >::fTableName, and DbiWriter< T >::WritingToMaster().

Referenced by DbiWriter< T >::CanOutput(), and DbiWriter< T >::Close().

00603                                          {
00604 //
00605 //
00606 //  Purpose:  Return true if a log entry is required.
00607 
00608   // Some tables are created automatically so don't require entries.
00609   string tableName(fTableName);
00610   if (    tableName.substr(0,7)  == "BEAMMON"
00611        || tableName.substr(0,16) == "BFLDDBICOILSTATE"
00612        || tableName.substr(0,3)  == "CAL"
00613        || tableName.substr(0,20) == "CANDDIGITBADCHANNELS"
00614        || tableName.substr(0,3)  == "DBU"
00615        || tableName.substr(0,3)  == "DCS"
00616        || tableName.substr(0,6)  == "PULSER"
00617        || tableName.substr(0,9)  == "SPILLTIME" ) return kFALSE;
00618 
00619   // All other tables need entries if writing to a Master database.
00620 
00621   return this->WritingToMaster();
00622 
00623 }

template<class T >
Bool_t DbiWriter< T >::Open ( const DbiValidityRec vrec,
UInt_t  dbNo = 0,
const std::string &  logComment = "" 
) [inline]

Definition at line 716 of file DbiWriter.tpl.

References DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiWriter< T >::CompleteOpen(), DbiWriter< T >::fTableProxy, DbiWriter< T >::fUseOverlayCreationDate, DbiWriter< T >::fValidRec, DbiValidityRec::GetCreationDate(), DbiTableProxy::GetTableName(), DbiWriter< T >::GetTableProxy(), DbiValidityRec::GetTableProxy(), DbiTableProxyRegistry::IsActive(), Msg::kError, MSG, and DbiWriter< T >::Reset().

00718                                                        {
00719 
00720 //
00721 //  Purpose:  Output any existing data and open new validity set.
00722 //
00723 //  Arguments: 
00724 //    vrec          in       Validity record for set.
00725 //                           MUST have an associated DbiTableProxy
00726 //    dbNo          in       Database number in cascade (starting at 0).
00727 //    logComment    in       Reason for update.
00728 //
00729 //
00730 //  Return:    kTRUE if no errors detected.
00731 //
00732 //  Contact:   N. West
00733 //
00734 //  Specification:-
00735 //  =============
00736 //
00737 //  o Output any existing data and open new validity set.
00738 
00739 
00740 //  Program Notes:-
00741 //  =============
00742 
00743 //  None.
00744 
00745   bool ok = true;
00746 
00747   if ( ! DbiTableProxyRegistry::IsActive() ) return kFALSE;
00748   if ( this->CanOutput(kFALSE) ) ok = Close();
00749 
00750   
00751 // Check that vrec is associated with the right table, but waive
00752 // test for DbiConfigSet so that it can be used with any.
00753   const DbiTableProxy& proxyDefault = DbiWriter<T>::GetTableProxy();
00754   const DbiTableProxy& proxyVrec    = *vrec.GetTableProxy();
00755   if (    proxyDefault.GetTableName() != "DBICONFIGSET"
00756        &&    proxyVrec.GetTableName() != proxyDefault.GetTableName() ) {
00757     MSG("Dbi",Msg::kError) 
00758        << "Unable to create DbiWriter from query:" << endl
00759        << vrec
00760        << " was filled by " << proxyVrec.GetTableName() 
00761        << " not by " << proxyDefault.GetTableName() << endl;
00762     this->Reset();
00763     return false;
00764   }
00765   else { 
00766 //  Have to cast away const - DbiWriter needs a modifiable DbiTableProxy.
00767     fTableProxy = const_cast<DbiTableProxy*>(&proxyVrec);
00768   }
00769 
00770   fUseOverlayCreationDate = vrec.GetCreationDate() == VldTimeStamp(0,0);
00771 
00772   delete fValidRec;
00773   fValidRec = new DbiValidityRec(vrec);
00774 
00775 // Complete opening.
00776   this->CompleteOpen(dbNo,logComment);
00777   return ok;
00778 
00779 }

template<class T >
Bool_t DbiWriter< T >::Open ( const DbiValidityRec vrec,
const string &  dbName,
const std::string &  logComment = "" 
) [inline]

Definition at line 784 of file DbiWriter.tpl.

References DbiWriter< T >::fDbNo, DbiWriter< T >::Open(), and DbiWriter< T >::SetDbName().

00786                                                        {
00787 
00788 //
00789 //  Purpose:  Output any existing data and open new validity set.
00790 //
00791 //  Arguments: 
00792 //    vrec          in       Validity record for set.
00793 //                           MUST have an associated DbiTableProxy
00794 //    dbName        in       Database name.
00795 //    logComment    in       Reason for update.
00796 //
00797 //
00798 //  Return:    kTRUE if no errors detected.
00799 
00800   this->SetDbName(dbName);
00801   return this->Open(vrec,
00802                     fDbNo,
00803                     logComment);
00804 
00805 }

template<class T >
Bool_t DbiWriter< T >::Open ( const VldRange vr,
Int_t  aggNo,
Dbi::Task  task = 0,
VldTimeStamp  creationDate = VldTimeStamp(),
UInt_t  dbNo = 0,
const std::string &  logComment = "" 
) [inline]

Definition at line 628 of file DbiWriter.tpl.

References DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiWriter< T >::CompleteOpen(), DbiWriter< T >::fTableName, DbiWriter< T >::fTableProxy, DbiWriter< T >::fUseOverlayCreationDate, DbiWriter< T >::fValidRec, DbiWriter< T >::GetTableProxy(), and DbiTableProxyRegistry::IsActive().

00633                                                         {
00634 //
00635 //
00636 //  Purpose:  Output any existing data and open new validity set.
00637 //
00638 //  Arguments: 
00639 //    vr            in       Validity range of validity set.
00640 //    aggNo         in       Aggregate number of validity set.
00641 //    task          in       Task of validity set.
00642 //    creationDate  in       Creation date of validity set.
00643 //    dbNo          in       Database number in cascade (starting at 0).
00644 //    logComment    in       Reason for update.
00645 //
00646 //  Return:    kTRUE if no errors detected.
00647 //
00648 //  Contact:   N. West
00649 //
00650 //  Specification:-
00651 //  =============
00652 //
00653 //  o Output any existing data and open new validity set.
00654 
00655 //  Program Notes:-
00656 //  =============
00657 
00658 //  None.
00659 
00660   bool ok = true;
00661 
00662   if ( ! DbiTableProxyRegistry::IsActive() ) return kFALSE;
00663   if ( this->CanOutput(kFALSE) ) ok = Close();
00664 
00665 // Test for special creation date.
00666   fUseOverlayCreationDate = creationDate == VldTimeStamp(0,0);
00667 
00668 //  Create a validity record.
00669   delete fValidRec;
00670   fValidRec = new DbiValidityRec(vr,task,aggNo,0,0,kFALSE,creationDate);
00671 
00672 // Get a proxy.
00673   fTableProxy = &DbiWriter<T>::GetTableProxy(fTableName); 
00674 
00675 // Complete opening.
00676   this->CompleteOpen(dbNo,logComment);
00677   return ok;
00678 
00679 }

template<class T >
Bool_t DbiWriter< T >::Open ( const VldRange vr,
Int_t  aggNo,
Dbi::Task  task,
VldTimeStamp  creationDate,
const string &  dbName,
const std::string &  logComment = "" 
) [inline]

Definition at line 683 of file DbiWriter.tpl.

References DbiWriter< T >::fDbNo, and DbiWriter< T >::SetDbName().

Referenced by DbiWriter< T >::DbiWriter(), DbiWriter< T >::Open(), PulserGainFit::RunNearFarFits(), PulserGainFit::RunPinFits(), and FitGC::WriteDB().

00688                                                         {
00689 //
00690 //
00691 //  Purpose:  Output any existing data and open new validity set.
00692 //
00693 //  Arguments: 
00694 //    vr            in       Validity range of validity set.
00695 //    aggNo         in       Aggregate number of validity set.
00696 //    task          in       Task of validity set.
00697 //    creationDate  in       Creation date of validity set.
00698 //    dbName        in       Database name.
00699 //    logComment    in       Reason for update.
00700 //
00701 //  Return:    kTRUE if no errors detected.
00702 
00703   this->SetDbName(dbName);
00704   return this->Open(vr,
00705                     aggNo,
00706                     task,
00707                     creationDate,
00708                     fDbNo,
00709                     logComment);
00710 
00711 }

template<class T>
DbiWriter< T > & DbiWriter< T >::operator<< ( const T &  row  )  [inline]

Definition at line 306 of file DbiWriter.tpl.

References DbiWriter< T >::Abort(), DbiSqlValPacket::AddDataRow(), DbiWriter< T >::fAggregateNo, DbiWriter< T >::fPacket, DbiWriter< T >::fTableName, DbiWriter< T >::fTableProxy, DbiWriter< T >::fValidRec, DbiWriter< T >::IsOpen(), Msg::kError, and MSG.

00306                                                    {
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 }

template<class T>
DbiWriter& DbiWriter< T >::operator= ( const DbiWriter< T > &   )  [private]
template<class T >
void DbiWriter< T >::Reset (  )  [inline, private]

Definition at line 810 of file DbiWriter.tpl.

References DbiSqlValPacket::Clear(), DbiWriter< T >::fAggregateNo, DbiWriter< T >::fDbNo, DbiWriter< T >::fPacket, DbiWriter< T >::fTableName, DbiWriter< T >::fTableProxy, DbiWriter< T >::fValidRec, DbiTableProxy::GetTableName(), and DbiWriter< T >::GetTableProxy().

Referenced by DbiWriter< BeamMonSwicRel >::Abort(), DbiWriter< T >::CompleteOpen(), DbiWriter< T >::Open(), and DbiWriter< T >::~DbiWriter().

00810                          {
00811 //
00812 //
00813 //  Purpose:  Clear out data and reset ready for any further I/O.
00814 //
00815 //  Arguments: None.
00816 //
00817 //  Return:    None.
00818 //
00819 //  Contact:   N. West
00820 //
00821 //  Specification:-
00822 //  =============
00823 //
00824 //  o Clear out data and reset ready for any further I/O.
00825 
00826 //  Program Notes:-
00827 //  =============
00828 
00829 //  None.
00830 
00831   fAggregateNo = 0;
00832   fDbNo        = 0;
00833   fPacket->Clear();
00834   fTableProxy  = &DbiWriter<T>::GetTableProxy();
00835   fTableName   = fTableProxy->GetTableName();
00836 
00837   delete fValidRec;
00838   fValidRec    = 0;
00839 
00840 }

template<class T >
void DbiWriter< T >::SetDbName ( const string &  dbName  )  [inline]

Definition at line 844 of file DbiWriter.tpl.

References DbiWriter< T >::fDbNo, DbiTableProxyRegistry::GetCascader(), DbiCascader::GetDbNo(), and DbiTableProxyRegistry::Instance().

Referenced by PulserGainFit::ConfigModified(), PulserDBModule::DoWriteGC(), DbiWriter< T >::Open(), and FitGC::WriteDB().

00844                                                  {
00845 //
00846 //
00847 //  Purpose:  Set Database entry by name.  Default: entry 0.
00848 
00849   if ( dbName == "" ) {
00850     fDbNo = 0;
00851   }
00852   else {
00853     fDbNo =  DbiTableProxyRegistry::Instance().GetCascader().GetDbNo(dbName);
00854   }
00855 }

template<class T>
void DbiWriter< T >::SetDbNo ( UInt_t  dbNo  )  [inline]

Definition at line 86 of file DbiWriter.h.

00086 { fDbNo = dbNo;}

template<class T >
void DbiWriter< T >::SetLogComment ( const std::string &  reason  )  [inline]

Definition at line 860 of file DbiWriter.tpl.

References DbiWriter< T >::fLogEntry, and DbiLogEntry::SetReason().

Referenced by BMWriteHadMuRelImp::BMWriteHadMuRelImp().

00860                                                         {
00861 //
00862 //
00863 //  Purpose:  Set log comment.
00864 
00865   fLogEntry.SetReason(reason);
00866 
00867 }

template<class T>
void DbiWriter< T >::SetOverlayCreationDate (  )  [inline]

Definition at line 91 of file DbiWriter.h.

Referenced by DbiConfigStream::Write(), and FitGC::WriteDB().

00091 {fUseOverlayCreationDate = kTRUE;}

template<class T>
void DbiWriter< T >::SetRequireGlobalSeqno ( Int_t  requireGlobal  )  [inline]

Definition at line 90 of file DbiWriter.h.

Referenced by DbiConfigStream::Write(), and BMCutsFiller::Write().

00090 {fRequireGlobalSeqno = requireGlobal;}

template<class T >
DbiTableProxy & DbiWriter< T >::TableProxy (  )  const [inline]

Definition at line 872 of file DbiWriter.tpl.

References DbiWriter< T >::fTableProxy, and DbiTableProxyRegistry::IsActive().

Referenced by PulserDBModule::DoWriteGC(), UgliGeometryReroot::MakeTempDbiGeometry(), UgliGeometryReroot::MakeTempDbiPosInfo(), and UgliGeometryReroot::MakeTempDbiScintStruct().

00872                                                {
00873 //
00874 //
00875 //  Purpose:  Return DbiTableProxy.
00876 //
00877 
00878   assert( DbiTableProxyRegistry::IsActive() );
00879   return *fTableProxy;
00880 }

template<class T >
Bool_t DbiWriter< T >::WritingToMaster (  )  const [inline, private]

Definition at line 885 of file DbiWriter.tpl.

References DbiWriter< T >::fDbNo, DbiWriter< T >::fTableName, DbiCascader::GetAuthorisingDbNo(), DbiTableProxyRegistry::GetCascader(), DbiTableProxyRegistry::Instance(), and DbiCascader::IsTemporaryTable().

Referenced by DbiWriter< T >::Close(), and DbiWriter< T >::NeedsLogEntry().

00885                                            {
00886 //
00887 //
00888 //  Purpose:  Return true if writing permanent data to a Master Database.
00889 
00890 
00891   DbiCascader& cascader = DbiTableProxyRegistry::Instance().GetCascader();
00892   return  (    fDbNo == (UInt_t) cascader.GetAuthorisingDbNo()
00893             && ! cascader.IsTemporaryTable(fTableName,fDbNo));
00894 
00895 }


Member Data Documentation

template<class T>
Int_t DbiWriter< T >::fAggregateNo [private]

Aggregate noumber for set.

Definition at line 139 of file DbiWriter.h.

Referenced by DbiWriter< T >::CompleteOpen(), DbiWriter< T >::operator<<(), and DbiWriter< T >::Reset().

template<class T>
UInt_t DbiWriter< T >::fDbNo [private]
template<class T>
DbiLogEntry DbiWriter< T >::fLogEntry [private]

Associated log entry (if any) for update.

Definition at line 163 of file DbiWriter.h.

Referenced by DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiWriter< T >::CompleteOpen(), and DbiWriter< T >::SetLogComment().

template<class T>
DbiSqlValPacket* DbiWriter< T >::fPacket [private]
template<class T>
Int_t DbiWriter< T >::fRequireGlobalSeqno [private]

Controls SEQNO type (see DbiCascader::AllocateSeqNo).

Definition at line 148 of file DbiWriter.h.

Referenced by DbiWriter< T >::Close(), and DbiWriter< BeamMonSwicRel >::SetRequireGlobalSeqno().

template<class T>
std::string DbiWriter< T >::fTableName [private]
template<class T>
DbiTableProxy* DbiWriter< T >::fTableProxy [private]
template<class T>
Bool_t DbiWriter< T >::fUseOverlayCreationDate [private]

Use overlay creation date if true.

Definition at line 157 of file DbiWriter.h.

Referenced by DbiWriter< T >::Close(), DbiWriter< T >::Open(), and DbiWriter< BeamMonSwicRel >::SetOverlayCreationDate().

template<class T>
DbiValidityRec* DbiWriter< T >::fValidRec [private]

The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1