|
// // Class BrMainDb // // Singleton class, that connects woth top level database // Name and host of database is set at compile time in // BrDBInc.hh, unless overriden in ctor. // // Provides methods to connect ot additional databases. // // $Author: cholm $ // $Date: 2001/10/08 10:55:05 $ // $Copyright: BRAHMS Collabration // $Id: BrMainDb.cxx,v 1.6 2001/10/08 10:55:05 cholm Exp $ // // 20-jun-2000 ah Substitute hostname for "localhost" // 20-jun-2000 ah BrMainDb now uses the passwd parameter when connecting #include <BrMainDb.h> #include <TString.h> #ifndef BRAT_BrException #include "BrException.h" #endif #ifndef BRAT_BrRdbmMainDb #include "BrRdbmMainDb.h" #endif #ifndef ROOT_TSystem #include "TSystem.h" #endif #include <iostream.h> //____________________________________________________________________ ClassImp(BrMainDb); // Database manager class for BRAT //____________________________________________________________________ BrMainDb* BrMainDb::fgInstance = 0; //____________________________________________________________________ BrDbPerson* gPerson = 0; //____________________________________________________________________ BrMainDb::BrMainDb() { if (fgInstance) throw new BrWarning("BrMainDb", "Only one instance of BrMainDb allowed"); fCalibDB = 0; fRunDB = 0; fGeomDB = 0; fPassDB = 0; } //____________________________________________________________________ BrMainDb::~BrMainDb() { delete fCalibDB; delete fRunDB; delete fGeomDB; delete fPassDB; } //____________________________________________________________________ BrMainDb* BrMainDb::Instance() { if (!fgInstance) fgInstance = BrRdbmMainDb::Instance(); return fgInstance; } //____________________________________________________________________ Bool_t BrMainDb::ConnectToDB(BrDb*& db, const Char_t* user) { // Connect to the a database listed in the main database. Throws a // BrException in case of error. if (!db) { if (Verbose() > 0) Error("ConnectToDb", "null pointer to a BrDb passed"); return kFALSE; } // Get the information on the database from the DB table. if(Verbose() > 3) cout << "Connecting to " << db->GetName() << endl; BrDbDb* dbInfo = GetDb(db->GetName()); if (!dbInfo) { Warning("ConnectToDB", "Couldn't get database info '%s'", db->GetName()); // Clean up delete db; db = 0; } if (db) { db->SetDbName(dbInfo->GetFile()); db->SetHostName(dbInfo->GetHost()); db->SetUserName(user); #if 0 db->SetRdbmType(dbInfo->GetType()); #endif } // Clean up delete dbInfo; if (db && !db->Connect()) { Error("ConnectToDb", "couldn't connect to database %s", db->GetDbName()); delete db; db = 0; } return db ? kTRUE : kFALSE; } //____________________________________________________________________ BrRunsDb* BrMainDb::ConnectToRun(const Char_t *user) { // Connect to Run database if(!fRunDB) { if(Verbose()) cout << "Connecting to runs" << endl; fRunDB = BrRunsDb::Instance(); fRunDB->SetName("runs"); } ConnectToDB((BrDb*)fRunDB, user); return fRunDB; } //____________________________________________________________________ BrPassDb* BrMainDb::ConnectToPass(const Char_t *user) { // Connect to Run database if(!fPassDB) { fPassDB = BrPassDb::Instance(); fPassDB->SetName("pass%"); } ConnectToDB((BrDb*)fPassDB, user); return fPassDB; } //____________________________________________________________________ BrCalibrationsDb* BrMainDb::ConnectToCalib(const Char_t* user) { // Connect to Calibrations database if (!fCalibDB) { fCalibDB = BrCalibrationsDb::Instance(); fCalibDB->SetName("calib%"); } if(DebugLevel()){ cout << "Connecting to Calibration DB" << endl; cout << "Name" << fCalibDB->GetName() << endl; cout << "user" << user << endl; } ConnectToDB((BrDb*)fCalibDB, user); return fCalibDB; } //____________________________________________________________________ BrGeometriesDb* BrMainDb::ConnectToGeom(const Char_t *user) { // Connect to Geometries database if (!fGeomDB) { fGeomDB = BrGeometriesDb::Instance(); fGeomDB->SetName("geom%"); } ConnectToDB((BrDb*)fGeomDB, user); return fGeomDB; } // EOF |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|