BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//________________________________________________________________
//                                                                 
// BrDataTable is a BRAHMS data object that has a list of          
// data objects.  It is meant to be used in grouping like kinds    
// of information together.  The list is fObjectList which is a    
// TObjArray.  Several methods manage the fObjectList with the same
// names as TObjArray                                              
//                                                                 
//________________________________________________________________

//
// $Id: BrDataTable.cxx,v 1.1.1.1 2001/06/21 14:54:58 hagel Exp $
// $Author: hagel $
// $Date: 2001/06/21 14:54:58 $
//
#include <iostream.h>
#include "BrDataTable.h"
#include "TClass.h"
#ifndef ROOT_TROOT
#include "TROOT.h"
#endif

ClassImp(BrDataTable);


//________________________________________________________________
 BrDataTable::BrDataTable()
{
  // Defaults constructor. Does nothing.
  // Don't use this constructor unless you have to and know
  // what you are doing
  // Use BrDataTable(Char_t *name) instead.

  fObjectList = 0;
}

//________________________________________________________________
 BrDataTable::BrDataTable(const Char_t *Name, 
			 const Char_t *Title) 
  : BrDataObject(Name, Title)
{
  // Constructor. Create the data container setting the name
  // (and title, if supplied)
   
  if(Title)
    SetTitle(Title);

  fObjectList = new TObjArray();
}

//________________________________________________________________
 BrDataTable::~BrDataTable()
{
  // Destructor. Delete BrDataTable and all the data objects
  // currently owned by BrDataTable
#ifdef _BRDEBUG
  cout << "BrDataTable : dtor" << endl;
#endif
  if(fObjectList){
    fObjectList->Delete();
    delete fObjectList; fObjectList = 0;
  }
}

//________________________________________________________________
void 
 BrDataTable::Add(TObject *object)
{
  // Add an object to the object list.  Essentially uses
  // TObjArray::Add(object); 
  if(!fObjectList)
    fObjectList = new TObjArray();
  
  fObjectList->Add(object);
}

//________________________________________________________________
void 
 BrDataTable::AddAt(TObject *object,Int_t idx)
{
  // Add an object to the object list at a specific index.
  // Essentially  uses TObjArray::AddAt(object,idx); 
  if(!fObjectList)
    fObjectList = new TObjArray();
  
  fObjectList->AddAt(object,idx);
}

//________________________________________________________________
void 
 BrDataTable::DeleteAndCompress(TObject *obj)
{
  // Removes an object from the Object List.  Object is then deleted. 
  // Then the object list is compressed
  DeleteObject(obj);
  Compress();
}

//________________________________________________________________
void 
 BrDataTable::DeleteAndCompressAt(Int_t i)
{
  // Removes an object an object at specified index from the Object List.
  // Essentially uses TObjArray::RemoveAt(i);
  // After object is removed, it is deleted.
  // Then the object list is compressed
  DeleteObjectAt(i);
  Compress();
}

//________________________________________________________________
void 
 BrDataTable::DeleteObject(TObject *obj)
{
  // Removes an object from the Object List.  Object is then deleted. 
  delete(fObjectList->Remove(obj));
}

//________________________________________________________________
void 
 BrDataTable::DeleteObjectAt(Int_t i)
{
  // Removes an object an object at specified index from the Object List.
  // Essentially uses TObjArray::RemoveAt(i);
  // After object is removed, it is deleted.
  delete (fObjectList->RemoveAt(i));
}

//________________________________________________________________
void 
 BrDataTable::Browse(TBrowser* b) 
{
  TIter   next(fObjectList);
  TObject *obj;
  while((obj = next()))
    b->Add(obj,obj->GetName());
}

//________________________________________________________________
void 
 BrDataTable::Print(Option_t* option) const
{
  // Print all contained objects, passing the option along. 
  // Options:
  //    R         Recursive print [Default]
  // See also BrDataObject::Print
  BrDataObject::Print(option);

  TString opt(option);
  opt.ToLower();
  
  if (opt.Contains("r")) {
    gROOT->IncreaseDirLevel();
    TIter   next(fObjectList);
    TObject *obj = 0;
    while((obj = next())) {
      gROOT->IndentLevel();
      obj->Print(option);
    }
    
    gROOT->DecreaseDirLevel();
  }
}

