|
//____________________________________________________________________ // // See BrPassDb and BrRootDb // //____________________________________________________________________ // // $Id: BrRootPassDb.cxx,v 1.1 2001/10/08 11:01:29 cholm Exp $ // $Author: cholm $ // $Date: 2001/10/08 11:01:29 $ // $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov> // #ifndef BRAT_BrRootPassDb #include "BrRootPassDb.h" #endif #ifndef BRAT_BrException #include "BrException.h" #endif #ifndef WIN32 #include <cstdlib> #include <iostream> #else #include <stdlib.h> #include <iostream.h> #endif #include "TObjString.h" //____________________________________________________________________ ClassImp(BrRootPassDb); //____________________________________________________________________ BrRootPassDb::BrRootPassDb(const Char_t* name, const Char_t* title) { // Normal constructor. Singleton. fImplementation = new BrRootDb(name, title); fPass = 0; fInputFile = 0; fOutputFile = 0; } //____________________________________________________________________ BrPassDb* BrRootPassDb::Instance(void) { // Returns an instance of the Calibration Database connection. // Connection _must_ be constructed somewhere previousto calling // this static method. if (!fgInstance) fgInstance = new BrRootPassDb; return fgInstance; } //____________________________________________________________________ Bool_t BrRootPassDb::Connect(Option_t* option) { if (!fImplementation->Connect()) return kFALSE; TFile* connection = (TFile*)fImplementation->GetConnection(); if (!connection) return kFALSE; Bool_t retval = kTRUE; if (!(fPass = (TObjArray*)connection->Get(BrDbPass::kTableName))) retval = kFALSE; if (!(fOutputFile = (TObjArray*)connection->Get(BrDbOutputFile::kTableName))) retval = kFALSE; if (!(fInputFile = (TObjArray*)connection->Get(BrDbInputFile::kTableName))) retval = kFALSE; if (!retval) { fPass = 0; fInputFile = 0; fOutputFile = 0; Close(); } return retval; } //____________________________________________________________________ void BrRootPassDb::AddPass(BrDbPass*& pass) { // Add a pass to the database. Make sure that there are not two // entries of same run number with same revision. if (!IsConnected()) return; // First see if there is a pass in DB with this run number. If so, // we get it, find the revision id, increment and put the new one // in. TIter next(fPass); BrDbPass* s = 0; BrDbPass* p = 0; while ((p = (BrDbPass*)next())) { if (p->GetRunNo() == pass->GetRunNo()) { if (!s) s = p; if (s->GetRevisionId() <= p->GetRevisionId()) s = p; } } Int_t largestRev = (s ? s->GetRevisionId() : 0); if (DebugLevel() > 1) cout << "Setting revision to " << largestRev + 1 << endl; pass->SetRevisionId(largestRev + 1); //First do the pass tables. LockTables(BrDbPass::kTableName); pass->SetDBID(Increment()); fPass->Add(pass); UnLockTables(); } //____________________________________________________________________ void BrRootPassDb::AddInputFile(BrDbInputFile*& inputFile) { // Add an inputfile to the database. Make sure that the passId is // set. if (!IsConnected()) return; if (strlen(inputFile->GetFileName()) < 1) throw new BrWarning("AddInputFile", "no file name"); if (inputFile->GetRunNo() < 0) throw new BrWarning("AddInputFile", "run number invalid: %d", inputFile->GetRunNo()); if (inputFile->GetPassId() < 0) throw new BrWarning("AddInputFile", "pass id invalid: %d", inputFile->GetPassId()); TString fn(inputFile->GetFileName()); TIter next(fInputFile); BrDbInputFile* i = 0; while ((i = (BrDbInputFile*)next())) if (fn == i->GetFileName() && inputFile->GetRunNo() == i->GetRunNo() && inputFile->GetPassId() == i->GetPassId()) throw new BrWarning("BrRootPassDb::AddInputFile", "inputfile %s already exists", inputFile->GetFileName()); LockTables(BrDbInputFile::kTableName); inputFile->SetDBID(Increment()); fInputFile->Add(inputFile); UnLockTables(); } //____________________________________________________________________ void BrRootPassDb::AddOutputFile(BrDbOutputFile*& outputFile) { // Add an outputfile to the database. Make sure that the passId is // set. if (!IsConnected()) return; if (strlen(outputFile->GetFileName()) < 1) throw new BrWarning("AddOutputFile", "no file name"); if (outputFile->GetRunNo() < 0) throw new BrWarning("AddOutputFile", "run number invalid: %d", outputFile->GetRunNo()); if (outputFile->GetPassId() < 0) throw new BrWarning("AddOutputFile", "pass id invalid: %d", outputFile->GetPassId()); TString fn(outputFile->GetFileName()); TIter next(fOutputFile); BrDbOutputFile* i = 0; while ((i = (BrDbOutputFile*)next())) if (fn == i->GetFileName() && outputFile->GetRunNo() == i->GetRunNo() && outputFile->GetPassId() == i->GetPassId()) throw new BrWarning("BrRootPassDb::AddOutputFile", "outputfile %s already exists", outputFile->GetFileName()); LockTables(BrDbOutputFile::kTableName); outputFile->SetDBID(Increment()); fOutputFile->Add(outputFile); UnLockTables(); } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXPass(const Char_t* condition) { // Always returns all passes return fPass; } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXPass(const Char_t* name, Int_t runno) { // Always returns all passes TObjArray* gotcha = new TObjArray; TString n(name); TIter next(fPass); BrDbPass* p = 0; while ((p = (BrDbPass*)next())) if (n == p->GetName() && runno == p->GetRunNo()) gotcha->Add(new BrDbPass(*p)); if (gotcha->GetEntries() < 1) { delete gotcha; return 0; } return gotcha; } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXInputFile(const Char_t* condition) { // Always returns allinput files return fInputFile; } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXInputFile(Int_t passId) { // Get all input files associated with the pass ID given. TObjArray* gotcha = new TObjArray; TIter next(fInputFile); BrDbInputFile* i = 0; while ((i = (BrDbInputFile*)next())) if (passId == i->GetPassId()) gotcha->Add(new BrDbInputFile(*i)); if (gotcha->GetEntries() < 1) { delete gotcha; return 0; } return gotcha; } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXOutputFile(const Char_t* condition) { // Always returns all output files return fOutputFile; } //____________________________________________________________________ TObjArray* BrRootPassDb::GetXOutputFile(Int_t passId) { // Get all output files associated with the pass ID given. TObjArray* gotcha = new TObjArray; TIter next(fOutputFile); BrDbOutputFile* o = 0; while ((o = (BrDbOutputFile*)next())) if (passId == o->GetPassId()) gotcha->Add(new BrDbOutputFile(*o)); if (gotcha->GetEntries() < 1) { delete gotcha; return 0; } return gotcha; } //____________________________________________________________________ BrDbPass* BrRootPassDb::GetPass(const Char_t* condition) { // Not implmented Warning("GetPass", "not implmented"); return 0; } //____________________________________________________________________ BrDbPass* BrRootPassDb::GetPass(const Char_t* name, Int_t runno, Int_t revision) { // Find a pass with name <name> belonging to run <runno>. The latest // revision is returned, unless a specific revision is specified. TObjArray* a = GetXPass(name, runno); if (!a) return 0; TIter next(a); BrDbPass* s = revision >= 0 ? 0 :(BrDbPass*)a->At(0); BrDbPass* p = 0; while ((p = (BrDbPass*)next())) { if (revision >= 0) { if (revision == p->GetRevisionId()) { s = new BrDbPass(*p); a->Delete(); delete a; return s; } } else { if (s->GetRevisionId() <= p->GetRevisionId()) s = p; } } p = new BrDbPass(*s); a->Delete(); delete a; return p; } //____________________________________________________________________ BrDbInputFile* BrRootPassDb::GetInputFile(const Char_t* condition) { Warning("GetPass", "not implmented"); return 0; } //____________________________________________________________________ BrDbInputFile* BrRootPassDb::GetInputFile(const Char_t* fn, Int_t passId) { TObjArray* a = GetXInputFile(passId); if (!a) return 0; TString n(fn); TIter next(a); BrDbInputFile* i = 0; while ((i = (BrDbInputFile*)next())) { if (n == i->GetFileName()) { BrDbInputFile* r = new BrDbInputFile(*i); a->Delete(); delete a; return r; } } return 0; } //____________________________________________________________________ BrDbOutputFile* BrRootPassDb::GetOutputFile(const Char_t* condition) { Warning("GetPass", "not implmented"); return 0; } //____________________________________________________________________ BrDbOutputFile* BrRootPassDb::GetOutputFile(const Char_t* fn, Int_t passId) { TObjArray* a = GetXOutputFile(passId); if (!a) return 0; TString n(fn); TIter next(a); BrDbOutputFile* o = 0; while ((o = (BrDbOutputFile*)next())) { if (n == o->GetFileName()) { BrDbOutputFile* r = new BrDbOutputFile(*o); a->Delete(); delete a; return r; } } return 0; } //____________________________________________________________________ // // EOF // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|