BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
// 
// Class BrDbComponent
//
// Rep of a Component inside and outside of Database.
// 

// $Author: hagel $
// $Date: 2001/06/21 14:55:16 $
// $Copyright: Brahms collaboration
// $Id: BrDbComponent.cxx,v 1.1.1.1 2001/06/21 14:55:16 hagel Exp $
//

#include <BrDbComponent.h>
#ifndef BRAT_BrException
#include "BrException.h"
#endif
#ifndef WIN32 
#include <stdlib.h>
#else 
#include <cstdlib>
#endif

ClassImp(BrDbComponent); // Component Class for BRAHMS database

//____________________________________________________________________
const Char_t* BrDbComponent::kTableName = COMPONENT_NAME;

//____________________________________________________________________
 BrDbComponent::BrDbComponent(const Char_t* name,
			 Int_t typeId,
			 Int_t detectorId)
{
  SetName(name);
  fDetectorID = typeId;
  fTypeID = detectorId;
}

//____________________________________________________________________
 BrDbComponent* BrDbComponent::SingleInstance(TSQLRow* row)
{
  // Returns an instance of a BrDbComponent. User needs to store this
  // object imidiatly. 
  if (!row) return 0;
  BrDbComponent* com = new BrDbComponent(row->GetField(1),
				     strtol(row->GetField(2),NULL,0),
				     strtol(row->GetField(3),NULL,0));
  com->SetDBID(strtol(row->GetField(0),NULL,0));
  return com;
}


//____________________________________________________________________
 TObjArray* BrDbComponent::MultipleInstance(TSQLResult* res)
{
  // Returns an (1D) array of BrDbComponents matching Query that made the
  // TSQLResult. User need to store this immediately. 
  Int_t count = (res) ? res->GetRowCount() : 0;
  TObjArray* table = new TObjArray(count);

  for (Int_t i = 0; i < count; i++)
    table->Add(BrDbComponent::SingleInstance(res->Next()));
  
  return table;
}

//____________________________________________________________________
BrDbQuery* 
 BrDbComponent::Create(void) 
{
  return BrDbQuery::Create(BrDbComponent::kTableName,
			   "name     VARCHAR(64) NOT NULL,"
			   "type     INT NOT NULL,"
			   "detector INT NOT NULL");
}

//____________________________________________________________________
BrDbQuery* 
 BrDbComponent::Insert(void) 
{
  return BrDbQuery::Insert(BrDbComponent::kTableName,
			   Form("%d, '%s', %d, %d", 
				GetDBID(), fName, 
				fTypeID, fDetectorID));
}

//____________________________________________________________________
void 
 BrDbComponent::SetName(const Char_t* name) 
{ 
  if (strlen(name) > 64) {
    strncpy(fName, name, 63);
    fName[63] = '0';
  }
  else 
    strcpy(fName, name);
}


//
// $Log: BrDbComponent.cxx,v $
// Revision 1.1.1.1  2001/06/21 14:55:16  hagel
// Initial revision of brat2
//
// Revision 1.5  2001/06/05 18:40:10  cholm
// Removed BrDbInc.h an all references to it
//
// Revision 1.4  2001/03/22 20:44:03  cholm
// Added protection for NULL TSqlRow in SingleInstance methods, and cleaned
// up a bit of the stuff.
//
// Revision 1.3  2000/05/10 15:56:12  nbi
// Added the classes BrRunsDb, BrGeometriesDb, changed some code, bug
// corrections , and so on. It's almost there ;-)
//
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS