//*-- Author : Valeriy Onuchin 11/09/2000
//
//
////////////////////////////////////////////////////////////////////////////////
//
// rooDBObj corresponds to ooHandle(ooDBObj) class
//
// Handle class for databases
#include "rooObjy.h"
#include <ooas.h>
#include <oo.h>
#include <TROOT.h>
#include <TBrowser.h>
ClassImp(rooDBObj)
rooDBObj* gprevDB; // previously opened database
rooDBObj* gooTopDB; // most recently opened database
////////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
rooDBObj::rooDBObj()
{
// default ctor.
fImp = new ooHandle(ooDBObj)();
}
//______________________________________________________________________________
rooDBObj::rooDBObj(const rooDBObj& db)
{
// copy ctor.
fImp = new ooHandle(ooDBObj)(*((ooHandle(ooDBObj)*)db.getImp()));
}
//______________________________________________________________________________
rooDBObj& rooDBObj::operator=(const rooDBObj& db)
{
// assignment operator
*((ooHandle(ooDBObj)*)fImp) = *((ooHandle(ooDBObj)*)db.getImp());
return *this;
}
//______________________________________________________________________________
Bool_t rooDBObj::change(const TString& newDB,
const TString& newHost,
const TString& newPath,
FILE* fp) const
{
// newDB - new system name of the database. This feature
// is currently not implemented. Always pass the
// value of "" for this parameter.
// newHost - new name of the host on which the database
// file resides
// newPath - new local path name of the database file. The
// database file name should be the last component of
// the path name.
// fp - pointer to a transcript file to which the
// information for the database is echoed before
// and after invoking this member function. The
// default is stdout.
//
// Use this member function to rename or physically move a database file
// to a new location. Objectivity/DB tries to get an exclusive update lock
// on the corresponding database when the member function is invoked.
// If it cannot obtain the lock, the member function returns an error
// status.
// If Objectivity/DB obtains the exclusive update lock, this member
// function logically renames or relocates the database file within the
// federated database. However, you must then physically move or
// rename the file using the operating system command to move a file.
const char* db = newDB.IsNull() ? 0 : newDB.Data();
return ((ooHandle(ooDBObj)*)fImp)->change(db,
newHost.Data(),
newPath.Data(),fp);
}
//______________________________________________________________________________
Bool_t rooDBObj::close() const
{
// Closes the referenced database.
gooTopDB = gprevDB;
return ((ooHandle(ooDBObj)*)fImp)->close();
}
//______________________________________________________________________________
rooFDObj rooDBObj::containedIn()
{
// Returns object handle to federated database in which the
// database is contained.
ooHandle(ooFDObj) fd = ((ooHandle(ooDBObj)*)fImp)->containedIn();
if(!fFD) fFD = new rooFDObj(&fd);
else fFD->setImp(&fd);
return *fFD;
}
//______________________________________________________________________________
rooFDObj& rooDBObj::containedIn(rooFDObj& fd)
{
// Returns object handle to federated database in which the
// database is contained.
ooHandle(ooFDObj)* contFD = (ooHandle(ooFDObj)*)fd.getImp();
((ooHandle(ooDBObj)*)fImp)->containedIn(*contFD);
if(!fFD) fFD = new rooFDObj((void*)contFD);
else fFD->setImp(&contFD);
return *fFD;
}
//______________________________________________________________________________
Bool_t rooDBObj::contains(rooContItr& itr,Int_t openMode) const
{
// Initializes the iterator contI to traverse all containers in the
// referenced database. Objects of the iteration are automatically opened
// in the mode specified by openMode. The default is kooNoOpen (do not
// open the container automatically).
ooItr(ooContObj)* contItr = (ooItr(ooContObj)*)itr.getImp();
return ((ooHandle(ooDBObj)*)fImp)->contains(*contItr,(ooMode)openMode);
}
//______________________________________________________________________________
Bool_t rooDBObj::convertObjects()
{
// Convert all objects affected by schema evolution operations within a
// database to their current class representations.
return ((ooHandle(ooDBObj)*)fImp)->convertObjects();
}
//______________________________________________________________________________
Bool_t rooDBObj::exist(const TString& dbName,
Int_t openMode)
{
// Tests for the existence of a database. Returns the constant kTRUE if
// the database with system name dbName exists in the federated
// database referenced by handle fdH, otherwise returns oocFalse. If the
// database exists and openMode is oocRead or kooUpdate, the database
// is opened and its object reference or handle is initialized to the
// database. If openMode is kooRead or kooUpdate, and exist returns
// kFALSE, the database either does not exist or the database exists but
// is not accessible, and the object reference or handle is set to null. If
// openMode is kooNoOpen and the database exists, the database is not
// opened, but the object reference or handle is initialized to the database.
// If openMode is kooNoOpen and the database does not exist, the
// database is not opened, and the object reference or handle is set to null.
return ((ooHandle(ooDBObj)*)fImp)->exist(dbName.Data(),(ooMode)openMode);
}
//______________________________________________________________________________
Bool_t rooDBObj::exist(const rooFDObj &fd,
const TString& dbName,
Int_t openMode)
{
// Tests for the existence of a database. Returns the constant kTRUE if
// the database with system name dbName exists in the federated
// database referenced by handle fdH, otherwise returns oocFalse. If the
// database exists and openMode is oocRead or kooUpdate, the database
// is opened and its object reference or handle is initialized to the
// database. If openMode is kooRead or kooUpdate, and exist returns
// kFALSE, the database either does not exist or the database exists but
// is not accessible, and the object reference or handle is set to null. If
// openMode is kooNoOpen and the database exists, the database is not
// opened, but the object reference or handle is initialized to the database.
// If openMode is kooNoOpen and the database does not exist, the
// database is not opened, and the object reference or handle is set to null.
ooHandle(ooFDObj)* fdObj = (ooHandle(ooFDObj)*)fd.getImp();
return ((ooHandle(ooDBObj)*)fImp)->exist(*fdObj,dbName.Data(),(ooMode)openMode);
}
//______________________________________________________________________________
TString rooDBObj::fileName() const
{
// Returns string containing full file name of the
// database file, including path information.
return TString(((ooHandle(ooDBObj)*)fImp)->fileName());
}
//______________________________________________________________________________
rooContObj rooDBObj::getDefaultContObj(Int_t openMode) const
{
// Returns object handle of the default container for the
// database.
ooHandle(ooContObj) cont;
cont = ((ooHandle(ooDBObj)*)fImp)->getDefaultContObj((ooMode)openMode);
return rooContObj(&cont);
}
//______________________________________________________________________________
TString rooDBObj::hostName() const
{
// Returns string containing name of the network
// host on which the database file is located
return TString(((ooHandle(ooDBObj)*)fImp)->hostName());
}
//______________________________________________________________________________
Bool_t rooDBObj::isValid() const
{
// kTRUE if the object handle is valid.
return ((ooHandle(ooDBObj)*)fImp)->isValid();
}
//______________________________________________________________________________
Bool_t rooDBObj::lock(Int_t lockMode) const
{
// Explicitly locks the database and propagates the lock to any objects
// associated through links that have lock propagation enabled.
return ((ooHandle(ooDBObj)*)fImp)->lock((ooLockMode)lockMode);
}
//______________________________________________________________________________
TString rooDBObj::name() const
{
// Returns the system name of the referenced database
return TString(((ooHandle(ooDBObj)*)fImp)->name());
}
//______________________________________________________________________________
ULong_t rooDBObj::numContObjs() const
{
// Returns the number of containers in a database.
return ((ooHandle(ooDBObj)*)fImp)->numContObjs();
}
//______________________________________________________________________________
Bool_t rooDBObj::open(const TString& DBname, Int_t openMode)
{
// Opens the referenced database in the access mode specified by
// openMode, either kooRead and kooUpdate. The default open mode is
// kooRead.
Bool_t ret = ((ooHandle(ooDBObj)*)fImp)->open(DBname.Data(),(ooMode)openMode);
if(ret) {
gprevDB = gooTopDB;
gooTopDB = this;
}
return ret;
}
//______________________________________________________________________________
Bool_t rooDBObj::open(const rooFDObj& FDhandle,
const TString& DBname, Int_t openMode )
{
// Opens the referenced database in the access mode specified by
// openMode, either kooRead and kooUpdate. The default open mode is
// kooRead.
ooHandle(ooFDObj)* fdObj = (ooHandle(ooFDObj)*)FDhandle.getImp();
Bool_t ret = ((ooHandle(ooDBObj)*)fImp)->open(*fdObj,DBname.Data(),(ooMode)openMode);
if(ret) {
gprevDB = gooTopDB;
gooTopDB = this;
}
return ret;
}
//______________________________________________________________________________
Bool_t rooDBObj::open(Int_t openMode) const
{
// Opens the referenced database in the access mode specified by
// openMode, either kooRead and kooUpdate. The default open mode is
// kooRead.
Bool_t ret = ((ooHandle(ooDBObj)*)fImp)->open((ooMode)openMode);
if(ret) {
gprevDB = gooTopDB;
gooTopDB = this;
}
return ret;
}
//______________________________________________________________________________
Int_t rooDBObj::openMode() const
{
// Returns the mode in which the currently referenced database has been
// opened.
return ((ooHandle(ooDBObj)*)fImp)->openMode();
}
//______________________________________________________________________________
TString rooDBObj::pathName() const
{
// Returns string containing full path of the directory
// where the database file is located
return TString(((ooHandle(ooDBObj)*)fImp)->pathName());
}
//______________________________________________________________________________
Bool_t rooDBObj::tidy(FILE* fp, const TString& hostName,
const TString& pathName) const
{
// Use the tidy member function to invoke the
// ootidy tool from within an application to tidy a database.
// When Objectivity/DB is tidying a database, it needs a temporary
// scratch file to hold the intermediate data. By default, this scratch file
// is created in the directory that contains the database file. The
// hostName and pathName arguments allow you to control where the
// scratch file is created. If either hostName or pathName is zero or empty
// (""), the scratch file is created in the default directory.
//
// When using this member function, you must follow these steps:
// 1. Start a transaction.
// 2. Open the database for update.
// 3. Invoke the rooDBObj::tidy member function.
// 4. Immediately commit the transaction.
//
// You cannot manipulate any database, container, or basic object within
// the transaction before invoking the rooDBObj::tidy
// member function. This member function performs physical storage
// compaction and relocation. After calling this function, some of the
// cached system data is in an inconsistent state, so it is important that
// you immediately commit the transaction so that the system data can be
// reinitialized to a known state.
// You cannot abort a transaction after calling this member function.
return ((ooHandle(ooDBObj)*)fImp)->tidy(fp,hostName.Data(),pathName.Data());
}
//______________________________________________________________________________
Int_t rooDBObj::typeN() const
{
// Returns the string "ooDBObj"
return ((ooHandle(ooDBObj)*)fImp)->typeN();
}
//______________________________________________________________________________
TString rooDBObj::typeName() const
{
// Returns the type number of ooDBObj.
return TString(((ooHandle(ooDBObj)*)fImp)->typeName());
}
//______________________________________________________________________________
Bool_t rooDBObj::update() const
{
// Opens the referenced database in update access mode
return ((ooHandle(ooDBObj)*)fImp)->update();
}
//______________________________________________________________________________
const char* rooDBObj::GetTitle()
{
// returns hostname::pathname of this database
fTitle = hostName() + "::" + fileName();
return fTitle.Data();
}
//______________________________________________________________________________
void rooDBObj::Print(Option_t *option)
{
// print out content of database
if(!isValid()) return;
rooContItr cI;
Bool_t rc;
rc = contains(cI);
if(!rc) return;
while(cI.next()) {
cI.Print();
}
}
//______________________________________________________________________________
void rooDBObj::Browse(TBrowser *b)
{
// browse content of database
rooContObj* cont;
if(!isValid() || !b) return;
rooContItr cI;
Bool_t rc;
rc = contains(cI);
if(!rc) return;
while(cI.next()) {
cont = new rooContObj(cI); // mem.leak ?
b->Add(cont);
}
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.