//________________________________________________________________
BrDataTable& 
BrDataTable::operator += (const BrDataTable& table)
{
  // Add all of the entries of the argument to the table we are in.  
  // Copies of the entries in the adding table are made.  The copies
  // are made by transferring the persistent data into a buffer using
  // the Streamer() method, then transferring from the buffer into the
  // new object using the Streamer() method of the new object.  One
  // should evaluate if we really want copies or just to  point to the
  // objects.  That would be much easier to do, but can cause
  // conflicts when the entries in table1 and table2 are deleted and
  // one still tries to access the entries in the new table.
  TBuffer buf(TBuffer::kRead);
  TObject *object;
  TClass  *cl;
  
  Int_t nument = table.GetEntries();
  
  //First do for the first table
  for(Int_t i1 = 0; i1 < nument; i1++) {
    object = table.At(i1);
    cl = object->IsA();
    // Create a new instance of this class
    TObject *p = (TObject*)cl->New();
    // Now we need to get the data out of the other one and put into
    // the new instance. We do that here by reading the data from the
    // original object into a buffer via the Streamer.  Then the
    // Buffer Offset is reset to beginning and buffer is set to read
    // mode and the streamer for the new object is run to get out of
    // the buffer and into the new object.  A simple mcpy might be
    // faster, and would get all of the data instead of just the
    // persistent data, but might have some nasty surprises.  
    buf.Reset();
    buf.SetWriteMode();
    object->Streamer(buf);
    buf.Reset();
    buf.SetReadMode();
    p->Streamer(buf);
    
    // Add this element to the table.
   this->Add(p);
  }

  return *this;
}


//________________________________________________________________
BrDataTable 
operator+(const BrDataTable& table1, 
	  const BrDataTable& table2) 
{
  // Create a new data table and put all of the entries of the first
  // one and the second one into the new one.  Copies of the entries
  // are made.  The copies are made by transferring the persistent
  // data into a buffer using the Streamer() method,  then
  // transferring from the buffer into the new object using the
  // Streamer() method of the new object.  One should evaluate if we
  // really want copies or just to  point to the objects.  That would
  // be much easier to do, but can cause conflicts when the entries in
  // table1 and table2 are deleted and one still tries to access the
  // entries in the new table. 
  TBuffer buf(TBuffer::kRead);
  TObject *object;
  TClass  *cl;
  BrDataTable *tmp = new BrDataTable(table1.GetName());
  
  Int_t nument1 = table1.GetEntries();
  Int_t nument2 = table2.GetEntries();
  
  //First do for the first table
  for(Int_t i1=0;i1<nument1;i1++) {
    object = table1.At(i1);
    cl = object->IsA();
    // Create a new instance of this class
    TObject *p = (TObject*)cl->New();
    // Now we need to get the data out of the other one and put into
    // the new instance.  We do that here by reading the data from the
    // original object into a buffer via the Streamer.  Then the
    // Buffer Offset is reset to beginning and buffer is set to read
    // mode and the streamer for the new object is run to get out of
    // the buffer and into the new object.  A simple mcpy might be
    // faster, and would get all of the data instead of just the
    // persistent data, but might have some nasty surprises.  
    buf.Reset();
    buf.SetWriteMode();
    object->Streamer(buf);
    buf.Reset();
    buf.SetReadMode();
    p->Streamer(buf);
    
    // Add this element to the table.
    tmp->Add(p);
  }
  
  //Now do for the second table
  for(Int_t i2=0;i2<nument2;i2++) {
    object = table2.At(i2);
    cl = object->IsA();
    // Create a new instance of this class
    TObject *p = (TObject*)cl->New();
    // Now we need to get the data out of the other one and put into
    // the new instance. We do that here by reading the data from the
    // original object into a buffer via the streamer.  Then the
    // Buffer Offset is reset to beginning and buffer is set to read
    // mode and the streamer for the new object is run to get out of
    // the buffer and into the new object.  A simple mcpy might be
    // faster and would get all of the data instead of just the
    // persistent data, but might have some nasty surprises.   
    buf.Reset();
    buf.SetWriteMode();
    object->Streamer(buf);
    buf.Reset();
    buf.SetReadMode();
    p->Streamer(buf);
    
    // Add this element to the table.
    tmp->Add(p);
  }
  
  return *tmp;
}

