DbiLogEntry Class Reference

#include <DbiLogEntry.h>

Inheritance diagram for DbiLogEntry:

DbiTableRow List of all members.

Public Member Functions

 DbiLogEntry (const string &tableName="", const string &reason="", Int_t detMask=Detector::FullMask(), Int_t simMask=SimFlag::FullMask(), Dbi::Task task=0, Int_t logSeqNoMin=0, Int_t logSeqNoMax=0, Int_t logNumSeqNo=0)
virtual ~DbiLogEntry ()
virtual DbiTableRowCreateTableRow () const
Int_t GetAggregateNo () const
const string & GetLogTableName () const
Int_t GetDetectorMask () const
Int_t GetLogSeqNoMin () const
Int_t GetLogSeqNoMax () const
Int_t GetLogNumSeqNo () const
Int_t GetSimMask () const
Dbi::Task GetTask () const
const string & GetUserName () const
const string & GetProcessName () const
const string & GetHostName () const
const string & GetServerName () const
const string & GetReason () const
VldTimeStamp GetUpdateTime () const
Bool_t HasReason () const
void SetReason (const string &reason)
void SetDetectorMask (Int_t detMask)
void SetSimMask (Int_t simMask)
void SetTask (Dbi::Task task)
void SetUpdateTime (const VldTimeStamp &updateTime)
void Recreate (const string &tableName="", const string &reason="", Int_t detMask=Detector::FullMask(), Int_t simMask=SimFlag::FullMask(), Dbi::Task task=0, Int_t logSeqNoMin=0, Int_t logSeqNoMax=0, Int_t logNumSeqNo=0)
virtual void Fill (DbiResultSet &rs, const DbiValidityRec *vrec)
virtual void Store (DbiOutRowStream &ors, const DbiValidityRec *vrec) const
Bool_t Write (UInt_t dbNo, Int_t logSeqNo=0)

Private Member Functions

 DbiLogEntry (const DbiLogEntry &from)
void SetServerName ()

Private Attributes

UInt_t fDbNo
 Database no. written to. =0 if not output.
Int_t fSeqNo
 Seq. No. used to write this object. =0 if not output.
string fLogTableName
 Table being updated.
Int_t fLogDetMask
 Detector type mask of update.
Int_t fLogSimMask
 SimFlag mask of update.
Dbi::Task fLogTask
 Task of update.
Int_t fLogSeqNoMin
 Minimum Seq. No. being updated.
Int_t fLogSeqNoMax
 Maximum Seq. No. being updated.
Int_t fLogNumSeqNo
 Number of Seq. Nos. being updated.
VldTimeStamp fUpdateTime
 Time of update.
string fUserName
 User performing update.
string fProcessName
 Process performing update.
string fHostName
 Host performing update.
string fServerName
 Db server being updated.
string fReason
 Reason for update.

Detailed Description

Id
DbiLogEntry.h,v 1.5 2006/08/08 10:51:32 west Exp

Definition at line 45 of file DbiLogEntry.h.


Constructor & Destructor Documentation

DbiLogEntry::DbiLogEntry ( const string &  tableName = "",
const string &  reason = "",
Int_t  detMask = Detector::FullMask(),
Int_t  simMask = SimFlag::FullMask(),
Dbi::Task  task = 0,
Int_t  logSeqNoMin = 0,
Int_t  logSeqNoMax = 0,
Int_t  logNumSeqNo = 0 
)

Definition at line 47 of file DbiLogEntry.cxx.

References fLogNumSeqNo, fLogSeqNoMax, fLogSeqNoMin, fUserName, gSystem(), LEA_CTOR, SetReason(), and SetServerName().

