BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//
// $Id: BrDbMagnetVolume.cxx,v 1.6 2002/06/06 23:04:22 hagel Exp $
// $Author: hagel $
// $Date: 2002/06/06 23:04:22 $
// $Copyright: 2001 Brahms Collaboration 
//
///////////////////////////////////////////////////////////////////////
//
// BrDbMagnetVolume is a class that maps onto the BRAHMS DB
// magnet parameter tables.  This table has only information on the magnet
// which goes beyond the information contained in BrDbDetectorVolume.
// At the moment (3-May-2001), that is frontEdge and backEdge.
// It is anticipated that in the future, this class might also be
// extended to contain field maps.
//
///////////////////////////////////////////////////////////////////////


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

ClassImp(BrDbMagnetVolume);
 
//____________________________________________________________________
const Char_t* BrDbMagnetVolume::kTableName = "MagnetVolumes";

//____________________________________________________________________
 BrDbMagnetVolume::BrDbMagnetVolume(void)
{
  // Empty default constructor.
}

//____________________________________________________________________
 BrDbMagnetVolume::BrDbMagnetVolume(const Char_t *name, 
				   Int_t validstart, 
				   Int_t validstop, 
				   Int_t fromstart, 
				   Int_t fromend, 
				   Int_t date, 
				   Double_t frontEdge,
				   Double_t backEdge,
				   EFieldTypes fieldType,
				   const Char_t *fieldFilename,
				   ERunTypes runType) 
{
  // Constructor.
  SetName(name);
  fValidStart = validstart;
  fValidStop  = validstop;
  fFromStart  = fromstart;
  fFromEnd    = fromend;
  fDate       = date;
  fFrontEdge  = frontEdge;
  fBackEdge   = backEdge;
  fFieldType  = fieldType;
  SetFieldFilename(fieldFilename);
  fRunType    = runType;
  fRevisionId = 0;
}

//____________________________________________________________________
 BrDbQuery* BrDbMagnetVolume::Create(void)
{
  // Returns a SQL query string suitable for creation of this table in
  // a database. 

  return BrDbQuery::Create(BrDbMagnetVolume::kTableName,
			  "MagnetName    VARCHAR(64) NOT NULL,
                           validStart    INT         NOT NULL,
                           validStop     INT         NOT NULL,
                           fromStart     INT         NOT NULL,
                           fromStop      INT         NOT NULL,
                           date          INT         NOT NULL,
                           runType       INT         NOT NULL,
			   FrontEdge     FLOAT(12,4) NOT NULL,
                           BackEdge      FLOAT(12,4) NOT NULL,
                           FieldType     INT         NOT NULL,
                           FieldFileName VARCHAR(64) NOT NULL,
                           RevisionId    INT         NOT NULL");
}

//____________________________________________________________________
 BrDbMagnetVolume* BrDbMagnetVolume::SingleInstance(TSQLRow* row)
{
  // Returns an instance of a BrDbMagnetVolume. User needs to store this
  // object immediately.
  if (!row) return 0;
  Float_t frontEdge,backEdge;
  BrDbMagnetVolume::EFieldTypes fieldType;
  ERunTypes runType;
  sscanf(row->GetField(7),"%d",&runType);
  sscanf(row->GetField(8),"%f",&frontEdge);
  sscanf(row->GetField(9),"%f",&backEdge);
  sscanf(row->GetField(10),"%d",&fieldType);

  BrDbMagnetVolume* vol = new BrDbMagnetVolume(
			    row->GetField(1),                //name
                            strtol(row->GetField(2),NULL,0), //startvalid
                            strtol(row->GetField(3),NULL,0), //stopvalid
                            strtol(row->GetField(4),NULL,0), //fromstart
                            strtol(row->GetField(5),NULL,0), //fromstop
                            strtol(row->GetField(6),NULL,0), //creation date
                            frontEdge,backEdge,fieldType,
			    row->GetField(11));              //field file name

  vol->SetRevisionId(strtol(row->GetField(12),NULL,0));  //revision

  return vol;
}

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

//____________________________________________________________________
 BrDbQuery* BrDbMagnetVolume::Insert(void) 
{
  return BrDbQuery::Insert(BrDbMagnetVolume::kTableName,
	  Form("%d, '%s', %d, %d, %d, %d, %d, %d, %f, %f, %d, '%s', %d", 
		GetDBID(), fName,
                fValidStart,fValidStop,fFromStart, fFromEnd, fDate,
	        fRunType,
                fFrontEdge,fBackEdge,
	        fFieldType,fFieldFilename,fRevisionId));
}

//____________________________________________________________________
 void BrDbMagnetVolume::SetName(const Char_t *name) {
  //Set the detector name
  Int_t len = strlen(name);
  if(len > 63) len = 63;
  strncpy(fName,name,len);
  fName[len] = 0;
}

//____________________________________________________________________
 void BrDbMagnetVolume::SetFieldFilename(const Char_t *name) {
  //Set the detector name
  if(!name) {
     strcpy(fFieldFilename," ");
     return;
     }
  Int_t len = strlen(name);
  if(len > 63) len = 63;
  strncpy(fFieldFilename,name,len);
  fFieldFilename[len] = 0;
}


//
// $Log: BrDbMagnetVolume.cxx,v $
// Revision 1.6  2002/06/06 23:04:22  hagel
// Fix small bugs with magnet revisions
//
// Revision 1.5  2002/04/16 14:44:12  hagel
// Implement Hall Probe reading from Db in ySQL mode.  Major surgery on BrGeometryDbManager concerning building BrDetectorVolume and BrMagnetVolume
//
// Revision 1.4  2001/08/14 14:45:36  hagel
// Yet another iteration on GeometryDB
//
// Revision 1.3  2001/08/03 09:19:09  hagel
// Small iteration on Geometry DB stuff
//
// Revision 1.2  2001/08/02 03:13:46  hagel
// Yet another iteration on GeometryDB; this should be close to last
//
// Revision 1.1.1.1  2001/06/21 14:55:18  hagel
// Initial revision of brat2
//
// Revision 1.5  2001/06/05 18:40:44  cholm
// Removed BrDbInc.h an all references to it
//
// Revision 1.4  2001/05/07 21:22:02  hagel
// Next iteration of Geometry DB
//
// Revision 1.3  2001/04/20 16:13:47  hagel
// Rework MySQL mode of BrMagnetVolume
//
// Revision 1.2  2001/03/22 20:44:42  cholm
// Added protection for NULL TSqlRow in SingleInstance methods, and cleaned
// up a bit of the stuff.
//
// Revision 1.1  2001/03/07 16:54:03  hagel
// Initial revision, probably needs more iterations
//
//

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