// $Log: BrDataTable.cxx,v $
// Revision 1.1.1.1  2001/06/21 14:54:58  hagel
// Initial revision of brat2
//
// Revision 1.12  2001/06/01 15:46:43  cholm
// Fixed creation id class to be more clean.  Now sets the user name
// (if avaliable) has a Print method.
// PRint method in BrDataObject.
// Print method in BrDataTable
// Print method in BrEvent
// Print method in BrEventNode
//
// Revision 1.11  2001/05/28 15:35:00  pchristi
// Small changes. Added const arguments to container constructor and
// modified/added delete methods to BrDataTable.
//
// Revision 1.10  2000/10/03 19:29:56  cholm
// Made IsFolder() const (since it is in TObject) which was needed for the
// objects to be browsable. Aslo, as of ROOT version 2.25.02 there's a list
// of special objects, which BrEventIO now is added to. Some doc to
// BrEventNode::Clear() added! Added method BrEventNode::SetOwner().
// 						Christian Holm
//
// Revision 1.9  2000/04/13 00:02:27  cholm
// Added methods for browsing BrEvents, either directly or via
// a BrEventIO. Also added method GetROOTFile to BrEventIO.
//
// Revision 1.8  1999/09/13 21:06:51  videbaek
// Modify constructor to deal properly with Title param
//
// Revision 1.7  1999/05/12 16:22:20  hagel
// Implemented + , =+ and = operators for BrEventNode.  These will be
// useful for adding events together.  Has been tested for single pion
// events and seems to work. In the course of implementing this,
// several conflicts with const were identified.  These were cleaned
// up by adding appropriate const's where needed.