00054                                            :      /* = 0  */ 
00055 fDbNo(0),
00056 fSeqNo(0),
00057 fLogTableName(tableName),
00058 fLogDetMask(detMask),
00059 fLogSimMask(simMask),
00060 fLogTask(task),
00061 fLogSeqNoMin(logSeqNoMin),
00062 fLogSeqNoMax(logSeqNoMax),
00063 fLogNumSeqNo(logNumSeqNo),
00064 fUserName("unknown user"),
00065 fProcessName(gProgName),
00066 fHostName(gSystem->HostName())
00067 {
00068 //
00069 //
00070 //  Purpose:  Constructor
00071 
00072   LEA_CTOR;
00073 
00074   if ( fLogSeqNoMax == 0 ) fLogSeqNoMax = logSeqNoMin;
00075   if ( fLogNumSeqNo == 0 && logSeqNoMin != 0 
00076        ) fLogNumSeqNo = fLogSeqNoMax - fLogSeqNoMin +1;
00077 
00078   this->SetServerName();
00079   this->SetReason(reason);
00080 
00081   // Try to get username from the environment.
00082   const char* userName =  gSystem->Getenv("USER"); 
00083   if ( ! userName ) userName =  gSystem->Getenv("USERNAME");
00084   if ( ! userName ) userName =  gSystem->Getenv("LOGNAME");
00085   if ( userName ) fUserName = userName;
00086 
00087 }

DbiLogEntry::~DbiLogEntry (  )  [virtual]

Definition at line 90 of file DbiLogEntry.cxx.

References LEA_DTOR.

00090                           {
00091 //
00092 //
00093 //  Purpose:  Destructor
00094 
00095   LEA_DTOR;
00096 
00097 }

DbiLogEntry::DbiLogEntry ( const DbiLogEntry from  )  [private]


Member Function Documentation

virtual DbiTableRow* DbiLogEntry::CreateTableRow (  )  const [inline, virtual]

Implements DbiTableRow.

Definition at line 66 of file DbiLogEntry.h.

00066                                               { 
00067                                               return new DbiLogEntry; }

void DbiLogEntry::Fill ( DbiResultSet rs,
const DbiValidityRec vrec 
) [virtual]

Implements DbiTableRow.

Definition at line 146 of file DbiLogEntry.cxx.

References fHostName, fLogDetMask, fLogNumSeqNo, fLogSeqNoMax, fLogSeqNoMin, fLogSimMask, fLogTableName, fLogTask, fProcessName, fReason, fServerName, fUpdateTime, fUserName, VldRange::GetDetectorMask(), VldRange::GetSimMask(), DbiValidityRec::GetTask(), VldRange::GetTimeStart(), and DbiValidityRec::GetVldRange().

00147                                                    {
00148 //
00149 //
00150 //  Purpose:  Fill oject from Result Set
00151 
00152   rs >> fLogTableName
00153      >> fLogSeqNoMin
00154      >> fLogSeqNoMax
00155      >> fLogNumSeqNo
00156      >> fUserName
00157      >> fProcessName
00158      >> fHostName
00159      >> fServerName
00160      >> fReason;
00161   fLogDetMask = fLogSimMask = fLogTask = 0;
00162   if ( vrec ) {
00163     fLogDetMask = vrec->GetVldRange().GetDetectorMask();
00164     fLogSimMask = vrec->GetVldRange().GetSimMask();
00165     fLogTask    = vrec->GetTask();
00166     fUpdateTime = vrec->GetVldRange().GetTimeStart();
00167   }
00168 }

Int_t DbiLogEntry::GetAggregateNo (  )  const [inline, virtual]

Reimplemented from DbiTableRow.

Definition at line 68 of file DbiLogEntry.h.

00068 { return -1; }

Int_t DbiLogEntry::GetDetectorMask (  )  const [inline]

Definition at line 72 of file DbiLogEntry.h.

References fLogDetMask.

Referenced by operator<<().

00072 { return fLogDetMask; }

const string& DbiLogEntry::GetHostName (  )  const [inline]

Definition at line 80 of file DbiLogEntry.h.

References fHostName.

Referenced by operator<<().

00080 { return fHostName; }

Int_t DbiLogEntry::GetLogNumSeqNo (  )  const [inline]

