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

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

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

ClassImp(BrDbDetector); // Detector Class for BRAHMS database

//____________________________________________________________________
const Char_t* BrDbDetector::kTableName = DETECTOR_NAME;

//____________________________________________________________________
 BrDbDetector::BrDbDetector(const Char_t* name,
		       Int_t   typeId,
		       Int_t   sectorId,
		       Int_t   maintainerId)
{
  SetName(name);
  fSectorID = sectorId;
  fTypeID = typeId;
  fMaintainerID = maintainerId;
}

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


//____________________________________________________________________
TObjArray* 
 BrDbDetector::MultipleInstance(TSQLResult* res)
{
  // Returns an (1D) array of BrDbDetectors 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(BrDbDetector::SingleInstance(res->Next()));
  
  return table;
}

//____________________________________________________________________
BrDbQuery* 
 BrDbDetector::Create(void) 
{
  return BrDbQuery::Create(BrDbDetector::kTableName,
			   "name       VARCHAR(64) NOT NULL,"
			   "type       INT NOT NULL, "
			   "sector     INT NOT NULL, " 
			   "maintainer INT NOT NULL, " 
			   "UNIQUE(name)"); 
}

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

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

  
//
// $Log: BrDbDetector.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:24  cholm
// Removed BrDbInc.h an all references to it
//
// Revision 1.4  2001/03/22 20:44:23  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