// It was checked that it did not break other things.
//
// Revision 1.6  1999/03/07 00:00:42  hagel
// 1. Implemented  BrFSTrackingModule.  Started with
//    BrMRSTrackingModule and made appropriate changes to handle the 
//    forward spectrometer.  It uses the new track classes as well as
//    extensively using geometry classes.  It also uses new methods and
//    functionality as described below. 
// 2. Changed BrMagnetVolume
//    a.  Added method SwimBack(BrLine3D &,Double_t momentum): takes a
//        track at the exit of  magnet and given the momentum, calculates
//        where the track would come into the front of the magnet.
//    b.  Added method GlobalToLocal(BrLine3D &): does a combination of
//        GlobalToLocal(BrVector3D &,BrVector3D&,0) and
//        GlobalToLocal(BrVector3D &,BrVector3D&,1)
//    c.  Added method LocalToGlobal(BrLine3D &): does a combination of
//        LocalToGlobal(BrVector3D &,BrVector3D&,0) and
//        LocalToGlobal(BrVector3D &,BrVector3D&,1)
//    d.  Changed BrDetectorVolume: same additions of methods GlobalToLocal
//        and LocalToGlobal as in BrMagnetVolume
// 2.  Added a parameter base class BrDetectorParamsBase: helps when reading
//     in database files.  Declared ASCII reading routines to be virtual.
//     Has main ReadASCIIFile which decodes the ASCII parameter files, then
//     calls the detector specific methods SetASCIIParameter
// 3.  Implemented SetASCIIParameter in BrDetectorParamsDC,
//     BrDetectorParamsTPC, 
//     BrDetectorParamsTof, BrDetectorParamsBB
// 4.  Implemented BrParameterDbManager.  It currently works similarly to
//     BrGeometryDbManager and creates the BrDetectorParamsXXX objects when
//     called.  These objects then read in ASCII parameter files with
//     a currently "well defined" format using the above implemented
//     routines using a constructor: 
//     BrDetectorParamsXXX(Char_t *name, Char_t *title,Char_t *ASCIIFileName);
// 5.  If no parameter file is specified, it executes the constructor
//     we have been using so far, namely 
//       BrDetectorParamsXXX(Char_t *name,Char_t *title).
//     These constructors generate default parameters and are
//     semi-intelligent which means they generate approximately
//     appropriate parameters depending upon which detector they are.
//     I should say that the parameters were deemed appropriate at the
//     time of writing the SetDefaultParams routine. 
//     a. It is used in the same way as BrGeometryDbManager, that is:
//        BrParameterDbManager *gParamDb = BrParameterDbManager::Instance();
//        gParamDb->SetDbParameterFileName("DetectorParameters.txt");
// 6.  Added a new directory, params, in BRAT.  This directory has the file
//     DetectorParameters.txt in it.  If the BrParameterDbManager is started
//     and the DetectorParameter.txt file is specified, it will look in the
//     $BRATSYS/params directory if it cannot find the file in the directory
//     that the user has set default to.
// 7.  Implemented BrParameterDbManager in DC digitize and tracking
//     code.  The SetDetectorParams methods have been moved to private
//     and can no longer be used from the macro or program.
// 8.  Implemented BrParameterDbManager in TPC digitize and tracking code.
// 9.  Implemented BrParameterDbManager in Tof Calibrate and
//     GeneratePid code. 
// 10  Changed the GetEntries() in BrDataTable to use the GetLast()+1
//     method in TObjArray.  This should be much faster, but has the
//     caveat that it assumes that all slots in TObjArray are full.
//     That seems to me to be the case in how we use TObjArray at
//     least in BrDataTable, but if problems arise due to this change,
//     it can always be easily changed back.  It has been used a fair
//     amount before checking in and no problems were found. 
//
//  Modified Files:
//  	base/inc/BrBase_LinkDef.h base/inc/BrDataTable.h
//  	base/inc/BrDetectorVolume.h base/inc/BrMagnetVolume.h
//  	base/inc/LinkDefBratBaseINC.h base/src/BrDataTable.cxx
//  	base/src/BrDetectorVolume.cxx base/src/BrEventNode.cxx
//  	base/src/BrMagnetVolume.cxx base/src/BrTableManager.cxx
//  	base/src/Makefile bb/inc/BrDetectorParamsBB.h
//  	bb/src/BrDetectorParamsBB.cxx db/inc/BrParameterDbManager.h
//  	db/src/BrParameterDbManager.cxx dc/inc/BrDetectorParamsDC.h
//  	dc/src/BrDetectorDC.cxx dc/src/BrDetectorParamsDC.cxx
//  	dc/src/BrDigitizeDC.cxx dc/src/BrLocalTrackDC.cxx
//  	geometry/inc/BrPlane3D.h geometry/src/BrPlane3D.cxx
//  	params/DetectorParameters.txt tof/inc/BrDetectorParamsTof.h
//  	tof/src/BrDetectorParamsTof.cxx tof/src/BrGeneratePid.cxx
//  	tpc/inc/BrDetectorParamsTPC.h tpc/src/BrDetectorParamsTPC.cxx
//  	tpc/src/BrDetectorTPC.cxx tpc/src/BrDigitizeTPC.cxx
//  	tpc/src/BrLocalTrackTPC.cxx track/inc/BrDetectorTrack.h
//  	track/inc/BrFSTrackingModule.h
//  	track/inc/BrSpectrometerTracks.h track/src/BrDetectorTrack.cxx
//  	track/src/BrFSTrackingModule.cxx
//  	track/src/BrSpectrometerTracks.cxx
//
// Revision 1.5  1998/08/26 17:10:47  hagel
// Added Documentation for HTML facility
//
// Revision 1.4  1998/04/06 21:11:50  videbaek
// Clean up and additions for Win95
//
// Revision 1.3  1998/03/09 20:53:50  videbaek
// Ensure that pointers are non-NULL before deleting
//
// Revision 1.2  1998/03/06 22:09:58  videbaek
// Working update
//
// Revision 1.1.1.1  1998/03/04 21:32:48  brahmlib
// Brat base
//
//

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