Definition at line 75 of file DbiLogEntry.h.

References fLogNumSeqNo.

Referenced by operator<<().

00075 { return fLogNumSeqNo; }

Int_t DbiLogEntry::GetLogSeqNoMax (  )  const [inline]

Definition at line 74 of file DbiLogEntry.h.

References fLogSeqNoMax.

Referenced by operator<<().

00074 { return fLogSeqNoMax; }

Int_t DbiLogEntry::GetLogSeqNoMin (  )  const [inline]

Definition at line 73 of file DbiLogEntry.h.

References fLogSeqNoMin.

Referenced by operator<<().

00073 { return fLogSeqNoMin; }

const string& DbiLogEntry::GetLogTableName (  )  const [inline]

Definition at line 71 of file DbiLogEntry.h.

References fLogTableName.

Referenced by operator<<().

00071 { return fLogTableName; }

const string& DbiLogEntry::GetProcessName (  )  const [inline]

Definition at line 79 of file DbiLogEntry.h.

References fProcessName.

Referenced by operator<<().

00079 { return fProcessName; }

const string& DbiLogEntry::GetReason (  )  const [inline]

Definition at line 82 of file DbiLogEntry.h.

References fReason.

Referenced by operator<<().

00082 { return fReason; }

const string& DbiLogEntry::GetServerName (  )  const [inline]

Definition at line 81 of file DbiLogEntry.h.

References fServerName.

Referenced by operator<<().

00081 { return fServerName; }

Int_t DbiLogEntry::GetSimMask (  )  const [inline]

Definition at line 76 of file DbiLogEntry.h.

References fLogSimMask.

Referenced by operator<<().

00076 { return fLogSimMask; }

Dbi::Task DbiLogEntry::GetTask (  )  const [inline]

Definition at line 77 of file DbiLogEntry.h.

References fLogTask.

Referenced by operator<<().

00077 { return fLogTask; }

VldTimeStamp DbiLogEntry::GetUpdateTime (  )  const [inline]

Definition at line 83 of file DbiLogEntry.h.

References fUpdateTime.

Referenced by operator<<().

00083 { return fUpdateTime; }

const string& DbiLogEntry::GetUserName (  )  const [inline]

Definition at line 78 of file DbiLogEntry.h.

References fUserName.

Referenced by operator<<().

00078 { return fUserName; }

Bool_t DbiLogEntry::HasReason (  )  const [inline]

Definition at line 85 of file DbiLogEntry.h.

References fReason.

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

00085 { return fReason.size() > 0; }

void DbiLogEntry::Recreate ( const string &  tableName = "",
const string &  reason = "",
Int_t  detMask = Detector::FullMask(),
Int_t  simMask = SimFlag::FullMask(),
Dbi::Task  task = 0,
Int_t  logSeqNoMin = 0,
Int_t  logSeqNoMax = 0,
Int_t  logNumSeqNo = 0 
)

Definition at line 172 of file DbiLogEntry.cxx.

References fDbNo, fLogDetMask, fLogNumSeqNo, fLogSeqNoMax, fLogSeqNoMin, fLogSimMask, fLogTableName, fLogTask, fSeqNo, SimFlag::FullMask(), Detector::FullMask(), and SetReason().

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

00180 {
00181 //
00182 //
00183 //  Purpose:  Recreate, unless new state consistent with old.
00184 
00185   if (    fSeqNo > 0
00186        && ( tableName    == ""                       || tableName   == fLogTableName )
00187        && ( detMask      == Detector::FullMask()     || detMask     == fLogDetMask )
00188        && ( simMask      == SimFlag::FullMask()      || simMask     == fLogSimMask )
00189        && ( task         == 0                        || task        == fLogTask )
00190        && ( logSeqNoMin  == 0                        || logSeqNoMin ==  fLogSeqNoMin)
00191        && ( logSeqNoMax  == 0                        || logSeqNoMax == fLogSeqNoMax )
00192        && ( logNumSeqNo  == 0                        || logNumSeqNo == fLogNumSeqNo )
00193           ) {
00194     if ( reason != "" )  this->SetReason(reason);
00195     return;
00196   }
00197 
00198 
00199   fDbNo = 0;
00200   fSeqNo =0;
00201   fLogTableName = tableName;
00202   fLogDetMask = detMask;
00203   fLogSimMask = simMask;
00204   fLogTask = task;
00205   fLogSeqNoMin = logSeqNoMin;
00206   fLogSeqNoMax = logSeqNoMax;
00207   fLogNumSeqNo = logNumSeqNo;
00208   this->SetReason(reason);
00209 
00210 }

void DbiLogEntry::SetDetectorMask ( Int_t  detMask  )  [inline]

Definition at line 89 of file DbiLogEntry.h.

References fLogDetMask.

00089 { fLogDetMask = detMask; }

void DbiLogEntry::SetReason ( const string &  reason  ) 

Definition at line 214 of file DbiLogEntry.cxx.

References fReason, Msg::kError, and MSG.

Referenced by DbiLogEntry(), Recreate(), and DbiWriter< T >::SetLogComment().

00214                                                 {
00215 //
00216 //
00217 //  Purpose: Set reason. 
00218 //           String can  be "@file-containing-reason" in which case 
00219 //           contents of file is used to define the reason excluding
00220 //           any line begining:-
00221 //           
00222 //               FIXUP-FILE:
00223 //           or  BROADCAST:
00224 //           
00225 //           This allows DMauto fix-up files to provide log entries as well
00226 //           as updates.
00227 
00228   fReason = reason;
00229 
00230   // If fReason starts '@' treat remainder as file name 
00231   // to be read into fReason.
00232   if ( fReason.size() && fReason[0] == '@' ) {
00233     string fileName(fReason,1);
00234     fReason.clear();
00235     ifstream reasonFile(fileName.c_str());
00236     if ( ! reasonFile.is_open() ) {
00237       MSG("Dbm",Msg::kError) << "Cannot read \"Reason File\" " << fileName << endl;
00238     }
00239     else {
00240       string line;
00241       while ( ! reasonFile.eof() ) {
00242         getline(reasonFile,line);
00243         if (    line.substr(0,11) == "FIXUP-FILE:"
00244              || line.substr(0,10) == "BROADCAST:" ) {
00245           continue;
00246         }
00247         if ( fReason.size() ) fReason += '\n';
00248         fReason += line;
00249       }
00250       reasonFile.close();
00251     }
00252   } 
00253 }

void DbiLogEntry::SetServerName (  )  [private]

Definition at line 257 of file DbiLogEntry.cxx.

References fDbNo, fServerName, DbiTableProxyRegistry::GetCascader(), DbiCascader::GetURL(), and DbiTableProxyRegistry::Instance().

Referenced by DbiLogEntry().

00257                                 {
00258 //
00259 //
00260 //  Purpose: Set DB Server name from cascade number. 
00261 
00262   string urlStr = DbiTableProxyRegistry::Instance().GetCascader().GetURL(fDbNo);
00263   TUrl url(urlStr.c_str());
00264   fServerName = url.GetHost();
00265 
00266 }

void DbiLogEntry::SetSimMask ( Int_t  simMask  )  [inline]

Definition at line 90 of file DbiLogEntry.h.

References fLogSimMask.

00090 { fLogSimMask = simMask; }

void DbiLogEntry::SetTask ( Dbi::Task  task  )  [inline]

Definition at line 91 of file DbiLogEntry.h.

References fLogTask.

00091 { fLogTask = task; }

void DbiLogEntry::SetUpdateTime ( const VldTimeStamp updateTime  )  [inline]

Definition at line 92 of file DbiLogEntry.h.

References fUpdateTime.

Referenced by DbmModule::LogEntry().

00092                                                              { 
00093                                          fUpdateTime = updateTime; }

void DbiLogEntry::Store ( DbiOutRowStream ors,
const DbiValidityRec vrec 
) const [virtual]

Reimplemented from DbiTableRow.

Definition at line 269 of file DbiLogEntry.cxx.

References fHostName, fLogNumSeqNo, fLogSeqNoMax, fLogSeqNoMin, fLogTableName, fProcessName, fReason, fServerName, and fUserName.

00270                                                                  {
00271 //
00272 //
00273 //  Purpose:  Stream object to output row stream
00274 
00275  ors << fLogTableName
00276      << fLogSeqNoMin
00277      << fLogSeqNoMax
00278      << fLogNumSeqNo
00279      << fUserName
00280      << fProcessName
00281      << fHostName
00282      << fServerName
00283      << fReason;
00284 }

Bool_t DbiLogEntry::Write ( UInt_t  dbNo,
Int_t  logSeqNo = 0 
)

Definition at line 288 of file DbiLogEntry.cxx.

References DbiSqlValPacket::AddDataRow(), DbiCascader::AllocateSeqNo(), fDbNo, fLogDetMask, fLogNumSeqNo, fLogSeqNoMax, fLogSeqNoMin, fLogSimMask, fLogTask, fSeqNo, fUpdateTime, DbiTableProxy::GetCascader(), DbiValidityRec::GetCreationDate(), DbiTableProxyRegistry::GetTableProxy(), DbiValidityRec::GetTask(), DbiValidityRec::GetVldRange(), DbiTableProxyRegistry::Instance(), Msg::kError, MAXMSG, MSG, DbiSqlValPacket::Recreate(), DbiSqlValPacket::SetSeqNo(), and DbiSqlValPacket::Store().

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

00289                                                        {
00290 //
00291 //
00292 //  Purpose: Write, or rewrite this entry, adding logSeqNo to range of
00293 //           update SEQNOs if non-zero.
00294 
00295   if ( logSeqNo > 0 ) {
00296     if ( fLogNumSeqNo == 0 ) {
00297       fLogSeqNoMin = logSeqNo;
00298       fLogSeqNoMax = logSeqNo;
00299     }
00300     if ( logSeqNo < fLogSeqNoMin ) fLogSeqNoMin = logSeqNo;
00301     if ( logSeqNo > fLogSeqNoMax ) fLogSeqNoMax = logSeqNo;
00302     ++fLogNumSeqNo;
00303   }
00304 
00305   if ( ! this->HasReason() || fLogNumSeqNo == 0) {
00306     MSG("Dbm",Msg::kError) << "Cannot write LogEntry - no reason and/or no SEQNOs defined " 
00307                            << endl;
00308     return kFALSE;
00309   }
00310 
00311   if ( fSeqNo != 0 && dbNo != fDbNo ) {
00312     MSG("Dbm",Msg::kError) << "Cannot write LogEntry - attempting to switch from database" 
00313                            << fDbNo << " to " << dbNo << endl;
00314     return kFALSE;
00315   }
00316 
00317   fDbNo = dbNo;
00318   DbiTableProxy& tblProxy = DbiTableProxyRegistry::Instance()
00319                             .GetTableProxy("DBILOGENTRY",this);
00320   bool replace = true;
00321 
00322   // Allocate SEQNO before first write.
00323   if ( fSeqNo == 0 ) {
00324     replace = false;
00325     int seqNo = tblProxy.GetCascader().AllocateSeqNo("DBILOGENTRY",0,fDbNo);
00326     if ( seqNo <= 0 ) {
00327       MAXMSG("Dbi",Msg::kError,20)
00328         << "Cannot get sequence number for table DBILOGENTRY" << endl;
00329       return kFALSE;
00330     }
00331     fSeqNo = seqNo;
00332   }
00333 
00334   // Construct a DbiValidityRec.
00335   VldRange     vr(fLogDetMask,fLogSimMask,fUpdateTime,fUpdateTime,"DbiLogEntry");
00336   DbiValidityRec vrec(vr,fLogTask,-1,0);
00337 
00338   // Now build and output DbiSqlValPacket.
00339   DbiSqlValPacket packet;
00340   packet.Recreate("DBILOGENTRY",
00341                   vrec.GetVldRange(),
00342                   -1,
00343                   vrec.GetTask(),
00344                   vrec.GetCreationDate());
00345   packet.AddDataRow(tblProxy,0,*this);
00346   packet.SetSeqNo(fSeqNo);
00347   return packet.Store(fDbNo,replace);
00348 ;
00349 }


Member Data Documentation

UInt_t DbiLogEntry::fDbNo [private]

Database no. written to. =0 if not output.

Definition at line 119 of file DbiLogEntry.h.

Referenced by Recreate(), SetServerName(), and Write().

string DbiLogEntry::fHostName [private]

Host performing update.

Definition at line 155 of file DbiLogEntry.h.

Referenced by Fill(), GetHostName(), and Store().

Int_t DbiLogEntry::fLogDetMask [private]

Detector type mask of update.

Definition at line 128 of file DbiLogEntry.h.

Referenced by Fill(), GetDetectorMask(), Recreate(), SetDetectorMask(), and Write().

Int_t DbiLogEntry::fLogNumSeqNo [private]

Number of Seq. Nos. being updated.

Definition at line 143 of file DbiLogEntry.h.

Referenced by DbiLogEntry(), Fill(), GetLogNumSeqNo(), Recreate(), Store(), and Write().

Int_t DbiLogEntry::fLogSeqNoMax [private]

Maximum Seq. No. being updated.

Definition at line 140 of file DbiLogEntry.h.

Referenced by DbiLogEntry(), Fill(), GetLogSeqNoMax(), Recreate(), Store(), and Write().

Int_t DbiLogEntry::fLogSeqNoMin [private]

Minimum Seq. No. being updated.

Definition at line 137 of file DbiLogEntry.h.

Referenced by DbiLogEntry(), Fill(), GetLogSeqNoMin(), Recreate(), Store(), and Write().

Int_t DbiLogEntry::fLogSimMask [private]

SimFlag mask of update.

Definition at line 131 of file DbiLogEntry.h.

Referenced by Fill(), GetSimMask(), Recreate(), SetSimMask(), and Write().

string DbiLogEntry::fLogTableName [private]

Table being updated.

Definition at line 125 of file DbiLogEntry.h.

Referenced by Fill(), GetLogTableName(), Recreate(), and Store().

Dbi::Task DbiLogEntry::fLogTask [private]

Task of update.

Definition at line 134 of file DbiLogEntry.h.

Referenced by Fill(), GetTask(), Recreate(), SetTask(), and Write().

string DbiLogEntry::fProcessName [private]

Process performing update.

Definition at line 152 of file DbiLogEntry.h.

Referenced by Fill(), GetProcessName(), and Store().

string DbiLogEntry::fReason [private]

Reason for update.

Definition at line 161 of file DbiLogEntry.h.

Referenced by Fill(), GetReason(), HasReason(), SetReason(), and Store().

Int_t DbiLogEntry::fSeqNo [private]

Seq. No. used to write this object. =0 if not output.

Definition at line 122 of file DbiLogEntry.h.

Referenced by Recreate(), and Write().

string DbiLogEntry::fServerName [private]

Db server being updated.

Definition at line 158 of file DbiLogEntry.h.

Referenced by Fill(), GetServerName(), SetServerName(), and Store().

VldTimeStamp DbiLogEntry::fUpdateTime [private]

Time of update.

Definition at line 146 of file DbiLogEntry.h.

Referenced by Fill(), GetUpdateTime(), SetUpdateTime(), and Write().

string DbiLogEntry::fUserName [private]

User performing update.

Definition at line 149 of file DbiLogEntry.h.

Referenced by DbiLogEntry(), Fill(), GetUserName(), and Store().


The documentation for this class was generated from the following files:
Generated on Thu Apr 10 23:02:29 2014 for loon by  doxygen 1.4.7